nsresult nsUrlClassifierHashCompleterRequest::OpenChannel() { LOG(("nsUrlClassifierHashCompleterRequest::OpenChannel [%p]", this)); nsresult rv; PRUint32 loadFlags = nsIChannel::INHIBIT_CACHING | nsIChannel::LOAD_BYPASS_CACHE; rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, nsnull, nsnull, nsnull, loadFlags); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString requestBody; rv = BuildRequest(requestBody); NS_ENSURE_SUCCESS(rv, rv); rv = AddRequestBody(requestBody); NS_ENSURE_SUCCESS(rv, rv); rv = mChannel->AsyncOpen(this, nsnull); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
nsresult nsUrlClassifierStreamUpdater::FetchUpdate(nsIURI *aUpdateUrl, const nsACString & aRequestBody, const nsACString & aStreamTable) { #ifdef DEBUG { nsCString spec; aUpdateUrl->GetSpec(spec); LOG(("Fetching update %s from %s", aRequestBody.Data(), spec.get())); } #endif nsresult rv; uint32_t loadFlags = nsIChannel::INHIBIT_CACHING | nsIChannel::LOAD_BYPASS_CACHE; rv = NS_NewChannel(getter_AddRefs(mChannel), aUpdateUrl, nsContentUtils::GetSystemPrincipal(), nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsIContentPolicy::TYPE_OTHER, nullptr, // aLoadGroup this, // aInterfaceRequestor loadFlags); NS_ENSURE_SUCCESS(rv, rv); mBeganStream = false; // If aRequestBody is empty, construct it for the test. if (!aRequestBody.IsEmpty()) { rv = AddRequestBody(aRequestBody); NS_ENSURE_SUCCESS(rv, rv); } // Set the appropriate content type for file/data URIs, for unit testing // purposes. // This is only used for testing and should be deleted. bool match; if ((NS_SUCCEEDED(aUpdateUrl->SchemeIs("file", &match)) && match) || (NS_SUCCEEDED(aUpdateUrl->SchemeIs("data", &match)) && match)) { mChannel->SetContentType(NS_LITERAL_CSTRING("application/vnd.google.safebrowsing-update")); } else { // We assume everything else is an HTTP request. // Disable keepalive. nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Connection"), NS_LITERAL_CSTRING("close"), false); NS_ENSURE_SUCCESS(rv, rv); } // Create a custom LoadContext for SafeBrowsing, so we can use callbacks on // the channel to query the appId which allows separation of safebrowsing // cookies in a separate jar. nsCOMPtr<nsIInterfaceRequestor> sbContext = new mozilla::LoadContext(NECKO_SAFEBROWSING_APP_ID); rv = mChannel->SetNotificationCallbacks(sbContext); NS_ENSURE_SUCCESS(rv, rv); // Make the request. rv = mChannel->AsyncOpen2(this); NS_ENSURE_SUCCESS(rv, rv); mStreamTable = aStreamTable; return NS_OK; }