Title: [271424] trunk
Revision
271424
Author
[email protected]
Date
2021-01-12 16:19:38 -0800 (Tue, 12 Jan 2021)

Log Message

[Cocoa] Web Inspector: move browser domain activation methods back to WKWebView and UIDelegate
https://bugs.webkit.org/show_bug.cgi?id=220480

Reviewed by Devin Rousso.

Source/WebKit:

Having browser domain activation methods on WKInspectorDelegate means that
the browser domain will not work with remote inspection of WKWebViews on
macOS. Move these methods back to UIDelegate/WKWebView so that it is possible
to remote inspect Safari Technology Preview with another Safari while still
benefiting from the browser domain being turned on.

Covered by existing API tests.

* UIProcess/API/APIInspectorClient.h:
(API::InspectorClient::browserDomainEnabled): Deleted.
(API::InspectorClient::browserDomainDisabled): Deleted.
* UIProcess/API/APIUIClient.h:
(API::UIClient::didEnableInspectorBrowserDomain): Moved.
(API::UIClient::didDisableInspectorBrowserDomain): Moved.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didEnableBrowserExtensions:]): Moved.
(-[WKWebView _didDisableBrowserExtensions:]): Moved.
Moved from WKInspector.mm. Rather than accessing the browser agent
directly from ObjC code, use the page's WebPageInspectorController.

* UIProcess/API/Cocoa/_WKInspectorDelegate.h:
* UIProcess/API/Cocoa/_WKInspectorPrivate.h:
* UIProcess/API/Cocoa/_WKInspector.mm:
(-[_WKInspector _browserExtensionsEnabled:]): Deleted.
(-[_WKInspector _browserExtensionsDisabled:]): Deleted.

* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::didEnableInspectorBrowserDomain):
(WebKit::UIDelegate::UIClient::didDisableInspectorBrowserDomain):
* UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp:
(WebKit::InspectorBrowserAgent::enable):
(WebKit::InspectorBrowserAgent::disable):
* UIProcess/Inspector/Cocoa/InspectorDelegate.h:
* UIProcess/Inspector/Cocoa/InspectorDelegate.mm:
(WebKit::InspectorDelegate::setDelegate):
(WebKit::InspectorDelegate::InspectorClient::~InspectorClient):
(WebKit::InspectorDelegate::InspectorClient::browserDomainEnabled): Deleted.
(WebKit::InspectorDelegate::InspectorClient::browserDomainDisabled): Deleted.
* UIProcess/Inspector/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::browserExtensionsEnabled): Deleted.
(WebKit::WebInspectorProxy::browserExtensionsDisabled): Deleted.
* UIProcess/Inspector/WebInspectorProxy.h:

* UIProcess/Inspector/WebPageInspectorController.h:
* UIProcess/Inspector/WebPageInspectorController.cpp:
(WebKit::WebPageInspectorController::WebPageInspectorController):
(WebKit::WebPageInspectorController::init):
(WebKit::WebPageInspectorController::connectFrontend):
(WebKit::WebPageInspectorController::disconnectFrontend):
(WebKit::WebPageInspectorController::disconnectAllFrontends):
(WebKit::WebPageInspectorController::setIndicating):
(WebKit::WebPageInspectorController::createInspectorTarget):
(WebKit::WebPageInspectorController::webPageAgentContext):
(WebKit::WebPageInspectorController::setEnabledBrowserAgent): Added.
(WebKit::WebPageInspectorController::browserExtensionsEnabled): Added.
(WebKit::WebPageInspectorController::browserExtensionsDisabled): Added.
Drive-by: rename m_page to m_inspectedPage to emphasize that this
class exists as part of Web Inspector's backend, not its frontend.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm:
(-[UIDelegate _webViewDidEnableInspectorBrowserDomain:]):
(-[UIDelegate _webViewDidDisableInspectorBrowserDomain:]):
(-[InspectorDelegate inspectorDidEnableBrowserDomain:]): Deleted.
(-[InspectorDelegate inspectorDidDisableBrowserDomain:]): Deleted.
Adapt to new location for delegate methods.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (271423 => 271424)


