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

Changeset 243909 in webkit


Ignore:
Timestamp:
Apr 4, 2019, 2:56:38 PM (7 years ago)
Author:
Wenson Hsieh
Message:

Changing default website policies shouldn't change default website policies in subsequent navigations
https://bugs.webkit.org/show_bug.cgi?id=196562
<rdar://problem/49573377>

Reviewed by Tim Horton.

Currently, changing the default WKWebpagePreferences object when deciding navigation policy causes the set of
default policies to change in subsequent navigations. Among other things, this prevents clients from passing
a modified version of the default website policies into the decision handler without impacting future
navigations. To fix this, teach API::WebsitePolicies to make a copy of itself, and then use this to pass a copy
of the default website policies to the navigation delegate when deciding navigation policies.

Test: DoNotAllowChangingDefaultWebpagePreferencesInDelegateMethod

  • UIProcess/API/APIWebsitePolicies.cpp:

(API::WebsitePolicies::copy const):

Add a helper method to copy a set of website policies.

  • UIProcess/API/APIWebsitePolicies.h:
  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243902 r243909  
     12019-04-04  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Changing default website policies shouldn't change default website policies in subsequent navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=196562
     5        <rdar://problem/49573377>
     6
     7        Reviewed by Tim Horton.
     8
     9        Currently, changing the default WKWebpagePreferences object when deciding navigation policy causes the set of
     10        default policies to change in subsequent navigations. Among other things, this prevents clients from passing
     11        a modified version of the default website policies into the decision handler without impacting future
     12        navigations. To fix this, teach API::WebsitePolicies to make a copy of itself, and then use this to pass a copy
     13        of the default website policies to the navigation delegate when deciding navigation policies.
     14
     15        Test: DoNotAllowChangingDefaultWebpagePreferencesInDelegateMethod
     16
     17        * UIProcess/API/APIWebsitePolicies.cpp:
     18        (API::WebsitePolicies::copy const):
     19
     20        Add a helper method to copy a set of website policies.
     21
     22        * UIProcess/API/APIWebsitePolicies.h:
     23        * UIProcess/Cocoa/NavigationState.mm:
     24        (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
     25
    1262019-04-04  Michael Catanzaro  <mcatanzaro@igalia.com>
    227
  • trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp

    r243798 r243909  
    4343{ }
    4444
     45Ref<WebsitePolicies> WebsitePolicies::copy() const
     46{
     47    auto policies = WebsitePolicies::create();
     48    policies->setContentBlockersEnabled(m_contentBlockersEnabled);
     49    policies->setAllowedAutoplayQuirks(m_allowedAutoplayQuirks);
     50    policies->setAutoplayPolicy(m_autoplayPolicy);
     51    policies->setDeviceOrientationAndMotionAccessState(m_deviceOrientationAndMotionAccessState);
     52    policies->setPopUpPolicy(m_popUpPolicy);
     53    policies->setWebsiteDataStore(m_websiteDataStore.get());
     54    policies->setCustomUserAgent(m_customUserAgent);
     55    policies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(m_customJavaScriptUserAgentAsSiteSpecificQuirks);
     56    policies->setCustomNavigatorPlatform(m_customNavigatorPlatform);
     57    policies->setPreferredCompatibilityMode(m_preferredCompatibilityMode);
     58    policies->setMetaViewportPolicy(m_metaViewportPolicy);
     59    Vector<WebCore::HTTPHeaderField> customHeaderFields;
     60    customHeaderFields.reserveInitialCapacity(m_customHeaderFields.size());
     61    for (auto& field : m_customHeaderFields)
     62        customHeaderFields.append(WebCore::HTTPHeaderField(field));
     63    policies->setCustomHeaderFields(WTFMove(customHeaderFields));
     64    return policies;
     65}
     66
    4567WebsitePolicies::~WebsitePolicies()
    4668{
  • trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h

    r243798 r243909  
    4949    WebsitePolicies();
    5050    ~WebsitePolicies();
     51
     52    Ref<WebsitePolicies> copy() const;
    5153
    5254    bool contentBlockersEnabled() const { return m_contentBlockersEnabled; }
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r243797 r243909  
    511511{
    512512    bool subframeNavigation = navigationAction->targetFrame() && !navigationAction->targetFrame()->isMainFrame();
    513     auto defaultWebsitePolicies = makeRefPtr(webPageProxy.configuration().defaultWebsitePolicies());
     513
     514    RefPtr<API::WebsitePolicies> defaultWebsitePolicies;
     515    if (auto* policies = webPageProxy.configuration().defaultWebsitePolicies())
     516        defaultWebsitePolicies = policies->copy();
    514517
    515518    if (!m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandler
Note: See TracChangeset for help on using the changeset viewer.