Add WKUIDelegatePrivate equivalent of WKPageUIClient's unavailablePluginButtonClicked
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Sep 2017 17:36:52 +0000 (17:36 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Sep 2017 17:36:52 +0000 (17:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176274
<rdar://problem/29270035>

Reviewed by Darin Adler.

Source/WebKit:

* UIProcess/API/APIUIClient.h:
(API::UIClient::unavailablePluginButtonClicked):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient):
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _setPluginsEnabled:]):
(-[WKPreferences _pluginsEnabled]):
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::toWKPluginUnavailabilityReason):
(WebKit::UIDelegate::UIClient::unavailablePluginButtonClicked):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::unavailablePluginButtonClicked):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(-[PluginDelegate _webView:unavailablePluginButtonClickedWithReason:pluginInfo:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221621 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIUIClient.h
Source/WebKit/UIProcess/API/C/WKPage.cpp
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

index f18273b..0da52c1 100644 (file)
@@ -1,3 +1,28 @@
+2017-09-05  Alex Christensen  <achristensen@webkit.org>
+
+        Add WKUIDelegatePrivate equivalent of WKPageUIClient's unavailablePluginButtonClicked
+        https://bugs.webkit.org/show_bug.cgi?id=176274
+        <rdar://problem/29270035>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::unavailablePluginButtonClicked):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient):
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences _setPluginsEnabled:]):
+        (-[WKPreferences _pluginsEnabled]):
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::toWKPluginUnavailabilityReason):
+        (WebKit::UIDelegate::UIClient::unavailablePluginButtonClicked):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::unavailablePluginButtonClicked):
+
 2017-09-04  Alex Christensen  <achristensen@webkit.org>
 
         Allow classes to have modern and legacy decoders to aid transition
index 1b8b339..13e5c48 100644 (file)
@@ -93,7 +93,7 @@ public:
     virtual void setStatusText(WebKit::WebPageProxy*, const WTF::String&) { }
     virtual void mouseDidMoveOverElement(WebKit::WebPageProxy*, const WebKit::WebHitTestResultData&, WebKit::WebEvent::Modifiers, Object*) { }
 #if ENABLE(NETSCAPE_PLUGIN_API)
-    virtual void unavailablePluginButtonClicked(WebKit::WebPageProxy*, WKPluginUnavailabilityReason, Dictionary*) { }
+    virtual void unavailablePluginButtonClicked(WebKit::WebPageProxy&, WKPluginUnavailabilityReason, Dictionary&) { }
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 
     virtual void didNotHandleKeyEvent(WebKit::WebPageProxy*, const WebKit::NativeWebKeyboardEvent&) { }
index efbe246..89d85b5 100644 (file)
@@ -1788,32 +1788,32 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient
         }
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
-        void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) final
+        void unavailablePluginButtonClicked(WebPageProxy& page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary& pluginInformation) final
         {
             if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
                 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
                     m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
-                        toAPI(page),
-                        toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
-                        toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
-                        toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
+                        toAPI(&page),
+                        toAPI(pluginInformation.get<API::String>(pluginInformationMIMETypeKey())),
+                        toAPI(pluginInformation.get<API::String>(pluginInformationPluginURLKey())),
+                        toAPI(pluginInformation.get<API::String>(pluginInformationPluginspageAttributeURLKey())),
                         m_client.base.clientInfo);
             }
 
             if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
                 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
-                    toAPI(page),
+                    toAPI(&page),
                     pluginUnavailabilityReason,
-                    toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
-                    toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
-                    toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
+                    toAPI(pluginInformation.get<API::String>(pluginInformationMIMETypeKey())),
+                    toAPI(pluginInformation.get<API::String>(pluginInformationPluginURLKey())),
+                    toAPI(pluginInformation.get<API::String>(pluginInformationPluginspageAttributeURLKey())),
                     m_client.base.clientInfo);
 
             if (m_client.unavailablePluginButtonClicked)
                 m_client.unavailablePluginButtonClicked(
-                    toAPI(page),
+                    toAPI(&page),
                     pluginUnavailabilityReason,
-                    toAPI(pluginInformation),
+                    toAPI(&pluginInformation),
                     m_client.base.clientInfo);
         }
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
index 36da8d9..aa87128 100644 (file)
@@ -637,6 +637,16 @@ static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPo
     _preferences->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
 }
 