--- trunk/Source/WebKit/ChangeLog	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/ChangeLog	2021-01-13 00:19:38 UTC (rev 271424)
@@ -1,3 +1,74 @@
+2021-01-12  BJ Burg  <[email protected]>
+
+        [Cocoa] Web Inspector: move browser domain activation methods back to WKWebView and UIDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=220480
+
+        Reviewed by Devin Rousso.
+
+        Having browser domain activation methods on WKInspectorDelegate means that
+        the browser domain will not work with remote inspection of WKWebViews on
+        macOS. Move these methods back to UIDelegate/WKWebView so that it is possible
+        to remote inspect Safari Technology Preview with another Safari while still
+        benefiting from the browser domain being turned on.
+
+        Covered by existing API tests.
+
+        * UIProcess/API/APIInspectorClient.h:
+        (API::InspectorClient::browserDomainEnabled): Deleted.
+        (API::InspectorClient::browserDomainDisabled): Deleted.
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::didEnableInspectorBrowserDomain): Moved.
+        (API::UIClient::didDisableInspectorBrowserDomain): Moved.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _didEnableBrowserExtensions:]): Moved.
+        (-[WKWebView _didDisableBrowserExtensions:]): Moved.
+        Moved from WKInspector.mm. Rather than accessing the browser agent
+        directly from ObjC code, use the page's WebPageInspectorController.
+
+        * UIProcess/API/Cocoa/_WKInspectorDelegate.h:
+        * UIProcess/API/Cocoa/_WKInspectorPrivate.h:
+        * UIProcess/API/Cocoa/_WKInspector.mm:
+        (-[_WKInspector _browserExtensionsEnabled:]): Deleted.
+        (-[_WKInspector _browserExtensionsDisabled:]): Deleted.
+
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::didEnableInspectorBrowserDomain):
+        (WebKit::UIDelegate::UIClient::didDisableInspectorBrowserDomain):
+        * UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp:
+        (WebKit::InspectorBrowserAgent::enable):
+        (WebKit::InspectorBrowserAgent::disable):
+        * UIProcess/Inspector/Cocoa/InspectorDelegate.h:
+        * UIProcess/Inspector/Cocoa/InspectorDelegate.mm:
+        (WebKit::InspectorDelegate::setDelegate):
+        (WebKit::InspectorDelegate::InspectorClient::~InspectorClient):
+        (WebKit::InspectorDelegate::InspectorClient::browserDomainEnabled): Deleted.
+        (WebKit::InspectorDelegate::InspectorClient::browserDomainDisabled): Deleted.
+        * UIProcess/Inspector/WebInspectorProxy.cpp:
+        (WebKit::WebInspectorProxy::browserExtensionsEnabled): Deleted.
+        (WebKit::WebInspectorProxy::browserExtensionsDisabled): Deleted.
+        * UIProcess/Inspector/WebInspectorProxy.h:
+
+        * UIProcess/Inspector/WebPageInspectorController.h:
+        * UIProcess/Inspector/WebPageInspectorController.cpp:
+        (WebKit::WebPageInspectorController::WebPageInspectorController):
+        (WebKit::WebPageInspectorController::init):
+        (WebKit::WebPageInspectorController::connectFrontend):
+        (WebKit::WebPageInspectorController::disconnectFrontend):
+        (WebKit::WebPageInspectorController::disconnectAllFrontends):
+        (WebKit::WebPageInspectorController::setIndicating):
+        (WebKit::WebPageInspectorController::createInspectorTarget):
+        (WebKit::WebPageInspectorController::webPageAgentContext):
+        (WebKit::WebPageInspectorController::setEnabledBrowserAgent): Added.
+        (WebKit::WebPageInspectorController::browserExtensionsEnabled): Added. 
+        (WebKit::WebPageInspectorController::browserExtensionsDisabled): Added.
+        Drive-by: rename m_page to m_inspectedPage to emphasize that this
+        class exists as part of Web Inspector's backend, not its frontend.
+
 2021-01-12  Brent Fulgham  <[email protected]>
 
         [macOS] GPU Process unable to play MSE content due to missing sandbox rules 

