⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 270606 in webkit


Ignore:
Timestamp:
Dec 9, 2020, 3:08:25 PM (6 years ago)
Author:
BJ Burg
Message:

[Cocoa] Web Inspector: add support for creating extension tabs in WebInspectorUI via _WKInspectorExtension
https://bugs.webkit.org/show_bug.cgi?id=219380

Reviewed by Devin Rousso and Timothy Hatcher.

Source/WebInspectorUI:

  • UserInterface/Controllers/WebInspectorExtensionController.js:

(WI.WebInspectorExtensionController):
(WI.WebInspectorExtensionController.prototype._makeNextExtensionTabID):
(WI.WebInspectorExtensionController.prototype.unregisterExtension):
(WI.WebInspectorExtensionController.prototype.createTabForExtension):

  • UserInterface/Main.html:
  • UserInterface/Protocol/InspectorFrontendAPI.js:

(InspectorFrontendAPI.createTabForExtension):

  • UserInterface/Views/GeneralTabBarItem.js:

(WI.GeneralTabBarItem.fromTabContentView):
(WI.GeneralTabBarItem.get displayName): Deleted.

  • UserInterface/Views/PinnedTabBarItem.js:

(WI.PinnedTabBarItem.fromTabContentView):
(WI.PinnedTabBarItem):

  • UserInterface/Views/TabContentView.js:

(WI.TabContentView.prototype.get tabBarItem):
(WI.TabContentView.prototype.tabInfo):
(WI.TabContentView.prototype.get managesNavigationSidebarPanel): Deleted.
(WI.TabContentView.prototype.attached): Deleted.

  • UserInterface/Views/WebInspectorExtensionTabContentView.css: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtension.h.

(.content-view.web-inspector-extension-tab > iframe):

  • UserInterface/Views/WebInspectorExtensionTabContentView.js: Copied from Source/WebKit/UIProcess/API/APIInspectorExtension.h.

(WI.WebInspectorExtensionTabContentView):
(WI.WebInspectorExtensionTabContentView.prototype.tabInfo):
(WI.WebInspectorExtensionTabContentView.prototype.get type):
(WI.WebInspectorExtensionTabContentView.prototype.get supportsSplitContentBrowser):
(WI.WebInspectorExtensionTabContentView.prototype.get extensionTabID):
(WI.WebInspectorExtensionTabContentView.prototype.initialLayout):

Source/WebKit:

Add a new method to _WKInspectorExtension for creating an extension tab in WebInpectorUI.
This can be used to implement browser.devtools.panels.create() as provided by the Web Extensions API.

  • Platform/Logging.h: Add Inspector channel for error logging.
  • Shared/InspectorExtensionTypes.h: Add a missing EnumTraits case.
  • WebKit.xcodeproj/project.pbxproj:
  • Sources.txt: Add files.
  • UIProcess/API/APIInspectorExtension.h:
  • UIProcess/API/APIInspectorExtension.cpp:

(API::InspectorExtension::InspectorExtension):
(API::InspectorExtension::create):
(API::InspectorExtension::createTab):
Inspector extensions need to be able to invoke commands in the WebProcess-side
extension proxy controller, so keep a WeakRef to the extension controller that
created the extension object. Also, implement the new API by forwarding it on.

  • UIProcess/API/Cocoa/_WKInspector.mm:

(-[_WKInspector registerExtensionWithID:displayName:completionHandler:]):
Adapt to the new constructor as explained above.

  • UIProcess/API/Cocoa/_WKInspectorExtensionInternal.h:

Expose member m_remoteInspectorPorxy for use in the API::InspectorExtension constructor.

  • UIProcess/API/Cocoa/_WKInspectorExtension.h:
  • UIProcess/API/Cocoa/_WKInspectorExtension.mm:

(-[_WKInspectorExtension initWithIdentifier:]): Deleted.

(-[_WKInspectorExtension createTabWithName:tabIconURL:sourceURL:completionHandler:]):
Implement new API.

  • UIProcess/API/Cocoa/_WKRemoteWebInspectorViewControllerInternal.h: Added.

Make the RefPtr<RemoteWebInspectorProxy> member variable accessible to the API object constructor.

  • UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm:

(-[_WKRemoteWebInspectorViewController registerExtensionWithID:displayName:completionHandler:]):
Adapt to new constructor as explained above.

  • UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h:
  • UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp:

(WebKit::WebInspectorUIExtensionControllerProxy::createTabForExtension):
Forward the request to the inspector frontend WebProcess.

  • WebProcess/Inspector/WebInspectorUIExtensionController.messages.in:

Add a new async IPC command for creating a new inspector extension tab.

  • WebProcess/Inspector/WebInspectorUIExtensionController.h:
  • WebProcess/Inspector/WebInspectorUIExtensionController.cpp:

(WebKit::WebInspectorUIExtensionController::unwrapEvaluationResultAsObject):
Added. Pull out the code needed for error-handling this common operation.

(WebKit::WebInspectorUIExtensionController::createTabForExtension):
Added. Call into InspectorFrontendAPI to request a new tab. Turn the result
into an InspectorExtensionError or InspectorExtensionTabID and send the IPC reply.

  • UIProcess/RemoteLayerTree/mac/ScrollingTreeOverflowScrollingNodeRemoteMac.h:

Fix unified sources fallout.

