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

Changeset 286799 in webkit


Ignore:
Timestamp:
Dec 9, 2021, 12:55:16 PM (5 years ago)
Author:
BJ Burg
Message:

[Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates
https://bugs.webkit.org/show_bug.cgi?id=233935
<rdar://86123899>

Reviewed by Patrick Angle.

Source/WebCore:

Add new InspectorFrontendHost hooks to notify the client about didNavigateExtensionTab().

  • inspector/InspectorFrontendClient.h:

(WebCore::InspectorFrontendClient::didNavigateExtensionTab):

  • inspector/InspectorFrontendHost.cpp:

(WebCore::InspectorFrontendHost::didNavigateExtensionTab):

  • inspector/InspectorFrontendHost.h:
  • inspector/InspectorFrontendHost.idl:

Source/WebInspectorUI:

In order instrument all loads inside the extension iframe, we cannot rely on the <iframe src> attribute
to query the currently loaded page, or to change the current page. Use a helper method to query and set
the iframe location indirectly using document.location.

  • UserInterface/Protocol/InspectorFrontendAPI.js:
  • UserInterface/Controllers/WebInspectorExtensionController.js:

(WI.WebInspectorExtensionController.prototype.createTabForExtension):
(WI.WebInspectorExtensionController.prototype.showExtensionTab):
Standardize on returning {"result": value} from these methods.

  • UserInterface/Views/WebInspectorExtensionTabContentView.js:

(WI.WebInspectorExtensionTabContentView):
(WI.WebInspectorExtensionTabContentView.prototype.whenPageAvailable): Added.
(WI.WebInspectorExtensionTabContentView.prototype._extensionFrameDidLoad):
Trigger a load of the actual requested page by evaluating document.location.href = <url>
in the context of the extension tab iframe. Notify clients when this non-initial load completes.

(WI.WebInspectorExtensionTabContentView.prototype.async _maybeDispatchDidNavigateExtensionTab):
Dispatch didNavigateExtensionTab with the new URL when the extension tab iframe completes a load.
Don't notify the client if the extension tab has not yet loaded.

Source/WebKit:

Add plumbing to notify clients when an extension tab loads. This is implemented similarly to
-inspectorExtension:didShowExtensionTab: and -inspectorExtension:didHideExtensionTab:.

  • UIProcess/API/APIInspectorExtensionClient.h:

(API::InspectorExtensionClient::didNavigateExtensionTab):

  • UIProcess/API/Cocoa/_WKInspectorExtensionDelegate.h:
  • UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.h:
  • UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.mm:

(WebKit::InspectorExtensionDelegate::InspectorExtensionDelegate):
(WebKit::InspectorExtensionDelegate::InspectorExtensionClient::didNavigateExtensionTab):

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

(WebKit::WebInspectorUIExtensionControllerProxy::didNavigateExtensionTab):

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

(WebKit::RemoteWebInspectorUI::didNavigateExtensionTab):

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

(WebKit::WebInspectorUI::didHideExtensionTab):
(WebKit::WebInspectorUI::didNavigateExtensionTab):

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

(WebKit::WebInspectorUIExtensionController::createTabForExtension):
Standardize on returning {result: value} for showExtensionTab.

(WebKit::WebInspectorUIExtensionController::showExtensionTab):
Standardize on returning {result: value} for showExtensionTab.
Also, there's no need to inspect the result value if it's not an error.

(WebKit::WebInspectorUIExtensionController::didNavigateExtensionTab):
Add plumbing.

Tools:

Add API test coverage for -inspectorExtension:didNavigateTabWithIdentifier:newURL:

  • TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtension.mm:

(TEST):
Drive-by, fix an outdated completion handler type signature.

  • TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionDelegate.mm:

(-[InspectorExtensionDelegateForTesting inspectorExtension:didNavigateTabWithIdentifier:newURL:]):
(TEST):
Add a test case which exercises the new delegate method.

Location:
trunk
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286796 r286799  
     12021-12-08  BJ Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates
     4        https://bugs.webkit.org/show_bug.cgi?id=233935
     5        <rdar://86123899>
     6
     7        Reviewed by Patrick Angle.
     8
     9        Add new InspectorFrontendHost hooks to notify the client about didNavigateExtensionTab().
     10
     11        * inspector/InspectorFrontendClient.h:
     12        (WebCore::InspectorFrontendClient::didNavigateExtensionTab):
     13        * inspector/InspectorFrontendHost.cpp:
     14        (WebCore::InspectorFrontendHost::didNavigateExtensionTab):
     15        * inspector/InspectorFrontendHost.h:
     16        * inspector/InspectorFrontendHost.idl:
     17
    1182021-12-09  Said Abou-Hallawa  <said@apple.com>
    219
  • trunk/Source/WebCore/inspector/InspectorFrontendClient.h

    r284857 r286799  
    123123    virtual void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) { }
    124124    virtual void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) { }
     125    virtual void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&) { }
    125126    virtual void inspectedPageDidNavigate(const URL&) { }
    126127#endif
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp

    r283857 r286799  
    708708}
    709709
     710void InspectorFrontendHost::didNavigateExtensionTab(const String& extensionID, const String& extensionTabID, const String& newURLString)
     711{
     712    if (!m_client)
     713        return;
     714   
     715    m_client->didNavigateExtensionTab(extensionID, extensionTabID, { URL(), newURLString });
     716}
     717
    710718void InspectorFrontendHost::inspectedPageDidNavigate(const String& newURLString)
    711719{
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.h

    r283857 r286799  
    144144    void didShowExtensionTab(const String& extensionID, const String& extensionTabID);
    145145    void didHideExtensionTab(const String& extensionID, const String& extensionTabID);
     146    void didNavigateExtensionTab(const String& extensionID, const String& extensionTabID, const String& url);
    146147    void inspectedPageDidNavigate(const String& url);
    147148    ExceptionOr<JSC::JSValue> evaluateScriptInExtensionTab(HTMLIFrameElement& extensionFrame, const String& scriptSource);
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.idl

    r283857 r286799  
    101101    [Conditional=INSPECTOR_EXTENSIONS] undefined didShowExtensionTab(DOMString extensionID, DOMString extensionTabID);
    102102    [Conditional=INSPECTOR_EXTENSIONS] undefined didHideExtensionTab(DOMString extensionID, DOMString extensionTabID);
     103    [Conditional=INSPECTOR_EXTENSIONS] undefined didNavigateExtensionTab(DOMString extensionID, DOMString extensionTabID, DOMString newURL);
    103104    [Conditional=INSPECTOR_EXTENSIONS] undefined inspectedPageDidNavigate(DOMString newURL);
    104105    [Conditional=INSPECTOR_EXTENSIONS] any evaluateScriptInExtensionTab(HTMLIFrameElement extensionFrame, DOMString scriptSource);
  • trunk/Source/WebInspectorUI/ChangeLog

    r286792 r286799  
     12021-12-08  BJ Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates
     4        https://bugs.webkit.org/show_bug.cgi?id=233935
     5        <rdar://86123899>
     6
     7        Reviewed by Patrick Angle.
     8
     9        In order instrument all loads inside the extension iframe, we cannot rely on the <iframe src> attribute
     10        to query the currently loaded page, or to change the current page. Use a helper method to query and set
     11        the iframe location indirectly using `document.location`.
     12
     13        * UserInterface/Protocol/InspectorFrontendAPI.js:
     14
     15        * UserInterface/Controllers/WebInspectorExtensionController.js:
     16        (WI.WebInspectorExtensionController.prototype.createTabForExtension):
     17        (WI.WebInspectorExtensionController.prototype.showExtensionTab):
     18        Standardize on returning {"result": value} from these methods.
     19
     20        * UserInterface/Views/WebInspectorExtensionTabContentView.js:
     21        (WI.WebInspectorExtensionTabContentView):
     22        (WI.WebInspectorExtensionTabContentView.prototype.whenPageAvailable): Added.
     23        (WI.WebInspectorExtensionTabContentView.prototype._extensionFrameDidLoad):
     24        Trigger a load of the actual requested page by evaluating `document.location.href = <url>`
     25        in the context of the extension tab iframe. Notify clients when this non-initial load completes.
     26
     27        (WI.WebInspectorExtensionTabContentView.prototype.async _maybeDispatchDidNavigateExtensionTab):
     28        Dispatch didNavigateExtensionTab with the new URL when the extension tab iframe completes a load.
     29        Don't notify the client if the extension tab has not yet loaded.
     30
    1312021-12-09  Razvan Caliman  <rcaliman@apple.com>
    232
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/WebInspectorExtensionController.js

    r286329 r286799  
    9494
    9595        // The calling convention is to return an error string or a result object.
    96         return {extensionTabID};
     96        return {"result": extensionTabID};
    9797    }
    9898
     
    184184
    185185        tabContentView.visible = true;
     186
     187        // Clients expect to be able to use evaluateScriptInExtensionTab() when this method
     188        // returns, so wait for the extension tab to finish its loading sequence. Wrap the result.
     189        return tabContentView.whenPageAvailable().then((sourceURL) => { return {"result": sourceURL}; });
    186190    }
    187191
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js

    r286329 r286799  
    211211    },
    212212
    213     // Returns a WI.WebInspectorExtension.ErrorCode if an error occurred, otherwise an object
    214     // with an 'extensionTabID' key representing the tab identifier for the newly created tab.
     213    // Returns a string (WI.WebInspectorExtension.ErrorCode) if an error occurred that prevented creating a tab.
     214    // Returns a Promise that is resolved if the evaluation completes and rejected if there was an internal error.
     215    // When the promise is fulfilled, it will be either:
     216    // - resolved with an object containing a 'result' key and value that is the tab identifier for the new tab.
     217    // - rejected with an object containing an 'error' key and value that is the exception that was thrown while evaluating script.
    215218    createTabForExtension(extensionID, tabName, tabIconURL, sourceURL)
    216219    {
     
    234237    },
    235238
    236     // Returns a WI.WebInspectorExtension.ErrorCode if an error occurred, otherwise nothing.
     239    // Returns a string (WI.WebInspectorExtension.ErrorCode) if an error occurred before attempting to switch tabs.
     240    // Returns a Promise that is resolved if the tab could be shown and rejected if the tab could not be shown.
     241    // When the promise is fulfilled, it will be either:
     242    // - resolved with no value.
     243    // - rejected with an object containing an 'error' key and value that is the exception that was thrown while showing the tab.
    237244    showExtensionTab(extensionTabID)
    238245    {
  • trunk/Source/WebInspectorUI/UserInterface/Views/WebInspectorExtensionTabContentView.js

    r286329 r286799  
    4141        this._sourceURL = sourceURL;
    4242
     43        this._iframeFinishedInitialLoad = false;
     44        this._whenPageAvailablePromise = new WI.WrappedPromise;
     45
    4346        this._iframeElement = this.element.appendChild(document.createElement("iframe"));
    4447        this._iframeElement.addEventListener("load", this._extensionFrameDidLoad.bind(this));
    45         this._iframeElement.src = this._sourceURL;
    46 
    47         this._frameContentDidLoad = false;
    4848    }
    4949
     
    7272    {
    7373        return true;
     74    }
     75
     76    whenPageAvailable()
     77    {
     78        return this._whenPageAvailablePromise.promise;
    7479    }
    7580
     
    110115    _extensionFrameDidLoad()
    111116    {
    112         this._frameContentDidLoad = true;
    113         this._maybeDispatchDidShowExtensionTab();
     117        // Bounce from the initial empty page to the requested sourceURL.
     118        if (!this._iframeFinishedInitialLoad) {
     119            this._iframeFinishedInitialLoad = true;
     120            WI.sharedApp.extensionController.evaluateScriptInExtensionTab(this._extensionTabID, `document.location.replace("${this._sourceURL}");`);
     121            return;
     122        }
     123
     124        // Signal that the page is available since we already bounced to the requested page.
     125        if (!this._whenPageAvailablePromise.settled)
     126            this._whenPageAvailablePromise.resolve(this._sourceURL);
     127
     128        this._maybeDispatchDidNavigateExtensionTab();
     129    }
     130
     131    async _maybeDispatchDidNavigateExtensionTab()
     132    {
     133        if (!this.element.isConnected)
     134            return;
     135
     136        let payload = await WI.sharedApp.extensionController.evaluateScriptInExtensionTab(this._extensionTabID, "document.location.href");
     137        console.assert(payload.result, "Should be able to unwrap evaluation in extension tab!", payload.result);
     138
     139        if (InspectorFrontendHost.supportsWebExtensions)
     140            InspectorFrontendHost.didNavigateExtensionTab(this._extension.extensionID, this._extensionTabID, payload.result);
    114141    }
    115142
    116143    _maybeDispatchDidShowExtensionTab()
    117144    {
    118         if (!this._frameContentDidLoad || !this.element.isConnected)
     145        if (!this.element.isConnected)
    119146            return;
    120147
  • trunk/Source/WebKit/ChangeLog

    r286788 r286799  
     12021-12-08  BJ Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates
     4        https://bugs.webkit.org/show_bug.cgi?id=233935
     5        <rdar://86123899>
     6
     7        Reviewed by Patrick Angle.
     8
     9        Add plumbing to notify clients when an extension tab loads. This is implemented similarly to
     10        -inspectorExtension:didShowExtensionTab: and -inspectorExtension:didHideExtensionTab:.
     11
     12        * UIProcess/API/APIInspectorExtensionClient.h:
     13        (API::InspectorExtensionClient::didNavigateExtensionTab):
     14
     15        * UIProcess/API/Cocoa/_WKInspectorExtensionDelegate.h:
     16
     17        * UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.h:
     18        * UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.mm:
     19        (WebKit::InspectorExtensionDelegate::InspectorExtensionDelegate):
     20        (WebKit::InspectorExtensionDelegate::InspectorExtensionClient::didNavigateExtensionTab):
     21
     22        * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in:
     23        * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h:
     24        * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp:
     25        (WebKit::WebInspectorUIExtensionControllerProxy::didNavigateExtensionTab):
     26
     27        * WebProcess/Inspector/RemoteWebInspectorUI.h:
     28        * WebProcess/Inspector/RemoteWebInspectorUI.cpp:
     29        (WebKit::RemoteWebInspectorUI::didNavigateExtensionTab):
     30
     31        * WebProcess/Inspector/WebInspectorUI.h:
     32        * WebProcess/Inspector/WebInspectorUI.cpp:
     33        (WebKit::WebInspectorUI::didHideExtensionTab):
     34        (WebKit::WebInspectorUI::didNavigateExtensionTab):
     35
     36        * WebProcess/Inspector/WebInspectorUIExtensionController.h:
     37        * WebProcess/Inspector/WebInspectorUIExtensionController.cpp:
     38        (WebKit::WebInspectorUIExtensionController::createTabForExtension):
     39        Standardize on returning {result: value} for showExtensionTab.
     40
     41        (WebKit::WebInspectorUIExtensionController::showExtensionTab):
     42        Standardize on returning {result: value} for showExtensionTab.
     43        Also, there's no need to inspect the result value if it's not an error.
     44
     45        (WebKit::WebInspectorUIExtensionController::didNavigateExtensionTab):
     46        Add plumbing.
     47
    1482021-12-09  Brady Eidson  <beidson@apple.com>
    249
  • trunk/Source/WebKit/UIProcess/API/APIInspectorExtensionClient.h

    r283857 r286799  
    3838    virtual void didShowExtensionTab(const Inspector::ExtensionTabID&) { }
    3939    virtual void didHideExtensionTab(const Inspector::ExtensionTabID&) { }
     40    virtual void didNavigateExtensionTab(const Inspector::ExtensionTabID&, const WTF::URL&) { }
    4041    virtual void inspectedPageDidNavigate(const WTF::URL&) { }
    4142};
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtensionDelegate.h

    r283857 r286799  
    5454
    5555/**
     56 * @abstract Called when a tab associated with this extension has navigated to a new URL.
     57 * @param extension The extension that created the tab.
     58 * @param tabIdentifier Identifier for the tab that navigated.
     59 * @param URL The new URL for the extension tab's page.
     60 */
     61- (void)inspectorExtension:(_WKInspectorExtension *)extension didNavigateTabWithIdentifier:(NSString *)tabIdentifier newURL:(NSURL *)newURL;
     62
     63/**
    5664 * @abstract Called when the inspected page has navigated to a new URL.
     65 * @param extension The extension that is being notified.
    5766 * @param url The new URL for the inspected page.
    5867 */
  • trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.h

    r283857 r286799  
    5757        void didShowExtensionTab(const Inspector::ExtensionTabID&) override;
    5858        void didHideExtensionTab(const Inspector::ExtensionTabID&) override;
     59        void didNavigateExtensionTab(const Inspector::ExtensionTabID&, const URL&) override;
    5960        void inspectedPageDidNavigate(const URL&) override;
    6061
     
    6869        bool inspectorExtensionDidShowTabWithIdentifier : 1;
    6970        bool inspectorExtensionDidHideTabWithIdentifier : 1;
     71        bool inspectorExtensionDidNavigateTabWithIdentifier : 1;
    7072        bool inspectorExtensionInspectedPageDidNavigate : 1;
    7173    } m_delegateMethods;
  • trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.mm

    r283857 r286799  
    4242    m_delegateMethods.inspectorExtensionDidShowTabWithIdentifier = [delegate respondsToSelector:@selector(inspectorExtension:didShowTabWithIdentifier:)];
    4343    m_delegateMethods.inspectorExtensionDidHideTabWithIdentifier = [delegate respondsToSelector:@selector(inspectorExtension:didHideTabWithIdentifier:)];
     44    m_delegateMethods.inspectorExtensionDidNavigateTabWithIdentifier = [delegate respondsToSelector:@selector(inspectorExtension:didNavigateTabWithIdentifier:newURL:)];
    4445    m_delegateMethods.inspectorExtensionInspectedPageDidNavigate = [delegate respondsToSelector:@selector(inspectorExtension:inspectedPageDidNavigate:)];
    4546
     
    8788}
    8889
     90void InspectorExtensionDelegate::InspectorExtensionClient::didNavigateExtensionTab(const Inspector::ExtensionTabID& extensionTabID, const WTF::URL& newURL)
     91{
     92    if (!m_inspectorExtensionDelegate.m_delegateMethods.inspectorExtensionDidNavigateTabWithIdentifier)
     93        return;
     94
     95    auto& delegate = m_inspectorExtensionDelegate.m_delegate;
     96    if (!delegate)
     97        return;
     98
     99    [delegate inspectorExtension:m_inspectorExtensionDelegate.m_inspectorExtension.get().get() didNavigateTabWithIdentifier:extensionTabID newURL:newURL];
     100}
     101
    89102void InspectorExtensionDelegate::InspectorExtensionClient::inspectedPageDidNavigate(const WTF::URL& newURL)
    90103{
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp

    r286329 r286799  
    269269}
    270270
     271void WebInspectorUIExtensionControllerProxy::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const WTF::URL& newURL)
     272{
     273    auto it = m_extensionAPIObjectMap.find(extensionID);
     274    if (it == m_extensionAPIObjectMap.end())
     275        return;
     276
     277    RefPtr<API::InspectorExtension> extension = it->value;
     278    auto extensionClient = extension->client();
     279    if (!extensionClient)
     280        return;
     281
     282    extensionClient->didNavigateExtensionTab(extensionTabID, newURL);
     283}
     284
    271285void WebInspectorUIExtensionControllerProxy::inspectedPageDidNavigate(const URL& newURL)
    272286{
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h

    r286329 r286799  
    6969    void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&);
    7070    void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&);
     71    void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&);
    7172    void inspectedPageDidNavigate(const URL&);
    7273
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in

    r283857 r286799  
    2626    DidShowExtensionTab(String extensionID, String extensionTabID)
    2727    DidHideExtensionTab(String extensionID, String extensionTabID)
     28    DidNavigateExtensionTab(String extensionID, String extensionTabID, URL newURL)
    2829    InspectedPageDidNavigate(URL newURL)
    2930}
  • trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp

    r283857 r286799  
    307307}
    308308
    309 void RemoteWebInspectorUI::inspectedPageDidNavigate(const URL& newURL)
     309void RemoteWebInspectorUI::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const URL& newURL)
    310310{
    311311    if (!m_extensionController)
    312312        return;
    313313
     314    m_extensionController->didNavigateExtensionTab(extensionID, extensionTabID, newURL);
     315}
     316
     317void RemoteWebInspectorUI::inspectedPageDidNavigate(const URL& newURL)
     318{
     319    if (!m_extensionController)
     320        return;
     321
    314322    m_extensionController->inspectedPageDidNavigate(newURL);
    315323}
  • trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h

    r283857 r286799  
    123123    void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override;
    124124    void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override;
     125    void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&) override;
    125126    void inspectedPageDidNavigate(const URL&) override;
    126127#endif
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp

    r283857 r286799  
    381381}
    382382
    383 void WebInspectorUI::inspectedPageDidNavigate(const URL& newURL)
     383void WebInspectorUI::didNavigateExtensionTab(const String& extensionID, const String& extensionTabID, const URL& newURL)
    384384{
    385385    if (!m_extensionController)
    386386        return;
    387387
     388    m_extensionController->didNavigateExtensionTab(extensionID, extensionTabID, newURL);
     389}
     390
     391void WebInspectorUI::inspectedPageDidNavigate(const URL& newURL)
     392{
     393    if (!m_extensionController)
     394        return;
     395
    388396    m_extensionController->inspectedPageDidNavigate(newURL);
    389397}
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.h

    r283857 r286799  
    157157    void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override;
    158158    void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override;
     159    void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&) override;
    159160    void inspectedPageDidNavigate(const URL&) override;
    160161#endif
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp

    r286747 r286799  
    205205
    206206        auto* frontendGlobalObject = weakThis->m_frontendClient->frontendAPIDispatcher().frontendGlobalObject();
    207         JSC::JSValue foundProperty = objectResult->get(frontendGlobalObject, JSC::Identifier::fromString(frontendGlobalObject->vm(), "extensionTabID"_s));
     207        JSC::JSValue foundProperty = objectResult->get(frontendGlobalObject, JSC::Identifier::fromString(frontendGlobalObject->vm(), "result"_s));
    208208        if (!foundProperty || !foundProperty.isString()) {
    209209            completionHandler(makeUnexpected(Inspector::ExtensionError::InternalError));
     
    358358
    359359        if (auto parsedError = weakThis->parseExtensionErrorFromEvaluationResult(result)) {
    360             LOG(Inspector, "Internal error encountered while evaluating upon the frontend: %s", Inspector::extensionErrorToString(*parsedError).utf8().data());
     360            if (!result.value().has_value()) {
     361                auto exceptionDetails = result.value().error();
     362                LOG(Inspector, "Internal error encountered while showing extension tab at %s:%d:%d: %s", exceptionDetails.sourceURL.utf8().data(), exceptionDetails.lineNumber, exceptionDetails.columnNumber, exceptionDetails.message.utf8().data());
     363            } else
     364                LOG(Inspector, "Internal error encountered while showing extension tab.");
     365
    361366            completionHandler(makeUnexpected(*parsedError));
    362367            return;
    363368        }
     369
     370        // If this assertion fails, then a `result.error()` was not handled above as expected.
     371        ASSERT(result.has_value());
    364372
    365373        completionHandler({ });
     
    445453}
    446454
     455void WebInspectorUIExtensionController::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const URL& newURL)
     456{
     457    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorUIExtensionControllerProxy::DidNavigateExtensionTab { extensionID, extensionTabID, newURL }, m_inspectorPageIdentifier);
     458}
     459
    447460void WebInspectorUIExtensionController::inspectedPageDidNavigate(const URL& newURL)
    448461{
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.h

    r286329 r286799  
    7777    void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&);
    7878    void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&);
     79    void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&);
    7980    void inspectedPageDidNavigate(const URL&);
    8081
  • trunk/Tools/ChangeLog

    r286797 r286799  
     12021-12-08  BJ Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates
     4        https://bugs.webkit.org/show_bug.cgi?id=233935
     5        <rdar://86123899>
     6
     7        Reviewed by Patrick Angle.
     8
     9        Add API test coverage for -inspectorExtension:didNavigateTabWithIdentifier:newURL:
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtension.mm:
     12        (TEST):
     13        Drive-by, fix an outdated completion handler type signature.
     14
     15        * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionDelegate.mm:
     16        (-[InspectorExtensionDelegateForTesting inspectorExtension:didNavigateTabWithIdentifier:newURL:]):
     17        (TEST):
     18        Add a test case which exercises the new delegate method.
     19
    1202021-12-09  Lauro Moura  <lmoura@igalia.com>
    221
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionDelegate.mm

    r286329 r286799  
    4444
    4545static RetainPtr<NSURL> sharedNewURLAfterNavigation;
     46static bool extensionTabDidNavigateWasCalled;
    4647
    4748@interface UIDelegateForTestingInspectorExtensionDelegate : NSObject <WKUIDelegate>
     
    8384{
    8485    didHideExtensionTabWasCalled = true;
     86}
     87
     88- (void)inspectorExtension:(_WKInspectorExtension *)extension didNavigateTabWithIdentifier:(NSString *)tabIdentifier newURL:(NSURL *)newURL
     89{
     90    extensionTabDidNavigateWasCalled = true;
    8591}
    8692
     
    235241}
    236242
     243// FIXME: Re-enable this test for debug once webkit.org/b/231847 is fixed.
     244#if !defined(NDEBUG)
     245TEST(WKInspectorExtensionDelegate, DISABLED_ExtensionTabNavigatedCallbacks)
     246#else
     247TEST(WKInspectorExtensionDelegate, ExtensionTabNavigatedCallbacks)
     248#endif
     249{
     250    resetGlobalState();
     251
     252    // Hook up the test-resource: handler so that we can navigate to a different test file.
     253    if (!sharedURLSchemeHandler)
     254        sharedURLSchemeHandler = adoptNS([[TestInspectorURLSchemeHandler alloc] init]);
     255
     256    auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     257    webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
     258    [webViewConfiguration setURLSchemeHandler:sharedURLSchemeHandler.get() forURLScheme:@"test-resource"];
     259
     260    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     261    auto uiDelegate = adoptNS([UIDelegateForTestingInspectorExtensionDelegate new]);
     262
     263    [webView setUIDelegate:uiDelegate.get()];
     264
     265    [[webView _inspector] show];
     266    TestWebKitAPI::Util::run(&didAttachLocalInspectorCalled);
     267
     268    // Register the test extension.
     269    auto extensionID = [NSUUID UUID].UUIDString;
     270    auto extensionBundleIdentifier = @"com.apple.webkit.ThirdExtension";
     271    auto extensionDisplayName = @"ThirdExtension";
     272    pendingCallbackWasCalled = false;
     273    [[webView _inspector] registerExtensionWithID:extensionID extensionBundleIdentifier:extensionBundleIdentifier displayName:extensionDisplayName completionHandler:^(NSError *error, _WKInspectorExtension *extension) {
     274        EXPECT_NULL(error);
     275        EXPECT_NOT_NULL(extension);
     276        sharedInspectorExtension = extension;
     277
     278        pendingCallbackWasCalled = true;
     279    }];
     280    TestWebKitAPI::Util::run(&pendingCallbackWasCalled);
     281
     282    auto extensionDelegate = adoptNS([InspectorExtensionDelegateForTesting new]);
     283    [sharedInspectorExtension setDelegate:extensionDelegate.get()];
     284
     285    auto baseURL = [NSURL URLWithString:@"http://example.com/"];
     286    [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:baseURL];
     287    [webView _test_waitForDidFinishNavigation];
     288
     289    inspectedPageDidNavigateWasCalled = false;
     290    TestWebKitAPI::Util::run(&inspectedPageDidNavigateWasCalled);
     291    EXPECT_NS_EQUAL(sharedNewURLAfterNavigation.get().absoluteString, baseURL.absoluteString);
     292    inspectedPageDidNavigateWasCalled = false;
     293
     294    // Create an extension tab.
     295    auto iconURL = [NSURL URLWithString:@"test-resource://ThirdExtension/InspectorExtension-TabIcon-30x30.png"];
     296    auto sourceURL = [NSURL URLWithString:@"test-resource://ThirdExtension/InspectorExtension-basic-tab.html"];
     297
     298    pendingCallbackWasCalled = false;
     299    [sharedInspectorExtension createTabWithName:@"ThirdExtension-Tab" tabIconURL:iconURL sourceURL:sourceURL completionHandler:^(NSError *error, NSString *extensionTabIdentifier) {
     300        EXPECT_NULL(error);
     301        EXPECT_NOT_NULL(extensionTabIdentifier);
     302        sharedExtensionTabIdentifier = extensionTabIdentifier;
     303
     304        pendingCallbackWasCalled = true;
     305    }];
     306    TestWebKitAPI::Util::run(&pendingCallbackWasCalled);
     307
     308    pendingCallbackWasCalled = false;
     309    [[webView _inspector] showExtensionTabWithIdentifier:sharedExtensionTabIdentifier.get() completionHandler:^(NSError *error) {
     310        EXPECT_NULL(error);
     311
     312        pendingCallbackWasCalled = true;
     313    }];
     314    TestWebKitAPI::Util::run(&pendingCallbackWasCalled);
     315
     316    pendingCallbackWasCalled = false;
     317    extensionTabDidNavigateWasCalled = false;
     318    auto newURL = [NSURL URLWithString:@"test-resource://ThirdExtension/InspectorExtension-basic-page.html"];
     319    [sharedInspectorExtension evaluateScript:[NSString stringWithFormat:@"window.location.replace(\"%@\")", newURL] inTabWithIdentifier:sharedExtensionTabIdentifier.get() completionHandler:^(NSError *error, id result) {
     320        EXPECT_NULL(error);
     321
     322        pendingCallbackWasCalled = true;
     323    }];
     324    TestWebKitAPI::Util::run(&pendingCallbackWasCalled);
     325    TestWebKitAPI::Util::run(&extensionTabDidNavigateWasCalled);
     326
     327    // Unregister the test extension.
     328    pendingCallbackWasCalled = false;
     329    [[webView _inspector] unregisterExtension:sharedInspectorExtension.get() completionHandler:^(NSError * _Nullable error) {
     330        EXPECT_NULL(error);
     331
     332        pendingCallbackWasCalled = true;
     333    }];
     334    TestWebKitAPI::Util::run(&pendingCallbackWasCalled);
     335}
     336
    237337#endif // ENABLE(INSPECTOR_EXTENSIONS)
Note: See TracChangeset for help on using the changeset viewer.