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

Changeset 267411 in webkit


Ignore:
Timestamp:
Sep 22, 2020, 9:14:08 AM (6 years ago)
Author:
BJ Burg
Message:

[Cocoa] _WKInspectorDelegate should handle showing external resources
https://bugs.webkit.org/show_bug.cgi?id=216334

Reviewed by Devin Rousso.

Source/WebCore:

Adapt to the rename of InspectorFrontendHost.{openInNewTab => openURLExternally}.

  • inspector/InspectorFrontendClient.h:
  • inspector/InspectorFrontendClientLocal.cpp:

(WebCore::InspectorFrontendClientLocal::openURLExternally):
(WebCore::InspectorFrontendClientLocal::openInNewTab): Deleted.

  • inspector/InspectorFrontendClientLocal.h:
  • inspector/InspectorFrontendHost.cpp:

(WebCore::InspectorFrontendHost::openURLExternally):
(WebCore::InspectorFrontendHost::openInNewTab): Deleted.

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

Source/WebInspectorUI:

Adapt to the rename of InspectorFrontendHost.{openInNewTab => openURLExternally}.

  • UserInterface/Base/Main.js:
  • UserInterface/Debug/UncaughtExceptionReporter.js:

(sheetElement.innerHTML.div):

  • UserInterface/Protocol/InspectorFrontendAPI.js:
  • UserInterface/Views/ResourceTreeElement.js:

(WI.ResourceTreeElement.prototype.ondblclick):

Source/WebKit:

WebKit clients need a way to control the loading and presentation of
external resources that are linked in Web Inspector's user interface.

Rename InspectorFrontendHost.openInNewTab to openURLExternally. Change
the implementation to forward the request to UIProcess rather than the
inspected WebProcess.

When a navigation is triggered in WKInspectorViewController's WKWebView,
allow the delegate to open the requested resource. Otherwise, redirect
the navigation to the inspected WebView or open it using NSWorkspace
(for the remote case).

New API test: WKInspectorDelegate.OpenURLExternally.

  • UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h: Added.
  • UIProcess/API/Cocoa/_WKInspectorTesting.mm: Added.

(snippetToOpenURLExternally):
(-[_WKInspector _openURLExternallyForTesting:useFrontendAPI:]):
Add some helpers for writing API tests.

  • UIProcess/API/APIInspectorClient.h:

(API::InspectorClient::openURLExternally):

  • UIProcess/API/Cocoa/_WKInspectorDelegate.h:
  • UIProcess/Cocoa/PageClientImplCocoa.mm:
  • UIProcess/Inspector/Cocoa/InspectorDelegate.h:
  • UIProcess/Inspector/Cocoa/InspectorDelegate.mm:

(WebKit::InspectorDelegate::setDelegate):
(WebKit::InspectorDelegate::InspectorClient::openURLExternally):
Add new delegate method to _WKInspectorDelegate.

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

