Add plumbing for a compatibility mode preference in WebKit
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Apr 2019 15:02:07 +0000 (15:02 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Apr 2019 15:02:07 +0000 (15:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196005

Reviewed by Tim Horton.

Source/WebKit:

Add plumbing between the Cocoa API object (WKWebpagePreferences) and the inner C++ API object
(API::WebsitePolicies) for compatibility mode.

* Shared/WebCompatibilityMode.h: Added.
* UIProcess/API/APIWebsitePolicies.h:
* UIProcess/API/Cocoa/WKWebpagePreferences.mm:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::adjustPoliciesForCompatibilityMode):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WebPageProxyIOS.mm:
* WebKit.xcodeproj/project.pbxproj:

Tools:

Add new API tests.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/ios/PreferredCompatibilityMode.mm: Added.

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

12 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCompatibilityMode.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/APIWebsitePolicies.h
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/ios/PreferredCompatibilityMode.mm [new file with mode: 0644]

index a4e24b1..d1083e9 100644 (file)
@@ -1,3 +1,24 @@
+2019-04-03  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Add plumbing for a compatibility mode preference in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=196005
+
+        Reviewed by Tim Horton.
+
+        Add plumbing between the Cocoa API object (WKWebpagePreferences) and the inner C++ API object
+        (API::WebsitePolicies) for compatibility mode.
+
+        * Shared/WebCompatibilityMode.h: Added.
+        * UIProcess/API/APIWebsitePolicies.h:
+        * UIProcess/API/Cocoa/WKWebpagePreferences.mm:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::adjustPoliciesForCompatibilityMode):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-04-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [CoordinatedGraphics] Hidden pages are not suspended after a web view resize
diff --git a/Source/WebKit/Shared/WebCompatibilityMode.h b/Source/WebKit/Shared/WebCompatibilityMode.h
new file mode 100644 (file)
index 0000000..a8420ca
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Forward.h>
+
+namespace WebKit {
+
+enum class WebCompatibilityMode {
+    Default,
+    Legacy,
+    Modern,
+};
+
+}
index 7eda19d..63213f4 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "APIObject.h"
+#include "WebCompatibilityMode.h"
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
 #include "WebsitePopUpPolicy.h"
@@ -80,6 +81,9 @@ public:
     void setCustomNavigatorPlatform(const WTF::String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; }
     const WTF::String& customNavigatorPlatform() const { return m_customNavigatorPlatform; }
 
+    WebKit::WebCompatibilityMode preferredCompatibilityMode() const { return m_preferredCompatibilityMode; }
+    void setPreferredCompatibilityMode(WebKit::WebCompatibilityMode mode) { m_preferredCompatibilityMode = mode; }
+
 private:
     WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&);
 
@@ -93,6 +97,7 @@ private:
     WTF::String m_customUserAgent;
     WTF::String m_customJavaScriptUserAgentAsSiteSpecificQuirks;
     WTF::String m_customNavigatorPlatform;
+    WebKit::WebCompatibilityMode m_preferredCompatibilityMode { WebKit::WebCompatibilityMode::Default };
 };
 
 } // namespace API
index ac178dc..617a318 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "WKWebpagePreferencesInternal.h"
 #import "WKWebsiteDataStoreInternal.h"
+#import "WebCompatibilityMode.h"
 #import "_WKWebsitePoliciesInternal.h"
 #import <wtf/RetainPtr.h>
 
     return *_websitePolicies;
 }
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/WKWebpagePreferencesAdditions.mm>
+#endif
+
 @end
index 32c6591..d912ca2 100644 (file)
@@ -522,6 +522,9 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
                 return;
             }
 
