Changeset 186964 in webkit


Ignore:
Timestamp:
Jul 17, 2015 2:16:09 PM (9 years ago)
Author:
mitz@apple.com
Message:

Source/WebCore:
WebCore part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
https://bugs.webkit.org/show_bug.cgi?id=147040

Reviewed by Dean Jackson.

Test: TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm

  • loader/FrameLoader.cpp:

(WebCore::shouldOpenExternalURLsPolicyToApply): Pulled the logic out of
applyShouldOpenExternalURLsPolicyToNewDocumentLoader into this new helper.
(WebCore::FrameLoader::loadURL): When targeting a new frame, apply the external URLs policy
to the action passed to checkNewWindowPolicy.
(WebCore::FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader): Call the new
helper function.
(WebCore::createWindow): Include the external URL policy in the action passed to
createWindow.

Source/WebKit2:
WebKit2 part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
https://bugs.webkit.org/show_bug.cgi?id=147040

Reviewed by Dean Jackson.

  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::UIClient::createNewPage): Disallow App Links if the new page is for the
same protocol, host and port as the main frame of this page.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::decidePolicyForNavigationAction): Disallow App Links if
m_shouldSuppressAppLinksInNextNavigationPolicyDecision is set, and reset it. See below for
when we set it.
(WebKit::WebPageProxy::decidePolicyForNewWindowAction): Disallow App Links if the new window
is for the same protocol, host and port as the main frame of this page.
(WebKit::WebPageProxy::createNewPage): Make the new page disallow App Links in the first
policy decision if it is for the same protocol, host and port as the main frame of this
page.

  • UIProcess/WebPageProxy.h: Added m_shouldSuppressAppLinksInNextNavigationPolicyDecision

member variable.

  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::createWindow): Pass the shouldOpenExternalURLsPolicy.

  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction): Ditto.

Tools:
Tests for <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
https://bugs.webkit.org/show_bug.cgi?id=147040

Reviewed by Dean Jackson.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm: Added.

