Bug 1380156 - Loading temporary unpacked extension breaks extension page's CSS in OOP Extensions. r=jimm
MozReview-Commit-ID: 3SskOcpAI5Z
--- 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.