Changeset 186664 in webkit


Ignore:
Timestamp:
Jul 9, 2015 10:18:53 PM (9 years ago)
Author:
mitz@apple.com
Message:

Source/WebCore:
WebCore part of Track and expose policies for external URL schemes and App Links separately
https://bugs.webkit.org/show_bug.cgi?id=146822

Reviewed by Anders Carlsson.

  • loader/FrameLoaderTypes.h: Added ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes,

meaning external schemes are allowed but App Links are not. The opposite state doesn’t
exist.

  • page/ContextMenuController.cpp:

(WebCore::ContextMenuController::contextMenuItemSelected): Opening a link in a new window
or in the current window should never open it as an App Link.

Source/WebKit2:
WebKit2 part of Track and expose policies for external URL schemes and App Links separately
https://bugs.webkit.org/show_bug.cgi?id=146822

Reviewed by Anders Carlsson.

  • Shared/NavigationActionData.cpp:

(WebKit::NavigationActionData::encode):
(WebKit::NavigationActionData::decode):

  • Shared/NavigationActionData.h: Replaced the shouldOpenExternalURLsPolicy boolean member with a shouldOpenExternalURLsPolicy member whose type is ShouldOpenExternalURLsPolicy, and updated encoding and decoding:
  • UIProcess/API/APINavigationAction.h: Added shouldOpenAppLinks boolean to NavigationAction::create and the constructor. It augments the policy in the NavigationActionData with a valude decided in the UI process. Replaced shouldOpenExternalURLs() with shouldOpenExternalSchemes() and shouldOpenAppLinks() which check the policy and the new m_shouldOpenAppLinks boolean.
  • UIProcess/API/Cocoa/WKNavigationAction.mm:

(-[WKNavigationAction _shouldOpenExternalSchemes]): Getter for new property, calls through

to the NavigationAction.

(-[WKNavigationAction _shouldOpenAppLinks]): Ditto.
(-[WKNavigationAction _shouldOpenExternalURLs]): Now deprecated and returns the

_shouldOpenExternalSchemes value.

  • UIProcess/API/Cocoa/WKNavigationActionPrivate.h: Declared new properties for the two policies and deprecated old property.
  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::tryAppLink): Changed to use NavigationAction::shouldOpenAppLinks, which

encapsulates logic that used to be here.

  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::UIClient::createNewPage): Allow App Links (if already allowed by policy).

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::decidePolicyForNavigationAction): Moved logic from tryAppLink in

NavigationState.mm here and pass the result to NavigationAction::create.

(WebKit::WebPageProxy::decidePolicyForNewWindowAction): Allow App Links (if already allowed

by policy).

  • UIProcess/WebPageProxy.h:

(WebKit::WebPageProxy::loadRequest): Changed the default policy to not allow App Links (but

still allow external schemes).

  • WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.cpp:

(WKBundleNavigationActionGetShouldTryAppLinks): Added this getter.

  • WebProcess/InjectedBundle/API/c/WKBundleNavigationActionPrivate.h:
  • WebProcess/InjectedBundle/InjectedBundleNavigationAction.cpp:

(WebKit::InjectedBundleNavigationAction::InjectedBundleNavigationAction):

  • WebProcess/InjectedBundle/InjectedBundleNavigationAction.h: Added m_shouldTryAppLinks boolean member, initialized from the policy. Updated the initialization of m_shouldOpenExternalURLs to account for the new policy.
  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Pass the policy

in the navigation data.

