[Cocoa] Inspector Extensions: Add _WKInspectorExtension and related plumbing
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Nov 2020 00:03:43 +0000 (00:03 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Nov 2020 00:03:43 +0000 (00:03 +0000)
commitfee9779701b80a418a92aec87ff53ab7588db358
tree54599256489a5bd59f25e59fe619ba5eca3b14ee
parentf6f2fb5a4123124a661908422cb4f5a23b591a58
[Cocoa] Inspector Extensions: Add _WKInspectorExtension and related plumbing
https://bugs.webkit.org/show_bug.cgi?id=217783
<rdar://problem/69968787>

Reviewed by Devin Rousso.

Source/WebCore:

* inspector/InspectorFrontendClient.h:
* inspector/InspectorFrontendClientLocal.h:
In order for WebInspectorUIExtensionController to work with remote and local
inspectors, it stores a weak pointer the inspector's InspectorFrontendClient.
Expose the frontend's page so that the frontend API dispatcher can dispatch to it.

Source/WebInspectorUI:

* UserInterface/Main.html: Add new files.

* UserInterface/Controllers/AppControllerBase.js:
(WI.AppControllerBase):
(WI.AppControllerBase.prototype.get extensionController):
Hang the extension controller off of the global singleton, as there can only be one.

* UserInterface/Controllers/WebInspectorExtensionController.js:
(WI.WebInspectorExtensionController):
(WI.WebInspectorExtensionController.prototype.registerExtension):
(WI.WebInspectorExtensionController.prototype.unregisterExtension):
Added. For now, just keep the UUIDs in a map and log the result.

* UserInterface/Models/WebInspectorExtension.js:
(WI.WebInspectorExtension):
(WI.WebInspectorExtension.prototype.get extensionID):
(WI.WebInspectorExtension.prototype.get displayName):
Added. This is a data object for now.

* UserInterface/Protocol/InspectorFrontendAPI.js:
(InspectorFrontendAPI.loadCompleted):
(InspectorFrontendAPI.registerExtension):
(InspectorFrontendAPI.unregisterExtension):
Added. Forward invocations to the extension controller.

Source/WebKit:

_WKInspectorExtension is new SPI that represents a Web Extension that uses the 'devtools'
API to interact with Web Inspector. An extension is associated with its _WKInspectorExtensionHost.
A WebKit client that supports Web Extensions can use this class to implement 'devtools' extension APIs.

Add _WKInspectorExtensionHost methods to register and unregister an extension.
Add plumbing so that the extension in registered in the frontend with WI.InspectorExtensionController.

Later patches will flesh out the needed functionality to implement rest of the 'devtools' API.

* Sources.txt:
* SourcesCocoa.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* WebKit.xcodeproj/project.pbxproj:
Add new files.

* Scripts/webkit/messages.py: If a message includes InspectorExtensionError,
then generate an include for InspectorExtensionTypes.h where it is declared.

* Shared/API/APIObject.h:
* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):
New API object type.

* Shared/InspectorExtensionTypes.h: Added error code enum and useful type aliases.
* Shared/InspectorExtensionTypes.cpp:
(WebKit::inspectorExtensionErrorToString):

* UIProcess/API/APIInspectorExtension.h:
* UIProcess/API/APIInspectorExtension.cpp:
(API::InspectorExtension::create):
(API::InspectorExtension::InspectorExtension):
(API::InspectorExtension::~InspectorExtension):
Added. This is a placeholder object that's used for the wrapper system,
since we don't have single C++ objects for each extension to back the API object.

* UIProcess/API/Cocoa/_WKInspector.h:
* UIProcess/API/Cocoa/_WKInspector.mm:
(-[_WKInspector registerExtensionWithID:displayName:completionHandler:]):
(-[_WKInspector unregisterExtension:completionHandler:]):
Implement new _WKInspectorExtensionHost methods. Send IPC to the Inspector web process.

* UIProcess/API/Cocoa/_WKInspectorExtension.h:
* UIProcess/API/Cocoa/_WKInspectorExtension.mm:
(-[_WKInspectorExtension initWithIdentifier:]):
(-[_WKInspectorExtension dealloc]):
(-[_WKInspectorExtension _apiObject]):
(-[_WKInspectorExtension extensionID]):
Added. This is a data object that's also used as a token to unregister the extension.

* UIProcess/API/Cocoa/_WKInspectorExtensionHost.h: Add new SPI.
* UIProcess/API/Cocoa/_WKInspectorExtensionInternal.h:

* UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.h:
* UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm:
(-[_WKRemoteWebInspectorViewController registerExtensionWithID:displayName:completionHandler:]):
(-[_WKRemoteWebInspectorViewController unregisterExtension:completionHandler:]):
Implement new _WKInspectorExtensionHost methods. Send IPC to the Inspector web process.

* UIProcess/Inspector/RemoteWebInspectorProxy.h:
* UIProcess/Inspector/RemoteWebInspectorProxy.messages.in: Add FrontendLoaded.
(WebKit::RemoteWebInspectorProxy::extensionController const): Added.
* UIProcess/Inspector/RemoteWebInspectorProxy.cpp:
(WebKit::RemoteWebInspectorProxy::frontendLoaded):
(WebKit::RemoteWebInspectorProxy::createFrontendPageAndWindow):
Set up the extension controller object after the frontend has been created.
Hook up the FrontendLoaded event sent from Inspector web process so that the
extension controller can be notified of when it's safe to message the frontend.

