Title: [243909] trunk/Source/WebKit
Revision
243909
Author
[email protected]
Date
2019-04-04 14:56:38 -0700 (Thu, 04 Apr 2019)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (243908 => 243909)


--- trunk/Source/WebKit/ChangeLog	2019-04-04 21:47:29 UTC (rev 243908)
+++ trunk/Source/WebKit/ChangeLog	2019-04-04 21:56:38 UTC (rev 243909)
@@ -1,3 +1,28 @@
+2019-04-04  Wenson Hsieh  <[email protected]>
+
+        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):
+
 2019-04-04  Michael Catanzaro  <[email protected]>
 
         Unreviewed, fix -Wreturn-type warning

Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (243908 => 243909)


--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp	2019-04-04 21:47:29 UTC (rev 243908)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp	2019-04-04 21:56:38 UTC (rev 243909)
@@ -42,6 +42,28 @@
     , m_websiteDataStore(WTFMove(websiteDataStore))
 { }
 
+Ref<WebsitePolicies> WebsitePolicies::copy() const
+{
+    auto policies = WebsitePolicies::create();
+    policies->setContentBlockersEnabled(m_contentBlockersEnabled);
+    policies->setAllowedAutoplayQuirks(m_allowedAutoplayQuirks);
+    policies->setAutoplayPolicy(m_autoplayPolicy);
+    policies->setDeviceOrientationAndMotionAccessState(m_deviceOrientationAndMotionAccessState);
+    policies->setPopUpPolicy(m_popUpPolicy);
+    policies->setWebsiteDataStore(m_websiteDataStore.get());
+    policies->setCustomUserAgent(m_customUserAgent);
+    policies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(m_customJavaScriptUserAgentAsSiteSpecificQuirks);
+    policies->setCustomNavigatorPlatform(m_customNavigatorPlatform);
+    policies->setPreferredCompatibilityMode(m_preferredCompatibilityMode);
+    policies->setMetaViewportPolicy(m_metaViewportPolicy);
+    Vector<WebCore::HTTPHeaderField> customHeaderFields;
+    customHeaderFields.reserveInitialCapacity(m_customHeaderFields.size());
+    for (auto& field : m_customHeaderFields)
+        customHeaderFields.append(WebCore::HTTPHeaderField(field));
+    policies->setCustomHeaderFields(WTFMove(customHeaderFields));
+    return policies;
+}
+
 WebsitePolicies::~WebsitePolicies()
 {
 }

Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h (243908 => 243909)


--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h	2019-04-04 21:47:29 UTC (rev 243908)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h	2019-04-04 21:56:38 UTC (rev 243909)
@@ -49,6 +49,8 @@
     WebsitePolicies();
     ~WebsitePolicies();
 
+    Ref<WebsitePolicies> copy() const;
+
     bool contentBlockersEnabled() const { return m_contentBlockersEnabled; }
     void setContentBlockersEnabled(bool enabled) { m_contentBlockersEnabled = enabled; }
     

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (243908 => 243909)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2019-04-04 21:47:29 UTC (rev 243908)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2019-04-04 21:56:38 UTC (rev 243909)
@@ -510,8 +510,11 @@
 void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageProxy& webPageProxy, Ref<API::NavigationAction>&& navigationAction, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userInfo)
 {
     bool subframeNavigation = navigationAction->targetFrame() && !navigationAction->targetFrame()->isMainFrame();
-    auto defaultWebsitePolicies = makeRefPtr(webPageProxy.configuration().defaultWebsitePolicies());
 
+    RefPtr<API::WebsitePolicies> defaultWebsitePolicies;
+    if (auto* policies = webPageProxy.configuration().defaultWebsitePolicies())
+        defaultWebsitePolicies = policies->copy();
+
     if (!m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandler
         && !m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionWithPreferencesDecisionHandler
         && !m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to