Location:
trunk/Source
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r186663 r186664  
     12015-07-09  Dan Bernstein  <mitz@apple.com>
     2
     3        WebCore part of Track and expose policies for external URL schemes and App Links separately
     4        https://bugs.webkit.org/show_bug.cgi?id=146822
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * loader/FrameLoaderTypes.h: Added ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes,
     9        meaning external schemes are allowed but App Links are not. The opposite state doesn’t
     10        exist.
     11
     12        * page/ContextMenuController.cpp:
     13        (WebCore::ContextMenuController::contextMenuItemSelected): Opening a link in a new window
     14        or in the current window should never open it as an App Link.
     15
    1162015-07-09  Daniel Bates  <dabates@apple.com>
    217
  • trunk/Source/WebCore/loader/FrameLoaderTypes.h

    r184941 r186664  
    7474enum class ShouldOpenExternalURLsPolicy {
    7575    ShouldNotAllow,
     76    ShouldAllowExternalSchemes,
    7677    ShouldAllow,
    7778};
  • trunk/Source/WebCore/page/ContextMenuController.cpp

    r185231 r186664  
    239239    switch (item->action()) {
    240240    case ContextMenuItemTagOpenLinkInNewWindow:
    241         openNewWindow(m_context.hitTestResult().absoluteLinkURL(), frame, ShouldOpenExternalURLsPolicy::ShouldAllow);
     241        openNewWindow(m_context.hitTestResult().absoluteLinkURL(), frame, ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes);
    242242        break;
    243243    case ContextMenuItemTagDownloadLinkToDisk:
     
    407407        break;
    408408    case ContextMenuItemTagOpenLinkInThisWindow:
    409         frame->loader().loadFrameRequest(FrameLoadRequest(frame->document()->securityOrigin(), ResourceRequest(m_context.hitTestResult().absoluteLinkURL(), frame->loader().outgoingReferrer()), LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress, ShouldOpenExternalURLsPolicy::ShouldAllow), nullptr, nullptr);
     409        frame->loader().loadFrameRequest(FrameLoadRequest(frame->document()->securityOrigin(), ResourceRequest(m_context.hitTestResult().absoluteLinkURL(), frame->loader().outgoingReferrer()), LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress, ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes), nullptr, nullptr);
    410410        break;
    411411    case ContextMenuItemTagBold:
  • trunk/Source/WebKit2/ChangeLog

    r186662 r186664  
     12015-07-09  Dan Bernstein  <mitz@apple.com>
     2
     3        WebKit2 part of Track and expose policies for external URL schemes and App Links separately
     4        https://bugs.webkit.org/show_bug.cgi?id=146822
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * Shared/NavigationActionData.cpp:
     9        (WebKit::NavigationActionData::encode):
     10        (WebKit::NavigationActionData::decode):
     11        * Shared/NavigationActionData.h:
     12          Replaced the shouldOpenExternalURLsPolicy boolean member with a
     13          shouldOpenExternalURLsPolicy member whose type is ShouldOpenExternalURLsPolicy, and
     14          updated encoding and decoding:
     15
     16        * UIProcess/API/APINavigationAction.h:
     17          Added shouldOpenAppLinks boolean to NavigationAction::create and the constructor. It
     18          augments the policy in the NavigationActionData with a valude decided in the UI process.
     19          Replaced shouldOpenExternalURLs() with shouldOpenExternalSchemes() and
     20          shouldOpenAppLinks() which check the policy and the new m_shouldOpenAppLinks boolean.
     21
     22        * UIProcess/API/Cocoa/WKNavigationAction.mm:
     23        (-[WKNavigationAction _shouldOpenExternalSchemes]): Getter for new property, calls through
     24          to the NavigationAction.
     25        (-[WKNavigationAction _shouldOpenAppLinks]): Ditto.
     26        (-[WKNavigationAction _shouldOpenExternalURLs]): Now deprecated and returns the
     27          _shouldOpenExternalSchemes value.
     28        * UIProcess/API/Cocoa/WKNavigationActionPrivate.h: Declared new properties for the two
     29          policies and deprecated old property.
     30
     31        * UIProcess/Cocoa/NavigationState.mm:
     32        (WebKit::tryAppLink): Changed to use NavigationAction::shouldOpenAppLinks, which
     33          encapsulates logic that used to be here.
     34
     35        * UIProcess/Cocoa/UIDelegate.mm:
     36        (WebKit::UIDelegate::UIClient::createNewPage): Allow App Links (if already allowed by policy).
     37
     38        * UIProcess/WebPageProxy.cpp:
     39        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Moved logic from tryAppLink in
     40          NavigationState.mm here and pass the result to NavigationAction::create.
     41        (WebKit::WebPageProxy::decidePolicyForNewWindowAction): Allow App Links (if already allowed
     42          by policy).
     43        * UIProcess/WebPageProxy.h:
     44        (WebKit::WebPageProxy::loadRequest): Changed the default policy to not allow App Links (but
     45          still allow external schemes).
     46
     47        * WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.cpp:
     48        (WKBundleNavigationActionGetShouldTryAppLinks): Added this getter.
     49        * WebProcess/InjectedBundle/API/c/WKBundleNavigationActionPrivate.h:
     50
     51        * WebProcess/InjectedBundle/InjectedBundleNavigationAction.cpp:
     52        (WebKit::InjectedBundleNavigationAction::InjectedBundleNavigationAction):
     53        * WebProcess/InjectedBundle/InjectedBundleNavigationAction.h:
     54          Added m_shouldTryAppLinks boolean member, initialized from the policy. Updated the
     55          initialization of m_shouldOpenExternalURLs to account for the new policy.
     56
     57        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     58        (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Pass the policy
     59          in the navigation data.
     60
    1612015-07-09  Tim Horton  <timothy_horton@apple.com>
    262
  • trunk/Source/WebKit2/Shared/NavigationActionData.cpp

    r184941 r186664  
    4141    encoder << isProcessingUserGesture;
    4242    encoder << canHandleRequest;
    43     encoder << shouldOpenExternalURLs;
     43    encoder.encodeEnum(shouldOpenExternalURLsPolicy);
    4444}
    4545
     
    5656    if (!decoder.decode(result.canHandleRequest))
    5757        return false;
    58     if (!decoder.decode(result.shouldOpenExternalURLs))
     58    if (!decoder.decodeEnum(result.shouldOpenExternalURLsPolicy))
    5959        return false;
    6060
  • trunk/Source/WebKit2/Shared/NavigationActionData.h

    r184941 r186664  
    4646    bool isProcessingUserGesture { false };
    4747    bool canHandleRequest { false };
    48     bool shouldOpenExternalURLs { false };
     48    WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy { WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow };
    4949};
    5050
  • trunk/Source/WebKit2/UIProcess/API/APINavigationAction.h

    r184941 r186664  
    3939class NavigationAction final : public ObjectImpl<Object::Type::NavigationAction> {
    4040public:
    41     static Ref<NavigationAction> create(const WebKit::NavigationActionData& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, const WebCore::ResourceRequest& request, const WebCore::URL& originalURL)
     41    static Ref<NavigationAction> create(const WebKit::NavigationActionData& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, const WebCore::ResourceRequest& request, const WebCore::URL& originalURL, bool shouldOpenAppLinks)
    4242    {
    43         return adoptRef(*new NavigationAction(navigationActionData, sourceFrame, targetFrame, request, originalURL));
     43        return adoptRef(*new NavigationAction(navigationActionData, sourceFrame, targetFrame, request, originalURL, shouldOpenAppLinks));
    4444    }
    4545
    46     NavigationAction(const WebKit::NavigationActionData& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, const WebCore::ResourceRequest& request, const WebCore::URL& originalURL)
     46    NavigationAction(const WebKit::NavigationActionData& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, const WebCore::ResourceRequest& request, const WebCore::URL& originalURL, bool shouldOpenAppLinks)
    4747        : m_sourceFrame(sourceFrame)
    4848        , m_targetFrame(targetFrame)
    4949        , m_request(request)
    5050        , m_originalURL(originalURL)
     51        , m_shouldOpenAppLinks(shouldOpenAppLinks)
    5152        , m_navigationActionData(navigationActionData)
    5253    {
     
    6465    bool isProcessingUserGesture() const { return m_navigationActionData.isProcessingUserGesture; }
    6566    bool canHandleRequest() const { return m_navigationActionData.canHandleRequest; }
    66     bool shouldOpenExternalURLs() const { return m_navigationActionData.shouldOpenExternalURLs; }
     67    bool shouldOpenExternalSchemes() const { return m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow || m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes; }
     68    bool shouldOpenAppLinks() const { return m_shouldOpenAppLinks && m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow; }
    6769
    6870private:
     
    7375    WebCore::URL m_originalURL;
    7476
     77    bool m_shouldOpenAppLinks;
     78
    7579    WebKit::NavigationActionData m_navigationActionData;
    7680};
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKNavigationAction.mm

    r184941 r186664  
    173173}
    174174
     175- (BOOL)_shouldOpenExternalSchemes
     176{
     177    return _navigationAction->shouldOpenExternalSchemes();
     178}
     179
     180- (BOOL)_shouldOpenAppLinks
     181{
     182    return _navigationAction->shouldOpenAppLinks();
     183}
     184
    175185- (BOOL)_shouldOpenExternalURLs
    176186{
    177     return _navigationAction->shouldOpenExternalURLs();
     187    return [self _shouldOpenExternalSchemes];
    178188}
    179189
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKNavigationActionPrivate.h

    r184941 r186664  
    3333@property (nonatomic, readonly, getter=_isUserInitiated) BOOL _userInitiated;
    3434@property (nonatomic, readonly) BOOL _canHandleRequest;
    35 @property (nonatomic, readonly) BOOL _shouldOpenExternalURLs;
     35@property (nonatomic, readonly) BOOL _shouldOpenExternalSchemes WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
     36@property (nonatomic, readonly) BOOL _shouldOpenAppLinks WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
     37
     38@property (nonatomic, readonly) BOOL _shouldOpenExternalURLs WK_DEPRECATED(WK_MAC_TBA, WK_MAC_TBA, WK_IOS_TBA, WK_IOS_TBA, "use _shouldOpenExternalSchemes and _shouldOpenAppLinks");
    3639
    3740@end
  • trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.mm

    r186586 r186664  
    249249{
    250250#if HAVE(APP_LINKS)
    251     bool mainFrameNavigation = !navigationAction->targetFrame() || navigationAction->targetFrame()->isMainFrame();
    252     bool shouldOpenExternalURLs = navigationAction->shouldOpenExternalURLs();
    253     if (!mainFrameNavigation || !shouldOpenExternalURLs) {
    254         completionHandler(false);
    255         return;
    256     }
    257 
    258     // If the new URL is within the same origin as the current URL, do not try to open it externally.
    259     URL currentURL = URL(ParsedURLString, currentMainFrameURL);
    260     if (protocolHostAndPortAreEqual(currentURL, navigationAction->request().url())) {
     251    if (!navigationAction->shouldOpenAppLinks()) {
    261252        completionHandler(false);
    262253        return;
  • trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm

    r185877 r186664  
    106106
    107107    auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin());
    108     auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, request, WebCore::URL());
     108    auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, request, WebCore::URL(), true);
    109109
    110110    RetainPtr<WKWebView> webView = [delegate.get() webView:m_uiDelegate.m_webView createWebViewWithConfiguration:configuration.get() forNavigationAction:wrapper(navigationAction) windowFeatures:adoptNS([[WKWindowFeatures alloc] _initWithWindowFeatures:windowFeatures]).get()];
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r186538 r186664  
    32563256            sourceFrameInfo = API::FrameInfo::create(*originatingFrame, originatingFrameSecurityOrigin.securityOrigin());
    32573257
    3258         auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), destinationFrameInfo.get(), request, originalRequest.url());
     3258        bool shouldOpenAppLinks = (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
     3259
     3260        auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), destinationFrameInfo.get(), request, originalRequest.url(), shouldOpenAppLinks);
    32593261
    32603262        m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
     
    32853287            sourceFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin());
    32863288
    3287         auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url());
     3289        auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), true);
    32883290
    32893291        m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r186538 r186664  
    364364    bool isClosed() const { return m_isClosed; }
    365365
    366     RefPtr<API::Navigation> loadRequest(const WebCore::ResourceRequest&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow, API::Object* userData = nullptr);
     366    RefPtr<API::Navigation> loadRequest(const WebCore::ResourceRequest&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes, API::Object* userData = nullptr);
    367367    RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
    368368    RefPtr<API::Navigation> loadData(API::Data*, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr);
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.cpp

    r185072 r186664  
    7272    return toImpl(navigationActionRef)->shouldOpenExternalURLs();
    7373}
     74
     75bool WKBundleNavigationActionGetShouldTryAppLinks(WKBundleNavigationActionRef navigationActionRef)
     76{
     77    return toImpl(navigationActionRef)->shouldTryAppLinks();
     78}
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationActionPrivate.h

    r185072 r186664  
    3434
    3535WK_EXPORT bool WKBundleNavigationActionGetShouldOpenExternalURLs(WKBundleNavigationActionRef);
     36WK_EXPORT bool WKBundleNavigationActionGetShouldTryAppLinks(WKBundleNavigationActionRef);
    3637
    3738#ifdef __cplusplus
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.cpp

    r186566 r186664  
    9191    , m_modifiers(modifiersForNavigationAction(navigationAction))
    9292    , m_mouseButton(WebMouseEvent::NoButton)
    93     , m_shouldOpenExternalURLs(navigationAction.shouldOpenExternalURLsPolicy() == ShouldOpenExternalURLsPolicy::ShouldAllow)
     93    , m_shouldOpenExternalURLs(navigationAction.shouldOpenExternalURLsPolicy() == ShouldOpenExternalURLsPolicy::ShouldAllow || navigationAction.shouldOpenExternalURLsPolicy() == ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes)
     94    , m_shouldTryAppLinks(navigationAction.shouldOpenExternalURLsPolicy() == ShouldOpenExternalURLsPolicy::ShouldAllow)
    9495{
    9596    if (const MouseEvent* mouseEvent = mouseEventForNavigationAction(navigationAction)) {
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.h

    r186566 r186664  
    5858
    5959    bool shouldOpenExternalURLs() const { return m_shouldOpenExternalURLs; }
     60    bool shouldTryAppLinks() const { return m_shouldTryAppLinks; }
    6061
    6162private:
     
    6869    RefPtr<InjectedBundleNodeHandle> m_formElement;
    6970    bool m_shouldOpenExternalURLs;
     71    bool m_shouldTryAppLinks;
    7072};
    7173
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r185877 r186664  
    802802    navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
    803803    navigationActionData.canHandleRequest = webPage->canHandleRequest(request);
    804     navigationActionData.shouldOpenExternalURLs = navigationAction.shouldOpenExternalURLsPolicy() == ShouldOpenExternalURLsPolicy::ShouldAllow;
     804    navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
    805805
    806806    WebCore::Frame* coreFrame = m_frame->coreFrame();
Note: See TracChangeset for help on using the changeset viewer.