Bug 1616788 - Part 6: Propagate the HasStoragePermission from the loadInfo to the WindowContext. r=dimi,baku
authorTim Huang <tihuang@mozilla.com>
Mon, 30 Mar 2020 14:12:11 +0000
changeset 521063 05e0f36e1ef9b5cae5acbf3fd232ee98c8eb6c0d
parent 521062 d82ee126aceb8a31361d9622b7813433f947e522
child 521064 98e0adb65668803d2711ab00e88359f1573a3474
push id37266
push userccoroiu@mozilla.com
push dateMon, 30 Mar 2020 22:01:01 +0000
treeherdermozilla-central@7f9f804e9dbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi, baku
bugs1616788
milestone76.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 1616788 - Part 6: Propagate the HasStoragePermission from the loadInfo to the WindowContext. r=dimi,baku We propagate the HasStoragePermission flag from the loadInfo to the WindowContext in the patch. We add a flag HasStoragePermission in the document and this flag will get updated when the Document::StartDocumentLoad() happens. And then, we would sync this to the WindowContext in the final stage of the nsGlobalWindowOuter::SetNewDocument() where the WindowContext is ready. Differential Revision: https://phabricator.services.mozilla.com/D67471
dom/base/Document.cpp
dom/base/Document.h
dom/base/nsGlobalWindowOuter.cpp
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -1358,16 +1358,17 @@ Document::Document(const char* aContentT
       mScrollAnchorAdjustmentCount(0),
       mServoRestyleRootDirtyBits(0),
       mThrowOnDynamicMarkupInsertionCounter(0),
       mIgnoreOpensDuringUnloadCounter(0),
       mDocLWTheme(Doc_Theme_Uninitialized),
       mSavedResolution(1.0f),
       mSavedResolutionBeforeMVM(1.0f),
       mPendingInitialTranslation(false),
+      mHasStoragePermission(false),
       mGeneration(0),
       mCachedTabSizeGeneration(0),
       mNextFormNumber(0),
       mNextControlNumber(0) {
   MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug, ("DOCUMENT %p created", this));
 
   SetIsInDocument();
   SetIsConnected(true);
@@ -3223,16 +3224,18 @@ nsresult Document::StartDocumentLoad(con
 
   // Initialize FeaturePolicy
   rv = InitFeaturePolicy(aChannel);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = loadInfo->GetCookieJarSettings(getter_AddRefs(mCookieJarSettings));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  mHasStoragePermission = loadInfo->GetHasStoragePermission();
+
   return NS_OK;
 }
 
 nsIContentSecurityPolicy* Document::GetCsp() const { return mCSP; }
 
 void Document::SetCsp(nsIContentSecurityPolicy* aCSP) { mCSP = aCSP; }
 
 nsIContentSecurityPolicy* Document::GetPreloadCsp() const {
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -1425,16 +1425,19 @@ class Document : public nsINode,
 
   // Helper method that returns true if storage access API is enabled and
   // the passed flag has storage-access sandbox flag.
   static bool StorageAccessSandboxed(uint32_t aSandboxFlags);
 
   // Returns the cookie jar settings for this and sub contexts.
   nsICookieJarSettings* CookieJarSettings();
 
+  // Returns whether this document has the storage permission.
+  bool HasStoragePermission() { return mHasStoragePermission; }
+
   // Increments the document generation.
   inline void Changed() { ++mGeneration; }
 
   // Returns the current generation.
   inline int32_t GetGeneration() const { return mGeneration; }
 
   // Adds cached sizes values to aSizes if there's any
   // cached value and if the document generation hasn't
@@ -5032,16 +5035,18 @@ class Document : public nsINode,
 
   // Pres shell resolution saved before creating a MobileViewportManager.
   float mSavedResolutionBeforeMVM;
 
   bool mPendingInitialTranslation;
 
   nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
 
+  bool mHasStoragePermission;
+
   // Document generation. Gets incremented everytime it changes.
   int32_t mGeneration;
 
   // Cached TabSizes values for the document.
   int32_t mCachedTabSizeGeneration;
   nsTabSizes mCachedTabSizes;
 
   // The principal to use for the storage area of this document.
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -2498,16 +2498,20 @@ nsresult nsGlobalWindowOuter::SetNewDocu
     // Grant storage access by default if the first-party storage access
     // permission has been granted already.
     // Don't notify in this case, since we would be notifying the user
     // needlessly.
     mHasStorageAccess =
         ContentBlocking::ShouldAllowAccessFor(newInnerWindow, uri, nullptr);
   }
 
+  newInnerWindow->GetWindowGlobalChild()
+      ->WindowContext()
+      ->SetHasStoragePermission(aDocument->HasStoragePermission());
+
   return NS_OK;
 }
 
 /* static */
 void nsGlobalWindowOuter::PrepareForProcessChange(JSObject* aProxy) {
   JS::Rooted<JSObject*> localProxy(RootingCx(), aProxy);
   MOZ_ASSERT(js::IsWindowProxy(localProxy));