(WebKit::RemoteWebInspectorProxy::openURLExternally):
(WebKit::RemoteWebInspectorProxy::platformOpenURLExternally):
(WebKit::RemoteWebInspectorProxy::openInNewTab): Deleted.
(WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.

  • UIProcess/Inspector/gtk/RemoteWebInspectorProxyGtk.cpp:

(WebKit::RemoteWebInspectorProxy::platformURLExternally):
(WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.

  • UIProcess/Inspector/mac/RemoteWebInspectorProxyMac.mm:

(WebKit::RemoteWebInspectorProxy::platformOpenURLExternally):
(WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.

  • UIProcess/Inspector/win/RemoteWebInspectorProxyWin.cpp:

(WebKit::RemoteWebInspectorProxy::platformOpenURLExternally):
(WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.
Rename openInNewTab to openURLExternally. In some cases the client
may not choose to present a new tab, so the name is no longer accurate.

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

(WebKit::WebInspectorProxy::inspectorWindow const):
(WebKit::WebInspectorProxy::openURLExternally):
(WebKit::WebInspectorProxy::evaluateInFrontendForTesting):

  • UIProcess/Inspector/mac/WebInspectorProxyMac.mm:

(-[WKWebInspectorProxyObjCAdapter inspectorViewController:openURLExternally:]):
Add some helpers for writing API tests. Add an IPC message
for evaluating a JavaScript expression in the frontend page.
Also, add a message receiver for the OpenURLExternally message
which passes the request to the API layer.

  • UIProcess/Inspector/mac/WKInspectorViewController.h:
  • UIProcess/Inspector/mac/WKInspectorViewController.mm:

(-[WKInspectorViewController webView:decidePolicyForNavigationAction:decisionHandler:]):
Call the delegate method if a navigation inside the inspector WKWebView is an external URL.
Specifically the request is to load something other than the Web Inspector's main HTML page.

  • WebProcess/Inspector/WebInspector.cpp:

(WebKit::WebInspector::openInNewTab): Deleted.

  • WebProcess/Inspector/WebInspector.h:
  • WebProcess/Inspector/WebInspector.messages.in:

No need to handle this message anymore in the inspected WebProcess.

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

(WebKit::RemoteWebInspectorUI::openURLExternally):
(WebKit::RemoteWebInspectorUI::openInNewTab): Deleted.

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

(WebKit::WebInspectorUI::updateConnection):
(WebKit::WebInspectorUI::closeWindow):
(WebKit::WebInspectorUI::openURLExternally):
(WebKit::WebInspectorUI::evaluateInFrontendForTesting):
(WebKit::WebInspectorUI::openInNewTab): Deleted.
When we need to open the URL externally, send an IPC message to UIProcess.
The old implementation triggered the navigation from the inspected WebProcess.
That approach is no longer desirable. Remove the unneeded IPC connection.

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

(WebKit::WebInspectorFrontendAPIDispatcher::evaluateExpressionForTesting):
Fulfill the request to evaluate the expression in the frontend page.

  • SourcesCocoa.txt:
  • WebKit.xcodeproj/project.pbxproj:

Some files were added.

Tools:

Test the delegate using WebKit API and using InspectorFrontendHost API.

  • TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm:

(-[InspectorDelegate inspector:openURLExternally:]): Added.
(TEST):

Location:
trunk
Files:
44 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r267408 r267411  
     12020-09-22  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] _WKInspectorDelegate should handle showing external resources
     4        https://bugs.webkit.org/show_bug.cgi?id=216334
     5
     6        Reviewed by Devin Rousso.
     7
     8        Adapt to the rename of InspectorFrontendHost.{openInNewTab => openURLExternally}.
     9
     10        * inspector/InspectorFrontendClient.h:
     11        * inspector/InspectorFrontendClientLocal.cpp:
     12        (WebCore::InspectorFrontendClientLocal::openURLExternally):
     13        (WebCore::InspectorFrontendClientLocal::openInNewTab): Deleted.
     14        * inspector/InspectorFrontendClientLocal.h:
     15        * inspector/InspectorFrontendHost.cpp:
     16        (WebCore::InspectorFrontendHost::openURLExternally):
     17        (WebCore::InspectorFrontendHost::openInNewTab): Deleted.
     18        * inspector/InspectorFrontendHost.h:
     19        * inspector/InspectorFrontendHost.idl:
     20
    1212020-09-22  Sam Weinig  <weinig@apple.com>
    222
  • trunk/Source/WebCore/inspector/InspectorFrontendClient.h

    r257835 r267411  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2020 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    9192    WEBCORE_EXPORT virtual void changeSheetRect(const FloatRect&) = 0;
    9293
    93     WEBCORE_EXPORT virtual void openInNewTab(const String& url) = 0;
    94 
     94    WEBCORE_EXPORT virtual void openURLExternally(const String& url) = 0;
    9595    virtual bool canSave() = 0;
    9696    virtual void save(const WTF::String& url, const WTF::String& content, bool base64Encoded, bool forceSaveAs) = 0;
  • trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp

    r260317 r267411  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
    3  * Copyright (C) 2015 Apple Inc. All rights reserved.
     3 * Copyright (C) 2015-2020 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    251251}
    252252
    253 void InspectorFrontendClientLocal::openInNewTab(const String& url)
     253void InspectorFrontendClientLocal::openURLExternally(const String& url)
    254254{
    255255    UserGestureIndicator indicator { ProcessingUserGesture };
  • trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h

    r257835 r267411  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
    3  * Copyright (C) 2015 Apple Inc. All rights reserved.
     3 * Copyright (C) 2015-2020 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    7777    WEBCORE_EXPORT void changeAttachedWindowWidth(unsigned) final;
    7878    WEBCORE_EXPORT void changeSheetRect(const FloatRect&) final;
    79     WEBCORE_EXPORT void openInNewTab(const String& url) final;
     79    WEBCORE_EXPORT void openURLExternally(const String& url) final;
    8080    bool canSave()  override { return false; }
    8181    void save(const String&, const String&, bool, bool) override { }
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp

    r267143 r267411  
    11/*
    2  * Copyright (C) 2007-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2020 Apple Inc. All rights reserved.
    33 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
    44 *
     
    415415}
    416416
    417 void InspectorFrontendHost::openInNewTab(const String& url)
     417void InspectorFrontendHost::openURLExternally(const String& url)
    418418{
    419419    if (WTF::protocolIsJavaScript(url))
     
    421421
    422422    if (m_client)
    423         m_client->openInNewTab(url);
     423        m_client->openURLExternally(url);
    424424}
    425425
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.h

    r257835 r267411  
    11/*
    2  * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    103103    void copyText(const String& text);
    104104    void killText(const String& text, bool shouldPrependToKillRing, bool shouldStartNewSequence);
    105     void openInNewTab(const String& url);
     105    void openURLExternally(const String& url);
    106106    bool canSave();
    107107    void save(const String& url, const String& content, bool base64Encoded, bool forceSaveAs);
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.idl

    r266662 r267411  
    11/*
    2  * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2020 Apple Inc. All rights reserved.
    33 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
    44 * Copyright (C) 2009 Google Inc. All rights reserved.
     
    7272    undefined copyText(DOMString text);
    7373    undefined killText(DOMString text, boolean shouldPrependToKillRing, boolean shouldStartNewSequence);
    74     undefined openInNewTab(DOMString url);
     74    undefined openURLExternally(DOMString url);
    7575    boolean canSave();
    7676    undefined save(DOMString url, DOMString content, boolean base64Encoded, boolean forceSaveAs);
  • trunk/Source/WebInspectorUI/ChangeLog

    r267379 r267411  
     12020-09-22  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] _WKInspectorDelegate should handle showing external resources
     4        https://bugs.webkit.org/show_bug.cgi?id=216334
     5
     6        Reviewed by Devin Rousso.
     7
     8        Adapt to the rename of InspectorFrontendHost.{openInNewTab => openURLExternally}.
     9
     10        * UserInterface/Base/Main.js:
     11        * UserInterface/Debug/UncaughtExceptionReporter.js:
     12        (sheetElement.innerHTML.div):
     13        * UserInterface/Protocol/InspectorFrontendAPI.js:
     14        * UserInterface/Views/ResourceTreeElement.js:
     15        (WI.ResourceTreeElement.prototype.ondblclick):
     16
    1172020-09-21  Nikita Vasilyev  <nvasilyev@apple.com>
    218
  • trunk/Source/WebInspectorUI/UserInterface/Base/Main.js

    r267031 r267411  
    11/*
    2  * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    10611061
    10621062    if (options.alwaysOpenExternally) {
    1063         InspectorFrontendHost.openInNewTab(url);
     1063        InspectorFrontendHost.openURLExternally(url);
    10641064        return;
    10651065    }
     
    10881088    }
    10891089
    1090     InspectorFrontendHost.openInNewTab(url);
     1090    InspectorFrontendHost.openURLExternally(url);
    10911091};
    10921092
  • trunk/Source/WebInspectorUI/UserInterface/Debug/UncaughtExceptionReporter.js

    r253172 r267411  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    298298
    299299    document.getElementById("uncaught-exception-bug-report-link").addEventListener("click", (event) => {
    300         InspectorFrontendHost.openInNewTab(prefilledBugReportLink);
     300        InspectorFrontendHost.openURLExternally(prefilledBugReportLink);
    301301        event.stopImmediatePropagation();
    302302        event.preventDefault();
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js

    r260847 r267411  
    11/*
    2  * Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js

    r263429 r267411  
    11/*
    2  * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    122122            return;
    123123
    124         InspectorFrontendHost.openInNewTab(this._resource.url);
     124        WI.openURL(this._resource.url);
    125125    }
    126126
  • trunk/Source/WebKit/ChangeLog

    r267405 r267411  
     12020-09-22  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] _WKInspectorDelegate should handle showing external resources
     4        https://bugs.webkit.org/show_bug.cgi?id=216334
     5
     6        Reviewed by Devin Rousso.
     7
     8        WebKit clients need a way to control the loading and presentation of
     9        external resources that are linked in Web Inspector's user interface.
     10
     11        Rename InspectorFrontendHost.openInNewTab to openURLExternally. Change
     12        the implementation to forward the request to UIProcess rather than the
     13        inspected WebProcess.
     14
     15        When a navigation is triggered in WKInspectorViewController's WKWebView,
     16        allow the delegate to open the requested resource. Otherwise, redirect
     17        the navigation to the inspected WebView or open it using NSWorkspace
     18        (for the remote case).
     19
     20        New API test: WKInspectorDelegate.OpenURLExternally.
     21
     22        * UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h: Added.
     23        * UIProcess/API/Cocoa/_WKInspectorTesting.mm: Added.
     24        (snippetToOpenURLExternally):
     25        (-[_WKInspector _openURLExternallyForTesting:useFrontendAPI:]):
     26        Add some helpers for writing API tests.
     27
     28        * UIProcess/API/APIInspectorClient.h:
     29        (API::InspectorClient::openURLExternally):
     30        * UIProcess/API/Cocoa/_WKInspectorDelegate.h:
     31        * UIProcess/Cocoa/PageClientImplCocoa.mm:
     32        * UIProcess/Inspector/Cocoa/InspectorDelegate.h:
     33        * UIProcess/Inspector/Cocoa/InspectorDelegate.mm:
     34        (WebKit::InspectorDelegate::setDelegate):
     35        (WebKit::InspectorDelegate::InspectorClient::openURLExternally):
     36        Add new delegate method to _WKInspectorDelegate.
     37
     38        * UIProcess/Inspector/RemoteWebInspectorProxy.messages.in:
     39        * UIProcess/Inspector/RemoteWebInspectorProxy.h:
     40        * UIProcess/Inspector/RemoteWebInspectorProxy.cpp:
     41        (WebKit::RemoteWebInspectorProxy::openURLExternally):
     42        (WebKit::RemoteWebInspectorProxy::platformOpenURLExternally):
     43        (WebKit::RemoteWebInspectorProxy::openInNewTab): Deleted.
     44        (WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.
     45        * UIProcess/Inspector/gtk/RemoteWebInspectorProxyGtk.cpp:
     46        (WebKit::RemoteWebInspectorProxy::platformURLExternally):
     47        (WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.
     48        * UIProcess/Inspector/mac/RemoteWebInspectorProxyMac.mm:
     49        (WebKit::RemoteWebInspectorProxy::platformOpenURLExternally):
     50        (WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.
     51        * UIProcess/Inspector/win/RemoteWebInspectorProxyWin.cpp:
     52        (WebKit::RemoteWebInspectorProxy::platformOpenURLExternally):
     53        (WebKit::RemoteWebInspectorProxy::platformOpenInNewTab): Deleted.
     54        Rename openInNewTab to openURLExternally. In some cases the client
     55        may not choose to present a new tab, so the name is no longer accurate.
     56
     57        * UIProcess/Inspector/WebInspectorProxy.messages.in:
     58        * UIProcess/Inspector/WebInspectorProxy.h:
     59        * UIProcess/Inspector/WebInspectorProxy.cpp:
     60        (WebKit::WebInspectorProxy::inspectorWindow const):
     61        (WebKit::WebInspectorProxy::openURLExternally):
     62        (WebKit::WebInspectorProxy::evaluateInFrontendForTesting):
     63        * UIProcess/Inspector/mac/WebInspectorProxyMac.mm:
     64        (-[WKWebInspectorProxyObjCAdapter inspectorViewController:openURLExternally:]):
     65        Add some helpers for writing API tests. Add an IPC message
     66        for evaluating a JavaScript expression in the frontend page.
     67        Also, add a message receiver for the OpenURLExternally message
     68        which passes the request to the API layer.
     69
     70        * UIProcess/Inspector/mac/WKInspectorViewController.h:
     71        * UIProcess/Inspector/mac/WKInspectorViewController.mm:
     72        (-[WKInspectorViewController webView:decidePolicyForNavigationAction:decisionHandler:]):
     73        Call the delegate method if a navigation inside the inspector WKWebView is an external URL.
     74        Specifically the request is to load something other than the Web Inspector's main HTML page.
     75
     76        * WebProcess/Inspector/WebInspector.cpp:
     77        (WebKit::WebInspector::openInNewTab): Deleted.
     78        * WebProcess/Inspector/WebInspector.h:
     79        * WebProcess/Inspector/WebInspector.messages.in:
     80        No need to handle this message anymore in the inspected WebProcess.
     81
     82        * WebProcess/Inspector/RemoteWebInspectorUI.h:
     83        * WebProcess/Inspector/RemoteWebInspectorUI.cpp:
     84        (WebKit::RemoteWebInspectorUI::openURLExternally):
     85        (WebKit::RemoteWebInspectorUI::openInNewTab): Deleted.
     86        * WebProcess/Inspector/WebInspectorUI.messages.in:
     87        * WebProcess/Inspector/WebInspectorUI.h:
     88        * WebProcess/Inspector/WebInspectorUI.cpp:
     89        (WebKit::WebInspectorUI::updateConnection):
     90        (WebKit::WebInspectorUI::closeWindow):
     91        (WebKit::WebInspectorUI::openURLExternally):
     92        (WebKit::WebInspectorUI::evaluateInFrontendForTesting):
     93        (WebKit::WebInspectorUI::openInNewTab): Deleted.
     94        When we need to open the URL externally, send an IPC message to UIProcess.
     95        The old implementation triggered the navigation from the inspected WebProcess.
     96        That approach is no longer desirable. Remove the unneeded IPC connection.
     97
     98        * WebProcess/Inspector/WebInspectorFrontendAPIDispatcher.h:
     99        * WebProcess/Inspector/WebInspectorFrontendAPIDispatcher.cpp:
     100        (WebKit::WebInspectorFrontendAPIDispatcher::evaluateExpressionForTesting):
     101        Fulfill the request to evaluate the expression in the frontend page.
     102
     103        * SourcesCocoa.txt:
     104        * WebKit.xcodeproj/project.pbxproj:
     105        Some files were added.
     106
     107
    11082020-09-22  Per Arne Vollan  <pvollan@apple.com>
    2109
  • trunk/Source/WebKit/SourcesCocoa.txt

    r267156 r267411  
    260260UIProcess/API/Cocoa/_WKGeolocationPosition.mm
    261261UIProcess/API/Cocoa/_WKInspector.mm
     262UIProcess/API/Cocoa/_WKInspectorTesting.mm
    262263UIProcess/API/Cocoa/_WKInspectorDebuggableInfo.mm
    263264UIProcess/API/Cocoa/_WKInspectorWindow.mm
  • trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h

    r266890 r267411  
    2626#pragma once
    2727
     28#include <wtf/Forward.h>
     29
    2830namespace WebKit {
    2931class WebInspectorProxy;
     
    3941    virtual void browserDomainEnabled(WebKit::WebInspectorProxy&) { }
    4042    virtual void browserDomainDisabled(WebKit::WebInspectorProxy&) { }
     43    virtual void openURLExternally(WebKit::WebInspectorProxy&, const WTF::String& url) { }
    4144};
    4245
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h

    r266890 r267411  
    4242- (void)inspectorDidDisableBrowserDomain:(_WKInspector *)inspector;
    4343
     44/*! @abstract Called when the _WKInspector requests to show a resource externally. This
     45    is used to display documentation pages and to show external URLs that are linkified.
     46    @param inspector the associated inspector for which an external navigation should be triggered.
     47    @param url The resource to be shown.
     48 */
     49- (void)inspector:(_WKInspector *)inspector openURLExternally:(NSURL *)url;
     50
    4451@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h

    r267410 r267411  
    2424 */
    2525
    26 #pragma once
     26#import "_WKInspector.h"
    2727
    28 namespace WebKit {
    29 class WebInspectorProxy;
    30 }
    31 
    32 namespace API {
    33 
    34 class InspectorClient {
    35     WTF_MAKE_FAST_ALLOCATED;
    36 public:
    37     virtual ~InspectorClient() = default;
    38 
    39     virtual void browserDomainEnabled(WebKit::WebInspectorProxy&) { }
    40     virtual void browserDomainDisabled(WebKit::WebInspectorProxy&) { }
    41 };
    42 
    43 } // namespace API
     28@interface _WKInspector (WKTesting)
     29- (void)_openURLExternallyForTesting:(NSURL *)url useFrontendAPI:(BOOL)useFrontendAPI;
     30@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorTesting.mm

    r267410 r267411  
    2424 */
    2525
    26 #import <Foundation/Foundation.h>
    27 #import <WebKit/WKFoundation.h>
     26#import "config.h"
    2827
    29 @class _WKInspector;
     28#import "WKWebView.h"
     29#import "_WKInspectorInternal.h"
     30#import "_WKInspectorPrivateForTesting.h"
    3031
    31 @protocol _WKInspectorDelegate <NSObject>
    32 @optional
     32// This file exists to centralize all fragile code that is used by _WKInspector API tests. The tests
     33// trigger WebInspectorUI behavior by evaluating JavaScript or by calling internal methods.
    3334
    34 /*! @abstract Called when the Browser domain is enabled for the associated _WKInspector.
    35     @param inspector the associated _WKInspector for which the Browser domain has been enabled.
    36  */
    37 - (void)inspectorDidEnableBrowserDomain:(_WKInspector *)inspector;
     35static NSString *JavaScriptSnippetToOpenURLExternally(NSURL *url)
     36{
     37    return [NSString stringWithFormat:@"InspectorFrontendHost.openURLExternally(\"%@\")", url.absoluteString];
     38}
    3839
    39 /*! @abstract Called when the  Browser domain is disabled for the associated _WKInspector.
    40     @param inspector the associated _WKInspector for which the Browser domain has been disabled.
    41  */
    42 - (void)inspectorDidDisableBrowserDomain:(_WKInspector *)inspector;
     40@implementation _WKInspector (WKTesting)
     41
     42- (void)_openURLExternallyForTesting:(NSURL *)url useFrontendAPI:(BOOL)useFrontendAPI
     43{
     44    if (useFrontendAPI)
     45        _inspector->evaluateInFrontendForTesting(JavaScriptSnippetToOpenURLExternally(url));
     46    else {
     47        // Force the navigation request to be handled naturally through the
     48        // internal NavigationDelegate of WKInspectorViewController.
     49        [self.inspectorWebView loadRequest:[NSURLRequest requestWithURL:url]];
     50    }
     51}
    4352
    4453@end
  • trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm

    r266265 r267411  
    3939PageClientImplCocoa::PageClientImplCocoa(WKWebView *webView)
    4040    : m_webView { webView }
    41     , m_alternativeTextUIController { makeUnique<AlternativeTextUIController>() }
     41    , m_alternativeTextUIController { makeUnique<WebCore::AlternativeTextUIController>() }
    4242{
    4343}
  • trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.h

    r266890 r267411  
    5959        void browserDomainEnabled(WebInspectorProxy&);
    6060        void browserDomainDisabled(WebInspectorProxy&);
     61        void openURLExternally(WebInspectorProxy&, const String& url);
    6162
    6263        InspectorDelegate& m_inspectorDelegate;
     
    6970        bool inspectorDidEnableBrowserDomain : 1;
    7071        bool inspectorDidDisableBrowserDomain : 1;
     72        bool inspectorOpenURLExternally : 1;
    7173    } m_delegateMethods;
    7274};
  • trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorDelegate.mm

    r266890 r267411  
    5555    m_delegateMethods.inspectorDidEnableBrowserDomain = [delegate respondsToSelector:@selector(inspectorDidEnableBrowserDomain:)];
    5656    m_delegateMethods.inspectorDidDisableBrowserDomain = [delegate respondsToSelector:@selector(inspectorDidDisableBrowserDomain:)];
     57    m_delegateMethods.inspectorOpenURLExternally = [delegate respondsToSelector:@selector(inspector:openURLExternally:)];
    5758}
    5859
     
    8889}
    8990
     91void InspectorDelegate::InspectorClient::openURLExternally(WebInspectorProxy&, const String& url)
     92{
     93    if (!m_inspectorDelegate.m_delegateMethods.inspectorOpenURLExternally)
     94        return;
     95
     96    auto& delegate = m_inspectorDelegate.m_delegate;
     97    if (!delegate)
     98        return;
     99
     100    [delegate inspector:m_inspectorDelegate.m_inspector.get().get() openURLExternally:[NSURL URLWithString:url]];
     101}
     102
    90103} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorProxy.cpp

    r261299 r267411  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    149149}
    150150
    151 void RemoteWebInspectorProxy::openInNewTab(const String& url)
    152 {
    153     platformOpenInNewTab(url);
     151void RemoteWebInspectorProxy::openURLExternally(const String& url)
     152{
     153    platformOpenURLExternally(url);
    154154}
    155155
     
    206206void RemoteWebInspectorProxy::platformSetForcedAppearance(InspectorFrontendClient::Appearance) { }
    207207void RemoteWebInspectorProxy::platformStartWindowDrag() { }
    208 void RemoteWebInspectorProxy::platformOpenInNewTab(const String&) { }
     208void RemoteWebInspectorProxy::platformOpenURLExternally(const String&) { }
    209209void RemoteWebInspectorProxy::platformShowCertificate(const CertificateInfo&) { }
    210210void RemoteWebInspectorProxy::platformCloseFrontendPageAndWindow() { }
  • trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorProxy.h

    r260847 r267411  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    124124    void setForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
    125125    void startWindowDrag();
    126     void openInNewTab(const String& url);
     126    void openURLExternally(const String& url);
    127127    void showCertificate(const WebCore::CertificateInfo&);
    128128    void sendMessageToBackend(const String& message);
     
    141141    void platformSetForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
    142142    void platformStartWindowDrag();
    143     void platformOpenInNewTab(const String& url);
     143    void platformOpenURLExternally(const String& url);
    144144    void platformShowCertificate(const WebCore::CertificateInfo&);
    145145
  • trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorProxy.messages.in

    r257835 r267411  
    1 # Copyright (C) 2016 Apple Inc. All rights reserved.
     1# Copyright (C) 2016-2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    3636    StartWindowDrag()
    3737
    38     OpenInNewTab(String url)
     38    OpenURLExternally(String url)
    3939    ShowCertificate(WebCore::CertificateInfo certificateInfo)
    4040
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.cpp

    r267031 r267411  
    11/*
    2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
    44 *
     
    606606}
    607607
     608void WebInspectorProxy::openURLExternally(const String& url)
     609{
     610    m_inspectorClient->openURLExternally(*this, url);
     611}
     612
    608613void WebInspectorProxy::inspectedURLChanged(const String& urlString)
    609614{
     
    712717}
    713718
     719void WebInspectorProxy::evaluateInFrontendForTesting(const String& expression)
     720{
     721    if (!m_inspectorPage)
     722        return;
     723
     724    m_inspectorPage->send(Messages::WebInspectorUI::EvaluateInFrontendForTesting(expression));
     725}
     726
    714727// Unsupported configurations can use the stubs provided here.
    715728
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.h

    r266890 r267411  
    11/*
    2  * Copyright (C) 2010, 2014, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
    44 *
     
    129129    void windowFrameDidChange();
    130130    void windowFullScreenDidChange();
    131     NSWindow* inspectorWindow() const { return m_inspectorWindow.get(); }
     131    NSWindow *inspectorWindow() const { return m_inspectorWindow.get(); }
    132132
    133133    void closeFrontendPage();
     
    149149    void showResources();
    150150    void showMainResourceForFrame(WebFrameProxy*);
     151    void openURLExternally(const String& url);
    151152
    152153    AttachmentSide attachmentSide() const { return m_attachmentSide; }
     
    191192    static const unsigned initialWindowWidth;
    192193    static const unsigned initialWindowHeight;
     194
     195    // Testing methods.
     196    void evaluateInFrontendForTesting(const String&);
    193197
    194198private:
     
    216220    void platformAttachAvailabilityChanged(bool);
    217221    void platformSetForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
     222    void platformOpenURLExternally(const String&);
    218223    void platformInspectedURLChanged(const String&);
    219224    void platformShowCertificate(const WebCore::CertificateInfo&);
  • trunk/Source/WebKit/UIProcess/Inspector/WebInspectorProxy.messages.in

    r261103 r267411  
    1 # Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
     1# Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    3535
    3636    SetForcedAppearance(WebCore::InspectorFrontendClient::Appearance appearance)
     37    OpenURLExternally(String url)
    3738
    3839    InspectedURLChanged(String urlString)
  • trunk/Source/WebKit/UIProcess/Inspector/gtk/RemoteWebInspectorProxyGtk.cpp

    r262371 r267411  
    173173}
    174174
    175 void RemoteWebInspectorProxy::platformOpenInNewTab(const String&)
     175void RemoteWebInspectorProxy::platformOpenURLExternally(const String&)
    176176{
    177177}
  • trunk/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorProxyMac.mm

    r261299 r267411  
    11/*
    2  * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    262262}
    263263
    264 void RemoteWebInspectorProxy::platformOpenInNewTab(const String& url)
     264void RemoteWebInspectorProxy::platformOpenURLExternally(const String& url)
    265265{
    266266    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
  • trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.h

    r260847 r267411  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5757- (void)inspectorViewController:(WKInspectorViewController *)inspectorViewController willMoveToWindow:(NSWindow *)newWindow;
    5858- (void)inspectorViewControllerDidMoveToWindow:(WKInspectorViewController *)inspectorViewController;
     59- (void)inspectorViewController:(WKInspectorViewController *)inspectorViewController openURLExternally:(NSURL *)url;
    5960@end
    6061
  • trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.mm

    r260847 r267411  
    228228    // Prevent everything else.
    229229    decisionHandler(WKNavigationActionPolicyCancel);
    230    
    231     // And instead load it in the inspected page.
     230
     231    if (!!_delegate && [_delegate respondsToSelector:@selector(inspectorViewController:openURLExternally:)]) {
     232        [_delegate inspectorViewController:self openURLExternally:navigationAction.request.URL];
     233        return;
     234    }
     235
     236    // Try to load the request in the inspected page if the delegate can't handle it.
    232237    if (_inspectedPage)
    233238        _inspectedPage->loadRequest(navigationAction.request);
  • trunk/Source/WebKit/UIProcess/Inspector/mac/WebInspectorProxyMac.mm

    r264999 r267411  
    11/*
    2  * Copyright (C) 2010-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    194194}
    195195
     196- (void)inspectorViewController:(WKInspectorViewController *)inspectorViewController openURLExternally:(NSURL *)url
     197{
     198    if (_inspectorProxy)
     199        _inspectorProxy->openURLExternally(url.absoluteString);
     200}
     201
    196202@end
    197203
  • trunk/Source/WebKit/UIProcess/Inspector/win/RemoteWebInspectorProxyWin.cpp

    r257835 r267411  
    138138void RemoteWebInspectorProxy::platformSetForcedAppearance(WebCore::InspectorFrontendClient::Appearance) { }
    139139void RemoteWebInspectorProxy::platformStartWindowDrag() { }
    140 void RemoteWebInspectorProxy::platformOpenInNewTab(const String&) { }
     140void RemoteWebInspectorProxy::platformOpenURLExternally(const String&) { }
    141141void RemoteWebInspectorProxy::platformShowCertificate(const WebCore::CertificateInfo&) { }
    142142
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r267326 r267411  
    14071407                99788ACB1F421DDA00C08000 /* _WKAutomationSessionConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 99788AC91F421DCA00C08000 /* _WKAutomationSessionConfiguration.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14081408                9979CA58237F49F10039EC05 /* _WKInspectorPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 9979CA57237F49F00039EC05 /* _WKInspectorPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1409                99996A9F25004BCC004F7559 /* _WKInspectorPrivateForTesting.h in Headers */ = {isa = PBXBuildFile; fileRef = 99996A9D25004BCB004F7559 /* _WKInspectorPrivateForTesting.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14091410                99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C3AE2C1DADA6A700AF5C16 /* WebAutomationSessionMacros.h */; };
    14101411                99C81D5A1C20E7E2005C4C82 /* AutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D551C20DFBE005C4C82 /* AutomationClient.h */; };
     
    44794480                99788ACA1F421DCA00C08000 /* _WKAutomationSessionConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKAutomationSessionConfiguration.mm; sourceTree = "<group>"; };
    44804481                9979CA57237F49F00039EC05 /* _WKInspectorPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorPrivate.h; sourceTree = "<group>"; };
     4482                99996A9D25004BCB004F7559 /* _WKInspectorPrivateForTesting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorPrivateForTesting.h; sourceTree = "<group>"; };
     4483                99996A9E25004BCB004F7559 /* _WKInspectorTesting.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInspectorTesting.mm; sourceTree = "<group>"; };
    44814484                99C3AE231DAD8E3400AF5C16 /* WebAutomationSessionMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionMac.mm; sourceTree = "<group>"; };
    44824485                99C3AE261DAD948500AF5C16 /* WebAutomationSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionCocoa.mm; sourceTree = "<group>"; };
     
    72547257                                5CAFDE442130843600B1F7E1 /* _WKInspectorInternal.h */,
    72557258                                9979CA57237F49F00039EC05 /* _WKInspectorPrivate.h */,
     7259                                99996A9D25004BCB004F7559 /* _WKInspectorPrivateForTesting.h */,
     7260                                99996A9E25004BCB004F7559 /* _WKInspectorTesting.mm */,
    72567261                                A5C0F0AA2000656E00536536 /* _WKInspectorWindow.h */,
    72577262                                A5C0F0A92000656E00536536 /* _WKInspectorWindow.mm */,
     
    1061910624                                5CAFDE472130846A00B1F7E1 /* _WKInspectorInternal.h in Headers */,
    1062010625                                9979CA58237F49F10039EC05 /* _WKInspectorPrivate.h in Headers */,
     10626                                99996A9F25004BCC004F7559 /* _WKInspectorPrivateForTesting.h in Headers */,
    1062110627                                A5C0F0AB2000658200536536 /* _WKInspectorWindow.h in Headers */,
    1062210628                                31B362952141EBCD007BFA53 /* _WKInternalDebugFeature.h in Headers */,
  • trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp

    r261671 r267411  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    180180}
    181181
    182 void RemoteWebInspectorUI::openInNewTab(const String& url)
    183 {
    184     WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::OpenInNewTab(url), m_page.identifier());
     182void RemoteWebInspectorUI::openURLExternally(const String& url)
     183{
     184    WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::OpenURLExternally(url), m_page.identifier());
    185185}
    186186
  • trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h

    r260847 r267411  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8787    void resetState() override;
    8888
    89     void openInNewTab(const String& url) override;
     89    void openURLExternally(const String& url) override;
    9090    void save(const String& url, const String& content, bool base64Encoded, bool forceSaveAs) override;
    9191    void append(const String& url, const String& content) override;
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp

    r261103 r267411  
    11/*
    2  * Copyright (C) 2010, 2014-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    159159}
    160160
    161 void WebInspector::openInNewTab(const String& urlString)
    162 {
    163     UserGestureIndicator indicator { ProcessingUserGesture };
    164 
    165     Page* inspectedPage = m_page->corePage();
    166     if (!inspectedPage)
    167         return;
    168 
    169     Frame& inspectedMainFrame = inspectedPage->mainFrame();
    170     FrameLoadRequest frameLoadRequest { *inspectedMainFrame.document(), inspectedMainFrame.document()->securityOrigin(), ResourceRequest { urlString }, "_blank"_s, InitiatedByMainFrame::Unknown };
    171 
    172     NavigationAction action { *inspectedMainFrame.document(), frameLoadRequest.resourceRequest(), frameLoadRequest.initiatedByMainFrame(), NavigationType::LinkClicked };
    173     Page* newPage = inspectedPage->chrome().createWindow(inspectedMainFrame, { }, action);
    174     if (!newPage)
    175         return;
    176 
    177     newPage->mainFrame().loader().load(WTFMove(frameLoadRequest));
    178 }
    179 
    180161void WebInspector::evaluateScriptForTest(const String& script)
    181162{
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspector.h

    r261254 r267411  
    11/*
    2  * Copyright (C) 2010, 2014, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5656    void close();
    5757
    58     void openInNewTab(const String& urlString);
    59 
    6058    void canAttachWindow(bool& result);
    6159
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspector.messages.in

    r255214 r267411  
    1 # Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
     1# Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    3232    ShowMainResourceForFrame(WebCore::FrameIdentifier frameIdentifier)
    3333
    34     OpenInNewTab(String url)
    35 
    3634    StartPageProfiling()
    3735    StopPageProfiling()
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorFrontendAPIDispatcher.cpp

    r255214 r267411  
    11/*
    2  * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    116116}
    117117
     118void WebInspectorFrontendAPIDispatcher::evaluateExpressionForTesting(const String& expression)
     119{
     120    evaluateOrQueueExpression(expression);
     121}
     122
    118123} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorFrontendAPIDispatcher.h

    r255214 r267411  
    11/*
    2  * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4848    void dispatchMessageAsync(const String& message);
    4949
     50    void evaluateExpressionForTesting(const String&);
    5051private:
    5152    void evaluateOrQueueExpression(const String&);
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp

    r261671 r267411  
    11/*
    2  * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8383void WebInspectorUI::updateConnection()
    8484{
    85     if (m_backendConnection) {
    86         m_backendConnection->invalidate();
    87         m_backendConnection = nullptr;
    88     }
    89 
    9085#if USE(UNIX_DOMAIN_SOCKETS)
    9186    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
     
    111106#endif
    112107
    113 #if USE(UNIX_DOMAIN_SOCKETS) || OS(DARWIN) || PLATFORM(WIN)
    114     m_backendConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
    115     m_backendConnection->open();
    116 #endif
    117 
    118108    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::SetFrontendConnection(connectionClientPort), m_inspectedPageIdentifier);
    119109}
     
    163153{
    164154    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::DidClose(), m_inspectedPageIdentifier);
    165 
    166     if (m_backendConnection) {
    167         m_backendConnection->invalidate();
    168         m_backendConnection = nullptr;
    169     }
    170155
    171156    if (m_frontendController) {
     
    297282}
    298283
    299 void WebInspectorUI::openInNewTab(const String& url)
    300 {
    301     if (m_backendConnection) {
    302         m_backendConnection->send(Messages::WebInspector::OpenInNewTab(url), 0);
    303         WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::BringInspectedPageToFront(), m_inspectedPageIdentifier);
    304     }
     284void WebInspectorUI::openURLExternally(const String& url)
     285{
     286    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::OpenURLExternally(url), m_inspectedPageIdentifier);
    305287}
    306288
     
    396378}
    397379
     380void WebInspectorUI::evaluateInFrontendForTesting(const String& expression)
     381{
     382    m_frontendAPIDispatcher.evaluateExpressionForTesting(expression);
     383}
     384
    398385void WebInspectorUI::pagePaused()
    399386{
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.h

    r261671 r267411  
    11/*
    2  * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8787    void didAppend(const String& url);
    8888
    89     void sendMessageToFrontend(const String&);
     89    void sendMessageToFrontend(const String& message);
     90    void evaluateInFrontendForTesting(const String& expression);
    9091
    9192#if ENABLE(INSPECTOR_TELEMETRY)
    92     void setDiagnosticLoggingAvailable(bool avaliable);
     93    void setDiagnosticLoggingAvailable(bool);
    9394#endif
    9495
     
    126127    void changeSheetRect(const WebCore::FloatRect&) override;
    127128
    128     void openInNewTab(const String& url) override;
     129    void openURLExternally(const String& url) override;
    129130
    130131    bool canSave() override;
     
    154155    WebInspectorFrontendAPIDispatcher m_frontendAPIDispatcher;
    155156    RefPtr<WebCore::InspectorFrontendHost> m_frontendHost;
    156     RefPtr<IPC::Connection> m_backendConnection;
    157157
    158158    // Keep a pointer to the frontend's inspector controller rather than going through
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.messages.in

    r260847 r267411  
    1 # Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
     1# Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    5252
    5353    SendMessageToFrontend(String message)
     54    EvaluateInFrontendForTesting(String expression)
    5455}
  • trunk/Tools/ChangeLog

    r267410 r267411  
     12020-09-22  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] _WKInspectorDelegate should handle showing external resources
     4        https://bugs.webkit.org/show_bug.cgi?id=216334
     5
     6        Reviewed by Devin Rousso.
     7
     8        Test the delegate using WebKit API and using InspectorFrontendHost API.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm:
     11        (-[InspectorDelegate inspector:openURLExternally:]): Added.
     12        (TEST):
     13
    1142020-09-22  Truitt Savell  <tsavell@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm

    r266890 r267411  
    3333#import <WebKit/_WKInspector.h>
    3434#import <WebKit/_WKInspectorDelegate.h>
     35#import <WebKit/_WKInspectorPrivateForTesting.h>
    3536#import <wtf/RetainPtr.h>
    3637
     
    4243static bool browserDomainEnabledForInspectorCalled = false;
    4344static bool browserDomainDisabledForInspectorCalled = false;
    44 static RetainPtr<InspectorDelegate> sharedInspectorDelegate;
     45static bool openURLExternallyCalled = false;
     46static RetainPtr<id <_WKInspectorDelegate>> sharedInspectorDelegate;
     47static RetainPtr<NSURL> urlToOpen;
    4548
    4649@interface InspectorDelegate : NSObject <_WKInspectorDelegate>
     
    6164{
    6265    browserDomainDisabledForInspectorCalled = true;
     66}
     67
     68- (void)inspector:(_WKInspector *)inspector openURLExternally:(NSURL *)url
     69{
     70    EXPECT_STREQ(url.absoluteString.UTF8String, urlToOpen.get().absoluteString.UTF8String);
     71    openURLExternallyCalled = true;
    6372}
    6473
     
    8695@end
    8796
    88 TEST(WebKit_WKInspectorDelegate, DidNotifyForLocalInspector)
     97TEST(WKInspectorDelegate, DidNotifyForLocalInspector)
    8998{
    9099    auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     
    105114}
    106115
     116TEST(WKInspectorDelegate, ShowURLExternally)
     117{
     118    auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     119    webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
     120    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     121    auto uiDelegate = adoptNS([UIDelegate new]);
     122
     123    [webView setUIDelegate:uiDelegate.get()];
     124    [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
     125
     126    [[webView _inspector] show];
     127    TestWebKitAPI::Util::run(&didAttachLocalInspectorCalled);
     128
     129    urlToOpen = [NSURL URLWithString:@"https://www.webkit.org/"];
     130
     131    // Check the case where the load is intercepted by the navigation delegate.
     132    [[webView _inspector] _openURLExternallyForTesting:urlToOpen.get() useFrontendAPI:NO];
     133    TestWebKitAPI::Util::run(&openURLExternallyCalled);
     134
     135    // Check the case where the frontend calls InspectorFrontendHost.openURLExternally().
     136    [[webView _inspector] _openURLExternallyForTesting:urlToOpen.get() useFrontendAPI:YES];
     137    TestWebKitAPI::Util::run(&openURLExternallyCalled);
     138}
     139
    107140#endif // PLATFORM(MAC)
Note: See TracChangeset for help on using the changeset viewer.