Bug 1495862 - Ensure FeaturePolicy creation in the document, r=ckerschb
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 15 Oct 2018 12:00:23 +0200
changeset 499735 d49ecfa61467d95283e716c0f102c9fe26c497a4
parent 499734 b434eb7d318a4e4137de89b13cc06fea47398f9b
child 499736 4f99223da02146842694203124351f21b96dec5a
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1495862
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 1495862 - Ensure FeaturePolicy creation in the document, r=ckerschb
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2132,16 +2132,21 @@ nsDocument::Init()
   // via some events.
   nsCOMPtr<nsIGlobalObject> global = xpc::NativeGlobal(xpc::PrivilegedJunkScope());
   NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
   mScopeObject = do_GetWeakReference(global);
   MOZ_ASSERT(mScopeObject);
 
   mScriptLoader = new dom::ScriptLoader(this);
 
+  // we need to create a policy here so getting the policy within
+  // ::Policy() can *always* return a non null policy
+  mFeaturePolicy = new FeaturePolicy(this);
+  mFeaturePolicy->SetDefaultOrigin(NodePrincipal());
+
   mozilla::HoldJSObjects(this);
 
   return NS_OK;
 }
 
 void
 nsIDocument::DeleteAllProperties()
 {
@@ -3007,21 +3012,19 @@ nsIDocument::InitCSP(nsIChannel* aChanne
   }
   ApplySettingsFromCSP(false);
   return NS_OK;
 }
 
 nsresult
 nsIDocument::InitFeaturePolicy(nsIChannel* aChannel)
 {
-  MOZ_ASSERT(!mFeaturePolicy, "we should only call init once");
-
-  // we need to create a policy here so getting the policy within
-  // ::Policy() can *always* return a non null policy
-  mFeaturePolicy = new FeaturePolicy(this);
+  MOZ_ASSERT(mFeaturePolicy, "we should only call init once");
+
+  mFeaturePolicy->ResetDeclaredPolicy();
 
   if (!StaticPrefs::dom_security_featurePolicy_enabled()) {
     return NS_OK;
   }
 
   mFeaturePolicy->SetDefaultOrigin(NodePrincipal());
 
   RefPtr<FeaturePolicy> parentPolicy = nullptr;