Bug 1290420 - Add a docshell flag for overriding meta viewport handling. r=jryans draft
authorBotond Ballo <botond@mozilla.com>
Wed, 06 Dec 2017 17:45:10 -0500
changeset 712159 8e9cd7ae4483ad12e56eb29c73ccdf747bf5c4c1
parent 710422 3a33e3beb0cd41e0080a63f153a24e0230033578
child 712160 20a524da1b26a9e385f0d3f69e275a8169c297df
push id93256
push userbballo@mozilla.com
push dateFri, 15 Dec 2017 18:25:00 +0000
reviewersjryans
bugs1290420
milestone59.0a1
Bug 1290420 - Add a docshell flag for overriding meta viewport handling. r=jryans MozReview-Commit-ID: GyG2oXRGvjR
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -841,16 +841,17 @@ nsDocShell::nsDocShell()
   , mFrameType(FRAME_TYPE_REGULAR)
   , mPrivateBrowsingId(0)
   , mDisplayMode(nsIDocShell::DISPLAY_MODE_BROWSER)
   , mForcedCharset(nullptr)
   , mParentCharset(nullptr)
   , mParentCharsetSource(0)
   , mJSRunToCompletionDepth(0)
   , mTouchEventsOverride(nsIDocShell::TOUCHEVENTS_OVERRIDE_NONE)
+  , mMetaViewportOverride(nsIDocShell::META_VIEWPORT_OVERRIDE_NONE)
 {
   AssertOriginAttributesMatchPrivateBrowsing();
 
   nsContentUtils::GenerateUUIDInPlace(mHistoryID);
 
   if (gDocShellCount++ == 0) {
     NS_ASSERTION(sURIFixup == nullptr,
                  "Huh, sURIFixup not null in first nsDocShell ctor!");
@@ -3327,16 +3328,46 @@ 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;
+
+  uint32_t childCount = mChildList.Length();
+  for (uint32_t i = 0; i < childCount; ++i) {
+    nsCOMPtr<nsIDocShell> childShell = do_QueryInterface(ChildAt(i));
+    if (childShell) {
+      childShell->SetMetaViewportOverride(aMetaViewportOverride);
+    }
+  }
+  return NS_OK;
+}
+
 /* virtual */ int32_t
 nsDocShell::ItemType()
 {
   return mItemType;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetItemType(int32_t* aItemType)
@@ -3611,16 +3642,20 @@ 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);
     }
+    uint32_t metaViewportOverride;
+    if (NS_SUCCEEDED(parentAsDocShell->GetMetaViewportOverride(&metaViewportOverride))) {
+      SetMetaViewportOverride(metaViewportOverride);
+    }
   }
 
   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
@@ -1184,16 +1184,20 @@ private:
   // 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;
+
   // Our list of ancestor principals.
   nsTArray<nsCOMPtr<nsIPrincipal>> mAncestorPrincipals;
   // Our list of ancestor outerWindowIDs.
   nsTArray<uint64_t> mAncestorOuterWindowIDs;
 
   // Separate function to do the actual name (i.e. not _top, _self etc.)
   // searching for FindItemWithName.
   nsresult DoFindItemWithName(const nsAString& aName,
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -1143,16 +1143,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;
 
   /**
+   * 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 below.
+   */
+  attribute unsigned long metaViewportOverride;
+  /**
+   * 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 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.
    *