Web Inspector: safari app extension isolated worlds and injected files use the extens...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Feb 2020 06:05:13 +0000 (06:05 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Feb 2020 06:05:13 +0000 (06:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206911
<rdar://problem/58026635>

Reviewed by Brian Burg.

Source/JavaScriptCore:

* inspector/protocol/Browser.json: Added.
Add a `Browser` agent that can communicate with the inspected page's containing browser. It
lives in the UIProcess alongside the `Target` agent (meaning there should only be one per
debuggable rather than one per target) and as such is not routed through the `Target` agent.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources.make:

Source/WebCore:

* Modules/webauthn/AuthenticationExtensionsClientOutputs.h:
Drive-by: add missing include.
Source/WebInspectorUI:

* UserInterface/Controllers/BrowserManager.js: Added.
(WI.BrowserManager):
(WI.BrowserManager.prototype.initializeTarget):
(WI.BrowserManager.prototype.enable):
(WI.BrowserManager.prototype.disable):
(WI.BrowserManager.prototype.isExtensionScheme):
(WI.BrowserManager.prototype.extensionNameForId):
(WI.BrowserManager.prototype.extensionNameForURL):
* UserInterface/Protocol/BrowserObserver.js: Added.
(WI.BrowserObserver.prototype.extensionsEnabled):
(WI.BrowserObserver.prototype.extensionsDisabled):
* UserInterface/Protocol/Target.js:
(WI.Target.prototype.get BrowserAgent): Added.
* UserInterface/Base/Main.js:
(WI.loaded):
* UserInterface/Main.html:
* UserInterface/Test/Test.js:
(WI.loaded):
* UserInterface/Test.html:
Add an observer and manager for the `Browser` domain.

* UserInterface/Protocol/MultiplexingBackendTarget.js:
(WI.MultiplexingBackendTarget):
(WI.MultiplexingBackendTarget.prototype.initialize):
* UserInterface/Controllers/TargetManager.js:
(WI.TargetManager.prototype.initializeTarget): Added.
The `Browser` agent lives in the UIProcess alongside the `Target` agent (meaning there
should only be one per debuggable rather than one per target) and as such is not routed
through the `Target` agent.

* UserInterface/Views/QuickConsole.js:
(WI.QuickConsole.prototype._displayNameForExecutionContext):
Attempt to match the execution context name against any known extension identifier, and
use the extension's display name if one is found.

* UserInterface/Base/URLUtilities.js:
(WI.displayNameForHost):
Attempt to match the host against any known extension identifier, and use the extension's
display name if one is found.

* UserInterface/Views/SourcesNavigationSidebarPanel.js:
(WI.SourcesNavigationSidebarPanel.prototype._addStyleSheet):
(WI.SourcesNavigationSidebarPanel.prototype._addScript):
* UserInterface/Base/Utilities.js:
(isWebKitExtensionScheme): Deleted.
* .eslintrc:
Use `WI.BrowserManager.prototype.isExtensionScheme` instead of the global function.

* UserInterface/Models/SourceCode.js:
(WI.SourceCode):
(WI.SourceCode.prototype.get url): Added.
(WI.SourceCode.prototype.get urlComponents): Added.
* UserInterface/Models/CSSStyleSheet.js:
(WI.CSSStyleSheet):
(WI.CSSStyleSheet.prototype.get injected):
(WI.CSSStyleSheet.prototype.get url): Deleted.
(WI.CSSStyleSheet.prototype.get urlComponents): Deleted.
* UserInterface/Models/Resource.js:
(WI.Resource):
(WI.Resource.prototype.get url): Deleted.
(WI.Resource.prototype.get urlComponents): Deleted.
* UserInterface/Models/Script.js:
(WI.Script):
(WI.Script.prototype.get url): Deleted.
(WI.Script.prototype.get urlComponents): Deleted.
All subclasses of `WI.SourceCode` have separate `get url` and `get urlComponents` functions,
so unify them in the common superclass so that it's guaranteed to exist.

Source/WebKit:

* UIProcess/Inspector/WebPageInspectorController.h:
(WebKit::WebPageInspectorController::enabledInspectorBrowserAgent const): Added.
(WebKit::WebPageInspectorController::setEnabledInspectorBrowserAgent): Added.
* UIProcess/Inspector/WebPageInspectorController.cpp:
(WebKit::WebPageInspectorController::WebPageInspectorController):
(WebKit::WebPageInspectorController::connectFrontend):
(WebKit::WebPageInspectorController::webPageAgentContext): Added.
(WebKit::WebPageInspectorController::createLazyAgents): Added.
* UIProcess/Inspector/WebPageInspectorAgentBase.h: Added.
(WebKit::InspectorAgentBase::InspectorAgentBase):
* UIProcess/Inspector/Agents/InspectorBrowserAgent.h: Added.
* UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp: Added.
(WebKit::InspectorBrowserAgent::InspectorBrowserAgent):
(WebKit::InspectorBrowserAgent::enabled):
(WebKit::InspectorBrowserAgent::didCreateFrontendAndBackend):
(WebKit::InspectorBrowserAgent::willDestroyFrontendAndBackend):
(WebKit::InspectorBrowserAgent::enable):
(WebKit::InspectorBrowserAgent::disable):
(WebKit::InspectorBrowserAgent::extensionsEnabled):
(WebKit::InspectorBrowserAgent::extensionsDisabled):
Add a `Browser` agent that can communicate with the inspected page's containing browser. It
lives in the UIProcess alongside the `Target` agent (meaning there should only be one per
debuggable rather than one per target) and as such is not routed through the `Target` agent.

* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::inspectorClient): Added.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
(-[WKWebView _inspectorDelegate]): Added.
(-[WKWebView _setInspectorDelegate:]): Added.
(WebKit::WebPageProxy::setInspectorClient): Added.
* UIProcess/Inspector/Cocoa/InspectorDelegate.h: Added.
* UIProcess/Inspector/Cocoa/InspectorDelegate.mm: Added.
(WebKit::InspectorDelegate::InspectorDelegate):
(WebKit::InspectorDelegate::createInspectorClient):
(WebKit::InspectorDelegate::delegate):
(WebKit::InspectorDelegate::setDelegate):
(WebKit::InspectorDelegate::InspectorClient):
(WebKit::InspectorDelegate::InspectorClient::didAttachLocalInspector):
(WebKit::InspectorDelegate::InspectorClient::browserDomainEnabled):
(WebKit::InspectorDelegate::InspectorClient::browserDomainDisabled):
* UIProcess/API/APIInspectorClient.h: Added.
(API::InspectorClient::didAttachLocalInspector):
(API::InspectorClient::browserDomainEnabled):
(API::InspectorClient::browserDomainDisabled):
* UIProcess/API/Cocoa/_WKInspectorDelegate.h: Added.
Introduce an inspector delegate SPI for communicating information related to Web Inspector.

* UIProcess/API/Cocoa/_WKInspectorPrivate.h:
* UIProcess/API/Cocoa/_WKInspector.mm:
(-[_WKInspector _browserExtensionsEnabled:]): Added.
(-[_WKInspector _browserExtensionsDisabled:]): Added.
* UIProcess/Inspector/WebInspectorProxy.h:
* UIProcess/Inspector/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::openLocalInspectorFrontend):
(WebKit::WebInspectorProxy::browserExtensionsEnabled): Added.
(WebKit::WebInspectorProxy::browserExtensionsDisabled): Added.
Add SPI for when extensions are enabled/disabled so that Web Inspector can update.

* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::didAttachInspector): Deleted.
* UIProcess/API/APIUIClient.h:
(API::UIClient::didAttachInspector): Deleted.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
Move `_webView:didAttachInspector:` from `WKUIDelegatePrivate` to `_WKInspectorDelegate`.

* CMakeLists.txt:
* DerivedSources.make:
* PlatformMac.cmake:
* Sources.txt:
* SourcesCocoa.txt:
* WebKit.xcodeproj/project.pbxproj:

* UIProcess/WebAuthentication/Cocoa/LocalConnection.h:
Drive-by: add missing include.
Source/WTF:

* wtf/HashSet.h:
(WTF::HashSet::reserveInitialCapacity): Added.

Tools:

* TestWebKitAPI/Tests/WTF/HashSet.cpp:
(TestWebKitAPI::TEST):
Add test for `WTF::HashSet::reserveInitialCapacity`.

* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestWebKitAPI::TEST):
Actually check the value of `WTF::HashMap::capacity`.

* TestWebKitAPI/Tests/WebKitCocoa/_WKInspectorDelegate.mm: Added.
(-[InspectorDelegate _webView:didAttachInspector:])
(-[InspectorDelegate _webView:browserDomainEnabledForInspector:])
(-[InspectorDelegate _webView:browserDomainDisabledForInspector:])
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(-[InspectorDelegate _webView:didAttachInspector:]): Deleted.
(TestWebKitAPI::TEST): Deleted.

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