* UIProcess/Inspector/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::createFrontendPage):
(WebKit::WebInspectorProxy::closeFrontendPageAndWindow):
(WebKit::WebInspectorProxy::frontendLoaded):
Set up the extension controller object after the frontend has been created.

* UIProcess/Inspector/WebInspectorProxy.h:
(WebKit::WebInspectorProxy::extensionController const): Added.

* UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h:
* UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp: Added.
(WebKit::WebInspectorUIExtensionControllerProxy::WebInspectorUIExtensionControllerProxy):
(WebKit::WebInspectorUIExtensionControllerProxy::~WebInspectorUIExtensionControllerProxy):
(WebKit::WebInspectorUIExtensionControllerProxy::whenFrontendHasLoaded):
(WebKit::WebInspectorUIExtensionControllerProxy::inspectorFrontendLoaded):
(WebKit::WebInspectorUIExtensionControllerProxy::registerExtension):
(WebKit::WebInspectorUIExtensionControllerProxy::unregisterExtension):
Added. Forward API requests to the Web Inspector's web process to be evaluated in the frontend.

* WebProcess/Inspector/WebInspectorFrontendAPIDispatcher.h:
* WebProcess/Inspector/WebInspectorFrontendAPIDispatcher.cpp:
(WebKit::WebInspectorFrontendAPIDispatcher::dispatchCommand):
Add a more generic way to encode values to be passed as arguments to InspectorFrontendAPI.dispatch.

* WebProcess/Inspector/WebInspectorUI.cpp:
(WebKit::WebInspectorUI::establishConnection):
(WebKit::WebInspectorUI::closeWindow):
* WebProcess/Inspector/WebInspectorUI.h:
(WebKit::WebInspectorUI::frontendPage const): Added.
(WebKit::WebInspectorUI::frontendAPIDispatcher): Added.

* WebProcess/Inspector/WebInspectorUIExtensionController.h:
* WebProcess/Inspector/WebInspectorUIExtensionController.messages.in: Added.
* WebProcess/Inspector/WebInspectorUIExtensionController.cpp: Added.
(WebKit::WebInspectorUIExtensionController::WebInspectorUIExtensionController):
(WebKit::WebInspectorUIExtensionController::~WebInspectorUIExtensionController):
(WebKit::WebInspectorUIExtensionController::registerExtension):
(WebKit::WebInspectorUIExtensionController::unregisterExtension):
(WebKit::WebInspectorUIExtensionController::parseInspectorExtensionErrorFromResult):
Handle incoming messages by forwarding the associated command to WI.WebExtensionController
via InspectorFrontendAPI evaluations.

* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
Fallout from unified build chunking shifts.

* UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
(WebKit::LocalAuthenticatorInternal::getExistingCredentials):
(WebKit::LocalAuthenticator::continueMakeCredentialAfterUserVerification):
Fallout from unified build chunking shifts, but more.

Tools:

Add API tests to exercise new methods of the _WKInspectorExtensionHost protocol.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: New test file.
* TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionHost.mm: Added.
(resetGlobalState):
(-[UIDelegateForTestingInspectorExtensionHost _webView:didAttachLocalInspector:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269486 268f45cc-cd09-0410-ab3c-d52691b4dbfc
49 files changed:
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorFrontendClient.h
Source/WebCore/inspector/InspectorFrontendClientLocal.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/AppControllerBase.js
Source/WebInspectorUI/UserInterface/Controllers/WebInspectorExtensionController.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Main.html
Source/WebInspectorUI/UserInterface/Models/WebInspectorExtension.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js
Source/WebInspectorUI/UserInterface/Test.html
Source/WebKit/ChangeLog
Source/WebKit/DerivedSources-input.xcfilelist
Source/WebKit/DerivedSources-output.xcfilelist
Source/WebKit/DerivedSources.make
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/Shared/API/APIObject.h
Source/WebKit/Shared/Cocoa/APIObject.mm
Source/WebKit/Shared/InspectorExtensionTypes.cpp [new file with mode: 0644]
Source/WebKit/Shared/InspectorExtensionTypes.h [new file with mode: 0644]
Source/WebKit/Sources.txt
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/API/APIInspectorExtension.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKInspector.h
Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtension.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtension.mm [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtensionHost.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtensionInternal.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.h
Source/WebKit/UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm
Source/WebKit/UIProcess/Inspector/RemoteWebInspectorProxy.cpp
Source/WebKit/UIProcess/Inspector/RemoteWebInspectorProxy.h
Source/WebKit/UIProcess/Inspector/RemoteWebInspectorProxy.messages.in
Source/WebKit/UIProcess/Inspector/WebInspectorProxy.cpp
Source/WebKit/UIProcess/Inspector/WebInspectorProxy.h
Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h [new file with mode: 0644]
Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp
Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h
Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp
Source/WebKit/WebProcess/Inspector/WebInspectorUI.h
Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.h [new file with mode: 0644]
Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.messages.in [new file with mode: 0644]
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionHost.mm [new file with mode: 0644]