Introduce and add plumbing for a website policy for meta viewport tag handling
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Apr 2019 15:22:10 +0000 (15:22 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Apr 2019 15:22:10 +0000 (15:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196285

Reviewed by Tim Horton.

Source/WebCore:

Add MetaViewportPolicy to DocumentLoader. See WebKit ChangeLog for more detail.

* loader/DocumentLoader.h:
(WebCore::DocumentLoader::metaViewportPolicy const):
(WebCore::DocumentLoader::setMetaViewportPolicy):

Source/WebKit:

Add WebsiteMetaViewportPolicy, a bit that can be used to determine whether to respect or ignore the meta
viewport tag and use native web page parameters instead of the default parameters.

* Shared/WebsiteMetaViewportPolicy.h: Copied from Source/WebKit/Shared/WebsitePoliciesData.h.
* Shared/WebsitePoliciesData.cpp:
(WebKit::WebsitePoliciesData::encode const):
(WebKit::WebsitePoliciesData::decode):
(WebKit::WebsitePoliciesData::applyToDocumentLoader):

Convert WebKit::WebsiteMetaViewportPolicy into WebCore::MetaViewportPolicy.

* Shared/WebsitePoliciesData.h:
* UIProcess/API/APIWebsitePolicies.cpp:
(API::WebsitePolicies::data):
* UIProcess/API/APIWebsitePolicies.h:

Add additional plumbing for the policy flag.

* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::resetViewportDefaultConfiguration):

Use native web page parameters if either "shouldIgnoreMetaViewport" is enabled, or the new policy is set.
Eventually, the policy should completely replace the former preference once no internal clients depend on it.

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

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebsiteMetaViewportPolicy.h [new file with mode: 0644]
Source/WebKit/Shared/WebsitePoliciesData.cpp
Source/WebKit/Shared/WebsitePoliciesData.h
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
Source/WebKit/UIProcess/API/APIWebsitePolicies.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index d692efc..de287cc 100644 (file)
@@ -1,3 +1,16 @@
+2019-04-03  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Introduce and add plumbing for a website policy for meta viewport tag handling
+        https://bugs.webkit.org/show_bug.cgi?id=196285
+
+        Reviewed by Tim Horton.
+
+        Add MetaViewportPolicy to DocumentLoader. See WebKit ChangeLog for more detail.
+
+        * loader/DocumentLoader.h:
+        (WebCore::DocumentLoader::metaViewportPolicy const):
+        (WebCore::DocumentLoader::setMetaViewportPolicy):
+
 2019-04-03  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Remote Inspector indicate callback should always happen on the main thread
index 019d1b5..3c14d0d 100644 (file)
@@ -112,6 +112,12 @@ enum class PopUpPolicy {
     Block,
 };
 
+enum class MetaViewportPolicy {
+    Default,
+    Respect,
+    Ignore,
+};
+
 class DocumentLoader
     : public RefCounted<DocumentLoader>
     , public FrameDestructionObserver
@@ -283,6 +289,9 @@ public:
     PopUpPolicy popUpPolicy() const { return m_popUpPolicy; }
     void setPopUpPolicy(PopUpPolicy popUpPolicy) { m_popUpPolicy = popUpPolicy; }
 
+    MetaViewportPolicy metaViewportPolicy() const { return m_metaViewportPolicy; }
+    void setMetaViewportPolicy(MetaViewportPolicy policy) { m_metaViewportPolicy = policy; }
+
     void addSubresourceLoader(ResourceLoader*);
     void removeSubresourceLoader(LoadCompletionType, ResourceLoader*);
     void addPlugInStreamLoader(ResourceLoader&);
@@ -556,6 +565,7 @@ private:
     AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default };
     OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks;
     PopUpPolicy m_popUpPolicy { PopUpPolicy::Default };
+    MetaViewportPolicy m_metaViewportPolicy { MetaViewportPolicy::Default };
 
 #if ENABLE(SERVICE_WORKER)
     Optional<ServiceWorkerRegistrationData> m_serviceWorkerRegistrationData;
index d1083e9..722794f 100644 (file)
@@ -1,5 +1,37 @@
 2019-04-03  Wenson Hsieh  <wenson_hsieh@apple.com>
 