Modified: trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -38,8 +38,6 @@
 public:
     virtual ~InspectorClient() = default;
 
-    virtual void browserDomainEnabled(WebKit::WebInspectorProxy&) { }
-    virtual void browserDomainDisabled(WebKit::WebInspectorProxy&) { }
     virtual void openURLExternally(WebKit::WebInspectorProxy&, const WTF::String& url) { }
 };
 

Modified: trunk/Source/WebKit/UIProcess/API/APIUIClient.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/APIUIClient.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/APIUIClient.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -201,6 +201,8 @@
     {
         return API::InspectorConfiguration::create();
     }
+    virtual void didEnableInspectorBrowserDomain(WebKit::WebPageProxy&) { }
+    virtual void didDisableInspectorBrowserDomain(WebKit::WebPageProxy&) { }
 
     virtual void decidePolicyForSpeechRecognitionPermissionRequest(WebKit::WebPageProxy& page, API::SecurityOrigin& origin, CompletionHandler<void(bool)>&& completionHandler) { page.requestSpeechRecognitionPermissionByDefaultAction(origin.securityOrigin(), WTFMove(completionHandler)); }
 };

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -154,6 +154,9 @@
 
 - (void)_webView:(WKWebView *)webView requestSpeechRecognitionPermissionForOrigin:(WKSecurityOrigin *)origin decisionHandler:(void (^)(BOOL authorized))decisionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+- (void)_webViewDidEnableInspectorBrowserDomain:(WKWebView *)webView WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_webViewDidDisableInspectorBrowserDomain:(WKWebView *)webView WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 #if TARGET_OS_IPHONE
 
 - (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_API_AVAILABLE(ios(9.0));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-01-13 00:19:38 UTC (rev 271424)
@@ -90,6 +90,7 @@
 #import "WebCertificateInfo.h"
 #import "WebFullScreenManagerProxy.h"
 #import "WebPageGroup.h"
+#import "WebPageInspectorController.h"
 #import "WebPageProxy.h"
 #import "WebPreferences.h"
 #import "WebProcessPool.h"
@@ -1649,6 +1650,25 @@
     return nil;
 }
 
+- (void)_didEnableBrowserExtensions:(NSDictionary<NSString *, NSString *> *)extensionIDToNameMap
+{
+    HashMap<String, String> transformed;
+    transformed.reserveInitialCapacity(extensionIDToNameMap.count);
+    [extensionIDToNameMap enumerateKeysAndObjectsUsingBlock:[&](NSString *extensionID, NSString *extensionName, BOOL *) {
+        transformed.set(extensionID, extensionName);
+    }];
+    _page->inspectorController().browserExtensionsEnabled(WTFMove(transformed));
+}
+
+- (void)_didDisableBrowserExtensions:(NSSet<NSString *> *)extensionIDs
+{
+    HashSet<String> transformed;
+    transformed.reserveInitialCapacity(extensionIDs.count);
+    for (NSString *extensionID in extensionIDs)
+        transformed.addVoid(extensionID);
+    _page->inspectorController().browserExtensionsDisabled(WTFMove(transformed));
+}
+
 - (_WKFrameHandle *)_mainFrame
 {
     if (auto* frame = _page->mainFrame())

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -359,6 +359,9 @@
 
 @property (nonatomic, setter=_setCanUseCredentialStorage:) BOOL _canUseCredentialStorage WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+- (void)_didEnableBrowserExtensions:(NSDictionary<NSString *, NSString *> *)extensionIDToNameMap WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_didDisableBrowserExtensions:(NSSet<NSString *> *)extensionIDs WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #if TARGET_OS_IPHONE

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm	2021-01-13 00:19:38 UTC (rev 271424)
@@ -170,25 +170,6 @@
     _inspector->setDiagnosticLoggingAvailable(!!delegate);
 }
 