Location:
trunk/Source
Files:
24 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r270604 r270606  
     12020-11-30  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Inspector: add support for creating extension tabs in WebInspectorUI via _WKInspectorExtension
     4        https://bugs.webkit.org/show_bug.cgi?id=219380
     5
     6        Reviewed by Devin Rousso and Timothy Hatcher.
     7
     8        * UserInterface/Controllers/WebInspectorExtensionController.js:
     9        (WI.WebInspectorExtensionController):
     10        (WI.WebInspectorExtensionController.prototype._makeNextExtensionTabID):
     11        (WI.WebInspectorExtensionController.prototype.unregisterExtension):
     12        (WI.WebInspectorExtensionController.prototype.createTabForExtension):
     13        * UserInterface/Main.html:
     14        * UserInterface/Protocol/InspectorFrontendAPI.js:
     15        (InspectorFrontendAPI.createTabForExtension):
     16        * UserInterface/Views/GeneralTabBarItem.js:
     17        (WI.GeneralTabBarItem.fromTabContentView):
     18        (WI.GeneralTabBarItem.get displayName): Deleted.
     19        * UserInterface/Views/PinnedTabBarItem.js:
     20        (WI.PinnedTabBarItem.fromTabContentView):
     21        (WI.PinnedTabBarItem):
     22        * UserInterface/Views/TabContentView.js:
     23        (WI.TabContentView.prototype.get tabBarItem):
     24        (WI.TabContentView.prototype.tabInfo):
     25        (WI.TabContentView.prototype.get managesNavigationSidebarPanel): Deleted.
     26        (WI.TabContentView.prototype.attached): Deleted.
     27        * UserInterface/Views/WebInspectorExtensionTabContentView.css: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtension.h.
     28        (.content-view.web-inspector-extension-tab > iframe):
     29        * UserInterface/Views/WebInspectorExtensionTabContentView.js: Copied from Source/WebKit/UIProcess/API/APIInspectorExtension.h.
     30        (WI.WebInspectorExtensionTabContentView):
     31        (WI.WebInspectorExtensionTabContentView.prototype.tabInfo):
     32        (WI.WebInspectorExtensionTabContentView.prototype.get type):
     33        (WI.WebInspectorExtensionTabContentView.prototype.get supportsSplitContentBrowser):
     34        (WI.WebInspectorExtensionTabContentView.prototype.get extensionTabID):
     35        (WI.WebInspectorExtensionTabContentView.prototype.initialLayout):
     36
    1372020-12-09  Devin Rousso  <drousso@apple.com>
    238
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/WebInspectorExtensionController.js

    r269701 r270606  
    3030        super();
    3131
    32         this._extensionIDMap = new Map;
     32        this._extensionForExtensionIDMap = new Map;
     33        this._extensionTabContentViewForExtensionTabIDMap = new Map;
     34        this._tabIDsForExtensionIDMap = new Multimap;
     35        this._nextExtensionTabID = 1;
    3336    }
    3437
     
    3740    registerExtension(extensionID, displayName)
    3841    {
    39         if (this._extensionIDMap.has(extensionID)) {
    40             WI.reportInternalError("Unable to register extension, it's already registered: ", extensionID, displayName);
     42        if (this._extensionForExtensionIDMap.has(extensionID)) {
     43            WI.reportInternalError("Unable to register extension, it's already registered: " + extensionID);
    4144            return WI.WebInspectorExtension.ErrorCode.RegistrationFailed;
    4245        }
    4346
    4447        let extension = new WI.WebInspectorExtension(extensionID, displayName);
    45         this._extensionIDMap.set(extensionID, extension);
     48        this._extensionForExtensionIDMap.set(extensionID, extension);
    4649
    4750        this.dispatchEventToListeners(WI.WebInspectorExtensionController.Event.ExtensionAdded, {extension});
     
    5053    unregisterExtension(extensionID)
    5154    {
    52         let extension = this._extensionIDMap.take(extensionID);
     55        let extension = this._extensionForExtensionIDMap.take(extensionID);
    5356        if (!extension) {
    54             WI.reportInternalError("Unable to unregister extension with unknown ID: ", extensionID);
     57            WI.reportInternalError("Unable to unregister extension with unknown ID: " + extensionID);
    5558            return WI.WebInspectorExtension.ErrorCode.InvalidRequest;
    5659        }
    5760
     61        let extensionTabIDsToRemove = this._tabIDsForExtensionIDMap.take(extensionID) || [];
     62        for (let extensionTabID of extensionTabIDsToRemove) {
     63            let tabContentView = this._extensionTabContentViewForExtensionTabIDMap.take(extensionTabID);
     64            WI.tabBrowser.closeTabForContentView(tabContentView);
     65        }
     66
    5867        this.dispatchEventToListeners(WI.WebInspectorExtensionController.Event.ExtensionRemoved, {extension});
     68    }
     69
     70    createTabForExtension(extensionID, tabName, tabIconURL, sourceURL)
     71    {
     72        let extension = this._extensionForExtensionIDMap.get(extensionID);
     73        if (!extension) {
     74            WI.reportInternalError("Unable to create tab for extension with unknown ID: " + extensionID + " sourceURL: " + sourceURL);
     75            return WI.WebInspectorExtension.ErrorCode.InvalidRequest;
     76        }
     77
     78        let extensionTabID = `WebExtensionTab-${extensionID}-${this._nextExtensionTabID++}`;
     79        let tabContentView = new WI.WebInspectorExtensionTabContentView(extension, extensionTabID, tabName, tabIconURL, sourceURL);
     80
     81        this._tabIDsForExtensionIDMap.add(extensionID, extensionTabID);
     82        this._extensionTabContentViewForExtensionTabIDMap.set(extensionTabID, tabContentView);
     83        WI.tabBrowser.addTabForContentView(tabContentView);
     84
     85        // The calling convention is to return an error string or a result object.
     86        return {extensionTabID};
    5987    }
    6088};
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r270604 r270606  
    248248    <link rel="stylesheet" href="Views/URLBreakpointTreeElement.css">
    249249    <link rel="stylesheet" href="Views/Variables.css">
     250    <link rel="stylesheet" href="Views/WebInspectorExtensionTabContentView.css">
    250251    <link rel="stylesheet" href="Views/WebSocketContentView.css">
    251252
     
    584585    <script src="Views/StorageTabContentView.js"></script>
    585586    <script src="Views/TimelineTabContentView.js"></script>
     587    <script src="Views/WebInspectorExtensionTabContentView.js"></script>
    586588
    587589    <script src="Views/DetailsSection.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js

    r269701 r270606  
    210210        return WI.sharedApp.extensionController.unregisterExtension(extensionID);
    211211    },
     212
     213    // Returns a WI.WebInspectorExtension.ErrorCode if an error occurred, otherwise an object
     214    // with an 'inspectorExtensionID' key representing the tab identifier for the newly created tab.
     215    createTabForExtension(extensionID, tabName, tabIconURL, sourceURL)
     216    {
     217        return WI.sharedApp.extensionController.createTabForExtension(extensionID, tabName, tabIconURL, sourceURL);
     218    },
    212219};
  • trunk/Source/WebInspectorUI/UserInterface/Views/GeneralTabBarItem.js

    r259101 r270606  
    3333        console.assert(tabContentView instanceof WI.TabContentView);
    3434
    35         let {image, displayName, title} = tabContentView.constructor.tabInfo();
     35        let {image, displayName, title} = tabContentView.tabInfo();
    3636        return new WI.GeneralTabBarItem(tabContentView, image, displayName, title);
    3737    }
  • trunk/Source/WebInspectorUI/UserInterface/Views/PinnedTabBarItem.js

    r259101 r270606  
    3939        console.assert(tabContentView instanceof WI.TabContentView);
    4040
    41         let {image, displayName, title} = tabContentView.constructor.tabInfo();
     41        let {image, displayName, title} = tabContentView.tabInfo();
    4242        return new WI.PinnedTabBarItem(tabContentView, image, displayName, title);
    4343    }
  • trunk/Source/WebInspectorUI/UserInterface/Views/TabContentView.js

    r270134 r270606  
    3434
    3535        this._identifier = tabInfo.identifier;
    36         this._tabBarItem = this.constructor.shouldPinTab() ? WI.PinnedTabBarItem.fromTabContentView(this) : WI.GeneralTabBarItem.fromTabContentView(this);
    3736        this._navigationSidebarPanelConstructor = navigationSidebarPanelConstructor || null;
    3837        this._detailsSidebarPanelConstructors = detailsSidebarPanelConstructors || [];
     
    8382    get tabBarItem()
    8483    {
     84        // This is created lazily to break a dependency cycle for dynamically-created TabContentViews.
     85        // TabContentViews with a non-static tabInfo() must be fully constructed before calling tabInfo().
     86        if (!this._tabBarItem)
     87            this._tabBarItem = this.constructor.shouldPinTab() ? WI.PinnedTabBarItem.fromTabContentView(this) : WI.GeneralTabBarItem.fromTabContentView(this);
     88
    8589        return this._tabBarItem;
    8690    }
     
    124128        // Can be overridden by subclasses.
    125129        return false;
     130    }
     131
     132    tabInfo()
     133    {
     134        // Can be overridden by subclasses.
     135        return this.constructor.tabInfo();
    126136    }
    127137
  • trunk/Source/WebInspectorUI/UserInterface/Views/WebInspectorExtensionTabContentView.css

    r270605 r270606  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import <Foundation/Foundation.h>
    27 #import <WebKit/WKFoundation.h>
     26.content-view.tab.web-inspector-extension > iframe {
     27    border: 0;
    2828
    29 NS_ASSUME_NONNULL_BEGIN
     29    position: absolute;
     30    top: 0;
     31    left: 0;
     32    right: 0;
     33    bottom: 0;
    3034
    31 WK_CLASS_AVAILABLE(macos(WK_MAC_TBA))
    32 @interface _WKInspectorExtension : NSObject
    33 
    34 - (instancetype)init NS_UNAVAILABLE;
    35 
    36 @property (readonly, nonatomic) NSString *extensionID;
    37 
    38 @end
    39 
    40 NS_ASSUME_NONNULL_END
     35    /* This is required for the iframe to expand if its intrinsic size */
     36    /* is smaller than the tab content view. */
     37    width: 100%;
     38    height: 100%;
     39}
  • trunk/Source/WebInspectorUI/UserInterface/Views/WebInspectorExtensionTabContentView.js

    r270605 r270606  
    2424 */
    2525
    26 #pragma once
     26WI.WebInspectorExtensionTabContentView = class WebInspectorExtensionTabContentView extends WI.TabContentView
     27{
     28    constructor(extension, extensionTabID, tabLabel, iconURL, sourceURL)
     29    {
     30        let tabInfo = {
     31            identifier: WI.WebInspectorExtensionTabContentView.Type,
     32            image: iconURL,
     33            displayName: tabLabel,
     34            title: tabLabel,
     35        };
     36        super(tabInfo);
    2737
    28 #if ENABLE(INSPECTOR_EXTENSIONS)
    29 
    30 #include "APIObject.h"
    31 #include <wtf/Forward.h>
    32 
    33 namespace API {
    34 
    35 class InspectorExtension final : public API::ObjectImpl<Object::Type::InspectorExtension> {
    36 public:
    37     static Ref<InspectorExtension> create(const WTF::String& identifier)
    38     {
    39         return adoptRef(*new InspectorExtension(identifier));
     38        this._extension = extension;
     39        this._extensionTabID = extensionTabID;
     40        this._tabInfo = tabInfo;
     41        this._sourceURL = sourceURL;
    4042    }
    4143
    42     explicit InspectorExtension(const WTF::String& identifier)
    43         : m_identifier(identifier)
     44    // Public
     45
     46    get extensionTabID() { return this._extensionTabID; }
     47
     48    get type()
    4449    {
     50        return WI.WebInspectorExtensionTabContentView.Type;
    4551    }
    4652
    47     const WTF::String& identifier() const { return m_identifier; }
     53    get supportsSplitContentBrowser()
     54    {
     55        return true;
     56    }
    4857
    49 private:
    50     WTF::String m_identifier;
     58    tabInfo()
     59    {
     60        return this._tabInfo;
     61    }
     62
     63    static shouldSaveTab() { return false; }
     64
     65    // Protected
     66
     67    initialLayout()
     68    {
     69        super.initialLayout();
     70
     71        let iframeElement = this.element.appendChild(document.createElement("iframe"));
     72        iframeElement.src = this._sourceURL;
     73    }
    5174};
    5275
    53 } // namespace API
    54 
    55 #endif // ENABLE(INSPECTOR_EXTENSIONS)
     76WI.WebInspectorExtensionTabContentView.Type = "web-inspector-extension";
  • trunk/Source/WebKit/ChangeLog

    r270605 r270606  
     12020-11-30  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Inspector: add support for creating extension tabs in WebInspectorUI via _WKInspectorExtension
     4        https://bugs.webkit.org/show_bug.cgi?id=219380
     5
     6        Reviewed by Devin Rousso and Timothy Hatcher.
     7
     8        Add a new method to _WKInspectorExtension for creating an extension tab in WebInpectorUI.
     9        This can be used to implement browser.devtools.panels.create() as provided by the Web Extensions API.
     10
     11        * Platform/Logging.h: Add Inspector channel for error logging.
     12        * Shared/InspectorExtensionTypes.h: Add a missing EnumTraits case.
     13        * WebKit.xcodeproj/project.pbxproj:
     14        * Sources.txt: Add files.
     15
     16        * UIProcess/API/APIInspectorExtension.h:
     17        * UIProcess/API/APIInspectorExtension.cpp:
     18        (API::InspectorExtension::InspectorExtension):
     19        (API::InspectorExtension::create):
     20        (API::InspectorExtension::createTab):
     21        Inspector extensions need to be able to invoke commands in the WebProcess-side
     22        extension proxy controller, so keep a WeakRef to the extension controller that
     23        created the extension object. Also, implement the new API by forwarding it on.
     24
     25        * UIProcess/API/Cocoa/_WKInspector.mm:
     26        (-[_WKInspector registerExtensionWithID:displayName:completionHandler:]):
     27        Adapt to the new constructor as explained above.
     28
     29        * UIProcess/API/Cocoa/_WKInspectorExtensionInternal.h:
     30        Expose member m_remoteInspectorPorxy for use in the API::InspectorExtension constructor.
     31
     32        * UIProcess/API/Cocoa/_WKInspectorExtension.h:
     33        * UIProcess/API/Cocoa/_WKInspectorExtension.mm:
     34        (-[_WKInspectorExtension initWithIdentifier:]): Deleted.
     35
     36        (-[_WKInspectorExtension createTabWithName:tabIconURL:sourceURL:completionHandler:]):
     37        Implement new API.
     38
     39        * UIProcess/API/Cocoa/_WKRemoteWebInspectorViewControllerInternal.h: Added.
     40        Make the RefPtr<RemoteWebInspectorProxy> member variable accessible to the API object constructor.
     41
     42        * UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm:
     43        (-[_WKRemoteWebInspectorViewController registerExtensionWithID:displayName:completionHandler:]):
     44        Adapt to new constructor as explained above.
     45
     46        * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h:
     47        * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp:
     48        (WebKit::WebInspectorUIExtensionControllerProxy::createTabForExtension):
     49        Forward the request to the inspector frontend WebProcess.
     50
     51        * WebProcess/Inspector/WebInspectorUIExtensionController.messages.in:
     52        Add a new async IPC command for creating a new inspector extension tab.
     53
     54        * WebProcess/Inspector/WebInspectorUIExtensionController.h:
     55        * WebProcess/Inspector/WebInspectorUIExtensionController.cpp:
     56        (WebKit::WebInspectorUIExtensionController::unwrapEvaluationResultAsObject):
     57        Added. Pull out the code needed for error-handling this common operation.
     58
     59        (WebKit::WebInspectorUIExtensionController::createTabForExtension):
     60        Added. Call into InspectorFrontendAPI to request a new tab. Turn the result
     61        into an InspectorExtensionError or InspectorExtensionTabID and send the IPC reply.
     62
     63        * UIProcess/RemoteLayerTree/mac/ScrollingTreeOverflowScrollingNodeRemoteMac.h:
     64        Fix unified sources fallout.
     65
    1662020-12-09  Said Abou-Hallawa  <said@apple.com>
    267
  • trunk/Source/WebKit/Platform/Logging.h

    r270453 r270606  
    6161    M(IncrementalPDF) \
    6262    M(IncrementalPDFVerbose) \
     63    M(IndexedDB) \
    6364    M(Inspector) \
    64     M(IndexedDB) \
    6565    M(KeyHandling) \
    6666    M(Layers) \
  • trunk/Source/WebKit/Shared/InspectorExtensionTypes.h

    r269701 r270606  
    5151    using values = EnumValues<
    5252        WebKit::InspectorExtensionError,
     53        WebKit::InspectorExtensionError::ContextDestroyed,
     54        WebKit::InspectorExtensionError::InternalError,
    5355        WebKit::InspectorExtensionError::InvalidRequest,
    54         WebKit::InspectorExtensionError::ContextDestroyed,
    5556        WebKit::InspectorExtensionError::RegistrationFailed
    5657    >;
  • trunk/Source/WebKit/Sources.txt

    r270587 r270606  
    354354UIProcess/API/APIHitTestResult.cpp
    355355UIProcess/API/APIInspectorConfiguration.cpp
     356UIProcess/API/APIInspectorExtension.cpp
    356357UIProcess/API/APIInternalDebugFeature.cpp
    357358UIProcess/API/APINavigation.cpp
  • trunk/Source/WebKit/UIProcess/API/APIInspectorExtension.cpp

    r270605 r270606  
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "APIInspectorExtension.h"
    2728
    2829#if ENABLE(INSPECTOR_EXTENSIONS)
    2930
    30 #include "APIObject.h"
    31 #include <wtf/Forward.h>
     31#include "InspectorExtensionTypes.h"
     32#include "WebInspectorUIExtensionControllerProxy.h"
    3233
    3334namespace API {
    3435
    35 class InspectorExtension final : public API::ObjectImpl<Object::Type::InspectorExtension> {
    36 public:
    37     static Ref<InspectorExtension> create(const WTF::String& identifier)
    38     {
    39         return adoptRef(*new InspectorExtension(identifier));
     36InspectorExtension::InspectorExtension(const WTF::String& identifier, WebKit::WebInspectorUIExtensionControllerProxy& extensionControllerProxy)
     37    : m_identifier(identifier)
     38    , m_extensionControllerProxy(makeWeakPtr(extensionControllerProxy))
     39{
     40}
     41
     42Ref<InspectorExtension> InspectorExtension::create(const WTF::String& identifier, WebKit::WebInspectorUIExtensionControllerProxy& extensionControllerProxy)
     43{
     44    return adoptRef(*new InspectorExtension(identifier, extensionControllerProxy));
     45}
     46
     47void InspectorExtension::createTab(const WTF::String& tabName, const WTF::URL& tabIconURL, const WTF::URL& sourceURL, WTF::CompletionHandler<void(Expected<WebKit::InspectorExtensionTabID, WebKit::InspectorExtensionError>)>&& completionHandler)
     48{
     49    if (!m_extensionControllerProxy) {
     50        completionHandler(makeUnexpected(WebKit::InspectorExtensionError::ContextDestroyed));
     51        return;
    4052    }
    4153
    42     explicit InspectorExtension(const WTF::String& identifier)
    43         : m_identifier(identifier)
    44     {
    45     }
    46 
    47     const WTF::String& identifier() const { return m_identifier; }
    48 
    49 private:
    50     WTF::String m_identifier;
    51 };
     54    m_extensionControllerProxy->createTabForExtension(m_identifier, tabName, tabIconURL, sourceURL, WTFMove(completionHandler));
     55}
    5256
    5357} // namespace API
  • trunk/Source/WebKit/UIProcess/API/APIInspectorExtension.h

    r269701 r270606  
    2929
    3030#include "APIObject.h"
     31#include "InspectorExtensionTypes.h"
     32#include <wtf/CompletionHandler.h>
    3133#include <wtf/Forward.h>
     34#include <wtf/WeakPtr.h>
     35#include <wtf/text/WTFString.h>
     36
     37namespace WebKit {
     38class WebInspectorUIExtensionControllerProxy;
     39}
    3240
    3341namespace API {
     
    3543class InspectorExtension final : public API::ObjectImpl<Object::Type::InspectorExtension> {
    3644public:
    37     static Ref<InspectorExtension> create(const WTF::String& identifier)
    38     {
    39         return adoptRef(*new InspectorExtension(identifier));
    40     }
    41 
    42     explicit InspectorExtension(const WTF::String& identifier)
    43         : m_identifier(identifier)
    44     {
    45     }
     45    static Ref<InspectorExtension> create(const WTF::String& identifier, WebKit::WebInspectorUIExtensionControllerProxy&);
    4646
    4747    const WTF::String& identifier() const { return m_identifier; }
    4848
     49    void createTab(const WTF::String& tabName, const WTF::URL& tabIconURL, const WTF::URL& sourceURL, WTF::CompletionHandler<void(Expected<WebKit::InspectorExtensionTabID, WebKit::InspectorExtensionError>)>&&);
     50
    4951private:
     52    InspectorExtension(const WTF::String& identifier, WebKit::WebInspectorUIExtensionControllerProxy&);
     53
    5054    WTF::String m_identifier;
     55    WeakPtr<WebKit::WebInspectorUIExtensionControllerProxy> m_extensionControllerProxy;
    5156};
    5257
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm

    r269701 r270606  
    208208        }
    209209
    210         capturedBlock(nil, [[wrapper(API::InspectorExtension::create(protectedExtensionID.get())) retain] autorelease]);
     210        capturedBlock(nil, [[wrapper(API::InspectorExtension::create(protectedExtensionID.get(), protectedSelf->_inspector->extensionController())) retain] autorelease]);
    211211    });
    212212#else
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtension.h

    r269701 r270606  
    2424 */
    2525
     26#pragma once
     27
     28#import <WebKit/WKFoundation.h>
     29
     30#if TARGET_OS_OSX
     31
    2632#import <Foundation/Foundation.h>
    27 #import <WebKit/WKFoundation.h>
    2833
    2934NS_ASSUME_NONNULL_BEGIN
     
    3237@interface _WKInspectorExtension : NSObject
    3338
     39- (instancetype)new NS_UNAVAILABLE;
    3440- (instancetype)init NS_UNAVAILABLE;
     41
     42/**
     43 * @abstract Creates a new tab in the Web Inspector interface for this extension.
     44 * @param tabName A localized display name for the tab.
     45 * @param tabIconURL The location of an image resource to use for display in the created tab's title.
     46 * @param sourceURL The location of the main resource to load in the new tab's iframe browsing context.
     47 * @param completionHandler The completion handler to be called when creating a tab succeeds or fails.
     48 */
     49- (void)createTabWithName:(NSString *)tabName tabIconURL:(NSURL *)tabIconURL sourceURL:(NSURL *)sourceURL completionHandler:(void(^)(NSError * _Nullable, NSString * _Nullable inspectorTabID))completionHandler;
    3550
    3651@property (readonly, nonatomic) NSString *extensionID;
     
    3954
    4055NS_ASSUME_NONNULL_END
     56
     57#endif // TARGET_OS_OSX
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtension.mm

    r269701 r270606  
    2727#import "_WKInspectorExtensionInternal.h"
    2828
    29 NS_ASSUME_NONNULL_BEGIN
     29#if ENABLE(INSPECTOR_EXTENSIONS)
    3030
    3131@implementation _WKInspectorExtension
    32 
    33 #if ENABLE(INSPECTOR_EXTENSIONS)
    34 
    35 - (instancetype)initWithIdentifier:(NSString *)extensionID
    36 {
    37     if (!(self = [super init]))
    38         return nil;
    39 
    40     API::Object::constructInWrapper<API::InspectorExtension>(self, extensionID);
    41    
    42     return self;
    43 }
    4432
    4533- (void)dealloc
     
    5038}
    5139
    52 
    5340- (API::Object&)_apiObject
    5441{
    5542    return *_extension;
     43}
     44
     45// MARK: API
     46
     47- (void)createTabWithName:(NSString *)tabName tabIconURL:(NSURL *)tabIconURL sourceURL:(NSURL *)sourceURL completionHandler:(void(^)(NSError *, NSString *))completionHandler
     48{
     49    _extension->createTab(tabName, tabIconURL, sourceURL, [protectedSelf = retainPtr(self), capturedBlock = makeBlockPtr(completionHandler)] (Expected<WebKit::InspectorExtensionTabID, WebKit::InspectorExtensionError> result) mutable {
     50        if (!result) {
     51            capturedBlock([NSError errorWithDomain:WKErrorDomain code:WKErrorUnknown userInfo:@{ NSLocalizedFailureReasonErrorKey: inspectorExtensionErrorToString(result.error())}], nil);
     52            return;
     53        }
     54
     55        capturedBlock(nil, result.value());
     56    });
    5657}
    5758
     
    6364}
    6465
    65 #endif // ENABLE(INSPECTOR_EXTENSIONS)
    66 
    6766@end
    6867
    69 NS_ASSUME_NONNULL_END
     68#endif // ENABLE(INSPECTOR_EXTENSIONS)
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtensionInternal.h

    r269701 r270606  
    3939} // namespace WebKit
    4040
    41 NS_ASSUME_NONNULL_BEGIN
    42 
    4341@interface _WKInspectorExtension () <WKObject> {
    4442@package
     
    4644}
    4745
    48 - (instancetype)initWithIdentifier:(NSString *)extensionIdentifier;
    49 
    5046@end
    5147
    52 NS_ASSUME_NONNULL_END
    53 
    5448#endif // ENABLE(INSPECTOR_EXTENSIONS)
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm

    r269701 r270606  
    2525
    2626#import "config.h"
    27 #import "_WKRemoteWebInspectorViewControllerPrivate.h"
     27#import "_WKRemoteWebInspectorViewControllerInternal.h"
    2828
    2929#if PLATFORM(MAC)
     
    8888
    8989@implementation _WKRemoteWebInspectorViewController {
    90     RefPtr<WebKit::RemoteWebInspectorProxy> m_remoteInspectorProxy;
    9190    std::unique_ptr<WebKit::_WKRemoteWebInspectorProxyClient> m_remoteInspectorClient;
    9291    _WKInspectorConfiguration *_configuration;
     
    202201        }
    203202
    204         capturedBlock(nil, [[wrapper(API::InspectorExtension::create(protectedExtensionID.get())) retain] autorelease]);
     203        capturedBlock(nil, [[wrapper(API::InspectorExtension::create(protectedExtensionID.get(), protectedSelf->m_remoteInspectorProxy->extensionController())) retain] autorelease]);
    205204    });
    206205#else
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKRemoteWebInspectorViewControllerInternal.h

    r270605 r270606  
    2424 */
    2525
    26 #import <Foundation/Foundation.h>
    27 #import <WebKit/WKFoundation.h>
     26#import "_WKRemoteWebInspectorViewControllerPrivate.h"
     27
     28#if !TARGET_OS_IPHONE
     29
     30namespace WebKit {
     31class RemoteWebInspectorProxy;
     32}
    2833
    2934NS_ASSUME_NONNULL_BEGIN
    3035
    31 WK_CLASS_AVAILABLE(macos(WK_MAC_TBA))
    32 @interface _WKInspectorExtension : NSObject
    33 
    34 - (instancetype)init NS_UNAVAILABLE;
    35 
    36 @property (readonly, nonatomic) NSString *extensionID;
    37 
     36@interface _WKRemoteWebInspectorViewController () {
     37@package
     38    RefPtr<WebKit::RemoteWebInspectorProxy> m_remoteInspectorProxy;
     39}
    3840@end
    3941
    4042NS_ASSUME_NONNULL_END
     43
     44#endif // !TARGET_OS_IPHONE
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp

    r269701 r270606  
    9999}
    100100
     101void WebInspectorUIExtensionControllerProxy::createTabForExtension(const InspectorExtensionID& extensionID, const String& tabName, const URL& tabIconURL, const URL& sourceURL, WTF::CompletionHandler<void(Expected<InspectorExtensionTabID, InspectorExtensionError>)>&& completionHandler)
     102{
     103    whenFrontendHasLoaded([weakThis = makeWeakPtr(this), extensionID, tabName, tabIconURL, sourceURL, completionHandler = WTFMove(completionHandler)] () mutable {
     104        if (!weakThis || !weakThis->m_inspectorPage) {
     105            completionHandler(makeUnexpected(InspectorExtensionError::InvalidRequest));
     106            return;
     107        }
     108
     109        weakThis->m_inspectorPage->sendWithAsyncReply(Messages::WebInspectorUIExtensionController::CreateTabForExtension { extensionID, tabName, tabIconURL, sourceURL }, WTFMove(completionHandler));
     110    });
     111}
     112
    101113} // namespace WebKit
    102114
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h

    r269701 r270606  
    5050    void registerExtension(const InspectorExtensionID&, const String& displayName, WTF::CompletionHandler<void(Expected<bool, InspectorExtensionError>)>&&);
    5151    void unregisterExtension(const InspectorExtensionID&, WTF::CompletionHandler<void(Expected<bool, InspectorExtensionError>)>&&);
     52    void createTabForExtension(const InspectorExtensionID&, const String& tabName, const URL& tabIconURL, const URL& sourceURL, WTF::CompletionHandler<void(Expected<InspectorExtensionTabID, InspectorExtensionError>)>&&);
    5253
    5354    // Notifications.
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/mac/ScrollingTreeOverflowScrollingNodeRemoteMac.h

    r270130 r270606  
    4545
    4646    void commitStateBeforeChildren(const WebCore::ScrollingStateNode&) override;
    47     WebCore::WheelEventHandlingResult handleWheelEvent(const WebCore::PlatformWheelEvent&, EventTargeting) override;
     47    WebCore::WheelEventHandlingResult handleWheelEvent(const WebCore::PlatformWheelEvent&, WebCore::EventTargeting) override;
    4848    void repositionRelatedLayers() override;
    4949
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r270587 r270606  
    47394739                99996A9E25004BCB004F7559 /* _WKInspectorTesting.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInspectorTesting.mm; sourceTree = "<group>"; };
    47404740                999B7ED82550E4A800F450A4 /* InspectorExtensionTypes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorExtensionTypes.cpp; sourceTree = "<group>"; };
     4741                999B7F4F2554BA3F00F450A4 /* APIInspectorExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIInspectorExtension.cpp; sourceTree = "<group>"; };
    47414742                99B16754252BB7E00073140E /* _WKInspectorExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorExtension.h; sourceTree = "<group>"; };
    47424743                99B16755252BB7E10073140E /* _WKInspectorExtensionInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorExtensionInternal.h; sourceTree = "<group>"; };
     
    96569657                                994C6048253F820200BDF060 /* APIInspectorConfiguration.cpp */,
    96579658                                994C6046253CACB800BDF060 /* APIInspectorConfiguration.h */,
     9659                                999B7F4F2554BA3F00F450A4 /* APIInspectorExtension.cpp */,
    96589660                                99BE3B1225422F4100C6551C /* APIInspectorExtension.h */,
    96599661                                31B362902141EABC007BFA53 /* APIInternalDebugFeature.cpp */,
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp

    r270573 r270606  
    5757Optional<InspectorExtensionError> WebInspectorUIExtensionController::parseInspectorExtensionErrorFromEvaluationResult(InspectorFrontendAPIDispatcher::EvaluationResult result)
    5858{
    59     if (!result.has_value()) {
     59    if (!result) {
    6060        switch (result.error()) {
    6161        case WebCore::InspectorFrontendAPIDispatcher::EvaluationError::ContextDestroyed:
     
    150150}
    151151
     152JSC::JSObject* WebInspectorUIExtensionController::unwrapEvaluationResultAsObject(InspectorFrontendAPIDispatcher::EvaluationResult result)
     153{
     154    if (!result)
     155        return nullptr;
     156   
     157    auto valueOrException = result.value();
     158    if (!valueOrException.has_value())
     159        return nullptr;
     160   
     161    return valueOrException.value().getObject();
     162}
     163
     164void WebInspectorUIExtensionController::createTabForExtension(const InspectorExtensionID& extensionID, const String& tabName, const URL& tabIconURL, const URL& sourceURL, WTF::CompletionHandler<void(Expected<InspectorExtensionTabID, InspectorExtensionError>)>&& completionHandler)
     165{
     166    if (!m_frontendClient) {
     167        completionHandler(makeUnexpected(InspectorExtensionError::InvalidRequest));
     168        return;
     169    }
     170
     171    Vector<Ref<JSON::Value>> arguments {
     172        JSON::Value::create(extensionID),
     173        JSON::Value::create(tabName),
     174        JSON::Value::create(tabIconURL.string()),
     175        JSON::Value::create(sourceURL.string()),
     176    };
     177    m_frontendClient->frontendAPIDispatcher().dispatchCommandWithResultAsync("createTabForExtension"_s, WTFMove(arguments), [weakThis = makeWeakPtr(this), completionHandler = WTFMove(completionHandler)](InspectorFrontendAPIDispatcher::EvaluationResult&& result) mutable {
     178        if (!weakThis || !result) {
     179            completionHandler(makeUnexpected(InspectorExtensionError::ContextDestroyed));
     180            return;
     181        }
     182
     183        if (auto parsedError = weakThis->parseInspectorExtensionErrorFromEvaluationResult(result.value())) {
     184            completionHandler(makeUnexpected(parsedError.value()));
     185            return;
     186        }
     187
     188        // Expected result is either an ErrorString or {extensionTabID: <string>}.
     189        auto objectResult = weakThis->unwrapEvaluationResultAsObject(result);
     190        if (!objectResult) {
     191            LOG(Inspector, "Unexpected non-object value returned from InspectorFrontendAPI.createTabForExtension().");
     192            completionHandler(makeUnexpected(InspectorExtensionError::InternalError));
     193            return;
     194        }
     195
     196        auto* frontendGlobalObject = weakThis->m_frontendClient->frontendAPIDispatcher().frontendGlobalObject();
     197        JSC::JSValue foundProperty = objectResult->get(frontendGlobalObject, JSC::Identifier::fromString(frontendGlobalObject->vm(), "extensionTabID"_s));
     198        if (!foundProperty || !foundProperty.isString()) {
     199            completionHandler(makeUnexpected(InspectorExtensionError::InternalError));
     200            return;
     201        }
     202
     203        completionHandler({ foundProperty.toWTFString(frontendGlobalObject) });
     204    });
     205}
     206
    152207} // namespace WebKit
    153208
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.h

    r270453 r270606  
    6565    void registerExtension(const InspectorExtensionID&, const String& displayName, CompletionHandler<void(Expected<bool, InspectorExtensionError>)>&&);
    6666    void unregisterExtension(const InspectorExtensionID&, CompletionHandler<void(Expected<bool, InspectorExtensionError>)>&&);
     67    void createTabForExtension(const InspectorExtensionID&, const String& tabName, const URL& tabIconURL, const URL& sourceURL, WTF::CompletionHandler<void(Expected<InspectorExtensionTabID, InspectorExtensionError>)>&&);
    6768
    6869private:
     70    JSC::JSObject* unwrapEvaluationResultAsObject(WebCore::InspectorFrontendAPIDispatcher::EvaluationResult);
    6971    Optional<InspectorExtensionError> parseInspectorExtensionErrorFromEvaluationResult(WebCore::InspectorFrontendAPIDispatcher::EvaluationResult);
    7072
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.messages.in

    r269701 r270606  
    2626    RegisterExtension(String extensionID, String displayName) -> (Expected<bool, WebKit::InspectorExtensionError> result) Async
    2727    UnregisterExtension(String extensionID) -> (Expected<bool, WebKit::InspectorExtensionError> result) Async
     28
     29    CreateTabForExtension(String extensionID, String tabName, URL tabIconURL, URL sourceURL) -> (Expected<String, WebKit::InspectorExtensionError> result) Async
    2830}
    2931
Note: See TracChangeset for help on using the changeset viewer.