Bug 1380156 - Loading temporary unpacked extension breaks extension page's CSS in OOP Extensions. r=jimm draft
authorHaik Aftandilian <haftandilian@mozilla.com>
Tue, 25 Jul 2017 22:27:30 -0700
changeset 616079 2ca3e48c66b3e2765a2a41882ddb4b01a83dd3fe
parent 615953 3c49008eaedf65befffc2f0327529817d9879cd5
child 639358 c7e0ae2264557373304027fa20beb0d2ae744cb6
push id70564
push userhaftandilian@mozilla.com
push dateWed, 26 Jul 2017 17:30:22 +0000
reviewersjimm
bugs1380156
milestone56.0a1
Bug 1380156 - Loading temporary unpacked extension breaks extension page's CSS in OOP Extensions. r=jimm MozReview-Commit-ID: 3SskOcpAI5Z
netwerk/protocol/res/ExtensionProtocolHandler.cpp
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -598,34 +598,48 @@ ExtensionProtocolHandler::NewStream(nsIU
 
   bool isDirectory = false;
   NS_TRY(extensionDir->IsDirectory(&isDirectory));
   if (!isDirectory) {
     // The host should map to a directory for unpacked extensions
     return Err(NS_ERROR_FILE_NOT_DIRECTORY);
   }
 
-  /*
-   * Now get a channel for the resolved child URI and make sure the
-   * channel is a file channel.
-   */
+  // Make sure the child URI resolves to a file URI then get a file
+  // channel for the request. The resultant channel should be a
+  // file channel because we only request remote streams for unpacked
+  // extension resource loads where the URI resolves to a file.
+  nsAutoCString resolvedSpec;
+  NS_TRY(ResolveURI(aChildURI, resolvedSpec));
+
+  nsAutoCString resolvedScheme;
+  NS_TRY(net_ExtractURLScheme(resolvedSpec, resolvedScheme));
+  if (!resolvedScheme.EqualsLiteral("file")) {
+    return Err(NS_ERROR_UNEXPECTED);
+  }
+
+  nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
+  NS_TRY(rv);
+
+  nsCOMPtr<nsIURI> resolvedURI;
+  NS_TRY(ioService->NewURI(resolvedSpec,
+                           nullptr,
+                           nullptr,
+                           getter_AddRefs(resolvedURI)));
 
   // We use the system principal to get a file channel for the request,
   // but only after we've checked (above) that the child URI is of
   // moz-extension scheme and that the URI host maps to a directory.
   nsCOMPtr<nsIChannel> channel;
   NS_TRY(NS_NewChannel(getter_AddRefs(channel),
-                       aChildURI,
+                       resolvedURI,
                        nsContentUtils::GetSystemPrincipal(),
                        nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                        nsIContentPolicy::TYPE_OTHER));
 
-  // Channel should be a file channel. It should never be a JAR
-  // channel because we only request remote streams for unpacked
-  // extension resource loads where the URI resolves to a file.
   nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel, &rv);
   NS_TRY(rv);
 
   nsCOMPtr<nsIFile> requestedFile;
   NS_TRY(fileChannel->GetFile(getter_AddRefs(requestedFile)));
 
   /*
    * Make sure the file we resolved to is within the extension directory.