Bug 1446937 - Have ContextForTopLevelLoad return already_AddRefed<nsISupports> within LoadInfo, r=qdot
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 30 May 2018 21:21:18 +0200
changeset 420495 f4a183ab4f48924081637f8bd33c0023fdd29a8f
parent 420494 eb54a3e980ae715692eb9e51804d478bec864b6e
child 420496 e47d4f48c69506ee7065687665f239049f244d73
push id103826
push useramarchesini@mozilla.com
push dateWed, 30 May 2018 19:22:24 +0000
treeherdermozilla-inbound@f4a183ab4f48 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1446937
milestone62.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 1446937 - Have ContextForTopLevelLoad return already_AddRefed<nsISupports> within LoadInfo, r=qdot
dom/security/nsContentSecurityManager.cpp
netwerk/base/LoadInfo.cpp
netwerk/base/nsILoadInfo.idl
toolkit/components/browser/nsWebBrowserContentPolicy.cpp
toolkit/mozapps/extensions/AddonContentPolicy.cpp
--- a/dom/security/nsContentSecurityManager.cpp
+++ b/dom/security/nsContentSecurityManager.cpp
@@ -89,17 +89,18 @@ nsContentSecurityManager::AllowTopLevelN
     return true;
   }
   nsAutoCString dataSpec;
   uri->GetSpec(dataSpec);
   if (dataSpec.Length() > 50) {
     dataSpec.Truncate(50);
     dataSpec.AppendLiteral("...");
   }
-  nsCOMPtr<nsITabChild> tabChild = do_QueryInterface(loadInfo->ContextForTopLevelLoad());
+  nsCOMPtr<nsISupports> context = loadInfo->ContextForTopLevelLoad();
+  nsCOMPtr<nsITabChild> tabChild = do_QueryInterface(context);
   nsCOMPtr<nsIDocument> doc;
   if (tabChild) {
     doc = static_cast<mozilla::dom::TabChild*>(tabChild.get())->GetDocument();
   }
   NS_ConvertUTF8toUTF16 specUTF16(NS_UnescapeURL(dataSpec));
   const char16_t* params[] = { specUTF16.get() };
   nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                   NS_LITERAL_CSTRING("DATA_URI_BLOCKED"),
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -637,25 +637,25 @@ LoadInfo::GetLoadingDocument(nsIDocument
 
 nsINode*
 LoadInfo::LoadingNode()
 {
   nsCOMPtr<nsINode> node = do_QueryReferent(mLoadingContext);
   return node;
 }
 
-nsISupports*
+already_AddRefed<nsISupports>
 LoadInfo::ContextForTopLevelLoad()
 {
   // Most likely you want to query LoadingNode() instead of
   // ContextForTopLevelLoad() if this assertion fires.
   MOZ_ASSERT(mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
             "should only query this context for top level document loads");
   nsCOMPtr<nsISupports> context = do_QueryReferent(mContextForTopLevelLoad);
-  return context;
+  return context.forget();
 }
 
 already_AddRefed<nsISupports>
 LoadInfo::GetLoadingContext()
 {
   nsCOMPtr<nsISupports> context;
   if (mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
     context = ContextForTopLevelLoad();
--- a/netwerk/base/nsILoadInfo.idl
+++ b/netwerk/base/nsILoadInfo.idl
@@ -364,17 +364,17 @@ interface nsILoadInfo : nsISupports
   /**
    * A C++ friendly version of the loadingContext for toplevel loads.
    * Most likely you want to query the ownerDocument or LoadingNode
    * and not this context only available for TYPE_DOCUMENT loads.
    * Please note that except for loads of TYPE_DOCUMENT, this
    * ContextForTopLevelLoad will always return null.
    */
   [noscript, notxpcom, nostdcall, binaryname(ContextForTopLevelLoad)]
-  nsISupports binaryContextForTopLevelLoad();
+  LoadContextRef binaryContextForTopLevelLoad();
 
   /**
    * For all loads except loads of TYPE_DOCUMENT, the loadingContext
    * simply returns the loadingNode. For loads of TYPE_DOCUMENT this
    * will return the context available for top-level loads which
    * do not have a loadingNode.
    */
   [binaryname(LoadingContextXPCOM)]
--- a/toolkit/components/browser/nsWebBrowserContentPolicy.cpp
+++ b/toolkit/components/browser/nsWebBrowserContentPolicy.cpp
@@ -29,18 +29,18 @@ nsWebBrowserContentPolicy::ShouldLoad(ns
   MOZ_ASSERT(aShouldLoad, "Null out param");
 
   uint32_t contentType = aLoadInfo->GetExternalContentPolicyType();
   MOZ_ASSERT(contentType == nsContentUtils::InternalContentPolicyTypeToExternal(contentType),
              "We should only see external content policy types here.");
 
   *aShouldLoad = nsIContentPolicy::ACCEPT;
 
-  nsIDocShell* shell =
-    NS_CP_GetDocShellFromContext(aLoadInfo->GetLoadingContext());
+  nsCOMPtr<nsISupports> context = aLoadInfo->GetLoadingContext();
+  nsIDocShell* shell = NS_CP_GetDocShellFromContext(context);
   /* We're going to dereference shell, so make sure it isn't null */
   if (!shell) {
     return NS_OK;
   }
 
   nsresult rv;
   bool allowed = true;
 
@@ -87,16 +87,16 @@ nsWebBrowserContentPolicy::ShouldProcess
 
   // Object tags will always open channels with TYPE_OBJECT, but may end up
   // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
   // actual-plugins at the process stage
   if (contentType != nsIContentPolicy::TYPE_OBJECT) {
     return NS_OK;
   }
 
-  nsIDocShell* shell =
-    NS_CP_GetDocShellFromContext(aLoadInfo->GetLoadingContext());
+  nsCOMPtr<nsISupports> context = aLoadInfo->GetLoadingContext();
+  nsIDocShell* shell = NS_CP_GetDocShellFromContext(context);
   if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
     *aShouldProcess = nsIContentPolicy::REJECT_TYPE;
   }
 
   return NS_OK;
 }
--- a/toolkit/mozapps/extensions/AddonContentPolicy.cpp
+++ b/toolkit/mozapps/extensions/AddonContentPolicy.cpp
@@ -127,18 +127,19 @@ AddonContentPolicy::ShouldLoad(nsIURI* a
 
     // Reject attempts to load JavaScript scripts with a non-default version.
     nsAutoString mimeType, version;
     if (NS_SUCCEEDED(mimeParser.GetType(mimeType)) &&
         nsContentUtils::IsJavascriptMIMEType(mimeType) &&
         NS_SUCCEEDED(mimeParser.GetParameter("version", version))) {
       *aShouldLoad = nsIContentPolicy::REJECT_REQUEST;
 
+      nsCOMPtr<nsISupports> context = aLoadInfo->GetLoadingContext();
       LogMessage(NS_LITERAL_STRING(VERSIONED_JS_BLOCKED_MESSAGE),
-                 requestOrigin, typeString, aLoadInfo->GetLoadingContext());
+                 requestOrigin, typeString, context);
       return NS_OK;
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP