Bug 1290420 Part 1: Add a docshell flag for overriding meta viewport handling. r=smaug
authorBotond Ballo <botond@mozilla.com>, Brad Werth <bwerth@mozilla.com>
Thu, 04 Oct 2018 00:19:40 +0000
changeset 495376 ec06f75313deec2dd3acf1d29b9cb3661a9bcc16
parent 495375 6fe284f84898c89846f765ae0746967789ecbe16
child 495377 e887b26390ec2f660536f6cac5d63e40163c182b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [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
@@ -334,16 +334,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)
@@ -2643,16 +2644,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)
@@ -2922,16 +2946,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
@@ -1149,16 +1149,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.
    *