+            if (defaultWebsitePolicies)
+                webPage->adjustPoliciesForCompatibilityMode(navigationAction, *defaultWebsitePolicies);
+
             if (!navigationAction->targetFrame()) {
                 listener->use(defaultWebsitePolicies.get());
                 return;
@@ -591,6 +594,8 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
                 [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._customUserAgent must be nil for subframe navigations."];
             if (!apiWebsitePolicies->customNavigatorPlatform().isNull() && subframeNavigation)
                 [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._customNavigatorPlatform must be nil for subframe navigations."];
+
+            webPageProxy->adjustPoliciesForCompatibilityMode(navigationAction, *apiWebsitePolicies);
         }
 
         switch (actionPolicy) {
index f846707..4e39ad3 100644 (file)
@@ -8902,6 +8902,14 @@ void WebPageProxy::speechSynthesisResume(CompletionHandler<void()>&& completionH
 }
 #endif // ENABLE(SPEECH_SYNTHESIS)
 
+#if !PLATFORM(IOS_FAMILY) || !USE(APPLE_INTERNAL_SDK)
+
+void WebPageProxy::adjustPoliciesForCompatibilityMode(const API::NavigationAction&, API::WebsitePolicies&)
+{
+}
+
+#endif // !PLATFORM(IOS_FAMILY) || !USE(APPLE_INTERNAL_SDK)
+
 void WebPageProxy::addObserver(WebViewDidMoveToWindowObserver& observer)
 {
     auto result = m_webViewDidMoveToWindowObservers.add(&observer, makeWeakPtr(observer));
index ac7feb5..f76c933 100644 (file)
@@ -1506,6 +1506,7 @@ public:
 #endif
 
     void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel);
+    void adjustPoliciesForCompatibilityMode(const API::NavigationAction&, API::WebsitePolicies&);
 
     void addObserver(WebViewDidMoveToWindowObserver&);
     void removeObserver(WebViewDidMoveToWindowObserver&);
index 2e8580e..c54d355 100644 (file)
@@ -28,7 +28,9 @@
 
 #if PLATFORM(IOS_FAMILY)
 
+#import "APINavigationAction.h"
 #import "APIUIClient.h"
+#import "APIWebsitePolicies.h"
 #import "Connection.h"
 #import "DataReference.h"
 #import "DocumentEditingContext.h"
@@ -1241,6 +1243,10 @@ const String& WebPageProxy::paymentCoordinatorCTDataConnectionServiceType(const
 
 #endif
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/WebPageProxyIOSAdditions.mm>
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS_FAMILY)
index ccb5011..b453232 100644 (file)
                ECA680D81E690E2500731D20 /* WebProcessCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = ECA680D71E690DF800731D20 /* WebProcessCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
                ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F409BA181E6E64BC009DA28E /* WKDragDestinationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               F430E94422473DFF005FE053 /* WebCompatibilityMode.h in Headers */ = {isa = PBXBuildFile; fileRef = F430E94322473DB8005FE053 /* WebCompatibilityMode.h */; };
                F438CD1C2241421400DE6DDA /* WKWebpagePreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
                F438CD1F22414D4000DE6DDA /* WKWebpagePreferencesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD1E22414D4000DE6DDA /* WKWebpagePreferencesInternal.h */; };
                F438CD212241F69500DE6DDA /* WKWebpagePreferencesPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD202241F69500DE6DDA /* WKWebpagePreferencesPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDragDestinationAction.h; sourceTree = "<group>"; };
                F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionContext.h; path = ios/WebAutocorrectionContext.h; sourceTree = "<group>"; };
                F41056612130699A0092281D /* APIAttachmentCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = APIAttachmentCocoa.mm; sourceTree = "<group>"; };
+               F430E94322473DB8005FE053 /* WebCompatibilityMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCompatibilityMode.h; sourceTree = "<group>"; };
                F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebpagePreferences.h; sourceTree = "<group>"; };
                F438CD1D22414AD600DE6DDA /* WKWebpagePreferences.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebpagePreferences.mm; sourceTree = "<group>"; };
                F438CD1E22414D4000DE6DDA /* WKWebpagePreferencesInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebpagePreferencesInternal.h; sourceTree = "<group>"; };
                                518D2CAB12D5153B003BB93B /* WebBackForwardListItem.cpp */,
                                518D2CAC12D5153B003BB93B /* WebBackForwardListItem.h */,
                                BCF50726124329AA005955AE /* WebCertificateInfo.h */,
+                               F430E94322473DB8005FE053 /* WebCompatibilityMode.h */,
                                7C4ABECE1AA8E9F00088AA37 /* WebCompiledContentRuleList.cpp */,
                                7C4ABECF1AA8E9F00088AA37 /* WebCompiledContentRuleList.h */,
                                7C4ABED21AA8FCB80088AA37 /* WebCompiledContentRuleListData.cpp */,
                                3F87B9BE158940190090FF62 /* WebColorChooser.h in Headers */,
                                3F87B9C0158940D80090FF62 /* WebColorPicker.h in Headers */,
                                728E86F11795188C0087879E /* WebColorPickerMac.h in Headers */,
+                               F430E94422473DFF005FE053 /* WebCompatibilityMode.h in Headers */,
                                7C4ABED11AA8E9F00088AA37 /* WebCompiledContentRuleList.h in Headers */,
                                7C4ABED51AA8FCB80088AA37 /* WebCompiledContentRuleListData.h in Headers */,
                                BC4A6290147312BE006C681A /* WebConnection.h in Headers */,
index a37158f..000d1b3 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-03  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Add plumbing for a compatibility mode preference in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=196005
+
+        Reviewed by Tim Horton.
+
+        Add new API tests.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/ios/PreferredCompatibilityMode.mm: Added.
+
 2019-04-03  Claudio Saavedra  <csaavedra@igalia.com>
 
         [WPE][GTK] Update libsrtp dependency package for Debian
index d2eb0ab..9c7a379 100644 (file)
                F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */; };
                F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; };
                F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */; };