(-[ShouldOpenExternalURLsInNewWindowActionsController webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[ShouldOpenExternalURLsInNewWindowActionsController webView:didFinishNavigation:]):
(-[ShouldOpenExternalURLsInNewWindowActionsController webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
(TEST):

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r186963 r186964  
     12015-07-17  Dan Bernstein  <mitz@apple.com>
     2
     3        WebCore part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
     4        https://bugs.webkit.org/show_bug.cgi?id=147040
     5
     6        Reviewed by Dean Jackson.
     7
     8        Test: TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm
     9
     10        * loader/FrameLoader.cpp:
     11        (WebCore::shouldOpenExternalURLsPolicyToApply): Pulled the logic out of
     12        applyShouldOpenExternalURLsPolicyToNewDocumentLoader into this new helper.
     13        (WebCore::FrameLoader::loadURL): When targeting a new frame, apply the external URLs policy
     14        to the action passed to checkNewWindowPolicy.
     15        (WebCore::FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader): Call the new
     16        helper function.
     17        (WebCore::createWindow): Include the external URL policy in the action passed to
     18        createWindow.
     19
    1202015-07-17  Anders Carlsson  <andersca@apple.com>
    221
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r186683 r186964  
    11881188}
    11891189
     1190static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& sourceFrame, ShouldOpenExternalURLsPolicy propagatedPolicy)
     1191{
     1192    if (!sourceFrame.isMainFrame())
     1193        return ShouldOpenExternalURLsPolicy::ShouldNotAllow;
     1194    if (ScriptController::processingUserGesture())
     1195        return ShouldOpenExternalURLsPolicy::ShouldAllow;
     1196    return propagatedPolicy;
     1197}
     1198
    11901199void FrameLoader::loadURL(const FrameLoadRequest& frameLoadRequest, const String& referrer, FrameLoadType newLoadType, Event* event, PassRefPtr<FormState> prpFormState)
    11911200{
     
    12341243
    12351244    if (!targetFrame && !frameName.isEmpty()) {
     1245        action = action.copyWithShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, frameLoadRequest.shouldOpenExternalURLsPolicy()));
    12361246        policyChecker().checkNewWindowPolicy(action, request, formState.release(), frameName, [this, allowNavigationToInvalidURL, openerPolicy](const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, const NavigationAction& action, bool shouldContinue) {
    12371247            continueLoadAfterNewWindowPolicy(request, formState, frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy);
     
    34583468void FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader(DocumentLoader& documentLoader, ShouldOpenExternalURLsPolicy propagatedPolicy)
    34593469{
    3460     if (!m_frame.isMainFrame())
    3461         documentLoader.setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy::ShouldNotAllow);
    3462     else if (ScriptController::processingUserGesture())
    3463         documentLoader.setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy::ShouldAllow);
    3464     else
    3465         documentLoader.setShouldOpenExternalURLsPolicy(propagatedPolicy);
     3470    documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, propagatedPolicy));
    34663471}
    34673472
     
    35053510        return nullptr;
    35063511
    3507     Page* page = oldPage->chrome().createWindow(&openerFrame, requestWithReferrer, features, NavigationAction(requestWithReferrer.resourceRequest()));
     3512    ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(openerFrame, request.shouldOpenExternalURLsPolicy());
     3513    Page* page = oldPage->chrome().createWindow(&openerFrame, requestWithReferrer, features, NavigationAction(requestWithReferrer.resourceRequest(), shouldOpenExternalURLsPolicy));
    35083514    if (!page)
    35093515        return nullptr;
  • trunk/Source/WebKit2/ChangeLog

    r186956 r186964  
     12015-07-17  Dan Bernstein  <mitz@apple.com>
     2
     3        WebKit2 part of <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
     4        https://bugs.webkit.org/show_bug.cgi?id=147040
     5
     6        Reviewed by Dean Jackson.
     7
     8        * UIProcess/Cocoa/UIDelegate.mm:
     9        (WebKit::UIDelegate::UIClient::createNewPage): Disallow App Links if the new page is for the
     10        same protocol, host and port as the main frame of this page.
     11
     12        * UIProcess/WebPageProxy.cpp:
     13        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Disallow App Links if
     14        m_shouldSuppressAppLinksInNextNavigationPolicyDecision is set, and reset it. See below for
     15        when we set it.
     16        (WebKit::WebPageProxy::decidePolicyForNewWindowAction): Disallow App Links if the new window
     17        is for the same protocol, host and port as the main frame of this page.
     18        (WebKit::WebPageProxy::createNewPage): Make the new page disallow App Links in the first
     19        policy decision if it is for the same protocol, host and port as the main frame of this
     20        page.
     21        * UIProcess/WebPageProxy.h: Added m_shouldSuppressAppLinksInNextNavigationPolicyDecision
     22        member variable.
     23
     24        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     25        (WebKit::WebChromeClient::createWindow): Pass the shouldOpenExternalURLsPolicy.
     26
     27        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     28        (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction): Ditto.
     29
    1302015-07-17  Tim Horton  <timothy_horton@apple.com>
    231
  • trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm

    r186719 r186964  
    4040#import "WKUIDelegatePrivate.h"
    4141#import "_WKFrameHandleInternal.h"
     42#import <WebCore/URL.h>
    4243
    4344namespace WebKit {
     
    109110
    110111    auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin());
    111     auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, request, WebCore::URL(), true);
     112
     113    bool shouldOpenAppLinks = !protocolHostAndPortAreEqual(WebCore::URL(WebCore::ParsedURLString, initiatingFrame->url()), request.url());
     114    auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, request, WebCore::URL(), shouldOpenAppLinks);
    112115
    113116    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

    r186913 r186964  
    33343334            sourceFrameInfo = API::FrameInfo::create(*originatingFrame, originatingFrameSecurityOrigin.securityOrigin());
    33353335
    3336         bool shouldOpenAppLinks = (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
     3336        bool shouldOpenAppLinks = !m_shouldSuppressAppLinksInNextNavigationPolicyDecision && (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
    33373337
    33383338        auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), destinationFrameInfo.get(), request, originalRequest.url(), shouldOpenAppLinks);
     
    33423342        m_policyClient->decidePolicyForNavigationAction(*this, frame, navigationActionData, originatingFrame, originalRequest, request, WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
    33433343
     3344    m_shouldSuppressAppLinksInNextNavigationPolicyDecision = false;
    33443345    m_inDecidePolicyForNavigationAction = false;
    33453346
     
    33673368            sourceFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin());
    33683369
    3369         auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), true);
     3370        bool shouldOpenAppLinks = !protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
     3371        auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), shouldOpenAppLinks);
    33703372
    33713373        m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
     
    35353537
    35363538    WebsiteDataStore::cloneSessionData(*this, *newPage);
     3539    newPage->m_shouldSuppressAppLinksInNextNavigationPolicyDecision = protocolHostAndPortAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
    35373540}
    35383541   
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r186913 r186964  
    16411641    WebCore::PolicyAction m_syncNavigationActionPolicyAction;
    16421642    uint64_t m_syncNavigationActionPolicyDownloadID;
     1643    bool m_shouldSuppressAppLinksInNextNavigationPolicyDecision { false };
    16431644
    16441645    Deque<NativeWebKeyboardEvent> m_keyEventQueue;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r186538 r186964  
    219219    navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
    220220    navigationActionData.canHandleRequest = m_page->canHandleRequest(request.resourceRequest());
     221    navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
    221222
    222223    uint64_t newPageID = 0;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r186664 r186964  
    739739    navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
    740740    navigationActionData.canHandleRequest = webPage->canHandleRequest(request);
     741    navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
    741742
    742743    webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), SecurityOriginData::fromFrame(m_frame), navigationActionData, request, frameName, listenerID, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
  • trunk/Tools/ChangeLog

    r186927 r186964  
     12015-07-17  Dan Bernstein  <mitz@apple.com>
     2
     3        Tests for <rdar://problem/21803781> The external URL policy is not reported correctly in navigation actions that create new windows
     4        https://bugs.webkit.org/show_bug.cgi?id=147040
     5
     6        Reviewed by Dean Jackson.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm: Added.
     10        (-[ShouldOpenExternalURLsInNewWindowActionsController webView:decidePolicyForNavigationAction:decisionHandler:]):
     11        (-[ShouldOpenExternalURLsInNewWindowActionsController webView:didFinishNavigation:]):
     12        (-[ShouldOpenExternalURLsInNewWindowActionsController webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
     13        (TEST):
     14
    1152015-07-16  Dean Johnson  <dean_johnson@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r186579 r186964  
    4242                378E64791632707400B6C676 /* link-with-title.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 378E647816326FDF00B6C676 /* link-with-title.html */; };
    4343                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */; };
     44                37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */; };
    4445                37D36ED71AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */; };
    4546                37D36F321B004DD400BAF5D9 /* ProvisionalURLChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */; };
     
    499500                3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringByEvaluatingJavaScriptFromString.mm; sourceTree = "<group>"; };
    500501                37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SubresourceErrorCrash.mm; sourceTree = "<group>"; };
     502                37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShouldOpenExternalURLsInNewWindowActions.mm; sourceTree = "<group>"; };
    501503                37C784DE197C8F2E0010A496 /* RenderedImageFromDOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageFromDOMNode.mm; sourceTree = "<group>"; };
    502504                37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadAlternateHTMLString.mm; sourceTree = "<group>"; };
     
    859861                                C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
    860862                                37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */,
     863                                37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
    861864                                2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
    862865                                7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
     
    14731476                                7CCE7EEE1A411AE600447C4C /* DownloadDecideDestinationCrash.cpp in Sources */,
    14741477                                7CCE7EBE1A411A7E00447C4C /* DynamicDeviceScaleFactor.mm in Sources */,
     1478                                37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */,
    14751479                                7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */,
    14761480                                7CCE7EE01A411A9A00447C4C /* EditorCommands.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.