64 files changed:
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources-input.xcfilelist
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/inspector/protocol/Browser.json [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/HashSet.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/webauthn/AuthenticationExtensionsClientOutputs.h
Source/WebInspectorUI/.eslintrc
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Base/URLUtilities.js
Source/WebInspectorUI/UserInterface/Base/Utilities.js
Source/WebInspectorUI/UserInterface/Controllers/BrowserManager.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Controllers/TargetManager.js
Source/WebInspectorUI/UserInterface/Main.html
Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js
Source/WebInspectorUI/UserInterface/Models/Resource.js
Source/WebInspectorUI/UserInterface/Models/Script.js
Source/WebInspectorUI/UserInterface/Models/SourceCode.js
Source/WebInspectorUI/UserInterface/Protocol/BrowserObserver.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Protocol/MultiplexingBackendTarget.js
Source/WebInspectorUI/UserInterface/Protocol/Target.js
Source/WebInspectorUI/UserInterface/Test.html
Source/WebInspectorUI/UserInterface/Test/Test.js
Source/WebInspectorUI/UserInterface/Views/QuickConsole.js
Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/DerivedSources.make
Source/WebKit/PlatformMac.cmake
Source/WebKit/Sources.txt
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/API/APIInspectorClient.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/APIUIClient.h
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.h [new file with mode: 0644]
Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h [new file with mode: 0644]
Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm [new file with mode: 0644]
Source/WebKit/UIProcess/Inspector/WebInspectorProxy.cpp
Source/WebKit/UIProcess/Inspector/WebInspectorProxy.h
Source/WebKit/UIProcess/Inspector/WebPageInspectorAgentBase.h [new file with mode: 0644]
Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp
Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h
Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp
Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp
Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInspectorDelegate.mm [new file with mode: 0644]

index 7556e95..5abd184 100644 (file)
@@ -1153,6 +1153,7 @@ set(JavaScriptCore_INSPECTOR_DOMAINS
     ${JAVASCRIPTCORE_DIR}/inspector/protocol/DOMStorage.json
     ${JAVASCRIPTCORE_DIR}/inspector/protocol/Database.json
     ${JAVASCRIPTCORE_DIR}/inspector/protocol/Debugger.json
+    ${JAVASCRIPTCORE_DIR}/inspector/protocol/Browser.json
     ${JAVASCRIPTCORE_DIR}/inspector/protocol/GenericTypes.json
     ${JAVASCRIPTCORE_DIR}/inspector/protocol/Heap.json
     ${JAVASCRIPTCORE_DIR}/inspector/protocol/Inspector.json
index e16eb4b..ca027fb 100644 (file)
@@ -1,3 +1,20 @@
+2020-02-25  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: safari app extension isolated worlds and injected files use the extension's identifier instead of its name
+        https://bugs.webkit.org/show_bug.cgi?id=206911
+        <rdar://problem/58026635>
+
+        Reviewed by Brian Burg.
+
+        * inspector/protocol/Browser.json: Added.
+        Add a `Browser` agent that can communicate with the inspected page's containing browser. It
+        lives in the UIProcess alongside the `Target` agent (meaning there should only be one per
+        debuggable rather than one per target) and as such is not routed through the `Target` agent.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources.make:
+
 2020-02-25  Justin Michaud  <justin_michaud@apple.com>
 
         Inline Cache delete by id/val
index 9ead653..2340cdf 100644 (file)
@@ -90,6 +90,7 @@ $(PROJECT_DIR)/inspector/protocol/DOMDebugger.json
 $(PROJECT_DIR)/inspector/protocol/DOMStorage.json
 $(PROJECT_DIR)/inspector/protocol/Database.json
 $(PROJECT_DIR)/inspector/protocol/Debugger.json
+$(PROJECT_DIR)/inspector/protocol/Browser.json
 $(PROJECT_DIR)/inspector/protocol/GenericTypes.json
 $(PROJECT_DIR)/inspector/protocol/Heap.json
 $(PROJECT_DIR)/inspector/protocol/IndexedDB.json
index e2a36fa..e9d804d 100644 (file)
@@ -249,6 +249,7 @@ INSPECTOR_DOMAINS := \
     $(JavaScriptCore)/inspector/protocol/DOMStorage.json \
     $(JavaScriptCore)/inspector/protocol/Database.json \
     $(JavaScriptCore)/inspector/protocol/Debugger.json \
+    $(JavaScriptCore)/inspector/protocol/Browser.json \
     $(JavaScriptCore)/inspector/protocol/GenericTypes.json \
     $(JavaScriptCore)/inspector/protocol/Heap.json \
     $(JavaScriptCore)/inspector/protocol/Inspector.json \
diff --git a/Source/JavaScriptCore/inspector/protocol/Browser.json b/Source/JavaScriptCore/inspector/protocol/Browser.json
new file mode 100644 (file)
index 0000000..fe0cf9c
--- /dev/null
@@ -0,0 +1,46 @@
+{
+    "domain": "Browser",
+    "description": "The Browser domain contains commands and events related to getting information about the browser ",
+    "debuggableTypes": ["web-page"],
+    "targetTypes": ["web-page"],
+    "types": [
+        {
+            "id": "ExtensionId",
+            "type": "string",
+            "description": "Unique extension identifier."
+        },
+        {
+            "id": "Extension",
+            "type": "object",
+            "description": "Information about an extension.",
+            "properties": [
+                { "name": "extensionId", "$ref": "ExtensionId", "description": "Extension identifier." },
+                { "name": "name", "type": "string", "description": "The display name for the extension." }
+            ]
+        }
+    ],
+    "commands": [
+        {
+            "name": "enable",
+            "description": "Enables Browser domain events."
+        },
+        {
+            "name": "disable",
+            "description": "Disables Browser domain events."
+        }
+    ],
+    "events": [
+        {
+            "name": "extensionsEnabled",
+            "parameters": [
+                { "name": "extensions", "type": "array", "items": { "$ref": "Extension" }, "description": "Information about the enabled extensions." }
+            ]
+        },
+        {
+            "name": "extensionsDisabled",
+            "parameters": [
+                { "name": "extensionIds", "type": "array", "items": { "$ref": "ExtensionId" }, "description": "Disabled extension identifiers." }
+            ]
+        }
+    ]
+}
index 97fac25..6e1d8ec 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-25  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: safari app extension isolated worlds and injected files use the extension's identifier instead of its name
+        https://bugs.webkit.org/show_bug.cgi?id=206911
+        <rdar://problem/58026635>
+
+        Reviewed by Brian Burg.
+
+        * wtf/HashSet.h:
+        (WTF::HashSet::reserveInitialCapacity): Added.
+
 2020-02-25  Justin Michaud  <justin_michaud@apple.com>
 
         Inline Cache delete by id/val
index ee2c291..74c09e0 100644 (file)
@@ -75,6 +75,8 @@ public:
     unsigned capacity() const;
     bool isEmpty() const;
 
+    void reserveInitialCapacity(unsigned keyCount) { m_impl.reserveInitialCapacity(keyCount); }
+
     iterator begin() const;
     iterator end() const;
 
index 39a8bba..7eb31d9 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-25  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: safari app extension isolated worlds and injected files use the extension's identifier instead of its name
+        https://bugs.webkit.org/show_bug.cgi?id=206911
+        <rdar://problem/58026635>
+
+        Reviewed by Brian Burg.
+
+        * Modules/webauthn/AuthenticationExtensionsClientOutputs.h:
+        Drive-by: add missing include.
+
 2020-02-25  Jer Noble  <jer.noble@apple.com>
 
         Unreviewed tvOS build fix; fix the compiler guards broken by r257189.
index 38b76c5..daa6148 100644 (file)
         "isWebInspectorConsoleEvaluationScript": true,
         "isWebInspectorInternalScript": true,
         "isWebKitInternalScript": true,
-        "isWebKitExtensionScheme": true,
         "multiplicationSign": true,
         "parseMIMEType": true,
         "resolveDotsInPath": true,
index 6f47f55..4691497 100644 (file)
@@ -1,5 +1,81 @@
 2020-02-25  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: safari app extension isolated worlds and injected files use the extension's identifier instead of its name
+        https://bugs.webkit.org/show_bug.cgi?id=206911
+        <rdar://problem/58026635>
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Controllers/BrowserManager.js: Added.
+        (WI.BrowserManager):
+        (WI.BrowserManager.prototype.initializeTarget):
+        (WI.BrowserManager.prototype.enable):
+        (WI.BrowserManager.prototype.disable):
+        (WI.BrowserManager.prototype.isExtensionScheme):
+        (WI.BrowserManager.prototype.extensionNameForId):
+        (WI.BrowserManager.prototype.extensionNameForURL):
+        * UserInterface/Protocol/BrowserObserver.js: Added.
+        (WI.BrowserObserver.prototype.extensionsEnabled):
+        (WI.BrowserObserver.prototype.extensionsDisabled):
+        * UserInterface/Protocol/Target.js:
+        (WI.Target.prototype.get BrowserAgent): Added.
+        * UserInterface/Base/Main.js:
+        (WI.loaded):
+        * UserInterface/Main.html:
+        * UserInterface/Test/Test.js:
+        (WI.loaded):
+        * UserInterface/Test.html:
+        Add an observer and manager for the `Browser` domain.
+
+        * UserInterface/Protocol/MultiplexingBackendTarget.js:
+        (WI.MultiplexingBackendTarget):
+        (WI.MultiplexingBackendTarget.prototype.initialize):
+        * UserInterface/Controllers/TargetManager.js:
+        (WI.TargetManager.prototype.initializeTarget): Added.
+        The `Browser` agent lives in the UIProcess alongside the `Target` agent (meaning there
+        should only be one per debuggable rather than one per target) and as such is not routed
+        through the `Target` agent.
+
+        * UserInterface/Views/QuickConsole.js:
+        (WI.QuickConsole.prototype._displayNameForExecutionContext):
+        Attempt to match the execution context name against any known extension identifier, and
+        use the extension's display name if one is found.
+
+        * UserInterface/Base/URLUtilities.js:
+        (WI.displayNameForHost):
+        Attempt to match the host against any known extension identifier, and use the extension's
+        display name if one is found.
+
+        * UserInterface/Views/SourcesNavigationSidebarPanel.js:
+        (WI.SourcesNavigationSidebarPanel.prototype._addStyleSheet):
+        (WI.SourcesNavigationSidebarPanel.prototype._addScript):
+        * UserInterface/Base/Utilities.js:
+        (isWebKitExtensionScheme): Deleted.
+        * .eslintrc:
+        Use `WI.BrowserManager.prototype.isExtensionScheme` instead of the global function.
+
+        * UserInterface/Models/SourceCode.js:
+        (WI.SourceCode):
+        (WI.SourceCode.prototype.get url): Added.
+        (WI.SourceCode.prototype.get urlComponents): Added.
+        * UserInterface/Models/CSSStyleSheet.js:
+        (WI.CSSStyleSheet):
+        (WI.CSSStyleSheet.prototype.get injected):
+        (WI.CSSStyleSheet.prototype.get url): Deleted.
+        (WI.CSSStyleSheet.prototype.get urlComponents): Deleted.
+        * UserInterface/Models/Resource.js:
+        (WI.Resource):
+        (WI.Resource.prototype.get url): Deleted.
+        (WI.Resource.prototype.get urlComponents): Deleted.
+        * UserInterface/Models/Script.js:
+        (WI.Script):
+        (WI.Script.prototype.get url): Deleted.
+        (WI.Script.prototype.get urlComponents): Deleted.
+        All subclasses of `WI.SourceCode` have separate `get url` and `get urlComponents` functions,
+        so unify them in the common superclass so that it's guaranteed to exist.
+
+2020-02-25  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: move code for debug outlined focus element to the Debug folder so it isn't shipped
         https://bugs.webkit.org/show_bug.cgi?id=208217
 
index eace126..2835376 100644 (file)
@@ -55,6 +55,8 @@ WI.loaded = function()
         InspectorBackend.registerAnimationDispatcher(WI.AnimationObserver);
     if (InspectorBackend.registerApplicationCacheDispatcher)
         InspectorBackend.registerApplicationCacheDispatcher(WI.ApplicationCacheObserver);
+    if (InspectorBackend.registerBrowserDispatcher)
+        InspectorBackend.registerBrowserDispatcher(WI.BrowserObserver);
     if (InspectorBackend.registerCPUProfilerDispatcher)
         InspectorBackend.registerCPUProfilerDispatcher(WI.CPUProfilerObserver);
     if (InspectorBackend.registerCSSDispatcher)
@@ -104,6 +106,7 @@ WI.loaded = function()
     // Create the singleton managers next, before the user interface elements, so the user interface can register
     // as event listeners on these managers.
     WI.managers = [
+        WI.browserManager = new WI.BrowserManager,
         WI.targetManager = new WI.TargetManager,
         WI.networkManager = new WI.NetworkManager,
         WI.domStorageManager = new WI.DOMStorageManager,
@@ -135,6 +138,7 @@ WI.loaded = function()
     WI.databaseManager.addEventListener(WI.DatabaseManager.Event.DatabaseWasInspected, WI._databaseWasInspected);
     WI.networkManager.addEventListener(WI.NetworkManager.Event.MainFrameDidChange, WI._mainFrameDidChange);
     WI.networkManager.addEventListener(WI.NetworkManager.Event.FrameWasAdded, WI._frameWasAdded);
+    WI.browserManager.enable();
 
     WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, WI._mainResourceDidChange);
 
index b59519e..e3fca2f 100644 (file)
@@ -311,7 +311,12 @@ WI.urlWithoutFragment = function(urlString)
 
 WI.displayNameForHost = function(host)
 {
+    let extensionName = WI.browserManager.extensionNameForId(host);
+    if (extensionName)
+        return extensionName;
+
     // FIXME <rdar://problem/11237413>: This should decode punycode hostnames.
+
     return host;
 };
 
index b774231..0459622 100644 (file)
@@ -1644,11 +1644,6 @@ function isWebKitInternalScript(url)
     return url && url.startsWith("__Web") && url.endsWith("__");
 }
 
-function isWebKitExtensionScheme(scheme)
-{
-    return scheme && scheme.endsWith("-extension");
-}
-
 function isFunctionStringNativeCode(str)
 {
     return str.endsWith("{\n    [native code]\n}");
diff --git a/Source/WebInspectorUI/UserInterface/Controllers/BrowserManager.js b/Source/WebInspectorUI/UserInterface/Controllers/BrowserManager.js
new file mode 100644 (file)
index 0000000..2e9704f
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WI.BrowserManager = class BrowserManager
+{
+    constructor()
+    {
+        this._enabled = false;
+        this._extensionNameIdentifierMap = new Map;
+    }
+
+    // Target
+
+    initializeTarget(target)
+    {
+        if (!this._enabled)
+            return;
+
+        // COMPATIBILITY (iOS 13.4): Browser did not exist yet.
+        if (target.hasDomain("Browser"))
+            target.BrowserAgent.enable();
+    }
+
+    // Public
+
+    enable()
+    {
+        console.assert(!this._enabled);
+
+        this._enabled = true;
+
+        for (let target of WI.targetManager.allTargets)
+            this.initializeTarget(target);
+    }
+
+    disable()
+    {
+        console.assert(this._enabled);
+
+        for (let target of WI.targetManager.allTargets) {
+            // COMPATIBILITY (iOS 13.4): Browser did not exist yet.
+            if (target.hasDomain("Browser"))
+                target.BrowserAgent.disable();
+        }
+
+        this._extensionNameIdentifierMap.clear();
+
+        this._enabled = false;
+    }
+
+    isExtensionScheme(scheme)
+    {
+        return scheme && scheme.endsWith("-extension");
+    }
+
+    extensionNameForId(extensionId)
+    {
+        return this._extensionNameIdentifierMap.get(extensionId) || null;
+    }
+
+    extensionNameForURL(url)
+    {
+        console.assert(this.isExtensionScheme(parseURL(url).scheme));
+
+        let match = url.match(/^[a-z\-]*extension:\/\/([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\//);
+        if (!match)
+            return null;
+
+        return this.extensionNameForId(match[1]);
+    }
+
+    extensionNameForExecutionContext(context)
+    {
+        console.assert(context instanceof WI.ExecutionContext);
+        console.assert(context.type === WI.ExecutionContext.Type.User);
+
+        let match = context.name.match(/^[A-Za-z]*ExtensionWorld-([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})$/);
+        if (!match)
+            return null;
+
+        return this.extensionNameForId(match[1]);
+    }
+
+    // BrowserObserver
+
+    extensionsEnabled(extensions)
+    {
+        for (let {extensionId, name} of extensions) {
+            console.assert(!this._extensionNameIdentifierMap.has(extensionId), `Extension already exists with id '${extensionId}'.`);
+
+            this._extensionNameIdentifierMap.set(extensionId, name);
+        }
+    }
+
+    extensionsDisabled(extensionIds)
+    {
+        for (let extensionId of extensionIds) {
+            let name = this._extensionNameIdentifierMap.take(extensionId);
+            console.assert(name, `Missing extension with id '${extensionId}'.`);
+        }
+    }
+};
index 84fa026..335e5eb 100644 (file)
@@ -35,6 +35,15 @@ WI.TargetManager = class TargetManager extends WI.Object
         this._transitionTimeoutIdentifier = undefined;
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        // COMPATIBILITY (iOS 13): Target.setPauseOnStart did not exist yet.
+        if (target.hasCommand("Target.setPauseOnStart"))
+            target.TargetAgent.setPauseOnStart(true);
+    }
+
     // Public
 
     get targets()
index 59a63ae..8bd92d9 100644 (file)
 
     <script src="Protocol/AnimationObserver.js"></script>
     <script src="Protocol/ApplicationCacheObserver.js"></script>
+    <script src="Protocol/BrowserObserver.js"></script>
     <script src="Protocol/CPUProfilerObserver.js"></script>
     <script src="Protocol/CSSObserver.js"></script>
     <script src="Protocol/CanvasObserver.js"></script>
     <script src="Controllers/BasicBlockAnnotator.js"></script>
     <script src="Controllers/BreakpointLogMessageLexer.js"></script>
     <script src="Controllers/BreakpointPopoverController.js"></script>
+    <script src="Controllers/BrowserManager.js"></script>
     <script src="Controllers/CSSManager.js"></script>
     <script src="Controllers/CallFrameTreeController.js"></script>
     <script src="Controllers/CanvasManager.js"></script>
index c9fd02e..8ca1c74 100644 (file)
@@ -32,7 +32,6 @@ WI.CSSStyleSheet = class CSSStyleSheet extends WI.SourceCode
         console.assert(id);
 
         this._id = id || null;
-        this._url = null;
         this._parentFrame = null;
         this._origin = null;
         this._startLineNumber = 0;
@@ -70,7 +69,7 @@ WI.CSSStyleSheet = class CSSStyleSheet extends WI.SourceCode
 
     get injected()
     {
-        return isWebKitExtensionScheme(this.urlComponents.scheme);
+        return WI.browserManager.isExtensionScheme(this.urlComponents.scheme);
     }
 
     get anonymous()
@@ -78,18 +77,6 @@ WI.CSSStyleSheet = class CSSStyleSheet extends WI.SourceCode
         return !this.isInspectorStyleSheet() && !this._url;
     }
 
-    get url()
-    {
-        return this._url;
-    }
-
-    get urlComponents()
-    {
-        if (!this._urlComponents)
-            this._urlComponents = parseURL(this._url);
-        return this._urlComponents;
-    }
-
     get mimeType()
     {
         return "text/css";
index 2c115e5..0eb5848 100644 (file)
@@ -28,10 +28,10 @@ WI.Resource = class Resource extends WI.SourceCode
 {
     constructor(url, {mimeType, type, loaderIdentifier, targetId, requestIdentifier, requestMethod, requestHeaders, requestData, requestSentTimestamp, requestSentWalltime, initiatorCallFrames, initiatorSourceCodeLocation, initiatorNode, originalRequestWillBeSentTimestamp} = {})
     {
-        super();
-
         console.assert(url);
 
+        super(url);
+
         if (type in WI.Resource.Type)
             type = WI.Resource.Type[type];
         else if (type === "Stylesheet") {
@@ -39,8 +39,6 @@ WI.Resource = class Resource extends WI.SourceCode
             type = WI.Resource.Type.StyleSheet;
         }
 
-        this._url = url;
-        this._urlComponents = null;
         this._mimeType = mimeType;
         this._mimeTypeComponents = null;
         this._type = Resource.resolvedType(type, mimeType);
@@ -310,7 +308,6 @@ WI.Resource = class Resource extends WI.SourceCode
 
     // Public
 
-    get url() { return this._url; }
     get mimeType() { return this._mimeType; }
     get target() { return this._target; }
     get type() { return this._type; }
@@ -352,13 +349,6 @@ WI.Resource = class Resource extends WI.SourceCode
     get cachedResponseBodySize() { return this._cachedResponseBodySize; }
     get redirects() { return this._redirects; }
 
-    get urlComponents()
-    {
-        if (!this._urlComponents)
-            this._urlComponents = parseURL(this._url);
-        return this._urlComponents;
-    }
-
     get loadedSecurely()
     {
         if (this.urlComponents.scheme !== "https" && this.urlComponents.scheme !== "wss" && this.urlComponents.scheme !== "sftp")
index e44b9f6..657c541 100644 (file)
@@ -27,7 +27,7 @@ WI.Script = class Script extends WI.SourceCode
 {
     constructor(target, id, range, url, sourceType, injected, sourceURL, sourceMapURL)
     {
-        super();
+        super(url);
 
         console.assert(target instanceof WI.Target || this instanceof WI.LocalScript);
         console.assert(range instanceof WI.TextRange);
@@ -35,7 +35,6 @@ WI.Script = class Script extends WI.SourceCode
         this._target = target;
         this._id = id || null;
         this._range = range || null;
-        this._url = url || null;
         this._sourceType = sourceType || WI.Script.SourceType.Program;
         this._sourceURL = sourceURL || null;
         this._sourceMappingURL = sourceMapURL || null;
@@ -80,7 +79,6 @@ WI.Script = class Script extends WI.SourceCode
     get target() { return this._target; }
     get id() { return this._id; }
     get range() { return this._range; }
-    get url() { return this._url; }
     get sourceType() { return this._sourceType; }
     get sourceURL() { return this._sourceURL; }
     get sourceMappingURL() { return this._sourceMappingURL; }
@@ -108,13 +106,6 @@ WI.Script = class Script extends WI.SourceCode
         return this._sourceURL;
     }
 
-    get urlComponents()
-    {
-        if (!this._urlComponents)
-            this._urlComponents = parseURL(this._url);
-        return this._urlComponents;
-    }
-
     get mimeType()
     {
         return this._resource ? this._resource.mimeType : "text/javascript";
index 4a40323..8ce7b58 100644 (file)
 
 WI.SourceCode = class SourceCode extends WI.Object
 {
-    constructor()
+    constructor(url)
     {
         super();
 
+        this._url = url || null;
+        this._urlComponents = null;
+
         this._originalRevision = new WI.SourceCodeRevision(this);
         this._currentRevision = this._originalRevision;
 
@@ -98,7 +101,14 @@ WI.SourceCode = class SourceCode extends WI.Object
 
     get url()
     {
-        // To be overridden by subclasses.
+        return this._url;
+    }
+
+    get urlComponents()
+    {
+        if (!this._urlComponents)
+            this._urlComponents = parseURL(this._url);
+        return this._urlComponents;
     }
 
     get contentIdentifier()
diff --git a/Source/WebInspectorUI/UserInterface/Protocol/BrowserObserver.js b/Source/WebInspectorUI/UserInterface/Protocol/BrowserObserver.js
new file mode 100644 (file)
index 0000000..26fefd2
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WI.BrowserObserver = class BrowserObserver extends InspectorBackend.Dispatcher
+{
+    // Events defined by the "Browser" domain.
+
+    extensionsEnabled(extensions)
+    {
+        WI.browserManager.extensionsEnabled(extensions);
+    }
+
+    extensionsDisabled(extensionIds)
+    {
+        WI.browserManager.extensionsDisabled(extensionIds);
+    }
+};
index 793709e..4fde18e 100644 (file)
@@ -24,9 +24,6 @@
  */
 
 // This class is used when connecting to a target which multiplexes to other targets.
-// The main connection is to a target that, currently, has only a Target agent.
-// All other Targets will have their messages be multiplexed through this
-// main connection's Target agent.
 
 WI.MultiplexingBackendTarget = class MultiplexingBackendTarget extends WI.Target
 {
@@ -36,18 +33,16 @@ WI.MultiplexingBackendTarget = class MultiplexingBackendTarget extends WI.Target
         const targetId = "multi";
         super(parentTarget, targetId, WI.UIString("Web Page"), WI.TargetType.WebPage, InspectorBackend.backendConnection);
 
-        console.assert(Array.shallowEqual(Object.keys(this._agents), ["Target"]), "A WebPage target should only have a single agent.");
+        console.assert(Array.shallowEqual(Object.keys(this._agents), ["Browser", "Target"]));
     }
 
     // Target
 
     initialize()
     {
-        // Intentionally not calling super. No agents other than the TargetAgent.
-
-        // COMPATIBILITY (iOS 13): Target.setPauseOnStart did not exist yet.
-        if (this.hasCommand("Target.setPauseOnStart"))
-            this.TargetAgent.setPauseOnStart(true);
+        // Only initialize with the managers that are known to support a multiplexing target.
+        WI.browserManager.initializeTarget(this);
+        WI.targetManager.initializeTarget(this);
     }
 
     // Protected (Target)
index c26a19a..9dca2aa 100644 (file)
@@ -132,6 +132,7 @@ WI.Target = class Target extends WI.Object
     get AnimationAgent() { return this._agents.Animation; }
     get ApplicationCacheAgent() { return this._agents.ApplicationCache; }
     get AuditAgent() { return this._agents.Audit; }
+    get BrowserAgent() { return this._agents.Browser; }
     get CPUProfilerAgent() { return this._agents.CPUProfiler; }
     get CSSAgent() { return this._agents.CSS; }
     get CanvasAgent() { return this._agents.Canvas; }
index 0ba560b..2bf1e13 100644 (file)
@@ -86,6 +86,7 @@
     <script src="Protocol/InspectorObserver.js"></script>
     <script src="Protocol/AnimationObserver.js"></script>
     <script src="Protocol/ApplicationCacheObserver.js"></script>
+    <script src="Protocol/BrowserObserver.js"></script>
     <script src="Protocol/CPUProfilerObserver.js"></script>
     <script src="Protocol/CSSObserver.js"></script>
     <script src="Protocol/CanvasObserver.js"></script>
     <script src="Controllers/AuditManager.js"></script>
     <script src="Controllers/ApplicationCacheManager.js"></script>
     <script src="Controllers/BreakpointLogMessageLexer.js"></script>
+    <script src="Controllers/BrowserManager.js"></script>
     <script src="Controllers/CSSManager.js"></script>
     <script src="Controllers/CanvasManager.js"></script>
     <script src="Controllers/ConsoleManager.js"></script>
index 006447a..6e05d92 100644 (file)
@@ -29,6 +29,7 @@ WI.loaded = function()
     // The initialization order should match the same in Main.js.
     InspectorBackend.registerAnimationDispatcher(WI.AnimationObserver);
     InspectorBackend.registerApplicationCacheDispatcher(WI.ApplicationCacheObserver);
+    InspectorBackend.registerBrowserDispatcher(WI.BrowserObserver);
     InspectorBackend.registerCPUProfilerDispatcher(WI.CPUProfilerObserver);
     InspectorBackend.registerCSSDispatcher(WI.CSSObserver);
     InspectorBackend.registerCanvasDispatcher(WI.CanvasObserver);
@@ -51,6 +52,7 @@ WI.loaded = function()
 
     // Instantiate controllers used by tests.
     WI.managers = [
+        WI.browserManager = new WI.BrowserManager,
         WI.targetManager = new WI.TargetManager,
         WI.networkManager = new WI.NetworkManager,
         WI.domStorageManager = new WI.DOMStorageManager,
@@ -75,6 +77,7 @@ WI.loaded = function()
 
     // Register for events.
     document.addEventListener("DOMContentLoaded", WI.contentLoaded);
+    WI.browserManager.enable();
 
     // Targets.
     WI.backendTarget = null;
index 9d234b2..c7b7bc2 100644 (file)
@@ -121,6 +121,12 @@ WI.QuickConsole = class QuickConsole extends WI.View
         if (context.type === WI.ExecutionContext.Type.Internal)
             return WI.unlocalizedString("[Internal] ") + context.name;
 
+        if (context.type === WI.ExecutionContext.Type.User) {
+            let extensionName = WI.browserManager.extensionNameForExecutionContext(context);
+            if (extensionName)
+                return truncate(extensionName, maxLength);
+        }
+
         let target = context.target;
         if (target.type === WI.TargetType.Worker)
             return truncate(target.displayName, maxLength);
index 6e49637..e095dbe 100644 (file)
@@ -969,7 +969,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
 
         let parentTreeElement = null;
 
-        if (isWebKitExtensionScheme(styleSheet.urlComponents.scheme)) {
+        if (WI.browserManager.isExtensionScheme(styleSheet.urlComponents.scheme)) {
             if (!this._extensionStyleSheetsFolderTreeElement)
                 this._extensionStyleSheetsFolderTreeElement = new WI.FolderTreeElement(WI.UIString("Extension Style Sheets"), new WI.CSSStyleSheetCollection);
             parentTreeElement = this._extensionStyleSheetsFolderTreeElement;
@@ -1024,7 +1024,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         } else {
             let parentFolderTreeElement = null;
 
-            if (isWebKitExtensionScheme(script.urlComponents.scheme)) {
+            if (WI.browserManager.isExtensionScheme(script.urlComponents.scheme)) {
                 if (!this._extensionScriptsFolderTreeElement) {
                     let collection = new WI.ScriptCollection;
                     this._extensionScriptsFolderTreeElement = new WI.FolderTreeElement(WI.UIString("Extension Scripts"), collection);
index 115b5df..4e32630 100644 (file)
@@ -57,6 +57,7 @@ set(WebKit_INCLUDE_DIRECTORIES
     "${WEBKIT_DIR}/UIProcess/Gamepad"
     "${WEBKIT_DIR}/UIProcess/GPU"
     "${WEBKIT_DIR}/UIProcess/Inspector"
+    "${WEBKIT_DIR}/UIProcess/Inspector/Agents"
     "${WEBKIT_DIR}/UIProcess/Launcher"
     "${WEBKIT_DIR}/UIProcess/Network"
     "${WEBKIT_DIR}/UIProcess/Network/CustomProtocols"
index ad4e6c0..6ece64a 100644 (file)
@@ -1,3 +1,93 @@
+2020-02-25  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: safari app extension isolated worlds and injected files use the extension's identifier instead of its name
+        https://bugs.webkit.org/show_bug.cgi?id=206911
+        <rdar://problem/58026635>
+
+        Reviewed by Brian Burg.
+
+        * UIProcess/Inspector/WebPageInspectorController.h:
+        (WebKit::WebPageInspectorController::enabledInspectorBrowserAgent const): Added.
+        (WebKit::WebPageInspectorController::setEnabledInspectorBrowserAgent): Added.
+        * UIProcess/Inspector/WebPageInspectorController.cpp:
+        (WebKit::WebPageInspectorController::WebPageInspectorController):
+        (WebKit::WebPageInspectorController::connectFrontend):
+        (WebKit::WebPageInspectorController::webPageAgentContext): Added.
+        (WebKit::WebPageInspectorController::createLazyAgents): Added.
+        * UIProcess/Inspector/WebPageInspectorAgentBase.h: Added.
+        (WebKit::InspectorAgentBase::InspectorAgentBase):
+        * UIProcess/Inspector/Agents/InspectorBrowserAgent.h: Added.
+        * UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp: Added.
+        (WebKit::InspectorBrowserAgent::InspectorBrowserAgent):
+        (WebKit::InspectorBrowserAgent::enabled):
+        (WebKit::InspectorBrowserAgent::didCreateFrontendAndBackend):
+        (WebKit::InspectorBrowserAgent::willDestroyFrontendAndBackend):
+        (WebKit::InspectorBrowserAgent::enable):
+        (WebKit::InspectorBrowserAgent::disable):
+        (WebKit::InspectorBrowserAgent::extensionsEnabled):
+        (WebKit::InspectorBrowserAgent::extensionsDisabled):
+        Add a `Browser` agent that can communicate with the inspected page's containing browser. It
+        lives in the UIProcess alongside the `Target` agent (meaning there should only be one per
+        debuggable rather than one per target) and as such is not routed through the `Target` agent.
+
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::inspectorClient): Added.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        (-[WKWebView _inspectorDelegate]): Added.
+        (-[WKWebView _setInspectorDelegate:]): Added.
+        (WebKit::WebPageProxy::setInspectorClient): Added.
+        * UIProcess/Inspector/Cocoa/InspectorDelegate.h: Added.
+        * UIProcess/Inspector/Cocoa/InspectorDelegate.mm: Added.
+        (WebKit::InspectorDelegate::InspectorDelegate):
+        (WebKit::InspectorDelegate::createInspectorClient):
+        (WebKit::InspectorDelegate::delegate):
+        (WebKit::InspectorDelegate::setDelegate):
+        (WebKit::InspectorDelegate::InspectorClient):
+        (WebKit::InspectorDelegate::InspectorClient::didAttachLocalInspector):
+        (WebKit::InspectorDelegate::InspectorClient::browserDomainEnabled):
+        (WebKit::InspectorDelegate::InspectorClient::browserDomainDisabled):
+        * UIProcess/API/APIInspectorClient.h: Added.
+        (API::InspectorClient::didAttachLocalInspector):
+        (API::InspectorClient::browserDomainEnabled):
+        (API::InspectorClient::browserDomainDisabled):
+        * UIProcess/API/Cocoa/_WKInspectorDelegate.h: Added.
+        Introduce an inspector delegate SPI for communicating information related to Web Inspector.
+
+        * UIProcess/API/Cocoa/_WKInspectorPrivate.h:
+        * UIProcess/API/Cocoa/_WKInspector.mm:
+        (-[_WKInspector _browserExtensionsEnabled:]): Added.
+        (-[_WKInspector _browserExtensionsDisabled:]): Added.
+        * UIProcess/Inspector/WebInspectorProxy.h:
+        * UIProcess/Inspector/WebInspectorProxy.cpp:
+        (WebKit::WebInspectorProxy::openLocalInspectorFrontend):
+        (WebKit::WebInspectorProxy::browserExtensionsEnabled): Added.
+        (WebKit::WebInspectorProxy::browserExtensionsDisabled): Added.
+        Add SPI for when extensions are enabled/disabled so that Web Inspector can update.
+
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::didAttachInspector): Deleted.
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::didAttachInspector): Deleted.
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        Move `_webView:didAttachInspector:` from `WKUIDelegatePrivate` to `_WKInspectorDelegate`.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * PlatformMac.cmake:
+        * Sources.txt:
+        * SourcesCocoa.txt:
+        * WebKit.xcodeproj/project.pbxproj:
+
+        * UIProcess/WebAuthentication/Cocoa/LocalConnection.h:
+        Drive-by: add missing include.
+
 2020-02-25  Justin Michaud  <justin_michaud@apple.com>
 
         Inline Cache delete by id/val
index 10d1725..6a9def1 100644 (file)
@@ -81,6 +81,7 @@ VPATH = \
     $(WebKit2)/UIProcess/Downloads \
     $(WebKit2)/UIProcess/GPU \
     $(WebKit2)/UIProcess/Inspector \
+    $(WebKit2)/UIProcess/Inspector/Agents \
     $(WebKit2)/UIProcess/MediaStream \
     $(WebKit2)/UIProcess/Network \
     $(WebKit2)/UIProcess/Network/CustomProtocols \
index 5c3074e..22c2e8b 100644 (file)
@@ -62,6 +62,7 @@ list(APPEND WebKit_PRIVATE_INCLUDE_DIRECTORIES
     "${WEBKIT_DIR}/UIProcess/Authentication/cocoa"
     "${WEBKIT_DIR}/UIProcess/Cocoa"
     "${WEBKIT_DIR}/UIProcess/Cocoa/SOAuthorization"
+    "${WEBKIT_DIR}/UIProcess/Inspector/Cocoa"
     "${WEBKIT_DIR}/UIProcess/Inspector/mac"
     "${WEBKIT_DIR}/UIProcess/Launcher/mac"
     "${WEBKIT_DIR}/UIProcess/RemoteLayerTree"
index a5d0be1..81bc02c 100644 (file)
@@ -427,6 +427,8 @@ UIProcess/Inspector/WebInspectorUtilities.cpp
 UIProcess/Inspector/WebPageDebuggable.cpp
 UIProcess/Inspector/WebPageInspectorController.cpp
 
+UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp
+
 UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp
 UIProcess/Notifications/WebNotification.cpp
 UIProcess/Notifications/WebNotificationManagerProxy.cpp
index da23b0e..ef88970 100644 (file)
@@ -402,6 +402,8 @@ UIProcess/Gamepad/cocoa/UIGamepadProviderCocoa.mm
 UIProcess/Gamepad/ios/UIGamepadProviderIOS.mm
 UIProcess/Gamepad/mac/UIGamepadProviderMac.mm
 
+UIProcess/Inspector/Cocoa/InspectorDelegate.mm
+
 UIProcess/Inspector/ios/WKInspectorHighlightView.mm
 UIProcess/Inspector/ios/WKInspectorNodeSearchGestureRecognizer.mm
 
diff --git a/Source/WebKit/UIProcess/API/APIInspectorClient.h b/Source/WebKit/UIProcess/API/APIInspectorClient.h
new file mode 100644 (file)
index 0000000..322a1d6
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebKit {
+class WebInspectorProxy;
+class WebPageProxy;
+}
+
+namespace API {
+
+class InspectorClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    virtual ~InspectorClient() = default;
+
+    virtual void didAttachLocalInspector(WebKit::WebPageProxy&, WebKit::WebInspectorProxy&) { }
+    virtual void browserDomainEnabled(WebKit::WebPageProxy&, WebKit::WebInspectorProxy&) { }
+    virtual void browserDomainDisabled(WebKit::WebPageProxy&, WebKit::WebInspectorProxy&) { }
+};
+
+} // namespace API
index 5451303..d922be0 100644 (file)
@@ -199,8 +199,6 @@ public:
 #if ENABLE(WEB_AUTHN)
     virtual void runWebAuthenticationPanel(WebKit::WebPageProxy&, WebAuthenticationPanel&, WebKit::WebFrameProxy&, WebCore::SecurityOriginData&&, CompletionHandler<void(WebKit::WebAuthenticationPanelResult)>&& completionHandler) { completionHandler(WebKit::WebAuthenticationPanelResult::Unavailable); }
 #endif
-
-    virtual void didAttachInspector(WebKit::WebPageProxy&, WebKit::WebInspectorProxy&) { }
 };
 
 } // namespace API
index 9b80d5b..25f46ec 100644 (file)
@@ -39,7 +39,6 @@
 @class _WKActivatedElementInfo;
 @class _WKElementAction;
 @class _WKFrameHandle;
-@class _WKInspector;
 
 #if TARGET_OS_IOS
 @class UIContextMenuConfiguration;
@@ -238,11 +237,6 @@ struct UIEdgeInsets;
 - (void)_webView:(WKWebView *)webView getContextMenuFromProposedMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo completionHandler:(void (^)(NSMenu *))completionHandler WK_API_AVAILABLE(macos(10.14));
 - (void)_webView:(WKWebView *)webView didPerformDragOperation:(BOOL)handled WK_API_AVAILABLE(macos(10.14.4));
 
-/*! @abstract Called when a Web Inspector instance is attached to this WKWebView. This is not called in the case of remote inspection.
-    @param inspector The Web Inspector instance attached to this WKWebView.
-*/
-- (void)_webView:(WKWebView *)webView didAttachInspector:(_WKInspector *)inspector WK_API_AVAILABLE(macos(WK_MAC_TBA));
-
 #endif // !TARGET_OS_IPHONE
 
 @end
index 80a5174..6d35f28 100644 (file)
@@ -37,6 +37,7 @@
 #import "FullscreenClient.h"
 #import "GlobalFindInPageState.h"
 #import "IconLoadingDelegate.h"
+#import "InspectorDelegate.h"
 #import "LegacySessionStateCoding.h"
 #import "Logging.h"
 #import "MediaUtilities.h"
 #import "_WKFullscreenDelegate.h"
 #import "_WKHitTestResultInternal.h"
 #import "_WKInputDelegate.h"
+#import "_WKInspectorDelegate.h"
 #import "_WKInspectorInternal.h"
 #import "_WKRemoteObjectRegistryInternal.h"
 #import "_WKSessionStateInternal.h"
@@ -391,6 +393,7 @@ static void hardwareKeyboardAvailabilityChangedCallback(CFNotificationCenterRef,
 
     _iconLoadingDelegate = makeUnique<WebKit::IconLoadingDelegate>(self);
     _resourceLoadDelegate = makeUnique<WebKit::ResourceLoadDelegate>(self);
+    _inspectorDelegate = makeUnique<WebKit::InspectorDelegate>(self);
 
     [self _setUpSQLiteDatabaseTrackerClient];
 
@@ -1556,6 +1559,17 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
     return nil;
 }
 
+- (id <_WKInspectorDelegate>)_inspectorDelegate
+{
+    return _inspectorDelegate->delegate().autorelease();
+}
+
+- (void)_setInspectorDelegate:(id<_WKInspectorDelegate>)delegate
+{
+    _page->setInspectorClient(_inspectorDelegate->createInspectorClient());
+    _inspectorDelegate->setDelegate(delegate);
+}
+
 - (_WKFrameHandle *)_mainFrame
 {
     if (auto* frame = _page->mainFrame())
index 572966d..8f97f40 100644 (file)
@@ -68,6 +68,7 @@ class Attachment;
 namespace WebKit {
 enum class ContinueUnsafeLoad : bool;
 class IconLoadingDelegate;
+class InspectorDelegate;
 class NavigationState;
 class ResourceLoadDelegate;
 class SafeBrowsingWarning;
@@ -112,6 +113,7 @@ class ViewGestureController;
     std::unique_ptr<WebKit::UIDelegate> _uiDelegate;
     std::unique_ptr<WebKit::IconLoadingDelegate> _iconLoadingDelegate;
     std::unique_ptr<WebKit::ResourceLoadDelegate> _resourceLoadDelegate;
+    std::unique_ptr<WebKit::InspectorDelegate> _inspectorDelegate;
 
     WeakObjCPtr<id <_WKTextManipulationDelegate>> _textManipulationDelegate;
     WeakObjCPtr<id <_WKInputDelegate>> _inputDelegate;
index d111b29..bce6d71 100644 (file)
@@ -125,6 +125,7 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 @protocol _WKFullscreenDelegate;
 @protocol _WKIconLoadingDelegate;
 @protocol _WKInputDelegate;
+@protocol _WKInspectorDelegate;
 @protocol _WKResourceLoadDelegate;
 @protocol _WKTextManipulationDelegate;
 
@@ -181,6 +182,8 @@ for this property.
 @property (nonatomic, setter=_setAllowsRemoteInspection:) BOOL _allowsRemoteInspection;
 @property (nonatomic, copy, setter=_setRemoteInspectionNameOverride:) NSString *_remoteInspectionNameOverride WK_API_AVAILABLE(macos(10.12), ios(10.0));
 @property (nonatomic, readonly) _WKInspector *_inspector WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
+@property (nonatomic, weak, setter=_setInspectorDelegate:) id <_WKInspectorDelegate> _inspectorDelegate WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @property (nonatomic, readonly) _WKFrameHandle *_mainFrame WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
 
 @property (nonatomic, weak, setter=_setTextManipulationDelegate:) id <_WKTextManipulationDelegate> _textManipulationDelegate WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
index afcda06..b6b4c1e 100644 (file)
 #import "WebProcessProxy.h"
 #import "_WKFrameHandleInternal.h"
 #import <WebCore/FrameIdentifier.h>
+#import <wtf/HashMap.h>
+#import <wtf/HashSet.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/text/WTFString.h>
 
 @implementation _WKInspector
 
     _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
diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h b/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h
new file mode 100644 (file)
index 0000000..02bd16b
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <WebKit/WKFoundation.h>
+
+@class WKWebView;
+@class _WKInspector;
+
+@protocol _WKInspectorDelegate <NSObject>
+@optional
+
+/*! @abstract Called when a Web Inspector instance is attached to this WKWebView. This is not called in the case of remote inspection.
+    @param inspector The Web Inspector instance attached to this WKWebView.
+ */
+- (void)_webView:(WKWebView *)webView didAttachLocalInspector:(_WKInspector *)inspector;
+
+/*! @abstract Called when the Web Inspector protocol Browser domain is enabled for the Web Inspector instance attached to this WKWebView.
+    @param inspector The Web Inspector instance attached to this WKWebView.
+ */
+- (void)_webView:(WKWebView *)webView browserDomainEnabledForInspector:(_WKInspector *)inspector;
+
+/*! @abstract Called when the Web Inspector protocol Browser domain is disabled for the Web Inspector instance attached to this WKWebView.
+    @param inspector The Web Inspector instance attached to this WKWebView.
+ */
+- (void)_webView:(WKWebView *)webView browserDomainDisabledForInspector:(_WKInspector *)inspector;
+
+@end
index c0d9849..e202af0 100644 (file)
@@ -31,4 +31,8 @@
 
 @property (nonatomic, weak, setter=_setDiagnosticLoggingDelegate:) id<_WKDiagnosticLoggingDelegate> _diagnosticLoggingDelegate;
 
+// Browser
+- (void)_browserExtensionsEnabled:(NSDictionary<NSString *, NSString *> *)extensionIDToName;
+- (void)_browserExtensionsDisabled:(NSSet<NSString *> *)extensionIDs;
+
 @end
index a3593ad..e0d47c8 100644 (file)
@@ -124,7 +124,6 @@ private:
         bool runOpenPanel(WebPageProxy&, WebFrameProxy*, WebCore::SecurityOriginData&&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
         void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
         void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const URL&, API::Data&) final;
-        void didAttachInspector(WebPageProxy&, WebInspectorProxy&) final;
 #endif
 #if ENABLE(DEVICE_ORIENTATION)
         void shouldAllowDeviceOrientationAndMotionAccess(WebKit::WebPageProxy&, WebFrameProxy&, WebCore::SecurityOriginData&&, CompletionHandler<void(bool)>&&) final;
@@ -199,7 +198,6 @@ private:
         bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
         bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
-        bool webViewDidAttachInspector : 1;
 #endif
 #if ENABLE(DEVICE_ORIENTATION)
         bool webViewShouldAllowDeviceOrientationAndMotionAccessRequestedByFrameDecisionHandler : 1;
index a3d0ded..e5fb69d 100644 (file)
 #import "WKWebViewInternal.h"
 #import "WKWindowFeaturesInternal.h"
 #import "WebEventFactory.h"
-#import "WebInspectorProxy.h"
 #import "WebOpenPanelResultListenerProxy.h"
 #import "WebProcessProxy.h"
 #import "_WKContextMenuElementInfo.h"
 #import "_WKFrameHandleInternal.h"
 #import "_WKHitTestResultInternal.h"
-#import "_WKInspectorInternal.h"
 #import "_WKWebAuthenticationPanelInternal.h"
 #import <WebCore/FontAttributes.h>
 #import <WebCore/SecurityOriginData.h>
@@ -133,7 +131,6 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
     m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
     m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
-    m_delegateMethods.webViewDidAttachInspector = [delegate respondsToSelector:@selector(_webView:didAttachInspector:)];
 #endif
 #if ENABLE(DEVICE_ORIENTATION)
     m_delegateMethods.webViewShouldAllowDeviceOrientationAndMotionAccessRequestedByFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:decisionHandler:)];
@@ -848,18 +845,6 @@ bool UIDelegate::UIClient::runOpenPanel(WebPageProxy&, WebFrameProxy* webFramePr
 
     return true;
 }
-
-void UIDelegate::UIClient::didAttachInspector(WebKit::WebPageProxy&, WebKit::WebInspectorProxy& inspector)
-{
-    if (!m_uiDelegate.m_delegateMethods.webViewDidAttachInspector)
-        return;
-
-    auto delegate = m_uiDelegate.m_delegate.get();
-    if (!delegate)
-        return;
-
-    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didAttachInspector:wrapper(inspector)];
-}
 #endif
 
 #if ENABLE(DEVICE_ORIENTATION)
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp b/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.cpp
new file mode 100644 (file)
index 0000000..ab23869
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InspectorBrowserAgent.h"
+
+#include "APIInspectorClient.h"
+#include "WebPageInspectorController.h"
+#include "WebPageProxy.h"
+#include <JavaScriptCore/InspectorProtocolObjects.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+using namespace Inspector;
+
+InspectorBrowserAgent::InspectorBrowserAgent(WebPageAgentContext& context)
+    : InspectorAgentBase("Browser"_s, context)
+    , m_frontendDispatcher(makeUnique<Inspector::BrowserFrontendDispatcher>(context.frontendRouter))
+    , m_backendDispatcher(Inspector::BrowserBackendDispatcher::create(context.backendDispatcher, this))
+    , m_inspectedPage(context.inspectedPage)
+{
+}
+
+InspectorBrowserAgent::~InspectorBrowserAgent() = default;
+
+bool InspectorBrowserAgent::enabled() const
+{
+    return m_inspectedPage.inspectorController().enabledInspectorBrowserAgent() == this;
+}
+
+void InspectorBrowserAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
+{
+}
+
+void InspectorBrowserAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason)
+{
+    ErrorString ignored;
+    disable(ignored);
+}
+
+void InspectorBrowserAgent::enable(ErrorString& errorString)
+{
+    if (enabled()) {
+        errorString = "Browser domain already enabled"_s;
+        return;
+    }
+
+    m_inspectedPage.inspectorController().setEnabledInspectorBrowserAgent(this);
+
+    auto* inspector = m_inspectedPage.inspector();
+    ASSERT(inspector);
+    m_inspectedPage.inspectorClient().browserDomainEnabled(m_inspectedPage, *inspector);
+}
+
+void InspectorBrowserAgent::disable(ErrorString& errorString)
+{
+    if (!enabled()) {
+        errorString = "Browser domain already disabled"_s;
+        return;
+    }
+
+    m_inspectedPage.inspectorController().setEnabledInspectorBrowserAgent(nullptr);
+
+    auto* inspector = m_inspectedPage.inspector();
+    ASSERT(inspector);
+    m_inspectedPage.inspectorClient().browserDomainDisabled(m_inspectedPage, *inspector);
+}
+
+void InspectorBrowserAgent::extensionsEnabled(HashMap<String, String>&& extensionIDToName)
+{
+    ASSERT(enabled());
+
+    auto extensionsPayload = JSON::ArrayOf<Inspector::Protocol::Browser::Extension>::create();
+    for (auto& [id, name] : extensionIDToName) {
+        auto extensionPayload = Inspector::Protocol::Browser::Extension::create()
+            .setExtensionId(id)
+            .setName(name)
+            .release();
+        extensionsPayload->addItem(WTFMove(extensionPayload));
+    }
+    m_frontendDispatcher->extensionsEnabled(WTFMove(extensionsPayload));
+}
+
+void InspectorBrowserAgent::extensionsDisabled(HashSet<String>&& extensionIDs)
+{
+    ASSERT(enabled());
+
+    auto extensionIdsPayload = JSON::ArrayOf<String>::create();
+    for (auto& extensionId : extensionIDs)
+        extensionIdsPayload->addItem(extensionId);
+    m_frontendDispatcher->extensionsDisabled(WTFMove(extensionIdsPayload));
+}
+
+
+} // namespace WebCore
diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorBrowserAgent.h
new file mode 100644 (file)
index 0000000..a139583
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "WebPageInspectorAgentBase.h"
+#include <JavaScriptCore/InspectorBackendDispatchers.h>
+#include <JavaScriptCore/InspectorFrontendDispatchers.h>
+#include <wtf/Forward.h>
+
+namespace WebKit {
+
+class WebPageProxy;
+typedef String ErrorString;
+
+class InspectorBrowserAgent final : public InspectorAgentBase, public Inspector::BrowserBackendDispatcherHandler {
+    WTF_MAKE_NONCOPYABLE(InspectorBrowserAgent);
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    InspectorBrowserAgent(WebPageAgentContext&);
+    ~InspectorBrowserAgent() override;
+    bool enabled() const;
+
+    // InspectorAgentBase
+    void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
+    void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
+
+    // BrowserBackendDispatcherHandler
+    void enable(ErrorString&) override;
+    void disable(ErrorString&) override;
+
+    void extensionsEnabled(HashMap<String, String>&&);
+    void extensionsDisabled(HashSet<String>&&);
+
+private:
+    std::unique_ptr<Inspector::BrowserFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<Inspector::BrowserBackendDispatcher> m_backendDispatcher;
+    WebPageProxy& m_inspectedPage;
+};
+
+} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h b/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h
new file mode 100644 (file)
index 0000000..a5bf7b3
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import "APIInspectorClient.h"
+#import "WKFoundation.h"
+#import <wtf/WeakObjCPtr.h>
+
+@class WKWebView;
+
+@protocol _WKInspectorDelegate;
+
+namespace WebKit {
+
+class WebInspectorProxy;
+class WebPageProxy;
+
+class InspectorDelegate {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit InspectorDelegate(WKWebView *);
+
+    std::unique_ptr<API::InspectorClient> createInspectorClient();
+
+    RetainPtr<id <_WKInspectorDelegate>> delegate();
+    void setDelegate(id <_WKInspectorDelegate>);
+
+private:
+    class InspectorClient : public API::InspectorClient {
+        WTF_MAKE_FAST_ALLOCATED;
+    public:
+        explicit InspectorClient(InspectorDelegate&);
+        ~InspectorClient();
+
+    private:
+        // API::InspectorClient
+        void didAttachLocalInspector(WebPageProxy&, WebInspectorProxy&) override;
+        void browserDomainEnabled(WebPageProxy&, WebInspectorProxy&) override;
+        void browserDomainDisabled(WebPageProxy&, WebInspectorProxy&) override;
+
+        InspectorDelegate& m_inspectorDelegate;
+    };
+
+    WeakObjCPtr<WKWebView> m_webView;
+    WeakObjCPtr<id <_WKInspectorDelegate>> m_delegate;
+
+    struct {
+        unsigned webviewDidAttachInspector : 1;
+        unsigned webViewBrowserDomainEnabledForInspector : 1;
+        unsigned webViewBrowserDomainDisabledForInspector : 1;
+    } m_delegateMethods;
+};
+
+} // namespace WebKit
diff --git a/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm b/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm
new file mode 100644 (file)
index 0000000..fdd0ff4
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "InspectorDelegate.h"
+
+#import "WebInspectorProxy.h"
+#import "WebPageProxy.h"
+#import "_WKInspectorDelegate.h"
+#import "_WKInspectorInternal.h"
+
+namespace WebKit {
+
+InspectorDelegate::InspectorDelegate(WKWebView *webView)
+    : m_webView(webView)
+{
+}
+
+std::unique_ptr<API::InspectorClient> InspectorDelegate::createInspectorClient()
+{
+    return makeUnique<InspectorClient>(*this);
+}
+
+RetainPtr<id <_WKInspectorDelegate>> InspectorDelegate::delegate()
+{
+    return m_delegate.get();
+}
+
+void InspectorDelegate::setDelegate(id <_WKInspectorDelegate> delegate)
+{
+    m_delegate = delegate;
+
+    m_delegateMethods.webviewDidAttachInspector = [delegate respondsToSelector:@selector(_webView:didAttachLocalInspector:)];
+    m_delegateMethods.webViewBrowserDomainEnabledForInspector = [delegate respondsToSelector:@selector(_webView:browserDomainEnabledForInspector:)];
+    m_delegateMethods.webViewBrowserDomainDisabledForInspector = [delegate respondsToSelector:@selector(_webView:browserDomainDisabledForInspector:)];
+}
+
+InspectorDelegate::InspectorClient::InspectorClient(InspectorDelegate& delegate)
+    : m_inspectorDelegate(delegate)
+{
+}
+
+InspectorDelegate::InspectorClient::~InspectorClient() = default;
+
+void InspectorDelegate::InspectorClient::didAttachLocalInspector(WebPageProxy&, WebInspectorProxy& inspector)
+{
+    if (!m_inspectorDelegate.m_delegateMethods.webviewDidAttachInspector)
+        return;
+
+    auto& delegate = m_inspectorDelegate.m_delegate;
+    if (!delegate)
+        return;
+
+    [delegate _webView:m_inspectorDelegate.m_webView.get().get() didAttachLocalInspector:wrapper(inspector)];
+}
+
+void InspectorDelegate::InspectorClient::browserDomainEnabled(WebPageProxy&, WebInspectorProxy& inspector)
+{
+    if (!m_inspectorDelegate.m_delegateMethods.webViewBrowserDomainEnabledForInspector)
+        return;
+
+    auto& delegate = m_inspectorDelegate.m_delegate;
+    if (!delegate)
+        return;
+
+    [delegate _webView:m_inspectorDelegate.m_webView.get().get() browserDomainEnabledForInspector:wrapper(inspector)];
+}
+
+void InspectorDelegate::InspectorClient::browserDomainDisabled(WebPageProxy&, WebInspectorProxy& inspector)
+{
+    if (!m_inspectorDelegate.m_delegateMethods.webViewBrowserDomainDisabledForInspector)
+        return;
+
+    auto& delegate = m_inspectorDelegate.m_delegate;
+    if (!delegate)
+        return;
+
+    [delegate _webView:m_inspectorDelegate.m_webView.get().get() browserDomainDisabledForInspector:wrapper(inspector)];
+}
+
+} // namespace WebKit
index 475bbc4..5772f87 100644 (file)
 #include "config.h"
 #include "WebInspectorProxy.h"
 
+#include "APIInspectorClient.h"
 #include "APINavigation.h"
 #include "APIProcessPoolConfiguration.h"
 #include "APIUIClient.h"
+#include "InspectorBrowserAgent.h"
 #include "WebAutomationSession.h"
 #include "WebFrameProxy.h"
 #include "WebInspectorInterruptDispatcherMessages.h"
 #include <WebCore/MockRealtimeMediaSourceCenter.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/TextEncoding.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
 #include <wtf/SetForScope.h>
+#include <wtf/text/WTFString.h>
 
 #if PLATFORM(GTK)
 #include "WebInspectorProxyClient.h"
@@ -460,7 +465,7 @@ void WebInspectorProxy::openLocalInspectorFrontend(bool canAttach, bool underTes
     }
 
     // Notify WebKit client when a local inspector attaches so that it may install delegates prior to the _WKInspector loading its frontend.
-    m_inspectedPage->uiClient().didAttachInspector(*m_inspectedPage, *this);
+    m_inspectedPage->inspectorClient().didAttachLocalInspector(*m_inspectedPage, *this);
 
     // Bail out if the client closed the inspector from the delegate method.
     if (!m_inspectorPage)
@@ -633,6 +638,18 @@ void WebInspectorProxy::setDiagnosticLoggingAvailable(bool available)
 #endif
 }
 
+void WebInspectorProxy::browserExtensionsEnabled(HashMap<String, String>&& extensionIDToName)
+{
+    if (auto* browserAgent = m_inspectedPage->inspectorController().enabledInspectorBrowserAgent())
+        browserAgent->extensionsEnabled(WTFMove(extensionIDToName));
+}
+
+void WebInspectorProxy::browserExtensionsDisabled(HashSet<String>&& extensionIDs)
+{
+    if (auto* browserAgent = m_inspectedPage->inspectorController().enabledInspectorBrowserAgent())
+        browserAgent->extensionsDisabled(WTFMove(extensionIDs));
+}
+
 void WebInspectorProxy::save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs)
 {
     ASSERT(!filename.isEmpty());
index 2b1fdfc..bbb6f57 100644 (file)
@@ -162,6 +162,10 @@ public:
 
     void setDiagnosticLoggingAvailable(bool);
 
+    // Browser
+    void browserExtensionsEnabled(HashMap<String, String>&&);
+    void browserExtensionsDisabled(HashSet<String>&&);
+
     // Provided by platform WebInspectorProxy implementations.
     static String inspectorPageURL();
     static String inspectorTestPageURL();
diff --git a/Source/WebKit/UIProcess/Inspector/WebPageInspectorAgentBase.h b/Source/WebKit/UIProcess/Inspector/WebPageInspectorAgentBase.h
new file mode 100644 (file)
index 0000000..769de17
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <JavaScriptCore/InspectorAgentBase.h>
+#include <wtf/text/WTFString.h>
+
+namespace Inspector {
+class BackendDispatcher;
+class FrontendRouter;
+}
+
+namespace WebKit {
+
+class WebPageProxy;
+
+// FIXME: move this to Inspector namespace when remaining agents move.
+struct WebPageAgentContext {
+    Inspector::FrontendRouter& frontendRouter;
+    Inspector::BackendDispatcher& backendDispatcher;
+    WebPageProxy& inspectedPage;
+};
+
+class InspectorAgentBase : public Inspector::InspectorAgentBase {
+protected:
+    InspectorAgentBase(const String& name, WebPageAgentContext&)
+        : Inspector::InspectorAgentBase(name)
+    {
+    }
+};
+
+} // namespace WebKit
index 1ee28bf..1861cff 100644 (file)
 #include "config.h"
 #include "WebPageInspectorController.h"
 
+#include "InspectorBrowserAgent.h"
 #include "ProvisionalPageProxy.h"
 #include "WebFrameProxy.h"
+#include "WebPageInspectorAgentBase.h"
 #include "WebPageInspectorTarget.h"
 #include "WebPageProxy.h"
 #include <JavaScriptCore/InspectorAgentBase.h>
@@ -47,14 +49,12 @@ static String getTargetID(const ProvisionalPageProxy& provisionalPage)
 }
 
 WebPageInspectorController::WebPageInspectorController(WebPageProxy& page)
-    : m_page(page)
-    , m_frontendRouter(FrontendRouter::create())
+    : m_frontendRouter(FrontendRouter::create())
     , m_backendDispatcher(BackendDispatcher::create(m_frontendRouter.copyRef()))
+    , m_page(page)
 {
     auto targetAgent = makeUnique<InspectorTargetAgent>(m_frontendRouter.get(), m_backendDispatcher.get());
-
     m_targetAgent = targetAgent.get();
-
     m_agents.append(WTFMove(targetAgent));
 }
 
@@ -78,6 +78,8 @@ bool WebPageInspectorController::hasLocalFrontend() const
 
 void WebPageInspectorController::connectFrontend(Inspector::FrontendChannel& frontendChannel, bool, bool)
 {
+    createLazyAgents();
+
     bool connectingFirstFrontend = !m_frontendRouter->hasFrontends();
 
     m_frontendRouter->connectFrontend(frontendChannel);
@@ -212,6 +214,27 @@ void WebPageInspectorController::didCommitProvisionalPage(WebCore::PageIdentifie
     m_targets.set(newTarget->identifier(), WTFMove(newTarget));
 }
 
+WebPageAgentContext WebPageInspectorController::webPageAgentContext()
+{
+    return {
+        m_frontendRouter.get(),
+        m_backendDispatcher.get(),
+        m_page,
+    };
+}
+
+void WebPageInspectorController::createLazyAgents()
+{
+    if (m_didCreateLazyAgents)
+        return;
+
+    m_didCreateLazyAgents = true;
+
+    auto webPageContext = webPageAgentContext();
+
+    m_agents.append(makeUnique<InspectorBrowserAgent>(webPageContext));
+}
+
 void WebPageInspectorController::addTarget(std::unique_ptr<InspectorTargetProxy>&& target)
 {
     m_targetAgent->targetCreated(*target);
index 78caedf..9ce5ef3 100644 (file)
@@ -41,6 +41,9 @@ class FrontendRouter;
 
 namespace WebKit {
 
+class InspectorBrowserAgent;
+struct WebPageAgentContext;
+
 class WebPageInspectorController {
     WTF_MAKE_NONCOPYABLE(WebPageInspectorController);
     WTF_MAKE_FAST_ALLOCATED;
@@ -73,15 +76,27 @@ public:
     void willDestroyProvisionalPage(const ProvisionalPageProxy&);
     void didCommitProvisionalPage(WebCore::PageIdentifier oldWebPageID, WebCore::PageIdentifier newWebPageID);
 
+    InspectorBrowserAgent* enabledInspectorBrowserAgent() const { return m_enabledInspectorBrowserAgent; }
+    void setEnabledInspectorBrowserAgent(InspectorBrowserAgent* agent) { m_enabledInspectorBrowserAgent = agent; }
+
 private:
+    WebPageAgentContext webPageAgentContext();
+    void createLazyAgents();
+
     void addTarget(std::unique_ptr<InspectorTargetProxy>&&);
 
-    WebPageProxy& m_page;
     Ref<Inspector::FrontendRouter> m_frontendRouter;
     Ref<Inspector::BackendDispatcher> m_backendDispatcher;
     Inspector::AgentRegistry m_agents;
+
+    WebPageProxy& m_page;
+
     Inspector::InspectorTargetAgent* m_targetAgent;
     HashMap<String, std::unique_ptr<InspectorTargetProxy>> m_targets;
+
+    InspectorBrowserAgent* m_enabledInspectorBrowserAgent;
+
+    bool m_didCreateLazyAgents { false };
 };
 
 } // namespace WebKit
index 545ac5f..8a7662c 100644 (file)
 
 OBJC_CLASS LAContext;
 
+namespace WebCore {
+
+class AuthenticatorAssertionResponse;
+
+}
+
 namespace WebKit {
 
 // Local authenticators normally doesn't need to establish connections
index 47230d8..6dcbd02 100644 (file)
@@ -40,6 +40,7 @@
 #include "APIHistoryClient.h"
 #include "APIHitTestResult.h"
 #include "APIIconLoadingClient.h"
+#include "APIInspectorClient.h"
 #include "APILegacyContextHistoryClient.h"
 #include "APILoaderClient.h"
 #include "APINavigation.h"
@@ -440,6 +441,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, Ref
 #if ENABLE(CONTEXT_MENUS)
     , m_contextMenuClient(makeUnique<API::ContextMenuClient>())
 #endif
+    , m_inspectorClient(makeUnique<API::InspectorClient>())
     , m_navigationState(makeUnique<WebNavigationState>())
     , m_process(process)
     , m_pageGroup(*m_configuration->pageGroup())
@@ -672,6 +674,16 @@ void WebPageProxy::setIconLoadingClient(std::unique_ptr<API::IconLoadingClient>&
     send(Messages::WebPage::SetUseIconLoadingClient(hasClient));
 }
 
+void WebPageProxy::setInspectorClient(std::unique_ptr<API::InspectorClient>&& inspectorClient)
+{
+    if (!inspectorClient) {
+        m_inspectorClient = makeUnique<API::InspectorClient>();
+        return;
+    }
+
+    m_inspectorClient = WTFMove(inspectorClient);
+}
+
 void WebPageProxy::setPageLoadStateObserver(std::unique_ptr<PageLoadState::Observer>&& observer)
 {
     if (m_pageLoadStateObserver)
index 9bf63b3..ed1008f 100644 (file)
@@ -177,6 +177,7 @@ class FormClient;
 class FullscreenClient;
 class HistoryClient;
 class IconLoadingClient;
+class InspectorClient;
 class LoaderClient;
 class Navigation;
 class NavigationClient;
@@ -556,6 +557,9 @@ public:
     API::IconLoadingClient& iconLoadingClient() { return *m_iconLoadingClient; }
     void setIconLoadingClient(std::unique_ptr<API::IconLoadingClient>&&);
 
+    API::InspectorClient& inspectorClient() { return *m_inspectorClient; }
+    void setInspectorClient(std::unique_ptr<API::InspectorClient>&&);
+
     void setPageLoadStateObserver(std::unique_ptr<PageLoadState::Observer>&&);
 
     void initializeWebPage();
@@ -2278,6 +2282,7 @@ private:
 #if ENABLE(CONTEXT_MENUS)
     std::unique_ptr<API::ContextMenuClient> m_contextMenuClient;
 #endif
+    std::unique_ptr<API::InspectorClient> m_inspectorClient;
     std::unique_ptr<WebPageInjectedBundleClient> m_injectedBundleClient;
     std::unique_ptr<PageLoadState::Observer> m_pageLoadStateObserver;
 
index 45eccc5..a2c3a43 100644 (file)
                86F9536518FF58F5001DB2EF /* ProcessAssertion.h in Headers */ = {isa = PBXBuildFile; fileRef = 86F9536018FF4FD4001DB2EF /* ProcessAssertion.h */; };
                8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
                909854ED12BC4E18000AD080 /* WebMemorySampler.h in Headers */ = {isa = PBXBuildFile; fileRef = 905620E912BC248B000799B6 /* WebMemorySampler.h */; };
+               9197940223DBC49000257892 /* InspectorDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 9197940023DBC49000257892 /* InspectorDelegate.h */; };
+               9197940523DBC4BB00257892 /* InspectorBrowserAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 9197940323DBC4BB00257892 /* InspectorBrowserAgent.h */; };
+               9197940823DBC4CB00257892 /* WebPageInspectorAgentBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 9197940723DBC4CA00257892 /* WebPageInspectorAgentBase.h */; };
+               9197940A23DBC4E000257892 /* APIInspectorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 9197940923DBC4E000257892 /* APIInspectorClient.h */; };
+               9197940C23DBC50300257892 /* _WKInspectorDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 9197940B23DBC50300257892 /* _WKInspectorDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9321D5861A38EE3C008052BE /* WKImmediateActionController.h in Headers */ = {isa = PBXBuildFile; fileRef = 9321D5851A38EE3C008052BE /* WKImmediateActionController.h */; };
                9321D58A1A38F196008052BE /* WKImmediateActionTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 9321D5891A38F196008052BE /* WKImmediateActionTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9323611E1B015DA800FA9232 /* _WKOverlayScrollbarStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 9323611D1B015DA800FA9232 /* _WKOverlayScrollbarStyle.h */; settings = {ATTRIBUTES = (Private, ); }; };
                905620E512BC2476000799B6 /* WebMemorySampler.mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebMemorySampler.mac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                905620E812BC248B000799B6 /* WebMemorySampler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebMemorySampler.cpp; sourceTree = "<group>"; };
                905620E912BC248B000799B6 /* WebMemorySampler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMemorySampler.h; sourceTree = "<group>"; };
+               919793FF23DBC49000257892 /* InspectorDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InspectorDelegate.mm; sourceTree = "<group>"; };
+               9197940023DBC49000257892 /* InspectorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorDelegate.h; sourceTree = "<group>"; };
+               9197940323DBC4BB00257892 /* InspectorBrowserAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBrowserAgent.h; sourceTree = "<group>"; };
+               9197940423DBC4BB00257892 /* InspectorBrowserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorBrowserAgent.cpp; sourceTree = "<group>"; };
+               9197940723DBC4CA00257892 /* WebPageInspectorAgentBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageInspectorAgentBase.h; sourceTree = "<group>"; };
+               9197940923DBC4E000257892 /* APIInspectorClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIInspectorClient.h; sourceTree = "<group>"; };
+               9197940B23DBC50300257892 /* _WKInspectorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorDelegate.h; sourceTree = "<group>"; };
                9321D5851A38EE3C008052BE /* WKImmediateActionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKImmediateActionController.h; sourceTree = "<group>"; };
                9321D5871A38EE74008052BE /* WKImmediateActionController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKImmediateActionController.mm; sourceTree = "<group>"; };
                9321D5891A38F196008052BE /* WKImmediateActionTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKImmediateActionTypes.h; sourceTree = "<group>"; };
                                991F492D23A812C50054642B /* _WKInspectorDebuggableInfo.h */,
                                991F492E23A812C60054642B /* _WKInspectorDebuggableInfo.mm */,
                                99036AE123A949CE0000B06A /* _WKInspectorDebuggableInfoInternal.h */,
+                               9197940B23DBC50300257892 /* _WKInspectorDelegate.h */,
                                5CAFDE442130843600B1F7E1 /* _WKInspectorInternal.h */,
                                9979CA57237F49F00039EC05 /* _WKInspectorPrivate.h */,
                                A5C0F0AA2000656E00536536 /* _WKInspectorWindow.h */,
                        path = cocoa;
                        sourceTree = "<group>";
                };
+               919793FE23DBC47400257892 /* Cocoa */ = {
+                       isa = PBXGroup;
+                       children = (
+                               9197940023DBC49000257892 /* InspectorDelegate.h */,
+                               919793FF23DBC49000257892 /* InspectorDelegate.mm */,
+                       );
+                       path = Cocoa;
+                       sourceTree = "<group>";
+               };
                91D970D423DA6D250057DBC3 /* Inspector */ = {
                        isa = PBXGroup;
                        children = (
                                91D970D523DA6D500057DBC3 /* Agents */,
+                               919793FE23DBC47400257892 /* Cocoa */,
                                91D970D723DA6D5B0057DBC3 /* ios */,
                                91D970D623DA6D550057DBC3 /* mac */,
                                A5E391FB2183C1E900C8FB31 /* InspectorTargetProxy.cpp */,
                                A55BA8281BA38E1E007CD33D /* WebInspectorUtilities.h */,
                                A5EC6AD22151BD6900677D17 /* WebPageDebuggable.cpp */,
                                A5EC6AD32151BD6900677D17 /* WebPageDebuggable.h */,
+                               9197940723DBC4CA00257892 /* WebPageInspectorAgentBase.h */,
                                A513F53F2154A5CD00662841 /* WebPageInspectorController.cpp */,
                                A513F53E2154A5CC00662841 /* WebPageInspectorController.h */,
                        );
                91D970D523DA6D500057DBC3 /* Agents */ = {
                        isa = PBXGroup;
                        children = (
+                               9197940423DBC4BB00257892 /* InspectorBrowserAgent.cpp */,
+                               9197940323DBC4BB00257892 /* InspectorBrowserAgent.h */,
                        );
                        path = Agents;
                        sourceTree = "<group>";
                                7AB6EA441EEAAE2300037B2B /* APIIconDatabaseClient.h */,
                                5143B2611DDD0DA00014FAC6 /* APIIconLoadingClient.h */,
                                7A8A9D571EF119AA009801AE /* APIInjectedBundleClient.h */,
+                               9197940923DBC4E000257892 /* APIInspectorClient.h */,
                                31B362902141EABC007BFA53 /* APIInternalDebugFeature.cpp */,
                                31B3628E2141EA4D007BFA53 /* APIInternalDebugFeature.h */,
                                7CE4D2061A46775700C7F152 /* APILegacyContextHistoryClient.h */,
                                5CAFDE452130846300B1F7E1 /* _WKInspector.h in Headers */,
                                991F492F23A812C60054642B /* _WKInspectorDebuggableInfo.h in Headers */,
                                99036AE223A949CF0000B06A /* _WKInspectorDebuggableInfoInternal.h in Headers */,
+                               9197940C23DBC50300257892 /* _WKInspectorDelegate.h in Headers */,
                                5CAFDE472130846A00B1F7E1 /* _WKInspectorInternal.h in Headers */,
                                9979CA58237F49F10039EC05 /* _WKInspectorPrivate.h in Headers */,
                                A5C0F0AB2000658200536536 /* _WKInspectorWindow.h in Headers */,
                                7A3ACE1B1EEEF79B00A864A4 /* APIInjectedBundlePageLoaderClient.h in Headers */,
                                7A8A9D5C1EF14598009801AE /* APIInjectedBundlePageResourceLoadClient.h in Headers */,
                                3769079A18F31CB2001DFF04 /* APIInjectedBundlePageUIClient.h in Headers */,
+                               9197940A23DBC4E000257892 /* APIInspectorClient.h in Headers */,
                                31B3628F2141EA5D007BFA53 /* APIInternalDebugFeature.h in Headers */,
                                7CE4D2071A46776100C7F152 /* APILegacyContextHistoryClient.h in Headers */,
                                1A2464F31891E45100234C5B /* APILoaderClient.h in Headers */,
                                BC14DF77120B5B7900826C0C /* InjectedBundleScriptWorld.h in Headers */,
                                2DD45ADE1E5F8972006C355F /* InputViewUpdateDeferrer.h in Headers */,
                                CE550E152283752200D28791 /* InsertTextOptions.h in Headers */,
+                               9197940523DBC4BB00257892 /* InspectorBrowserAgent.h in Headers */,
+                               9197940223DBC49000257892 /* InspectorDelegate.h in Headers */,
                                A5E391FD2183C1F800C8FB31 /* InspectorTargetProxy.h in Headers */,
                                C5BCE5DF1C50766A00CDE3FA /* InteractionInformationAtPosition.h in Headers */,
                                2D4D2C811DF60BF3002EB10C /* InteractionInformationRequest.h in Headers */,
                                BC7B625212A43C9600D174A4 /* WebPageGroupData.h in Headers */,
                                BC7B621512A4219A00D174A4 /* WebPageGroupProxy.h in Headers */,
                                2D9EA30F1A96CBFF002D2807 /* WebPageInjectedBundleClient.h in Headers */,
+                               9197940823DBC4CB00257892 /* WebPageInspectorAgentBase.h in Headers */,
                                A513F5402154A5D700662841 /* WebPageInspectorController.h in Headers */,
                                A543E30C215C8A8D00279CD9 /* WebPageInspectorTarget.h in Headers */,
                                A543E30D215C8A9000279CD9 /* WebPageInspectorTargetController.h in Headers */,
index 73a476a..5560503 100644 (file)
@@ -1,3 +1,28 @@
+2020-02-25  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: safari app extension isolated worlds and injected files use the extension's identifier instead of its name
+        https://bugs.webkit.org/show_bug.cgi?id=206911
+        <rdar://problem/58026635>
+
+        Reviewed by Brian Burg.
+
+        * TestWebKitAPI/Tests/WTF/HashSet.cpp:
+        (TestWebKitAPI::TEST):
+        Add test for `WTF::HashSet::reserveInitialCapacity`.
+
+        * TestWebKitAPI/Tests/WTF/HashMap.cpp:
+        (TestWebKitAPI::TEST):
+        Actually check the value of `WTF::HashMap::capacity`.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/_WKInspectorDelegate.mm: Added.
+        (-[InspectorDelegate _webView:didAttachInspector:])
+        (-[InspectorDelegate _webView:browserDomainEnabledForInspector:])
+        (-[InspectorDelegate _webView:browserDomainDisabledForInspector:])
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (-[InspectorDelegate _webView:didAttachInspector:]): Deleted.
+        (TestWebKitAPI::TEST): Deleted.
+
 2020-02-25  Matt Lewis  <jlewis3@apple.com>
 
         Add checkout_root to stubrepository.py
index 81f52d3..d607d9f 100644 (file)
                8C10AF98206467920018FD90 /* localstorage-empty-string-value.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 8C10AF97206467830018FD90 /* localstorage-empty-string-value.html */; };
                8C10AF99206467A90018FD90 /* LocalStoragePersistence.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8C10AF96206467770018FD90 /* LocalStoragePersistence.mm */; };
                8E4A85371E1D1AB200F53B0F /* GridPosition.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8E4A85361E1D1AA100F53B0F /* GridPosition.cpp */; };
+               912479FA23E269A200C6CEC8 /* _WKInspectorDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 912479F923E269A100C6CEC8 /* _WKInspectorDelegate.mm */; };
                930AD402150698D00067970F /* lots-of-text.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 930AD401150698B30067970F /* lots-of-text.html */; };
                9310CD381EF708FB0050FFE0 /* Function.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9310CD361EF708FB0050FFE0 /* Function.cpp */; };
                931C281D22BC55F2001D98C4 /* WebSQLBasics.mm in Sources */ = {isa = PBXBuildFile; fileRef = 931C281C22BC55A7001D98C4 /* WebSQLBasics.mm */; };
                8C10AF97206467830018FD90 /* localstorage-empty-string-value.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "localstorage-empty-string-value.html"; sourceTree = "<group>"; };
                8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; };
                8E4A85361E1D1AA100F53B0F /* GridPosition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GridPosition.cpp; sourceTree = "<group>"; };
+               912479F923E269A100C6CEC8 /* _WKInspectorDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInspectorDelegate.mm; sourceTree = "<group>"; };
                930AD401150698B30067970F /* lots-of-text.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-text.html"; sourceTree = "<group>"; };
                9310CD361EF708FB0050FFE0 /* Function.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Function.cpp; sourceTree = "<group>"; };
                931C281B22BC5583001D98C4 /* opendatabase-always-exists.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "opendatabase-always-exists.html"; sourceTree = "<group>"; };
                        children = (
                                A16F66B81C40E9E100BD4D24 /* Resources */,
                                5CEAB5DF1FA937CB00A77FAA /* _WKInputDelegate.mm */,
+                               912479F923E269A100C6CEC8 /* _WKInspectorDelegate.mm */,
                                7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */,
                                57C6244D2346BCFA00383FE7 /* _WKWebAuthenticationPanel.mm */,
                                0746645822FF630500E3451A /* AccessibilityTestPlugin.mm */,
                        buildActionMask = 2147483647;
                        files = (
                                5CEAB5E11FA939F400A77FAA /* _WKInputDelegate.mm in Sources */,
+                               912479FA23E269A200C6CEC8 /* _WKInspectorDelegate.mm in Sources */,
                                7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */,
                                57C6244E2346BCFA00383FE7 /* _WKWebAuthenticationPanel.mm in Sources */,
                                7CCE7EE41A411AE600447C4C /* AboutBlankLoad.cpp in Sources */,
index 7bab193..208d965 100644 (file)
@@ -1047,33 +1047,48 @@ TEST(WTF_HashMap, ReserveInitialCapacity)
 {
     HashMap<String, String> map;
     EXPECT_EQ(0u, map.size());
+    EXPECT_EQ(0u, map.capacity());
+
     map.reserveInitialCapacity(9999);
     EXPECT_EQ(0u, map.size());
+    EXPECT_EQ(32768u, map.capacity());
+
     for (int i = 0; i < 9999; ++i)
         map.add(makeString("foo", i), makeString("bar", i));
     EXPECT_EQ(9999u, map.size());
+    EXPECT_EQ(32768u, map.capacity());
     EXPECT_TRUE(map.contains("foo3"_str));
     EXPECT_STREQ("bar3", map.get("foo3"_str).utf8().data());
+
     for (int i = 0; i < 9999; ++i)
         map.add(makeString("excess", i), makeString("baz", i));
     EXPECT_EQ(9999u + 9999u, map.size());
+    EXPECT_EQ(32768u + 32768u, map.capacity());
+
     for (int i = 0; i < 9999; ++i)
         EXPECT_TRUE(map.remove(makeString("foo", i)));
     EXPECT_EQ(9999u, map.size());
+    EXPECT_EQ(32768u, map.capacity());
     EXPECT_STREQ("baz3", map.get("excess3"_str).utf8().data());
+
     for (int i = 0; i < 9999; ++i)
         EXPECT_TRUE(map.remove(makeString("excess", i)));
     EXPECT_EQ(0u, map.size());
-    
+    EXPECT_EQ(8u, map.capacity());
+
     HashMap<String, String> map2;
     map2.reserveInitialCapacity(9999);
     EXPECT_FALSE(map2.remove("foo1"_s));
+
     for (int i = 0; i < 2000; ++i)
         map2.add(makeString("foo", i), makeString("bar", i));
     EXPECT_EQ(2000u, map2.size());
+    EXPECT_EQ(32768u, map2.capacity());
+
     for (int i = 0; i < 2000; ++i)
         EXPECT_TRUE(map2.remove(makeString("foo", i)));
     EXPECT_EQ(0u, map2.size());
+    EXPECT_EQ(8u, map2.capacity());
 }
 
 TEST(WTF_HashMap, Random_IsEvenlyDistributedAfterRemove)
index 498e9ea..4cc247f 100644 (file)
 #include "DeletedAddressOfOperator.h"
 #include "MoveOnly.h"
 #include "RefLogger.h"
+#include "Test.h"
 #include <functional>
 #include <wtf/HashSet.h>
 #include <wtf/RefPtr.h>
+#include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/StringHash.h>
 
 namespace TestWebKitAPI {
 
@@ -506,4 +509,50 @@ TEST(WTF_HashSet, RemoveIfShrinkToBestSize)
     ASSERT_EQ(set1.capacity(), originalCapacity);
 }
 
+TEST(WTF_HashSet, ReserveInitialCapacity)
+{
+    HashSet<String> set;
+    EXPECT_EQ(0u, set.size());
+    EXPECT_EQ(0u, set.capacity());
+
+    set.reserveInitialCapacity(9999);
+    EXPECT_EQ(0u, set.size());
+    EXPECT_EQ(32768u, set.capacity());
+
+    for (int i = 0; i < 9999; ++i)
+        set.add(makeString("foo", i));
+    EXPECT_EQ(9999u, set.size());
+    EXPECT_EQ(32768u, set.capacity());
+    EXPECT_TRUE(set.contains("foo3"_str));
+
+    for (int i = 0; i < 9999; ++i)
+        set.add(makeString("excess", i));
+    EXPECT_EQ(9999u + 9999u, set.size());
+    EXPECT_EQ(32768u + 32768u, set.capacity());
+
+    for (int i = 0; i < 9999; ++i)
+        EXPECT_TRUE(set.remove(makeString("foo", i)));
+    EXPECT_EQ(9999u, set.size());
+    EXPECT_EQ(32768u, set.capacity());
+
+    for (int i = 0; i < 9999; ++i)
+        EXPECT_TRUE(set.remove(makeString("excess", i)));
+    EXPECT_EQ(0u, set.size());
+    EXPECT_EQ(8u, set.capacity());
+
+    HashSet<String> set2;
+    set2.reserveInitialCapacity(9999);
+    EXPECT_FALSE(set2.remove("foo1"_s));
+
+    for (int i = 0; i < 2000; ++i)
+        set2.add(makeString("foo", i));
+    EXPECT_EQ(2000u, set2.size());
+    EXPECT_EQ(32768u, set2.capacity());
+
+    for (int i = 0; i < 2000; ++i)
+        EXPECT_TRUE(set2.remove(makeString("foo", i)));
+    EXPECT_EQ(0u, set2.size());
+    EXPECT_EQ(8u, set2.capacity());
+}
+
 } // namespace TestWebKitAPI
index 0f8b129..82c3358 100644 (file)
@@ -38,7 +38,6 @@
 #import <WebKit/WKUIDelegatePrivate.h>
 #import <WebKit/WKWebViewPrivateForTesting.h>
 #import <WebKit/_WKHitTestResult.h>
-#import <WebKit/_WKInspector.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
 
@@ -900,34 +899,4 @@ TEST(WebKit, DidNotHandleWheelEvent)
 
 #endif // RELIABLE_DID_NOT_HANDLE_WHEEL_EVENT
 
-@interface InspectorDelegate : NSObject <WKUIDelegatePrivate>
-@end
-
-@implementation InspectorDelegate
-
-- (void)_webView:(WKWebView *)webView didAttachInspector:(_WKInspector *)inspector
-{
-    EXPECT_EQ(webView._inspector, inspector);
-    EXPECT_TRUE(webView._hasInspectorFrontend);
-    [inspector close];
-    done = true;
-}
-
-@end
-
-TEST(WebKit, DidNotifyWhenInspectorAttached)
-{
-    auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
-    webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
-    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
-    auto delegate = adoptNS([InspectorDelegate new]);
-    [webView setUIDelegate:delegate.get()];
-    [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
-
-    EXPECT_FALSE(webView.get()._hasInspectorFrontend);
-
-    [[webView _inspector] show];
-    TestWebKitAPI::Util::run(&done);
-}
-
 #endif // PLATFORM(MAC)
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInspectorDelegate.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInspectorDelegate.mm
new file mode 100644 (file)
index 0000000..a4cc3f2
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "Test.h"
+#import "Utilities.h"
+#import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <WebKit/_WKInspector.h>
+#import <WebKit/_WKInspectorDelegate.h>
+#import <wtf/RetainPtr.h>
+
+#if PLATFORM(MAC)
+
+static bool didAttachLocalInspectorCalled = false;
+static bool browserDomainEnabledForInspectorCalled = false;
+static bool browserDomainDisabledForInspectorCalled = false;
+
+@interface InspectorDelegate : NSObject <_WKInspectorDelegate>
+@end
+
+@implementation InspectorDelegate
+
+- (void)_webView:(WKWebView *)webView didAttachLocalInspector:(_WKInspector *)inspector
+{
+    didAttachLocalInspectorCalled = false;
+    browserDomainEnabledForInspectorCalled = false;
+    browserDomainDisabledForInspectorCalled = false;
+
+    EXPECT_EQ(webView._inspector, inspector);
+    EXPECT_TRUE(webView._hasInspectorFrontend);
+
+    didAttachLocalInspectorCalled = true;
+}
+
+- (void)_webView:(WKWebView *)webView browserDomainEnabledForInspector:(_WKInspector *)inspector
+{
+    EXPECT_EQ(webView._inspector, inspector);
+
+    // Wait for the Browser domain to be enabled before closing Web Inspector, which will
+    // automatically disable the domain.
+    [inspector close];
+
+    browserDomainEnabledForInspectorCalled = true;
+}
+
+- (void)_webView:(WKWebView *)webView browserDomainDisabledForInspector:(_WKInspector *)inspector
+{
+    EXPECT_EQ(webView._inspector, inspector);
+
+    browserDomainDisabledForInspectorCalled = true;
+}
+
+@end
+
+TEST(WebKit_WKInspectorDelegate, DidNotifyForLocalInspector)
+{
+    auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
+    webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    auto delegate = adoptNS([InspectorDelegate new]);
+    [webView _setInspectorDelegate:delegate.get()];
+    [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
+
+    EXPECT_FALSE(webView.get()._hasInspectorFrontend);
+
+    [[webView _inspector] show];
+
+    TestWebKitAPI::Util::run(&didAttachLocalInspectorCalled);
+    TestWebKitAPI::Util::run(&browserDomainEnabledForInspectorCalled);
+    TestWebKitAPI::Util::run(&browserDomainDisabledForInspectorCalled);
+}
+
+#endif // PLATFORM(MAC)