Title: [210624] trunk/Source/WebKit2
- Revision
- 210624
- Author
- beid...@apple.com
- Date
- 2017-01-11 22:16:42 -0800 (Wed, 11 Jan 2017)
Log Message
Add IconLoadingDelegate functionality to WKView.
https://bugs.webkit.org/show_bug.cgi?id=166951
Reviewed by Tim Horton.
* UIProcess/API/mac/WKView.mm:
(-[WKView dealloc]):
(-[WKView maybeInstallIconLoadingClient]): If the subclass implements the delegate method, install the
icon loading client. Otherwise, maintain the normal IconDatabase loading behavior.
(-[WKView initWithFrame:processPool:configuration:webView:]):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (210623 => 210624)
--- trunk/Source/WebKit2/ChangeLog 2017-01-12 05:59:16 UTC (rev 210623)
+++ trunk/Source/WebKit2/ChangeLog 2017-01-12 06:16:42 UTC (rev 210624)
@@ -1,3 +1,16 @@
+2017-01-11 Brady Eidson <beid...@apple.com>
+
+ Add IconLoadingDelegate functionality to WKView.
+ https://bugs.webkit.org/show_bug.cgi?id=166951
+
+ Reviewed by Tim Horton.
+
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView dealloc]):
+ (-[WKView maybeInstallIconLoadingClient]): If the subclass implements the delegate method, install the
+ icon loading client. Otherwise, maintain the normal IconDatabase loading behavior.
+ (-[WKView initWithFrame:processPool:configuration:webView:]):
+
2017-01-11 Brent Fulgham <bfulg...@apple.com>
[WK2][Cocoa] Avoid null dereference in FullScreen code.
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (210623 => 210624)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2017-01-12 05:59:16 UTC (rev 210623)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2017-01-12 06:16:42 UTC (rev 210624)
@@ -29,8 +29,10 @@
#if PLATFORM(MAC)
#import "APIHitTestResult.h"
+#import "APIIconLoadingClient.h"
#import "APIPageConfiguration.h"
#import "WKBrowsingContextGroupPrivate.h"
+#import "WKNSData.h"
#import "WKProcessGroupPrivate.h"
#import "WebBackForwardListItem.h"
#import "WebKit2Initialize.h"
@@ -38,6 +40,8 @@
#import "WebPreferencesKeys.h"
#import "WebProcessPool.h"
#import "WebViewImpl.h"
+#import "_WKLinkIconParametersInternal.h"
+#import <wtf/BlockPtr.h>
using namespace WebKit;
using namespace WebCore;
@@ -78,6 +82,7 @@
- (void)dealloc
{
+ _data->_impl->page().setIconLoadingClient(nullptr);
_data->_impl = nullptr;
[_data release];
@@ -848,6 +853,48 @@
return _data->_impl->namesOfPromisedFilesDroppedAtDestination(dropDestination);
}
+- (void)maybeInstallIconLoadingClient
+{
+#if WK_API_ENABLED
+ class IconLoadingClient : public API::IconLoadingClient {
+ public:
+ explicit IconLoadingClient(WKView *wkView)
+ : m_wkView(wkView)
+ {
+ }
+
+ static SEL delegateSelector()
+ {
+ return sel_registerName("_shouldLoadIconWithParameters:completionHandler:");
+ }
+
+ private:
+ typedef void (^IconLoadCompletionHandler)(NSData*);
+
+ void getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, Function<void (std::function<void (API::Data*, WebKit::CallbackBase::Error)>)>&& completionHandler) override {
+ RetainPtr<_WKLinkIconParameters> parameters = adoptNS([[_WKLinkIconParameters alloc] _initWithLinkIcon:linkIcon]);
+
+ [m_wkView performSelector:delegateSelector() withObject:parameters.get() withObject:^void (IconLoadCompletionHandler loadCompletionHandler) {
+ if (loadCompletionHandler) {
+ completionHandler([loadCompletionHandler = BlockPtr<void (NSData *)>(loadCompletionHandler)](API::Data* data, WebKit::CallbackBase::Error error) {
+ if (error != CallbackBase::Error::None || !data)
+ loadCompletionHandler(nil);
+ else
+ loadCompletionHandler(wrapper(*data));
+ });
+ } else
+ completionHandler(nullptr);
+ }];
+ }
+
+ WKView *m_wkView;
+ };
+
+ if ([self respondsToSelector:IconLoadingClient::delegateSelector()])
+ _data->_impl->page().setIconLoadingClient(std::make_unique<IconLoadingClient>(self));
+#endif // WK_API_ENABLED
+}
+
- (instancetype)initWithFrame:(NSRect)frame processPool:(WebProcessPool&)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView
{
self = [super initWithFrame:frame];
@@ -859,6 +906,8 @@
_data = [[WKViewData alloc] init];
_data->_impl = std::make_unique<WebViewImpl>(self, webView, processPool, WTFMove(configuration));
+ [self maybeInstallIconLoadingClient];
+
return self;
}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes