Add API to disable meta refreshes.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 May 2015 18:19:58 +0000 (18:19 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 May 2015 18:19:58 +0000 (18:19 +0000)
<rdar://problem/20333198> and https://bugs.webkit.org/show_bug.cgi?id=144269

Reviewed by Alexey Proskuryakov.

Source/WebCore:

Test: loader/meta-refresh-disabled.html

* dom/Document.cpp:
(WebCore::Document::processHttpEquiv): Bail early if Settings have meta refreshes disabled.
* page/Settings.in:

Source/WebKit/mac:

Add a preference to enable/disable meta refreshes, enabled by default.

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences setMetaRefreshEnabled:]):
(-[WebPreferences metaRefreshEnabled]):
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

Source/WebKit2:

Add a preference to enable/disable meta refreshes, enabled by default.

* Shared/WebPreferencesDefinitions.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetMetaRefreshEnabled):
(WKPreferencesGetMetaRefreshEnabled):
(WKPreferencesGetIgnoreViewportScalingConstraints): Deleted.
* UIProcess/API/C/WKPreferencesRefPrivate.h:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

Tools:

* DumpRenderTree/mac/DumpRenderTree.mm:
(resetWebPreferencesToConsistentValues): Reset the meta refresh pref between tests.

LayoutTests:

* loader/meta-refresh-disabled-expected.txt: Added.
* loader/meta-refresh-disabled.html: Added.
* loader/resources/notify-done.html: Added.
* platform/win/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183682 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
LayoutTests/ChangeLog
LayoutTests/loader/meta-refresh-disabled-expected.txt [new file with mode: 0644]
LayoutTests/loader/meta-refresh-disabled.html [new file with mode: 0644]
LayoutTests/loader/resources/notify-done.html [new file with mode: 0644]
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/page/Settings.in
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKit/mac/WebView/WebPreferences.mm
Source/WebKit/mac/WebView/WebPreferencesPrivate.h
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPreferencesDefinitions.h
Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm

index 89fe7ba..f0b69ba 100644 (file)
@@ -1,3 +1,15 @@
+2015-05-01  Brady Eidson  <beidson@apple.com>
+
+        Add API to disable meta refreshes.
+        <rdar://problem/20333198> and https://bugs.webkit.org/show_bug.cgi?id=144269
+
+        Reviewed by Alexey Proskuryakov.
+
+        * loader/meta-refresh-disabled-expected.txt: Added.
+        * loader/meta-refresh-disabled.html: Added.
+        * loader/resources/notify-done.html: Added.
+        * platform/win/TestExpectations:
+
 2015-05-01  Martin Robinson  <mrobinson@igalia.com>
 
         Unreviewed gardening for WebKitGTK+
