Title: [243798] trunk/Source
Revision
243798
Author
[email protected]
Date
2019-04-03 08:22:10 -0700 (Wed, 03 Apr 2019)

Log Message

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.

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.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (243797 => 243798)


--- trunk/Source/WebCore/ChangeLog	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebCore/ChangeLog	2019-04-03 15:22:10 UTC (rev 243798)
@@ -1,3 +1,16 @@
+2019-04-03  Wenson Hsieh  <[email protected]>
+
+        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  <[email protected]>
 
         Web Inspector: Remote Inspector indicate callback should always happen on the main thread

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (243797 => 243798)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2019-04-03 15:22:10 UTC (rev 243798)
@@ -112,6 +112,12 @@
     Block,
 };
 
+enum class MetaViewportPolicy {
+    Default,
+    Respect,
+    Ignore,
+};
+
 class DocumentLoader
     : public RefCounted<DocumentLoader>
     , public FrameDestructionObserver
@@ -283,6 +289,9 @@
     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 @@
     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;

Modified: trunk/Source/WebKit/ChangeLog (243797 => 243798)


--- trunk/Source/WebKit/ChangeLog	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/ChangeLog	2019-04-03 15:22:10 UTC (rev 243798)
@@ -1,5 +1,37 @@
 2019-04-03  Wenson Hsieh  <[email protected]>
 
+        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  <[email protected]>
+
         Add plumbing for a compatibility mode preference in WebKit
         https://bugs.webkit.org/show_bug.cgi?id=196005
 

Copied: trunk/Source/WebKit/Shared/WebsiteMetaViewportPolicy.h (from rev 243797, trunk/Source/WebKit/Shared/WebsitePoliciesData.h) (0 => 243798)


--- trunk/Source/WebKit/Shared/WebsiteMetaViewportPolicy.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/WebsiteMetaViewportPolicy.h	2019-04-03 15:22:10 UTC (rev 243798)
@@ -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

Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp (243797 => 243798)


--- trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp	2019-04-03 15:22:10 UTC (rev 243798)
@@ -46,6 +46,7 @@
     encoder << customUserAgent;
     encoder << customJavaScriptUserAgentAsSiteSpecificQuirks;
     encoder << customNavigatorPlatform;
+    encoder << metaViewportPolicy;
 }
 
 Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
@@ -99,6 +100,11 @@
     decoder >> customNavigatorPlatform;
     if (!customNavigatorPlatform)
         return WTF::nullopt;
+
+    Optional<WebsiteMetaViewportPolicy> metaViewportPolicy;
+    decoder >> metaViewportPolicy;
+    if (!metaViewportPolicy)
+        return WTF::nullopt;
     
     return { {
         WTFMove(*contentBlockersEnabled),
@@ -111,6 +117,7 @@
         WTFMove(*customUserAgent),
         WTFMove(*customJavaScriptUserAgentAsSiteSpecificQuirks),
         WTFMove(*customNavigatorPlatform),
+        WTFMove(*metaViewportPolicy),
     } };
 }
 
@@ -170,6 +177,18 @@
         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())

Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.h (243797 => 243798)


--- trunk/Source/WebKit/Shared/WebsitePoliciesData.h	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.h	2019-04-03 15:22:10 UTC (rev 243798)
@@ -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 @@
     String customUserAgent;
     String customJavaScriptUserAgentAsSiteSpecificQuirks;
     String customNavigatorPlatform;
+    WebsiteMetaViewportPolicy metaViewportPolicy { WebsiteMetaViewportPolicy::Default };
 
     void encode(IPC::Encoder&) const;
     static Optional<WebsitePoliciesData> decode(IPC::Decoder&);

Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (243797 => 243798)


--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp	2019-04-03 15:22:10 UTC (rev 243798)
@@ -53,11 +53,19 @@
 
 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,
+    };
 }
 
 }

Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h (243797 => 243798)


--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h	2019-04-03 15:22:10 UTC (rev 243798)
@@ -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 @@
     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 @@
     WTF::String m_customJavaScriptUserAgentAsSiteSpecificQuirks;
     WTF::String m_customNavigatorPlatform;
     WebKit::WebCompatibilityMode m_preferredCompatibilityMode { WebKit::WebCompatibilityMode::Default };
+    WebKit::WebsiteMetaViewportPolicy m_metaViewportPolicy { WebKit::WebsiteMetaViewportPolicy::Default };
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (243797 => 243798)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-04-03 15:22:10 UTC (rev 243798)
@@ -1636,6 +1636,7 @@
 		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 */; };
@@ -4572,6 +4573,7 @@
 		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>"; };
@@ -5228,6 +5230,7 @@
 				511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */,
 				5C3AEA8E1FE1F1DF002318D3 /* WebsitePoliciesData.cpp */,
 				5C13024A1FE341A7000D9B31 /* WebsitePoliciesData.h */,
+				F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */,
 				0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */,
 				8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */,
 				8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */,
@@ -9820,6 +9823,7 @@
 				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 */,

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (243797 => 243798)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-04-03 15:02:07 UTC (rev 243797)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-04-03 15:22:10 UTC (rev 243798)
@@ -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 @@
     }
 
     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) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to