nsresult SubstitutingProtocolHandler::NewChannel2(nsIURI* uri, nsILoadInfo* aLoadInfo, nsIChannel** result) { NS_ENSURE_ARG_POINTER(uri); nsAutoCString spec; nsresult rv = ResolveURI(uri, spec); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> newURI; rv = NS_NewURI(getter_AddRefs(newURI), spec); NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewChannelInternal(result, newURI, aLoadInfo); NS_ENSURE_SUCCESS(rv, rv); nsLoadFlags loadFlags = 0; (*result)->GetLoadFlags(&loadFlags); (*result)->SetLoadFlags(loadFlags & ~nsIChannel::LOAD_REPLACE); rv = (*result)->SetOriginalURI(uri); NS_ENSURE_SUCCESS(rv, rv); return SubstituteChannel(uri, aLoadInfo, result); }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** aResult) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(aResult, "must not be null"); nsAutoCString path; nsresult rv = NS_GetAboutModuleName(aURI, path); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); for (int i = 0; i < kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; nsCOMPtr<nsIURI> tempURI; rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); NS_ENSURE_SUCCESS(rv, rv); // If tempURI links to an external URI (i.e. something other than // chrome:// or resource://) then set the LOAD_REPLACE flag on the // channel which forces the channel owner to reflect the displayed // URL rather then being the systemPrincipal. bool isUIResource = false; rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE, &isUIResource); NS_ENSURE_SUCCESS(rv, rv); bool isAboutBlank = NS_IsAboutBlank(tempURI); nsLoadFlags loadFlags = isUIResource || isAboutBlank ? static_cast<nsLoadFlags>(nsIChannel::LOAD_NORMAL) : static_cast<nsLoadFlags>(nsIChannel::LOAD_REPLACE); rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI, aLoadInfo, nullptr, // aLoadGroup nullptr, // aCallbacks loadFlags); NS_ENSURE_SUCCESS(rv, rv); tempChannel->SetOriginalURI(aURI); tempChannel.forget(aResult); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** result) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(result, "must not be null"); nsAutoCString path; nsresult rv = NS_GetAboutModuleName(aURI, path); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); for (int i=0; i<kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; nsCOMPtr<nsIURI> tempURI; rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); NS_ENSURE_SUCCESS(rv, rv); // Bug 1087720 (and Bug 1099296): // Once all callsites have been updated to call NewChannel2() // instead of NewChannel() we should have a non-null loadInfo // consistently. Until then we have to branch on the loadInfo. if (aLoadInfo) { rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI, aLoadInfo); } else { rv = ioService->NewChannelFromURI(tempURI, getter_AddRefs(tempChannel)); } if (NS_FAILED(rv)) return rv; tempChannel->SetOriginalURI(aURI); NS_ADDREF(*result = tempChannel); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** aResult) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(aResult, "must not be null"); nsAutoCString path; nsresult rv = NS_GetAboutModuleName(aURI, path); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); for (int i = 0; i < kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; nsCOMPtr<nsIURI> tempURI; rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI, aLoadInfo); if (NS_FAILED(rv)) { return rv; } tempChannel->SetOriginalURI(aURI); tempChannel.forget(aResult); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** aResult) { NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_ARG_POINTER(aLoadInfo); NS_ASSERTION(aResult, "must not be null"); nsAutoCString path; nsresult rv = NS_GetAboutModuleName(aURI, path); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); if (path.EqualsASCII("crashparent") || path.EqualsASCII("crashcontent")) { nsCOMPtr<nsIChannel> channel = new CrashChannel(aURI); channel.forget(aResult); return NS_OK; } #ifdef ABOUT_CONFIG_BLOCKED_GV // We don't want to allow access to about:config from // GeckoView on release or beta, but it's fine for Fennec. if (path.EqualsASCII("config") && !mozilla::jni::IsFennec()) { return NS_ERROR_NOT_AVAILABLE; } #endif for (int i = 0; i < kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; nsCOMPtr<nsIURI> tempURI; rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI, aLoadInfo); NS_ENSURE_SUCCESS(rv, rv); // If tempURI links to an external URI (i.e. something other than // chrome:// or resource://) then set result principal URI on the // load info which forces the channel principal to reflect the displayed // URL rather then being the systemPrincipal. bool isUIResource = false; rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE, &isUIResource); NS_ENSURE_SUCCESS(rv, rv); bool isAboutBlank = NS_IsAboutBlank(tempURI); if (!isUIResource && !isAboutBlank) { aLoadInfo->SetResultPrincipalURI(tempURI); } tempChannel->SetOriginalURI(aURI); tempChannel.forget(aResult); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
NS_IMETHODIMP nsChromeProtocolHandler::NewChannel(nsIURI *aURI, nsILoadInfo *aLoadInfo, nsIChannel **aResult) { nsresult rv; NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_ARG_POINTER(aLoadInfo); MOZ_ASSERT(aResult, "Null out param"); #ifdef DEBUG // Check that the uri we got is already canonified nsresult debug_rv; nsCOMPtr<nsIURI> debugURL = aURI; debug_rv = nsChromeRegistry::Canonify(debugURL); if (NS_SUCCEEDED(debug_rv)) { bool same; debug_rv = aURI->Equals(debugURL, &same); if (NS_SUCCEEDED(debug_rv)) { NS_ASSERTION(same, "Non-canonified chrome uri passed to " "nsChromeProtocolHandler::NewChannel!"); } } #endif nsCOMPtr<nsIChannel> result; if (!nsChromeRegistry::gChromeRegistry) { // We don't actually want this ref, we just want the service to // initialize if it hasn't already. nsCOMPtr<nsIChromeRegistry> reg = mozilla::services::GetChromeRegistryService(); NS_ENSURE_TRUE(nsChromeRegistry::gChromeRegistry, NS_ERROR_FAILURE); } nsCOMPtr<nsIURI> resolvedURI; rv = nsChromeRegistry::gChromeRegistry->ConvertChromeURL( aURI, getter_AddRefs(resolvedURI)); if (NS_FAILED(rv)) { #ifdef DEBUG printf("Couldn't convert chrome URL: %s\n", aURI->GetSpecOrDefault().get()); #endif return rv; } // We don't want to allow the inner protocol handler modify the result // principal URI since we want either |aURI| or anything pre-set by upper // layers to prevail. nsCOMPtr<nsIURI> savedResultPrincipalURI; rv = aLoadInfo->GetResultPrincipalURI(getter_AddRefs(savedResultPrincipalURI)); NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewChannelInternal(getter_AddRefs(result), resolvedURI, aLoadInfo); NS_ENSURE_SUCCESS(rv, rv); #ifdef DEBUG nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(result)); if (fileChan) { nsCOMPtr<nsIFile> file; fileChan->GetFile(getter_AddRefs(file)); bool exists = false; file->Exists(&exists); if (!exists) { printf("Chrome file doesn't exist: %s\n", file->HumanReadablePath().get()); } } #endif // Make sure that the channel remembers where it was // originally loaded from. rv = aLoadInfo->SetResultPrincipalURI(savedResultPrincipalURI); NS_ENSURE_SUCCESS(rv, rv); rv = result->SetOriginalURI(aURI); if (NS_FAILED(rv)) return rv; // Get a system principal for content files and set the owner // property of the result nsCOMPtr<nsIURL> url = do_QueryInterface(aURI); nsAutoCString path; rv = url->GetPathQueryRef(path); if (StringBeginsWith(path, NS_LITERAL_CSTRING("/content/"))) { result->SetOwner(nsContentUtils::GetSystemPrincipal()); } // XXX Removed dependency-tracking code from here, because we're not // tracking them anyways (with fastload we checked only in DEBUG // and with startupcache not at all), but this is where we would start // if we need to re-add. // See bug 531886, bug 533038. result->SetContentCharset(NS_LITERAL_CSTRING("UTF-8")); *aResult = result; NS_ADDREF(*aResult); return NS_OK; }
NS_IMETHODIMP nsChromeProtocolHandler::NewChannel2(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** aResult) { nsresult rv; NS_ENSURE_ARG_POINTER(aURI); NS_PRECONDITION(aResult, "Null out param"); #ifdef DEBUG // Check that the uri we got is already canonified nsresult debug_rv; nsCOMPtr<nsIURI> debugClone; debug_rv = aURI->Clone(getter_AddRefs(debugClone)); if (NS_SUCCEEDED(debug_rv)) { nsCOMPtr<nsIURL> debugURL (do_QueryInterface(debugClone)); debug_rv = nsChromeRegistry::Canonify(debugURL); if (NS_SUCCEEDED(debug_rv)) { bool same; debug_rv = aURI->Equals(debugURL, &same); if (NS_SUCCEEDED(debug_rv)) { NS_ASSERTION(same, "Non-canonified chrome uri passed to nsChromeProtocolHandler::NewChannel!"); } } } #endif nsCOMPtr<nsIChannel> result; if (!nsChromeRegistry::gChromeRegistry) { // We don't actually want this ref, we just want the service to // initialize if it hasn't already. nsCOMPtr<nsIChromeRegistry> reg = mozilla::services::GetChromeRegistryService(); NS_ENSURE_TRUE(nsChromeRegistry::gChromeRegistry, NS_ERROR_FAILURE); } nsCOMPtr<nsIURI> resolvedURI; rv = nsChromeRegistry::gChromeRegistry->ConvertChromeURL(aURI, getter_AddRefs(resolvedURI)); if (NS_FAILED(rv)) { #ifdef DEBUG nsAutoCString spec; aURI->GetSpec(spec); printf("Couldn't convert chrome URL: %s\n", spec.get()); #endif return rv; } rv = NS_NewChannelInternal(getter_AddRefs(result), resolvedURI, aLoadInfo); NS_ENSURE_SUCCESS(rv, rv); #ifdef DEBUG nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(result)); if (fileChan) { nsCOMPtr<nsIFile> file; fileChan->GetFile(getter_AddRefs(file)); bool exists = false; file->Exists(&exists); if (!exists) { nsAutoCString path; file->GetNativePath(path); printf("Chrome file doesn't exist: %s\n", path.get()); } } #endif // Make sure that the channel remembers where it was // originally loaded from. nsLoadFlags loadFlags = 0; result->GetLoadFlags(&loadFlags); result->SetLoadFlags(loadFlags & ~nsIChannel::LOAD_REPLACE); rv = result->SetOriginalURI(aURI); if (NS_FAILED(rv)) return rv; // Get a system principal for content files and set the owner // property of the result nsCOMPtr<nsIURL> url = do_QueryInterface(aURI); nsAutoCString path; rv = url->GetPath(path); if (StringBeginsWith(path, NS_LITERAL_CSTRING("/content/"))) { nsCOMPtr<nsIScriptSecurityManager> securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIPrincipal> principal; rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsISupports> owner = do_QueryInterface(principal); result->SetOwner(owner); } // XXX Removed dependency-tracking code from here, because we're not // tracking them anyways (with fastload we checked only in DEBUG // and with startupcache not at all), but this is where we would start // if we need to re-add. // See bug 531886, bug 533038. result->SetContentCharset(NS_LITERAL_CSTRING("UTF-8")); *aResult = result; NS_ADDREF(*aResult); return NS_OK; }