diff --git a/LayoutTests/loader/meta-refresh-disabled-expected.txt b/LayoutTests/loader/meta-refresh-disabled-expected.txt
new file mode 100644 (file)
index 0000000..bb9b5ed
--- /dev/null
@@ -0,0 +1,4 @@
+This test makes sure the preference to disable meta refreshes works as expected.
+You should see this text when the test is done.
+If you do not see this text, and instead you see a blank page, then the redirect happened, which it should not have.
+
diff --git a/LayoutTests/loader/meta-refresh-disabled.html b/LayoutTests/loader/meta-refresh-disabled.html
new file mode 100644 (file)
index 0000000..273e389
--- /dev/null
@@ -0,0 +1,39 @@
+<head>
+<script>
+if (window.testRunner) {
+    testRunner.overridePreference("WebKitMetaRefreshEnabled", "0");
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+// This bizarre practice of continuously delaying notifyDone() by multiple 0-delay timers
+// is meant to work around a few 0-delays in the meta refresh process.
+// The refresh itself is on a timer, and then the policy delegate's reply might be on a timer.
+// The goal here is to give a successfully scheduled meta refresh long enough to occur,
+// but to not also wait an arbitrary amount of clock time before concluding the test.
+function notifyDoneDelayer(iteration)
+{
+    if (iteration == 10) {
+        if (window.testRunner)
+            testRunner.notifyDone();
+        else
+            document.body.innerHTML = "This test can only be run under DRT/WKTR";
+        return;
+    }
+    
+    setTimeout("notifyDoneDelayer(" + ++iteration + ");", 0);
+}
+
+function loaded()
+{
+    setTimeout("notifyDoneDelayer(1);", 0);
+}
+
+</script>
+<meta http-equiv="refresh" content="0;url=resources/notify-done.html">    
+</head>
+<body onload="loaded();">
+This test makes sure the preference to disable meta refreshes works as expected.<br>
+You should see this text when the test is done.<br>
+If you do not see this text, and instead you see a blank page, then the redirect happened, which it should not have.<br>
+</body>
diff --git a/LayoutTests/loader/resources/notify-done.html b/LayoutTests/loader/resources/notify-done.html
new file mode 100644 (file)
index 0000000..cbd62e3
--- /dev/null
@@ -0,0 +1,4 @@
+<script>
+if (window.testRunner)
+    testRunner.notifyDone();
+</script>
index 4243df2..c98bd8e 100644 (file)
@@ -3083,6 +3083,9 @@ http/tests/contentfiltering [ Skip ]
 [ Release ] inspector-protocol/layers/layers-for-node.html [ Skip ] # Timeouts
 [ Release ] inspector-protocol/layers/layers-generated-content.html  [ Skip ] # Timeouts
 
+# Windows doesn't have API for disabling meta refresh
+loader/meta-refresh-disabled.html [ Skip ]
+
 # Started failing recently.
 webkit.org/b/143275 accessibility/aria-hidden-hides-all-elements.html [ Pass Failure ]
 
index dccf838..9a51822 100644 (file)
@@ -1,3 +1,16 @@
+2015-05-01  Brady Eidson  <beidson@apple.com>
+
+        Add API to disable meta refreshes.
+        <rdar://problem/20333198> and https://bugs.webkit.org/show_bug.cgi?id=144269
+
+        Reviewed by Alexey Proskuryakov.
+
+        Test: loader/meta-refresh-disabled.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::processHttpEquiv): Bail early if Settings have meta refreshes disabled.
+        * page/Settings.in:
+
 2015-05-01  Martin Robinson  <mrobinson@igalia.com>
 
         [Freetype] Properly support synthetic oblique in vertical text
