Bug 968334 Allow disabling content retargeting on child docshells only r=smaug
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Sat, 21 Mar 2015 10:48:48 +0000
changeset 252140 2232d2bce241d032aacb2a4548ba780e9e8f3894
parent 252139 bffc9502adb1a549be3213487f0a424ff27a9c74
child 252141 f949be6cd23e26be7bfab6f72e2b7fa093013097
child 252235 751aea13dd05b5353ce7d0f4ba5979e77433cec8
push id1174
push usernsm.nikhil@gmail.com
push dateSun, 22 Mar 2015 01:24:25 +0000
reviewerssmaug
bugs968334
milestone39.0a1
Bug 968334 Allow disabling content retargeting on child docshells only r=smaug
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -854,16 +854,17 @@ nsDocShell::nsDocShell()
   , mAllowPlugins(true)
   , mAllowJavascript(true)
   , mAllowMetaRedirects(true)
   , mAllowImages(true)
   , mAllowMedia(true)
   , mAllowDNSPrefetch(true)
   , mAllowWindowControl(true)
   , mAllowContentRetargeting(true)
+  , mAllowContentRetargetingOnChildren(true)
   , mCreatingDocument(false)
   , mUseErrorPages(false)
   , mObserveErrorPages(true)
   , mAllowAuth(true)
   , mAllowKeywordFixup(false)
   , mIsOffScreenBrowser(false)
   , mIsActive(true)
   , mIsPrerendered(false)
