Restrict conditions when the page's viewport meta overrides setInitialScale

1. The initial scale provided must be <= 100%. Larger scales are never got
overridden. On Blink side, this means that
m_userAgentConstraints.initialScale * deviceScaleFactor <= 1.0f

2. m_pageDefinedConstraints.initialScale can be reset in loadWithOverviewMode
handling code when adjustForAndroidWebViewQuirks is called from inside
WebViewImpl::Resize flow, and the viewport meta tag hasn't been parsed yet.
So check the original updated scale value instead of the one adjusted inside
adjustForAndroidWebViewQuirks.

3. Since width=320 is transformed into width=device-width, no additional check
for 320 is needed.

4. Also, re-layout in case userAgentInitialScale has been reset.
This prevents eBay ads pages from regressing.

Bug: 11283805

Corresponding CL upstream: http://crrev.com/55073002

[Android WebView] Add a quirk to clobber initial scale in certain cases

In the following cases, the viewport meta tag would take precedence over
the value specified in setInitialPageScaleOverride:

The value provided to setInitialPageScaleOverride is <= 1 / device pixel ratio AND

- viewport meta has width=device-width OR

- viewport meta has auto width, and the page would be displayed at 100% scale.

BUG=313754

Change-Id: I7e82617c395ba1dd66494b1ee2a43aa2904b8ab7
diff --git a/Source/core/page/PageScaleConstraintsSet.cpp b/Source/core/page/PageScaleConstraintsSet.cpp
index 1e1b1b6..983a032 100644
--- a/Source/core/page/PageScaleConstraintsSet.cpp
+++ b/Source/core/page/PageScaleConstraintsSet.cpp
@@ -162,16 +162,6 @@
             adjustedLayoutSizeWidth /= targetDensityDPIFactor;
             adjustedLayoutSizeHeight /= targetDensityDPIFactor;
         }
-
-        // In the following cases, a bug in the Classic WebView would mean that the viewport meta tag would take
-        // precedence over the app specified setInitialScale value. We keep bugward compatibility with the old
-        // WebView for legacy apps (the supportTargetDensityDPI case). New apps will see that setInitialScale()
-        // overrides what is specified in the viewport tag.
-        if (arguments.width == ViewportArguments::ValueAuto && m_pageDefinedConstraints.initialScale == 1.0f) {
-            m_userAgentConstraints.initialScale = -1;
-        } else if (arguments.width == ViewportArguments::ValueDeviceWidth || arguments.width == 320) {
-            m_userAgentConstraints.initialScale = -1;
-        }
     }
 
     if (wideViewportQuirkEnabled) {
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp
index 78232be..f123849 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -3069,6 +3069,19 @@
 
     float oldInitialScale = m_pageScaleConstraintsSet.pageDefinedConstraints().initialScale;
     m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedArguments, m_size, page()->settings()->layoutFallbackWidth());
+
+    if (settingsImpl()->supportDeprecatedTargetDensityDPI()
+        && m_pageScaleConstraintsSet.userAgentConstraints().initialScale != -1
+        && m_pageScaleConstraintsSet.userAgentConstraints().initialScale * deviceScaleFactor() <= 1.0f) {
+        // In the following cases, a bug in the Classic WebView would mean that the viewport meta tag would take
+        // precedence over the app specified setInitialScale value. We keep bugward compatibility with the old
+        // WebView for legacy apps (the supportTargetDensityDPI case). New apps will see that setInitialScale()
+        // overrides what is specified in the viewport tag.
+        if (adjustedArguments.width == ViewportArguments::ValueDeviceWidth
+            || (adjustedArguments.width == ViewportArguments::ValueAuto && m_pageScaleConstraintsSet.pageDefinedConstraints().initialScale == 1.0f)) {
+            setInitialPageScaleOverride(-1);
+        }
+    }
     m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedArguments, m_size, page()->settings()->layoutFallbackWidth(), deviceScaleFactor(), settingsImpl()->supportDeprecatedTargetDensityDPI(), page()->settings()->wideViewportQuirkEnabled(), page()->settings()->useWideViewport(), page()->settings()->loadWithOverviewMode());
     float newInitialScale = m_pageScaleConstraintsSet.pageDefinedConstraints().initialScale;
     if (oldInitialScale != newInitialScale && newInitialScale != -1)