+- (void)_setPlugInsEnabled:(BOOL)enabled
+{
+    _preferences->setPluginsEnabled(enabled);
+}
+
+- (BOOL)_plugInsEnabled
+{
+    return _preferences->pluginsEnabled();
+}
+
 - (BOOL)_javaScriptCanAccessClipboard
 {
     return _preferences->javaScriptCanAccessClipboard();
index b41bbda..2e4c78d 100644 (file)
@@ -117,6 +117,10 @@ typedef NS_OPTIONS(NSUInteger, _WKJavaScriptRuntimeFlags) {
 - (BOOL)_isEnabledForFeature:(_WKExperimentalFeature *)feature WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 - (void)_setEnabled:(BOOL)value forFeature:(_WKExperimentalFeature *)feature WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 
+#if !TARGET_OS_IPHONE
+@property (nonatomic, setter=_setPlugInsEnabled:) BOOL _plugInsEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+#endif
+
 @end
 
 #endif
index b762cd2..3709d06 100644 (file)
@@ -64,6 +64,12 @@ typedef NS_ENUM(NSInteger, _WKResourceLimit) {
     _WKResourceLimitCPU,
 } WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 
+typedef NS_ENUM(NSInteger, _WKPlugInUnavailabilityReason) {
+    _WKPlugInUnavailabilityReasonPluginMissing,
+    _WKPlugInUnavailabilityReasonPluginCrashed,
+    _WKPlugInUnavailabilityReasonInsecurePluginVersion
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
 typedef NS_OPTIONS(NSInteger, _WKAutoplayEventFlags) {
     _WKAutoplayEventFlagsNone = 0,
     _WKAutoplayEventFlagsHasAudio = 1 << 0,
@@ -153,6 +159,7 @@ struct UIEdgeInsets;
 - (void)_webView:(WKWebView *)webView getToolbarsAreVisibleWithCompletionHandler:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView didExceedBackgroundResourceLimitWhileInForeground:(_WKResourceLimit)limit WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_webView:(WKWebView *)webView unavailablePlugInButtonClickedWithReason:(_WKPlugInUnavailabilityReason)reason plugInInfo:(NSDictionary *)plugInInfo;
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
 #endif
index 573b8d8..dce00b2 100644 (file)
@@ -102,6 +102,7 @@ private:
         void unfocus(WebPageProxy*) final;
         void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
         void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
+        void unavailablePluginButtonClicked(WebKit::WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
         void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
         void toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&&) final;
         bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
@@ -152,6 +153,7 @@ private:
         bool webViewTakeFocus : 1;
         bool webViewDidNotHandleWheelEvent : 1;
         bool webViewHandleAutoplayEventWithFlags : 1;
+        bool webViewUnavailablePlugInButtonClicked : 1;
         bool webViewDidClickAutoFillButtonWithUserInfo : 1;
         bool webViewGetToolbarsAreVisibleWithCompletionHandler : 1;
         bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
index 3df1419..340bde2 100644 (file)
@@ -36,6 +36,7 @@
 #import "UserMediaPermissionRequestProxy.h"
 #import "WKFrameInfoInternal.h"
 #import "WKNSData.h"
+#import "WKNSDictionary.h"
 #import "WKNavigationActionInternal.h"
 #import "WKOpenPanelParametersInternal.h"
 #import "WKSecurityOriginInternal.h"
@@ -108,6 +109,7 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
     m_delegateMethods.webViewGetToolbarsAreVisibleWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:getToolbarsAreVisibleWithCompletionHandler:)];
     m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
+    m_delegateMethods.webViewUnavailablePlugInButtonClicked = [delegate respondsToSelector:@selector(_webView:unavailablePlugInButtonClickedWithReason:plugInInfo:)];
     m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
     m_delegateMethods.webViewDidClickAutoFillButtonWithUserInfo = [delegate respondsToSelector:@selector(_webView:didClickAutoFillButtonWithUserInfo:)];
     m_delegateMethods.webViewDidExceedBackgroundResourceLimitWhileInForeground = [delegate respondsToSelector:@selector(_webView:didExceedBackgroundResourceLimitWhileInForeground:)];
@@ -430,6 +432,32 @@ void UIDelegate::UIClient::unfocus(WebKit::WebPageProxy*)
     [(id <WKUIDelegatePrivate>)delegate _unfocusWebView:m_uiDelegate.m_webView];
 }
 
+static _WKPlugInUnavailabilityReason toWKPlugInUnavailabilityReason(WKPluginUnavailabilityReason reason)
+{
+    switch (reason) {
+    case kWKPluginUnavailabilityReasonPluginMissing:
+        return _WKPlugInUnavailabilityReasonPluginMissing;
+    case kWKPluginUnavailabilityReasonPluginCrashed:
+        return _WKPlugInUnavailabilityReasonPluginCrashed;
+    case kWKPluginUnavailabilityReasonInsecurePluginVersion:
+        return _WKPlugInUnavailabilityReasonInsecurePluginVersion;
+    }
+    ASSERT_NOT_REACHED();
+    return _WKPlugInUnavailabilityReasonPluginMissing;
+}
+    
+void UIDelegate::UIClient::unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason reason, API::Dictionary& plugInInfo)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewUnavailablePlugInButtonClicked)
+        return;
+    
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return;
+
+    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView unavailablePlugInButtonClickedWithReason:toWKPlugInUnavailabilityReason(reason) plugInInfo:wrapper(plugInInfo)];
+}
+    
 static _WKResourceLimit toWKResourceLimit(WKResourceLimit limit)
 {
     switch (limit) {
index 2180250..d2dd527 100644 (file)
@@ -4015,10 +4015,9 @@ void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailab
     MESSAGE_CHECK_URL(frameURLString);
     MESSAGE_CHECK_URL(pageURLString);
 
-    RefPtr<API::Dictionary> pluginInformation;
     String newMimeType = mimeType;
     PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL(URL(), pluginURLString));
-    pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, pluginspageAttributeURLString, pluginURLString);
+    auto pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, pluginspageAttributeURLString, pluginURLString);
 
     WKPluginUnavailabilityReason pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginMissing;
     switch (static_cast<RenderEmbeddedObject::PluginUnavailabilityReason>(opaquePluginUnavailabilityReason)) {
@@ -4035,7 +4034,7 @@ void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailab
         ASSERT_NOT_REACHED();
     }
 