index 5dae186..faed8fd 100644 (file)
@@ -3002,6 +3002,9 @@ void Document::processHttpEquiv(const String& equiv, const String& content)
         break;
 
     case HTTPHeaderName::Refresh: {
+        if (page() && !page()->settings().metaRefreshEnabled())
+            break;
+
         double delay;
         String urlString;
         if (frame && parseHTTPRefresh(content, true, delay, urlString)) {
index 5b1d483..70156d3 100644 (file)
@@ -241,3 +241,4 @@ attachmentElementEnabled initial=true, conditional=ATTACHMENT_ELEMENT
 
 newBlockInsideInlineModelEnabled initial=false, setNeedsStyleRecalcInAllFrames=1
 
+metaRefreshEnabled initial=true
index 930d927..afebb66 100644 (file)
@@ -1,3 +1,21 @@
+2015-05-01  Brady Eidson  <beidson@apple.com>
+
+        Add API to disable meta refreshes.
+        <rdar://problem/20333198> and https://bugs.webkit.org/show_bug.cgi?id=144269
+
+        Reviewed by Alexey Proskuryakov.
+
+        Add a preference to enable/disable meta refreshes, enabled by default.
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        (-[WebPreferences setMetaRefreshEnabled:]):
+        (-[WebPreferences metaRefreshEnabled]):
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2015-04-30  Jon Davis  <jond@apple.com>
 
         Web Inspector: console should show an icon for console.info() messages
index 4e905bb..aea90d4 100644 (file)
 #define WebKitDebugFullPageZoomPreferenceKey @"WebKitDebugFullPageZoomPreferenceKey"
 #define WebKitMinimumZoomFontSizePreferenceKey @"WebKitMinimumZoomFontSizePreferenceKey"
 #define WebKitAntialiasedFontDilationEnabledKey @"AntialiasedFontDilationEnabled"
+#define WebKitMetaRefreshEnabledPreferenceKey @"WebKitMetaRefreshEnabled"
 
 #if TARGET_OS_IPHONE
 #define WebKitStandalonePreferenceKey @"WebKitStandalonePreferenceKey"
index d4fc218..2974e03 100644 (file)
@@ -444,6 +444,7 @@ public:
 #endif
         [NSNumber numberWithBool:YES],  WebKitPluginsEnabledPreferenceKey,
         [NSNumber numberWithBool:YES],  WebKitDatabasesEnabledPreferenceKey,
+        [NSNumber numberWithBool:YES],  WebKitMetaRefreshEnabledPreferenceKey,
 #if PLATFORM(IOS)
         [NSNumber numberWithBool:NO],   WebKitStorageTrackerEnabledPreferenceKey,
 #endif
@@ -2496,6 +2497,16 @@ static NSString *classIBCreatorID = nil;
     return [self _boolValueForKey:WebKitAntialiasedFontDilationEnabledKey];
 }
 
+- (void)setMetaRefreshEnabled:(BOOL)enabled
+{
+    [self _setBoolValue:enabled forKey:WebKitMetaRefreshEnabledPreferenceKey];
+}
+
+- (BOOL)metaRefreshEnabled
+{
+    return [self _boolValueForKey:WebKitMetaRefreshEnabledPreferenceKey];
+}
+
 - (BOOL)javaScriptMarkupEnabled
 {
     return [self _boolValueForKey:WebKitJavaScriptMarkupEnabledPreferenceKey];
index 11ac483..6eb2976 100644 (file)
@@ -439,6 +439,9 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification;
 - (void)setAntialiasedFontDilationEnabled:(BOOL)flag;
 - (BOOL)antialiasedFontDilationEnabled;
 
+- (void)setMetaRefreshEnabled:(BOOL)flag;
+- (BOOL)metaRefreshEnabled;
+
 @property (nonatomic) BOOL javaScriptMarkupEnabled;
 
 #if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
index 146a04b..faa0255 100644 (file)
@@ -2330,6 +2330,7 @@ static bool needsSelfRetainWhileLoadingQuirk()
     }
 
     settings.setPlugInSnapshottingEnabled([preferences plugInSnapshottingEnabled]);
+    settings.setMetaRefreshEnabled([preferences metaRefreshEnabled]);
 
     settings.setFixedPositionCreatesStackingContext(true);
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
index 1c95c1b..526a06f 100644 (file)
@@ -1,3 +1,23 @@
+2015-05-01  Brady Eidson  <beidson@apple.com>
+
+        Add API to disable meta refreshes.
+        <rdar://problem/20333198> and https://bugs.webkit.org/show_bug.cgi?id=144269
+
+        Reviewed by Alexey Proskuryakov.
+
+        Add a preference to enable/disable meta refreshes, enabled by default.
+
+        * Shared/WebPreferencesDefinitions.h:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetMetaRefreshEnabled):
+        (WKPreferencesGetMetaRefreshEnabled):
+        (WKPreferencesGetIgnoreViewportScalingConstraints): Deleted.
+        * UIProcess/API/C/WKPreferencesRefPrivate.h:
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+
 2015-05-01  Antti Koivisto  <antti@apple.com>
 
         Remove network process load serialization code
index 31e9df9..462e0e7 100644 (file)
     macro(LongMousePressEnabled, longMousePressEnabled, Bool, bool, false) \
     macro(NewBlockInsideInlineModelEnabled, newBlockInsideInlineModelEnabled, Bool, bool, false) \
     macro(AntialiasedFontDilationEnabled, antialiasedFontDilationEnabled, Bool, bool, true) \
+    macro(MetaRefreshEnabled, metaRefreshEnabled, Bool, bool, true) \
 
 #define FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
     macro(IncrementalRenderingSuppressionTimeout, incrementalRenderingSuppressionTimeout, Double, double, 5) \