+        Introduce and add plumbing for a website policy for meta viewport tag handling
+        https://bugs.webkit.org/show_bug.cgi?id=196285
+
+        Reviewed by Tim Horton.
+
+        Add WebsiteMetaViewportPolicy, a bit that can be used to determine whether to respect or ignore the meta
+        viewport tag and use native web page parameters instead of the default parameters.
+
+        * Shared/WebsiteMetaViewportPolicy.h: Copied from Source/WebKit/Shared/WebsitePoliciesData.h.
+        * Shared/WebsitePoliciesData.cpp:
+        (WebKit::WebsitePoliciesData::encode const):
+        (WebKit::WebsitePoliciesData::decode):
+        (WebKit::WebsitePoliciesData::applyToDocumentLoader):
+
+        Convert WebKit::WebsiteMetaViewportPolicy into WebCore::MetaViewportPolicy.
+
+        * Shared/WebsitePoliciesData.h:
+        * UIProcess/API/APIWebsitePolicies.cpp:
+        (API::WebsitePolicies::data):
+        * UIProcess/API/APIWebsitePolicies.h:
+
+        Add additional plumbing for the policy flag.
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::resetViewportDefaultConfiguration):
+
+        Use native web page parameters if either "shouldIgnoreMetaViewport" is enabled, or the new policy is set.
+        Eventually, the policy should completely replace the former preference once no internal clients depend on it.
+
+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
 
diff --git a/Source/WebKit/Shared/WebsiteMetaViewportPolicy.h b/Source/WebKit/Shared/WebsiteMetaViewportPolicy.h
new file mode 100644 (file)
index 0000000..edea821
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 WebsiteMetaViewportPolicy {
+    Default,
+    Respect,
+    Ignore,
+};
+
+}
+
+namespace WTF {
+
+template<> struct EnumTraits<WebKit::WebsiteMetaViewportPolicy> {
+    using values = EnumValues<
+        WebKit::WebsiteMetaViewportPolicy,
+        WebKit::WebsiteMetaViewportPolicy::Default,
+        WebKit::WebsiteMetaViewportPolicy::Respect,
+        WebKit::WebsiteMetaViewportPolicy::Ignore
+    >;
+};
+
+} // namespace WTF
index a885289..4aefaca 100644 (file)
@@ -46,6 +46,7 @@ void WebsitePoliciesData::encode(IPC::Encoder& encoder) const
     encoder << customUserAgent;
     encoder << customJavaScriptUserAgentAsSiteSpecificQuirks;
     encoder << customNavigatorPlatform;
+    encoder << metaViewportPolicy;
 }
 
 Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
@@ -99,6 +100,11 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
     decoder >> customNavigatorPlatform;
     if (!customNavigatorPlatform)
         return WTF::nullopt;
+
+    Optional<WebsiteMetaViewportPolicy> metaViewportPolicy;
+    decoder >> metaViewportPolicy;
+    if (!metaViewportPolicy)
+        return WTF::nullopt;
     
     return { {
         WTFMove(*contentBlockersEnabled),
@@ -111,6 +117,7 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
         WTFMove(*customUserAgent),
         WTFMove(*customJavaScriptUserAgentAsSiteSpecificQuirks),
         WTFMove(*customNavigatorPlatform),
+        WTFMove(*metaViewportPolicy),
     } };
 }
 
@@ -170,6 +177,18 @@ void WebsitePoliciesData::applyToDocumentLoader(WebsitePoliciesData&& websitePol
         break;
     }
 
+    switch (websitePolicies.metaViewportPolicy) {
+    case WebsiteMetaViewportPolicy::Default:
+        documentLoader.setMetaViewportPolicy(WebCore::MetaViewportPolicy::Default);
+        break;
+    case WebsiteMetaViewportPolicy::Respect:
+        documentLoader.setMetaViewportPolicy(WebCore::MetaViewportPolicy::Respect);
+        break;
+    case WebsiteMetaViewportPolicy::Ignore:
+        documentLoader.setMetaViewportPolicy(WebCore::MetaViewportPolicy::Ignore);
+        break;
+    }
+
     if (websitePolicies.websiteDataStoreParameters) {
         if (auto* frame = documentLoader.frame()) {
             if (auto* page = frame->page())
index d3dd005..1911edd 100644 (file)
@@ -28,6 +28,7 @@
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
 #include "WebsiteDataStoreParameters.h"
+#include "WebsiteMetaViewportPolicy.h"
 #include "WebsitePopUpPolicy.h"
 #include <WebCore/HTTPHeaderField.h>
 #include <wtf/OptionSet.h>
@@ -56,6 +57,7 @@ struct WebsitePoliciesData {
     String customUserAgent;
     String customJavaScriptUserAgentAsSiteSpecificQuirks;
     String customNavigatorPlatform;
+    WebsiteMetaViewportPolicy metaViewportPolicy { WebsiteMetaViewportPolicy::Default };
 
     void encode(IPC::Encoder&) const;
     static Optional<WebsitePoliciesData> decode(IPC::Decoder&);
index 86fcac0..723309b 100644 (file)
@@ -53,11 +53,19 @@ void WebsitePolicies::setWebsiteDataStore(RefPtr<WebsiteDataStore>&& websiteData
 
 WebKit::WebsitePoliciesData WebsitePolicies::data()
 {
-    Optional<WebKit::WebsiteDataStoreParameters> parameters;
-    if (m_websiteDataStore)
-        parameters = m_websiteDataStore->websiteDataStore().parameters();
-    return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), deviceOrientationAndMotionAccessState(),
-        customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customJavaScriptUserAgentAsSiteSpecificQuirks, m_customNavigatorPlatform };
+    return {
+        contentBlockersEnabled(),
+        allowedAutoplayQuirks(),
+        autoplayPolicy(),
+        deviceOrientationAndMotionAccessState(),
+        customHeaderFields(),
+        popUpPolicy(),
+        m_websiteDataStore ? Optional<WebKit::WebsiteDataStoreParameters> { m_websiteDataStore->websiteDataStore().parameters() } : WTF::nullopt,
+        m_customUserAgent,
+        m_customJavaScriptUserAgentAsSiteSpecificQuirks,
+        m_customNavigatorPlatform,
+        m_metaViewportPolicy,
+    };
 }
 
 }
index 63213f4..cd51bad 100644 (file)
@@ -29,6 +29,7 @@
 #include "WebCompatibilityMode.h"
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
+#include "WebsiteMetaViewportPolicy.h"
 #include "WebsitePopUpPolicy.h"
 #include <WebCore/HTTPHeaderField.h>
 #include <wtf/OptionSet.h>
@@ -84,6 +85,9 @@ public:
     WebKit::WebCompatibilityMode preferredCompatibilityMode() const { return m_preferredCompatibilityMode; }
     void setPreferredCompatibilityMode(WebKit::WebCompatibilityMode mode) { m_preferredCompatibilityMode = mode; }
 
+    WebKit::WebsiteMetaViewportPolicy metaViewportPolicy() const { return m_metaViewportPolicy; }
+    void setMetaViewportPolicy(WebKit::WebsiteMetaViewportPolicy policy) { m_metaViewportPolicy = policy; }
+
 private:
     WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&);
 