-    m_uiClient->unavailablePluginButtonClicked(this, pluginUnavailabilityReason, pluginInformation.get());
+    m_uiClient->unavailablePluginButtonClicked(*this, pluginUnavailabilityReason, pluginInformation.get());
 }
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 
index ec4dfee..20bc491 100644 (file)
@@ -1,3 +1,15 @@
+2017-09-05  Alex Christensen  <achristensen@webkit.org>
+
+        Add WKUIDelegatePrivate equivalent of WKPageUIClient's unavailablePluginButtonClicked
+        https://bugs.webkit.org/show_bug.cgi?id=176274
+        <rdar://problem/29270035>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (-[PluginDelegate _webView:unavailablePluginButtonClickedWithReason:pluginInfo:]):
+        (TEST):
+
 2017-09-05  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Wrong use of PLUGIN_ARCHITECTURE(X11) in several places
index 1928031..a68b54b 100644 (file)
@@ -30,7 +30,9 @@
 #import "TestWKWebView.h"
 #import "Utilities.h"
 #import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKContextPrivateMac.h>
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKRetainPtr.h>
 #import <WebKit/WKUIDelegatePrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
@@ -122,6 +124,33 @@ TEST(WebKit, ShowWebView)
     ASSERT_EQ(webViewFromDelegateCallback, createdWebView);
 }
 
+
+@interface PlugInDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation PlugInDelegate
+
+- (void)_webView:(WKWebView *)webView unavailablePlugInButtonClickedWithReason:(_WKPlugInUnavailabilityReason)reason plugInInfo:(NSDictionary *)plugInInfo
+{
+    ASSERT_EQ(_WKPlugInUnavailabilityReasonPluginMissing, reason);
+    ASSERT_TRUE([@"application/x-shockwave-flash" isEqualToString:[plugInInfo objectForKey:@"PluginInformationMIMEType"]]);
+    done = true;
+}
+
+@end
+
+TEST(WebKit, UnavailablePlugIn)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration preferences] _setPlugInsEnabled:YES];
+    auto delegate = adoptNS([[PlugInDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView setUIDelegate:delegate.get()];
+    [webView synchronouslyLoadHTMLString:@"<object type='application/x-shockwave-flash'/>"];
+    [webView sendClicksAtPoint:NSMakePoint(210, 600 - 80) numberOfClicks:1];
+    TestWebKitAPI::Util::run(&done);
+}
+
 bool firstToolbarDone;
 
 @interface ToolbarDelegate : NSObject <WKUIDelegatePrivate>