index ae143a1..e78b74f 100644 (file)
@@ -1356,3 +1356,13 @@ bool WKPreferencesGetIgnoreViewportScalingConstraints(WKPreferencesRef preferenc
 {
     return toImpl(preferencesRef)->ignoreViewportScalingConstraints();
 }
+
+void WKPreferencesSetMetaRefreshEnabled(WKPreferencesRef preferencesRef, bool enabled)
+{
+    toImpl(preferencesRef)->setMetaRefreshEnabled(enabled);
+}
+
+bool WKPreferencesGetMetaRefreshEnabled(WKPreferencesRef preferencesRef)
+{
+    return toImpl(preferencesRef)->metaRefreshEnabled();
+}
index a0b4279..446a0d2 100644 (file)
@@ -369,6 +369,10 @@ WK_EXPORT bool WKPreferencesGetAntialiasedFontDilationEnabled(WKPreferencesRef p
 WK_EXPORT void WKPreferencesSetJavaScriptRuntimeFlags(WKPreferencesRef preferences, WKJavaScriptRuntimeFlagSet javascriptRuntimeFlagSet);
 WK_EXPORT WKJavaScriptRuntimeFlagSet WKPreferencesGetJavaScriptRuntimeFlags(WKPreferencesRef preferences);
 
+// Defaults to true.
+WK_EXPORT void WKPreferencesSetMetaRefreshEnabled(WKPreferencesRef preferences, bool enabled);
+WK_EXPORT bool WKPreferencesGetMetaRefreshEnabled(WKPreferencesRef preferences);
+
 #ifdef __cplusplus
 }
 #endif
index 1b8a539..2ff0283 100644 (file)
@@ -206,7 +206,8 @@ void InjectedBundle::overrideBoolPreferenceForTestRunner(WebPageGroupProxy* page
     macro(WebKitShouldRespectImageOrientation, ShouldRespectImageOrientation, shouldRespectImageOrientation) \
     macro(WebKitEnableCaretBrowsing, CaretBrowsingEnabled, caretBrowsingEnabled) \
     macro(WebKitDisplayImagesKey, LoadsImagesAutomatically, loadsImagesAutomatically) \
-    macro(WebKitMediaStreamEnabled, MediaStreamEnabled, mediaStreamEnabled)
+    macro(WebKitMediaStreamEnabled, MediaStreamEnabled, mediaStreamEnabled) \
+    macro(WebKitMetaRefreshEnabled, MetaRefreshEnabled, metaRefreshEnabled)
 
 #define OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES(TestRunnerName, SettingsName, WebPreferencesName) \
     if (preference == #TestRunnerName) { \
index 2042075..975a236 100644 (file)
@@ -2757,6 +2757,8 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
     settings.setInteractiveFormValidationEnabled(store.getBoolValueForKey(WebPreferencesKey::interactiveFormValidationEnabledKey()));
     settings.setSpatialNavigationEnabled(store.getBoolValueForKey(WebPreferencesKey::spatialNavigationEnabledKey()));
 
+    settings.setMetaRefreshEnabled(store.getBoolValueForKey(WebPreferencesKey::metaRefreshEnabledKey()));
+
     DatabaseManager::singleton().setIsAvailable(store.getBoolValueForKey(WebPreferencesKey::databasesEnabledKey()));
 
 #if ENABLE(FULLSCREEN_API)
index 97b4e9e..dddd42b 100644 (file)
@@ -1,3 +1,13 @@
+2015-05-01  Brady Eidson  <beidson@apple.com>
+
+        Add API to disable meta refreshes.
+        <rdar://problem/20333198> and https://bugs.webkit.org/show_bug.cgi?id=144269
+
+        Reviewed by Alexey Proskuryakov.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (resetWebPreferencesToConsistentValues): Reset the meta refresh pref between tests.
+
 2015-05-01  Brent Fulgham  <bfulgham@apple.com>
 
         Provide a runtime flag to run-webkit-tests that shows the test view
index 4b587f4..bccd4a9 100644 (file)
@@ -928,6 +928,8 @@ static void resetWebPreferencesToConsistentValues()
     [preferences setLoadsSiteIconsIgnoringImageLoadingPreference:NO];
     [preferences setFrameFlatteningEnabled:NO];
     [preferences setSpatialNavigationEnabled:NO];
+    [preferences setMetaRefreshEnabled:YES];
+
     if (persistentUserStyleSheetLocation) {
         [preferences setUserStyleSheetLocation:[NSURL URLWithString:(NSString *)(persistentUserStyleSheetLocation.get())]];
         [preferences setUserStyleSheetEnabled:YES];