Bug 1290420 Part 1: Add a docshell flag for overriding meta viewport handling. r=smaug
☠☠ backed out by 458e5b24da2f ☠ ☠
authorBotond Ballo <botond@mozilla.com>, Brad Werth <bwerth@mozilla.com>
Tue, 11 Sep 2018 15:17:24 +0000
changeset 435940 755a32f2794364243ae6f3c03eeba9cbc79f034d
parent 435939 0936ac1e0de3d820f77c82ddee434f4adc679373
child 435941 a6eb531e1216a2c78fc2ee36d9d52eec8bd5d636
push id34624
push userdvarga@mozilla.com
push dateThu, 13 Sep 2018 02:29:53 +0000
treeherdermozilla-central@458e5b24da2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1290420
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1290420 Part 1: Add a docshell flag for overriding meta viewport handling. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D3373
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -332,16 +332,17 @@ nsDocShell::nsDocShell()
   , mDefaultLoadFlags(nsIRequest::LOAD_NORMAL)
   , mReferrerPolicy(0)
   , mFailedLoadType(0)
   , mFrameType(FRAME_TYPE_REGULAR)
   , mPrivateBrowsingId(0)
   , mDisplayMode(nsIDocShell::DISPLAY_MODE_BROWSER)
   , mJSRunToCompletionDepth(0)
   , mTouchEventsOverride(nsIDocShell::TOUCHEVENTS_OVERRIDE_NONE)
+  , mMetaViewportOverride(nsIDocShell::META_VIEWPORT_OVERRIDE_NONE)
   , mFullscreenAllowed(CHECK_ATTRIBUTES)
   , mCreatingDocument(false)
 #ifdef DEBUG
   , mInEnsureScriptEnv(false)
 #endif
   , mCreated(false)
   , mAllowSubframes(true)
   , mAllowPlugins(true)
@@ -2636,16 +2637,39 @@ nsDocShell::SetTouchEventsOverride(uint3
     nsCOMPtr<nsIDocShell> childShell = do_QueryInterface(ChildAt(i));
     if (childShell) {
       childShell->SetTouchEventsOverride(aTouchEventsOverride);
     }
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsDocShell::GetMetaViewportOverride(uint32_t* aMetaViewportOverride)
+{
+  NS_ENSURE_ARG_POINTER(aMetaViewportOverride);
+
+  *aMetaViewportOverride = mMetaViewportOverride;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDocShell::SetMetaViewportOverride(uint32_t aMetaViewportOverride)
+{
+  if (!(aMetaViewportOverride == nsIDocShell::META_VIEWPORT_OVERRIDE_NONE ||
+        aMetaViewportOverride == nsIDocShell::META_VIEWPORT_OVERRIDE_ENABLED ||
+        aMetaViewportOverride == nsIDocShell::META_VIEWPORT_OVERRIDE_DISABLED)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  mMetaViewportOverride = aMetaViewportOverride;
+
+  return NS_OK;
+}
+
 /* virtual */ int32_t
 nsDocShell::ItemType()
 {
   return mItemType;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetItemType(int32_t* aItemType)
@@ -2915,16 +2939,19 @@ nsDocShell::SetDocLoaderParent(nsDocLoad
     uint32_t flags;
     if (NS_SUCCEEDED(parentAsDocShell->GetDefaultLoadFlags(&flags))) {
       SetDefaultLoadFlags(flags);
     }
     uint32_t touchEventsOverride;
     if (NS_SUCCEEDED(parentAsDocShell->GetTouchEventsOverride(&touchEventsOverride))) {
       SetTouchEventsOverride(touchEventsOverride);
     }
+    // We don't need to inherit metaViewportOverride, because the viewport
+    // is only relevant for the outermost nsDocShell, not for any iframes
+    // like this that might be embedded within it.
   }
 
   nsCOMPtr<nsILoadContext> parentAsLoadContext(do_QueryInterface(parent));
   if (parentAsLoadContext && mInheritPrivateBrowsingId &&
       NS_SUCCEEDED(parentAsLoadContext->GetUsePrivateBrowsing(&value))) {
     SetPrivateBrowsing(value);
   }
 
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -1074,16 +1074,20 @@ private: // data members
   // A depth count of how many times NotifyRunToCompletionStart
   // has been called without a matching NotifyRunToCompletionStop.
   uint32_t mJSRunToCompletionDepth;
 
   // Whether or not touch events are overridden. Possible values are defined
   // as constants in the nsIDocShell.idl file.
   uint32_t mTouchEventsOverride;
 
+  // Whether or not handling of the <meta name="viewport"> tag is overridden.
+  // Possible values are defined as constants in nsIDocShell.idl.
+  uint32_t mMetaViewportOverride;
+
   // mFullscreenAllowed stores how we determine whether fullscreen is allowed
   // when GetFullscreenAllowed() is called. Fullscreen is allowed in a
   // docshell when all containing iframes have the allowfullscreen
   // attribute set to true. When mFullscreenAllowed is CHECK_ATTRIBUTES
   // we check this docshell's containing frame for the allowfullscreen
   // attribute, and recurse onto the parent docshell to ensure all containing
   // frames also have the allowfullscreen attribute. If we find an ancestor
   // docshell with mFullscreenAllowed not equal to CHECK_ATTRIBUTES, we've
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -1152,16 +1152,38 @@ interface nsIDocShell : nsIDocShellTreeI
    */
   const unsigned long TOUCHEVENTS_OVERRIDE_ENABLED = 1;
   /**
    * Don't override the platform/pref default behaviour for touch events.
    */
   const unsigned long TOUCHEVENTS_OVERRIDE_NONE = 2;
 
   /**
+   * Override platform/pref default behaviour and force-disable support for
+   * <meta name="viewport">.
+   */
+  const unsigned long META_VIEWPORT_OVERRIDE_DISABLED = 0;
+  /**
+   * Override platform/pref default behaviour and force-enable support for
+   * <meta name="viewport">.
+   */
+  const unsigned long META_VIEWPORT_OVERRIDE_ENABLED = 1;
+  /**
+   * Don't override the platform/pref default behaviour for support for
+   * <meta name="viewport">.
+   */
+  const unsigned long META_VIEWPORT_OVERRIDE_NONE = 2;
+  /**
+   * This allows chrome to override the default choice of whether the
+   * <meta name="viewport"> tag is respected in a specific docshell.
+   * Possible values are listed above.
+   */
+  attribute unsigned long metaViewportOverride;
+
+  /**
    * This value is `true` if its corresponding unit of related browsing contexts
    * (TabGroup) contains only 1 toplevel window, and that window is the outer
    * window corresponding to this docshell.
    *
    * The value is `false` otherwise. This is the case if the docshell is an
    * iframe, has window.opener set, or another window with window.opener
    * referring to this window exists.
    *