@@ -98,6 +102,7 @@ private:
     WTF::String m_customJavaScriptUserAgentAsSiteSpecificQuirks;
     WTF::String m_customNavigatorPlatform;
     WebKit::WebCompatibilityMode m_preferredCompatibilityMode { WebKit::WebCompatibilityMode::Default };
+    WebKit::WebsiteMetaViewportPolicy m_metaViewportPolicy { WebKit::WebsiteMetaViewportPolicy::Default };
 };
 
 } // namespace API
index b453232..1c0205e 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, ); }; };
+               F430E9422247335F005FE053 /* WebsiteMetaViewportPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */; };
                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 */; };
                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>"; };
+               F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsiteMetaViewportPolicy.h; 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>"; };
                                511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */,
                                5C3AEA8E1FE1F1DF002318D3 /* WebsitePoliciesData.cpp */,
                                5C13024A1FE341A7000D9B31 /* WebsitePoliciesData.h */,
+                               F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */,
                                0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */,
                                8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */,
                                8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */,
                                BC4075F8124FF0270068F20A /* WKData.h in Headers */,
                                37A709A71E3EA0FD00CA5969 /* WKDataDetectorTypes.h in Headers */,
                                37A709A91E3EA40C00CA5969 /* WKDataDetectorTypesInternal.h in Headers */,
+                               F430E9422247335F005FE053 /* WebsiteMetaViewportPolicy.h in Headers */,
                                2E94FC1620351A6D00974BA0 /* WKDatePickerViewController.h in Headers */,
                                377EAD4517E2C51A002D193D /* WKDeclarationSpecifiers.h in Headers */,
                                5C359C0D2154739F009E7948 /* WKDeprecated.h in Headers */,
index 26122a8..0be07f2 100644 (file)
@@ -63,6 +63,7 @@
 #import <WebCore/DataDetection.h>
 #import <WebCore/DiagnosticLoggingClient.h>
 #import <WebCore/DiagnosticLoggingKeys.h>
+#import <WebCore/DocumentLoader.h>
 #import <WebCore/DragController.h>
 #import <WebCore/Editing.h>
 #import <WebCore/Editor.h>
@@ -2965,10 +2966,16 @@ void WebPage::resetViewportDefaultConfiguration(WebFrame* frame, bool hasMobileD
     }
 
     auto parametersForStandardFrame = [&] {
+        bool shouldIgnoreMetaViewport = false;
+        if (auto* mainDocument = m_page->mainFrame().document()) {
+            auto* loader = mainDocument->loader();
+            shouldIgnoreMetaViewport = loader && loader->metaViewportPolicy() == WebCore::MetaViewportPolicy::Ignore;
+        }
+
         if (m_page->settings().shouldIgnoreMetaViewport())
-            return m_viewportConfiguration.nativeWebpageParameters();
+            shouldIgnoreMetaViewport = true;
 
-        return ViewportConfiguration::webpageParameters();
+        return shouldIgnoreMetaViewport ? m_viewportConfiguration.nativeWebpageParameters() : ViewportConfiguration::webpageParameters();
     };
 
     if (!frame) {