-- (void)_browserExtensionsEnabled:(NSDictionary<NSString *, NSString *> *)extensionIDToNameMap
-{
-    HashMap<String, String> transformed;
-    transformed.reserveInitialCapacity(extensionIDToNameMap.count);
-    [extensionIDToNameMap enumerateKeysAndObjectsUsingBlock:[&](NSString *extensionID, NSString *extensionName, BOOL *) {
-        transformed.set(extensionID, extensionName);
-    }];
-    _inspector->browserExtensionsEnabled(WTFMove(transformed));
-}
-
-- (void)_browserExtensionsDisabled:(NSSet<NSString *> *)extensionIDs
-{
-    HashSet<String> transformed;
-    transformed.reserveInitialCapacity(extensionIDs.count);
-    for (NSString *extensionID in extensionIDs)
-        transformed.addVoid(extensionID);
-    _inspector->browserExtensionsDisabled(WTFMove(transformed));
-}
-
 // MARK: _WKInspectorInternal methods
 
 - (API::Object&)_apiObject

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -31,16 +31,6 @@
 @protocol _WKInspectorDelegate <NSObject>
 @optional
 
-/*! @abstract Called when the Browser domain is enabled for the associated _WKInspector.
-    @param inspector the associated _WKInspector for which the Browser domain has been enabled.
- */
-- (void)inspectorDidEnableBrowserDomain:(_WKInspector *)inspector;
-
-/*! @abstract Called when the  Browser domain is disabled for the associated _WKInspector.
-    @param inspector the associated _WKInspector for which the Browser domain has been disabled.
- */
-- (void)inspectorDidDisableBrowserDomain:(_WKInspector *)inspector;
-
 /*! @abstract Called when the _WKInspector requests to show a resource externally. This
     is used to display documentation pages and to show external URLs that are linkified.
     @param inspector the associated inspector for which an external navigation should be triggered.

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivate.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivate.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivate.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -31,8 +31,4 @@
 
 @property (nonatomic, weak, setter=_setDiagnosticLoggingDelegate:) id<_WKDiagnosticLoggingDelegate> _diagnosticLoggingDelegate;
 
-// Browser
-- (void)_browserExtensionsEnabled:(NSDictionary<NSString *, NSString *> *)extensionIDToName;
-- (void)_browserExtensionsDisabled:(NSSet<NSString *> *)extensionIDs;
-
 @end

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -163,6 +163,8 @@
         void runWebAuthenticationPanel(WebPageProxy&, API::WebAuthenticationPanel&, WebFrameProxy&, FrameInfoData&&, CompletionHandler<void(WebAuthenticationPanelResult)>&&) final;
 #endif
         void decidePolicyForSpeechRecognitionPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool)>&&) final;
+        void didEnableInspectorBrowserDomain(WebPageProxy&) final;
+        void didDisableInspectorBrowserDomain(WebPageProxy&) final;
 
         WeakPtr<UIDelegate> m_uiDelegate;
     };
@@ -250,6 +252,8 @@
 #if ENABLE(WEB_AUTHN)
         bool webViewRunWebAuthenticationPanelInitiatedByFrameCompletionHandler : 1;
 #endif
+        bool webViewDidEnableInspectorBrowserDomain : 1;
+        bool webViewDidDisableInspectorBrowserDomain : 1;
     } m_delegateMethods;
 };
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2021-01-13 00:19:38 UTC (rev 271424)
@@ -183,6 +183,9 @@
 #if ENABLE(WEB_AUTHN)
     m_delegateMethods.webViewRunWebAuthenticationPanelInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runWebAuthenticationPanel:initiatedByFrame:completionHandler:)];
 #endif
+    
+    m_delegateMethods.webViewDidEnableInspectorBrowserDomain = [delegate respondsToSelector:@selector(_webViewDidEnableInspectorBrowserDomain:)];
+    m_delegateMethods.webViewDidDisableInspectorBrowserDomain = [delegate respondsToSelector:@selector(_webViewDidDisableInspectorBrowserDomain:)];
 }
 
 #if ENABLE(CONTEXT_MENUS)
@@ -1550,4 +1553,34 @@
     }).get()];
 }
 
+void UIDelegate::UIClient::didEnableInspectorBrowserDomain(WebPageProxy&)
+{
+    if (!m_uiDelegate)
+        return;
+
+    if (!m_uiDelegate->m_delegateMethods.webViewDidEnableInspectorBrowserDomain)
+        return;
+
+    auto delegate = (id <WKUIDelegatePrivate>)m_uiDelegate->m_delegate.get();
+    if (!delegate)
+        return;
+
+    [delegate _webViewDidEnableInspectorBrowserDomain:m_uiDelegate->m_webView.get().get()];
+}
+
+void UIDelegate::UIClient::didDisableInspectorBrowserDomain(WebPageProxy&)
+{
+    if (!m_uiDelegate)
+        return;
+
+    if (!m_uiDelegate->m_delegateMethods.webViewDidDisableInspectorBrowserDomain)
+        return;
+
+    auto delegate = (id <WKUIDelegatePrivate>)m_uiDelegate->m_delegate.get();
+    if (!delegate)
+        return;
+
+    [delegate _webViewDidDisableInspectorBrowserDomain:m_uiDelegate->m_webView.get().get()];
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp	2021-01-13 00:19:38 UTC (rev 271424)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "InspectorBrowserAgent.h"
 
-#include "APIInspectorClient.h"
+#include "APIUIClient.h"
 #include "WebInspectorProxy.h"
 #include "WebPageInspectorController.h"
 #include "WebPageProxy.h"
@@ -71,9 +71,6 @@
 
     m_inspectedPage.inspectorController().setEnabledBrowserAgent(this);
 
-    if (auto* inspector = m_inspectedPage.inspector())
-        inspector->inspectorClient().browserDomainEnabled(*inspector);
-
     return { };
 }
 
@@ -84,9 +81,6 @@
 
     m_inspectedPage.inspectorController().setEnabledBrowserAgent(nullptr);
 
-    if (auto* inspector = m_inspectedPage.inspector())
-        inspector->inspectorClient().browserDomainDisabled(*inspector);
-
     return { };
 }
 

Modified: trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -35,7 +35,6 @@
 namespace WebKit {
 
 class WebInspectorProxy;
-class WebPageProxy;
 
 class InspectorDelegate {
     WTF_MAKE_FAST_ALLOCATED;
@@ -56,8 +55,6 @@
 
     private:
         // API::InspectorClient
-        void browserDomainEnabled(WebInspectorProxy&);
-        void browserDomainDisabled(WebInspectorProxy&);
         void openURLExternally(WebInspectorProxy&, const String& url);
 
         InspectorDelegate& m_inspectorDelegate;
@@ -67,8 +64,6 @@
     WeakObjCPtr<id <_WKInspectorDelegate>> m_delegate;
 
     struct {
-        bool inspectorDidEnableBrowserDomain : 1;
-        bool inspectorDidDisableBrowserDomain : 1;
         bool inspectorOpenURLExternally : 1;
     } m_delegateMethods;
 };

Modified: trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm	2021-01-13 00:19:38 UTC (rev 271424)
@@ -27,7 +27,6 @@
 #import "InspectorDelegate.h"
 
 #import "WebInspectorProxy.h"
-#import "WebPageProxy.h"
 #import "_WKInspectorDelegate.h"
 #import "_WKInspectorInternal.h"
 
@@ -52,8 +51,6 @@
 {
     m_delegate = delegate;
 
-    m_delegateMethods.inspectorDidEnableBrowserDomain = [delegate respondsToSelector:@selector(inspectorDidEnableBrowserDomain:)];
-    m_delegateMethods.inspectorDidDisableBrowserDomain = [delegate respondsToSelector:@selector(inspectorDidDisableBrowserDomain:)];
     m_delegateMethods.inspectorOpenURLExternally = [delegate respondsToSelector:@selector(inspector:openURLExternally:)];
 }
 
@@ -62,32 +59,10 @@
 {
 }
 
-InspectorDelegate::InspectorClient::~InspectorClient() = default;
-
-void InspectorDelegate::InspectorClient::browserDomainEnabled(WebInspectorProxy&)
+InspectorDelegate::InspectorClient::~InspectorClient()
 {
-    if (!m_inspectorDelegate.m_delegateMethods.inspectorDidEnableBrowserDomain)
-        return;
-
-    auto& delegate = m_inspectorDelegate.m_delegate;
-    if (!delegate)
-        return;
-
-    [delegate inspectorDidEnableBrowserDomain:m_inspectorDelegate.m_inspector.get().get()];
 }
 
-void InspectorDelegate::InspectorClient::browserDomainDisabled(WebInspectorProxy&)
-{
-    if (!m_inspectorDelegate.m_delegateMethods.inspectorDidDisableBrowserDomain)
-        return;
-
-    auto& delegate = m_inspectorDelegate.m_delegate;
-    if (!delegate)
-        return;
-
-    [delegate inspectorDidDisableBrowserDomain:m_inspectorDelegate.m_inspector.get().get()];
-}
-
 void InspectorDelegate::InspectorClient::openURLExternally(WebInspectorProxy&, const String& url)
 {
     if (!m_inspectorDelegate.m_delegateMethods.inspectorOpenURLExternally)

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.cpp (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.cpp	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.cpp	2021-01-13 00:19:38 UTC (rev 271424)
@@ -700,18 +700,6 @@
 #endif
 }
 
-void WebInspectorProxy::browserExtensionsEnabled(HashMap<String, String>&& extensionIDToName)
-{
-    if (auto* browserAgent = m_inspectedPage->inspectorController().enabledBrowserAgent())
-        browserAgent->extensionsEnabled(WTFMove(extensionIDToName));
-}
-
-void WebInspectorProxy::browserExtensionsDisabled(HashSet<String>&& extensionIDs)
-{
-    if (auto* browserAgent = m_inspectedPage->inspectorController().enabledBrowserAgent())
-        browserAgent->extensionsDisabled(WTFMove(extensionIDs));
-}
-
 void WebInspectorProxy::save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs)
 {
     if (!m_inspectedPage->preferences().developerExtrasEnabled())

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -184,10 +184,6 @@
 
     void setDiagnosticLoggingAvailable(bool);
 
-    // Browser
-    void browserExtensionsEnabled(HashMap<String, String>&&);
-    void browserExtensionsDisabled(HashSet<String>&&);
-
     // Provided by platform WebInspectorProxy implementations.
     static String inspectorPageURL();
     static String inspectorTestPageURL();

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp	2021-01-13 00:19:38 UTC (rev 271424)
@@ -1,5 +1,5 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+    /*
+ * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WebPageInspectorController.h"
 
+#include "APIUIClient.h"
 #include "InspectorBrowserAgent.h"
 #include "ProvisionalPageProxy.h"
 #include "WebFrameProxy.h"
@@ -48,10 +49,10 @@
     return WebPageInspectorTarget::toTargetID(provisionalPage.webPageID());
 }
 
-WebPageInspectorController::WebPageInspectorController(WebPageProxy& page)
+WebPageInspectorController::WebPageInspectorController(WebPageProxy& inspectedPage)
     : m_frontendRouter(FrontendRouter::create())
     , m_backendDispatcher(BackendDispatcher::create(m_frontendRouter.copyRef()))
-    , m_page(page)
+    , m_inspectedPage(inspectedPage)
 {
     auto targetAgent = makeUnique<InspectorTargetAgent>(m_frontendRouter.get(), m_backendDispatcher.get());
     m_targetAgent = targetAgent.get();
@@ -60,7 +61,7 @@
 
 void WebPageInspectorController::init()
 {
-    String pageTargetId = WebPageInspectorTarget::toTargetID(m_page.webPageID());
+    String pageTargetId = WebPageInspectorTarget::toTargetID(m_inspectedPage.webPageID());
     createInspectorTarget(pageTargetId, Inspector::InspectorTargetType::Page);
 }
 
@@ -87,11 +88,11 @@
     if (connectingFirstFrontend)
         m_agents.didCreateFrontendAndBackend(&m_frontendRouter.get(), &m_backendDispatcher.get());
 
-    m_page.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
+    m_inspectedPage.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
 
 #if ENABLE(REMOTE_INSPECTOR)
     if (hasLocalFrontend())
-        m_page.remoteInspectorInformationDidChange();
+        m_inspectedPage.remoteInspectorInformationDidChange();
 #endif
 }
 
@@ -103,11 +104,11 @@
     if (disconnectingLastFrontend)
         m_agents.willDestroyFrontendAndBackend(DisconnectReason::InspectorDestroyed);
 
-    m_page.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
+    m_inspectedPage.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
 
 #if ENABLE(REMOTE_INSPECTOR)
     if (disconnectingLastFrontend)
-        m_page.remoteInspectorInformationDidChange();
+        m_inspectedPage.remoteInspectorInformationDidChange();
 #endif
 }
 
@@ -124,10 +125,10 @@
     // Disconnect any remaining remote frontends.
     m_frontendRouter->disconnectAllFrontends();
 
-    m_page.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
+    m_inspectedPage.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
 
 #if ENABLE(REMOTE_INSPECTOR)
-    m_page.remoteInspectorInformationDidChange();
+    m_inspectedPage.remoteInspectorInformationDidChange();
 #endif
 }
 
@@ -140,12 +141,12 @@
 void WebPageInspectorController::setIndicating(bool indicating)
 {
 #if !PLATFORM(IOS_FAMILY)
-    m_page.setIndicating(indicating);
+    m_inspectedPage.setIndicating(indicating);
 #else
     if (indicating)
-        m_page.showInspectorIndication();
+        m_inspectedPage.showInspectorIndication();
     else
-        m_page.hideInspectorIndication();
+        m_inspectedPage.hideInspectorIndication();
 #endif
 }
 #endif
@@ -152,7 +153,7 @@
 
 void WebPageInspectorController::createInspectorTarget(const String& targetId, Inspector::InspectorTargetType type)
 {
-    addTarget(InspectorTargetProxy::create(m_page, targetId, type));
+    addTarget(InspectorTargetProxy::create(m_inspectedPage, targetId, type));
 }
 
 void WebPageInspectorController::destroyInspectorTarget(const String& targetId)
@@ -219,7 +220,7 @@
     return {
         m_frontendRouter.get(),
         m_backendDispatcher.get(),
-        m_page,
+        m_inspectedPage,
     };
 }
 
@@ -241,4 +242,29 @@
     m_targets.set(target->identifier(), WTFMove(target));
 }
 
+void WebPageInspectorController::setEnabledBrowserAgent(InspectorBrowserAgent* agent)
+{
+    if (m_enabledBrowserAgent == agent)
+        return;
+
+    m_enabledBrowserAgent = agent;
+
+    if (m_enabledBrowserAgent)
+        m_inspectedPage.uiClient().didEnableInspectorBrowserDomain(m_inspectedPage);
+    else
+        m_inspectedPage.uiClient().didDisableInspectorBrowserDomain(m_inspectedPage);
+}
+
+void WebPageInspectorController::browserExtensionsEnabled(HashMap<String, String>&& extensionIDToName)
+{
+    if (m_enabledBrowserAgent)
+        m_enabledBrowserAgent->extensionsEnabled(WTFMove(extensionIDToName));
+}
+
+void WebPageInspectorController::browserExtensionsDisabled(HashSet<String>&& extensionIDs)
+{
+    if (m_enabledBrowserAgent)
+        m_enabledBrowserAgent->extensionsDisabled(WTFMove(extensionIDs));
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h (271423 => 271424)


--- trunk/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h	2021-01-13 00:19:38 UTC (rev 271424)
@@ -77,8 +77,11 @@
     void didCommitProvisionalPage(WebCore::PageIdentifier oldWebPageID, WebCore::PageIdentifier newWebPageID);
 
     InspectorBrowserAgent* enabledBrowserAgent() const { return m_enabledBrowserAgent; }
-    void setEnabledBrowserAgent(InspectorBrowserAgent* agent) { m_enabledBrowserAgent = agent; }
+    void setEnabledBrowserAgent(InspectorBrowserAgent*);
 
+    void browserExtensionsEnabled(HashMap<String, String>&&);
+    void browserExtensionsDisabled(HashSet<String>&&);
+
 private:
     WebPageAgentContext webPageAgentContext();
     void createLazyAgents();
@@ -89,7 +92,7 @@
     Ref<Inspector::BackendDispatcher> m_backendDispatcher;
     Inspector::AgentRegistry m_agents;
 
-    WebPageProxy& m_page;
+    WebPageProxy& m_inspectedPage;
 
     Inspector::InspectorTargetAgent* m_targetAgent { nullptr };
     HashMap<String, std::unique_ptr<InspectorTargetProxy>> m_targets;

Modified: trunk/Tools/ChangeLog (271423 => 271424)


--- trunk/Tools/ChangeLog	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Tools/ChangeLog	2021-01-13 00:19:38 UTC (rev 271424)
@@ -1,3 +1,17 @@
+2021-01-12  BJ Burg  <[email protected]>
+
+        [Cocoa] Web Inspector: move browser domain activation methods back to WKWebView and UIDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=220480
+
+        Reviewed by Devin Rousso.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm:
+        (-[UIDelegate _webViewDidEnableInspectorBrowserDomain:]):
+        (-[UIDelegate _webViewDidDisableInspectorBrowserDomain:]):
+        (-[InspectorDelegate inspectorDidEnableBrowserDomain:]): Deleted.
+        (-[InspectorDelegate inspectorDidDisableBrowserDomain:]): Deleted.
+        Adapt to new location for delegate methods.
+
 2021-01-12  Wenson Hsieh  <[email protected]>
 
         REGRESSION (r265044): [macOS] Safari autocorrects text when typing in login field on amazon.com

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm (271423 => 271424)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm	2021-01-13 00:15:53 UTC (rev 271423)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm	2021-01-13 00:19:38 UTC (rev 271424)
@@ -104,16 +104,6 @@
 
 @implementation InspectorDelegate
 
-- (void)inspectorDidEnableBrowserDomain:(_WKInspector *)inspector
-{
-    browserDomainEnabledForInspectorCalled = true;
-}
-
-- (void)inspectorDidDisableBrowserDomain:(_WKInspector *)inspector
-{
-    browserDomainDisabledForInspectorCalled = true;
-}
-
 - (void)inspector:(_WKInspector *)inspector openURLExternally:(NSURL *)url
 {
     EXPECT_STREQ(url.absoluteString.UTF8String, urlToOpen.get().absoluteString.UTF8String);
@@ -156,6 +146,16 @@
         [inspector close];
 }
 
+- (void)_webViewDidEnableInspectorBrowserDomain:(WKWebView *)webView
+{
+    browserDomainEnabledForInspectorCalled = true;
+}
+
+- (void)_webViewDidDisableInspectorBrowserDomain:(WKWebView *)webView
+{
+    browserDomainDisabledForInspectorCalled = true;
+}
+
 @end
 
 TEST(WKInspectorDelegate, InspectorLifecycleCallbacks)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to