Bug 1459498: Avoid a useless QI. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 06 May 2018 16:52:15 +0200
changeset 791924 6c61476cff3e1c1e59766b7a8c16953e4c6add79
parent 791903 f23ca27993eeedd820d1450b738cb8009e73c3f8
child 792103 f8ff8171ba90a61a55b07ecf8025ee65238ac16d
push id108928
push userbmo:emilio@crisal.io
push dateMon, 07 May 2018 02:11:54 +0000
reviewersheycam
bugs1459498
milestone61.0a1
Bug 1459498: Avoid a useless QI. r?heycam MozReview-Commit-ID: FCLEoZnTjYG
layout/style/Loader.cpp
layout/style/Loader.h
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -874,34 +874,33 @@ Loader::ObsoleteSheet(nsIURI* aURI)
   }
   return NS_OK;
 }
 
 nsresult
 Loader::CheckContentPolicy(nsIPrincipal* aLoadingPrincipal,
                            nsIPrincipal* aTriggeringPrincipal,
                            nsIURI* aTargetURI,
-                           nsISupports* aContext,
+                           nsINode* aRequestingNode,
                            bool aIsPreload)
 {
   // When performing a system load (e.g. aUseSystemPrincipal = true)
   // then aLoadingPrincipal == null; don't consult content policies.
   if (!aLoadingPrincipal) {
     return NS_OK;
   }
 
   nsContentPolicyType contentPolicyType =
     aIsPreload ? nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD
                : nsIContentPolicy::TYPE_INTERNAL_STYLESHEET;
 
-  nsCOMPtr<nsINode> requestingNode = do_QueryInterface(aContext);
   nsCOMPtr<nsILoadInfo> secCheckLoadInfo =
     new net::LoadInfo(aLoadingPrincipal,
                       aTriggeringPrincipal,
-                      requestingNode,
+                      aRequestingNode,
                       nsILoadInfo::SEC_ONLY_FOR_EXPLICIT_CONTENTSEC_CHECK,
                       contentPolicyType);
 
   int16_t shouldLoad = nsIContentPolicy::ACCEPT;
   nsresult rv = NS_CheckContentLoadPolicy(aTargetURI,
                                           secCheckLoadInfo,
                                           NS_LITERAL_CSTRING("text/css"),
                                           &shouldLoad,
@@ -2158,18 +2157,20 @@ Loader::LoadChildSheet(StyleSheet* aPare
     LOG_WARN(("  Not enabled"));
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   LOG_URI("  Child uri: '%s'", aURL);
 
   nsCOMPtr<nsINode> owningNode;
 
-  // check for an associated document: if none, don't bother walking up the
-  // parent sheets
+  // Check for an associated document: if none, don't bother walking up the
+  // parent sheets.
+  //
+  // FIXME(emilio): This looks wrong for Shadow DOM.
   if (aParentSheet->GetAssociatedDocument()) {
     StyleSheet* topSheet = aParentSheet;
     while (StyleSheet* parent = topSheet->GetParentSheet()) {
       topSheet = parent;
     }
     owningNode = topSheet->GetOwnerNode();
   }
 
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -455,17 +455,17 @@ private:
 
   // Helper to select the correct dispatch target for asynchronous events for
   // this loader.
   already_AddRefed<nsISerialEventTarget> DispatchTarget();
 
   nsresult CheckContentPolicy(nsIPrincipal* aLoadingPrincipal,
                               nsIPrincipal* aTriggeringPrincipal,
                               nsIURI* aTargetURI,
-                              nsISupports* aContext,
+                              nsINode* aRequestingNode,
                               bool aIsPreload);
 
   nsresult CreateSheet(const StyleSheetInfo& aInfo,
                        nsIPrincipal* aLoaderPrincipal,
                        css::SheetParsingMode aParsingMode,
                        bool aSyncLoad,
                        StyleSheetState& aSheetState,
                        RefPtr<StyleSheet>* aSheet)