Bug 1125916 - Add SEC_FORCE_PRIVATE_BROWSING to LoadInfo. r=sicking, r=jduell
authorDragana Damjanovic <dd.mozilla@gmail.com>
Wed, 13 Apr 2016 10:22:49 +0200
changeset 331082 23c4b279a2b1e6ffcb18a026dfa913598ebed3a9
parent 331081 6ff8536a21bdbe6ad5e0c0ed7e89dd1b1648cb9d
child 331083 1324f1d0dcd0c2730866c171c9e6beed007e17a8
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, jduell
bugs1125916
milestone48.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 1125916 - Add SEC_FORCE_PRIVATE_BROWSING to LoadInfo. r=sicking, r=jduell
netwerk/base/LoadInfo.cpp
netwerk/base/nsILoadInfo.idl
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -140,16 +140,30 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadin
     if (channel) {
       nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
       if (loadInfo) {
         loadInfo->GetVerifySignedContent(&mEnforceSRI);
       }
     }
   }
 
+  if (!(mSecurityFlags & nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING)) {
+    if (aLoadingContext) {
+      nsCOMPtr<nsILoadContext> loadContext =
+        aLoadingContext->OwnerDoc()->GetLoadContext();
+      if (loadContext) {
+        bool usePrivateBrowsing;
+        nsresult rv = loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing);
+        if (NS_SUCCEEDED(rv) && usePrivateBrowsing) {
+          mSecurityFlags |= nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING;
+        }
+      }
+    }
+  }
+
   InheritOriginAttributes(mLoadingPrincipal, mOriginAttributes);
 }
 
 /* Constructor takes an outer window, but no loadingNode or loadingPrincipal.
  * This constructor should only be used for TYPE_DOCUMENT loads, since they
  * have a null loadingNode and loadingPrincipal.
 */
 LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
@@ -451,16 +465,24 @@ NS_IMETHODIMP
 LoadInfo::GetDontFollowRedirects(bool* aResult)
 {
   *aResult =
     (mSecurityFlags & nsILoadInfo::SEC_DONT_FOLLOW_REDIRECTS);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+LoadInfo::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
+{
+  *aUsePrivateBrowsing = (mSecurityFlags &
+                          nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 LoadInfo::GetExternalContentPolicyType(nsContentPolicyType* aResult)
 {
   *aResult = nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
   return NS_OK;
 }
 
 nsContentPolicyType
 LoadInfo::InternalContentPolicyType()
--- a/netwerk/base/nsILoadInfo.idl
+++ b/netwerk/base/nsILoadInfo.idl
@@ -153,16 +153,25 @@ interface nsILoadInfo : nsISupports
    *
    * Note: If this flag is set and the channel response is a redirect, then
    * the response body might not be available.
    * This can happen if the redirect was cached.
    */
   const unsigned long SEC_DONT_FOLLOW_REDIRECTS = (1<<11);
 
   /**
+   * Force private browsing. Setting this flag the private browsing can be
+   * enforce even when a loading is not happening in the context of a document.
+   *
+   * If the flag is true, even if a document context is present,
+   * GetUsePrivateBrowsing will always return true.
+   */
+  const unsigned long SEC_FORCE_PRIVATE_BROWSING = (1<<12);
+
+  /**
    * The loadingPrincipal is the principal that is responsible for the load.
    * It is *NOT* the principal tied to the resource/URI that this
    * channel is loading, it's the principal of the resource's
    * caller or requester. For example, if this channel is loading
    * an image from http://b.com that is embedded in a document
    * who's origin is http://a.com, the loadingPrincipal is http://a.com.
    *
    * The loadingPrincipal will never be null.
@@ -278,16 +287,21 @@ interface nsILoadInfo : nsISupports
 
   /**
    * If aboutBlankInherits is true, then about:blank should inherit
    * the principal.
    */
   [infallible] readonly attribute boolean aboutBlankInherits;
 
   /**
+   * If usePrivateBrowsing is true, private browsing will be used.
+   */
+  [infallible] readonly attribute boolean usePrivateBrowsing;
+
+  /**
    * If allowChrome is true, then use nsIScriptSecurityManager::ALLOW_CHROME
    * when calling CheckLoadURIWithPrincipal().
    */
   [infallible] readonly attribute boolean allowChrome;
 
   /**
    * Returns true if SEC_DONT_FOLLOW_REDIRECTS is set.
    */