+               F48D6C10224B377000E3E2FB /* PreferredCompatibilityMode.mm in Sources */ = {isa = PBXBuildFile; fileRef = F48D6C0F224B377000E3E2FB /* PreferredCompatibilityMode.mm */; };
                F4A32EC41F05F3850047C544 /* dragstart-change-selection-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A32EC31F05F3780047C544 /* dragstart-change-selection-offscreen.html */; };
                F4A32ECB1F0643370047C544 /* contenteditable-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A32ECA1F0642F40047C544 /* contenteditable-in-iframe.html */; };
                F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A9202E1FEE34C800F59590 /* apple-data-url.html */; };
                F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEditActions.mm; sourceTree = "<group>"; };
                F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; };
                F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "DataTransfer-setDragImage.html"; sourceTree = "<group>"; };
+               F48D6C0F224B377000E3E2FB /* PreferredCompatibilityMode.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferredCompatibilityMode.mm; sourceTree = "<group>"; };
                F493247C1F44DF8D006F4336 /* UIKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIKitSPI.h; sourceTree = "<group>"; };
                F4A32EC31F05F3780047C544 /* dragstart-change-selection-offscreen.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "dragstart-change-selection-offscreen.html"; sourceTree = "<group>"; };
                F4A32ECA1F0642F40047C544 /* contenteditable-in-iframe.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "contenteditable-in-iframe.html"; sourceTree = "<group>"; };
                                F4CDAB3322489FE10057A2D9 /* IPadUserInterfaceSwizzler.h */,
                                2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */,
                                2D61EC3021B0B75C00A7D1CB /* PencilKitTestSPI.h */,
+                               F48D6C0F224B377000E3E2FB /* PreferredCompatibilityMode.mm */,
                                F4517B652054C49500C26721 /* TestWKWebViewController.h */,
                                F4517B662054C49500C26721 /* TestWKWebViewController.mm */,
                                F493247C1F44DF8D006F4336 /* UIKitSPI.h */,
                                83BAEE8D1EF4625500DDE894 /* PluginLoadClientPolicies.mm in Sources */,
                                7CCE7F261A411AF600447C4C /* Preferences.mm in Sources */,
                                CD227E44211A4D5D00D285AF /* PreferredAudioBufferSize.mm in Sources */,
+                               F48D6C10224B377000E3E2FB /* PreferredCompatibilityMode.mm in Sources */,
                                7C1AF7951E8DCBAB002645B9 /* PrepareForMoveToWindow.mm in Sources */,
                                7CCE7F0B1A411AE600447C4C /* PreventEmptyUserAgent.cpp in Sources */,
                                7CCE7F2C1A411B1000447C4C /* PreventImageLoadWithAutoResizing.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/ios/PreferredCompatibilityMode.mm b/Tools/TestWebKitAPI/ios/PreferredCompatibilityMode.mm
new file mode 100644 (file)
index 0000000..a8e573e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/PreferredCompatibilityModeAdditions.mm>
+#endif