@@ -2582,21 +2583,36 @@ nsDocShell::GetAllowContentRetargeting(b
 {
   *aAllowContentRetargeting = mAllowContentRetargeting;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetAllowContentRetargeting(bool aAllowContentRetargeting)
 {
+  mAllowContentRetargetingOnChildren = aAllowContentRetargeting;
   mAllowContentRetargeting = aAllowContentRetargeting;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShell::GetAllowContentRetargetingOnChildren(bool* aAllowContentRetargetingOnChildren)
+{
+  *aAllowContentRetargetingOnChildren = mAllowContentRetargetingOnChildren;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDocShell::SetAllowContentRetargetingOnChildren(bool aAllowContentRetargetingOnChildren)
+{
+  mAllowContentRetargetingOnChildren = aAllowContentRetargetingOnChildren;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDocShell::GetFullscreenAllowed(bool* aFullscreenAllowed)
 {
   NS_ENSURE_ARG_POINTER(aFullscreenAllowed);
 
   // Browsers and apps have their mFullscreenAllowed retrieved from their
   // corresponding iframe in their parent upon creation.
   if (mFullscreenAllowed != CHECK_ATTRIBUTES) {
     *aFullscreenAllowed = (mFullscreenAllowed == PARENT_ALLOWS);
@@ -3456,17 +3472,17 @@ nsDocShell::SetDocLoaderParent(nsDocLoad
     }
     if (NS_SUCCEEDED(parentAsDocShell->GetAllowImages(&value))) {
       SetAllowImages(value);
     }
     SetAllowMedia(parentAsDocShell->GetAllowMedia());
     if (NS_SUCCEEDED(parentAsDocShell->GetAllowWindowControl(&value))) {
       SetAllowWindowControl(value);
     }
-    SetAllowContentRetargeting(parentAsDocShell->GetAllowContentRetargeting());
+    SetAllowContentRetargeting(parentAsDocShell->GetAllowContentRetargetingOnChildren());
     if (NS_SUCCEEDED(parentAsDocShell->GetIsActive(&value))) {
       SetIsActive(value);
     }
     if (parentAsDocShell->GetIsPrerendered()) {
       SetIsPrerendered(true);
     }
     if (NS_FAILED(parentAsDocShell->GetAllowDNSPrefetch(&value))) {
       value = false;
@@ -8733,16 +8749,17 @@ nsDocShell::RestoreFromHistory()
     childShell->GetAllowImages(&allowImages);
 
     bool allowMedia = childShell->GetAllowMedia();
 
     bool allowDNSPrefetch;
     childShell->GetAllowDNSPrefetch(&allowDNSPrefetch);
 
     bool allowContentRetargeting = childShell->GetAllowContentRetargeting();
+    bool allowContentRetargetingOnChildren = childShell->GetAllowContentRetargetingOnChildren();
 
     uint32_t defaultLoadFlags;
     childShell->GetDefaultLoadFlags(&defaultLoadFlags);
 
     // this.AddChild(child) calls child.SetDocLoaderParent(this), meaning that
     // the child inherits our state. Among other things, this means that the
     // child inherits our mIsActive, mIsPrerendered and mInPrivateBrowsing,
     // which is what we want.
@@ -8751,16 +8768,17 @@ nsDocShell::RestoreFromHistory()
     childShell->SetAllowPlugins(allowPlugins);
     childShell->SetAllowJavascript(allowJavascript);
     childShell->SetAllowMetaRedirects(allowRedirects);
     childShell->SetAllowSubframes(allowSubframes);
     childShell->SetAllowImages(allowImages);
     childShell->SetAllowMedia(allowMedia);
     childShell->SetAllowDNSPrefetch(allowDNSPrefetch);
     childShell->SetAllowContentRetargeting(allowContentRetargeting);
+    childShell->SetAllowContentRetargetingOnChildren(allowContentRetargetingOnChildren);
     childShell->SetDefaultLoadFlags(defaultLoadFlags);
 
     rv = childShell->BeginRestore(nullptr, false);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsIPresShell> shell = GetPresShell();
 
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -878,16 +878,17 @@ protected:
   bool mAllowPlugins;
   bool mAllowJavascript;
   bool mAllowMetaRedirects;
   bool mAllowImages;
   bool mAllowMedia;
   bool mAllowDNSPrefetch;
   bool mAllowWindowControl;
   bool mAllowContentRetargeting;
+  bool mAllowContentRetargetingOnChildren;
   bool mCreatingDocument; // (should be) debugging only
   bool mUseErrorPages;
   bool mObserveErrorPages;
   bool mAllowAuth;
   bool mAllowKeywordFixup;
   bool mIsOffScreenBrowser;
   bool mIsActive;
   bool mIsPrerendered;
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -49,17 +49,17 @@ interface nsIWebBrowserPrint;
 interface nsIVariant;
 interface nsIPrivacyTransitionObserver;
 interface nsIReflowObserver;
 interface nsIScrollObserver;
 interface nsITabParent;
  
 typedef unsigned long nsLoadFlags;
 
-[scriptable, builtinclass, uuid(f84b1ae4-2f78-4bad-b36a-6a8516ee6e40)]
+[scriptable, builtinclass, uuid(68ba7610-e33d-47ce-8fa2-af07af2422bc)]
 interface nsIDocShell : nsIDocShellTreeItem
 {
   /**
    * Loads a given URI.  This will give priority to loading the requested URI
    * in the object implementing	this interface.  If it can't be loaded here
    * however, the URL dispatcher will go through its normal process of content
    * loading.
    *
@@ -285,16 +285,22 @@ interface nsIDocShell : nsIDocShellTreeI
   /**
    * True if the docshell allows its content to be handled by a content listener
    * other than the docshell itself, including the external helper app service,
    * and false otherwise.  Defaults to true.
    */
   [infallible] attribute boolean allowContentRetargeting;
 
   /**
+   * True if new child docshells should allow content retargeting.
+   * Setting allowContentRetargeting also overwrites this value.
+   */
+  [infallible] attribute boolean allowContentRetargetingOnChildren;
+
+  /**
    * Get an enumerator over this docShell and its children.
    *
    * @param aItemType  - Only include docShells of this type, or if typeAll,
    *                     include all child shells.
    *                     Uses types from nsIDocShellTreeItem.
    * @param aDirection - Whether to enumerate forwards or backwards.
    */