Bug 1337893 - Part 4: Updating whole gecko to make all callers of DNS using correct originAttributes. r=baku

MozReview-Commit-ID: D6Vp8ANSzLI

--HG--
extra : rebase_source : f3608b09835040e4a4f8e7675aa53d003f298d32
This commit is contained in:
Tim Huang 2017-02-15 10:39:40 +08:00
parent 2d4b6a79e2
commit fc6e097c7a
8 changed files with 85 additions and 44 deletions

View File

@ -829,6 +829,8 @@ function gKeywordURIFixup({ target: browser, data: fixupInfo }) {
return;
}
let contentPrincipal = browser.contentPrincipal;
// At this point we're still only just about to load this URI.
// When the async DNS lookup comes back, we may be in any of these states:
// 1) still on the previous URI, waiting for the preferredURI (keyword
@ -931,7 +933,8 @@ function gKeywordURIFixup({ target: browser, data: fixupInfo }) {
};
try {
gDNSService.asyncResolve(hostName, 0, onLookupComplete, Services.tm.mainThread);
gDNSService.asyncResolve(hostName, 0, onLookupComplete, Services.tm.mainThread,
contentPrincipal.originAttributes);
} catch (ex) {
// Do nothing if the URL is invalid (we don't want to show a notification in that case).
if (ex.result != Cr.NS_ERROR_UNKNOWN_HOST) {

View File

@ -894,7 +894,8 @@ nsContentSink::PrefetchDNS(const nsAString &aHref)
}
if (!hostname.IsEmpty() && nsHTMLDNSPrefetch::IsAllowed(mDocument)) {
nsHTMLDNSPrefetch::PrefetchLow(hostname);
nsHTMLDNSPrefetch::PrefetchLow(hostname,
mDocument->NodePrincipal()->OriginAttributesRef());
}
}

View File

@ -129,7 +129,9 @@ nsHTMLDNSPrefetch::PrefetchHigh(Link *aElement)
}
nsresult
nsHTMLDNSPrefetch::Prefetch(const nsAString &hostname, uint16_t flags)
nsHTMLDNSPrefetch::Prefetch(const nsAString &hostname,
const OriginAttributes &aOriginAttributes,
uint16_t flags)
{
if (IsNeckoChild()) {
// We need to check IsEmpty() because net_IsValidHostName()
@ -138,7 +140,8 @@ nsHTMLDNSPrefetch::Prefetch(const nsAString &hostname, uint16_t flags)
net_IsValidHostName(NS_ConvertUTF16toUTF8(hostname))) {
// during shutdown gNeckoChild might be null
if (gNeckoChild) {
gNeckoChild->SendHTMLDNSPrefetch(nsAutoString(hostname), flags);
gNeckoChild->SendHTMLDNSPrefetch(nsString(hostname),
aOriginAttributes, flags);
}
}
return NS_OK;
@ -148,28 +151,31 @@ nsHTMLDNSPrefetch::Prefetch(const nsAString &hostname, uint16_t flags)
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsICancelable> tmpOutstanding;
return sDNSService->AsyncResolve(NS_ConvertUTF16toUTF8(hostname),
flags | nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, nullptr,
getter_AddRefs(tmpOutstanding));
return sDNSService->AsyncResolveNative(NS_ConvertUTF16toUTF8(hostname),
flags | nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, nullptr, aOriginAttributes,
getter_AddRefs(tmpOutstanding));
}
nsresult
nsHTMLDNSPrefetch::PrefetchLow(const nsAString &hostname)
nsHTMLDNSPrefetch::PrefetchLow(const nsAString &hostname,
const OriginAttributes &aOriginAttributes)
{
return Prefetch(hostname, nsIDNSService::RESOLVE_PRIORITY_LOW);
return Prefetch(hostname, aOriginAttributes, nsIDNSService::RESOLVE_PRIORITY_LOW);
}
nsresult
nsHTMLDNSPrefetch::PrefetchMedium(const nsAString &hostname)
nsHTMLDNSPrefetch::PrefetchMedium(const nsAString &hostname,
const OriginAttributes &aOriginAttributes)
{
return Prefetch(hostname, nsIDNSService::RESOLVE_PRIORITY_MEDIUM);
return Prefetch(hostname, aOriginAttributes, nsIDNSService::RESOLVE_PRIORITY_MEDIUM);
}
nsresult
nsHTMLDNSPrefetch::PrefetchHigh(const nsAString &hostname)
nsHTMLDNSPrefetch::PrefetchHigh(const nsAString &hostname,
const OriginAttributes &aOriginAttributes)
{
return Prefetch(hostname, 0);
return Prefetch(hostname, aOriginAttributes, 0);
}
nsresult
@ -182,11 +188,19 @@ nsHTMLDNSPrefetch::CancelPrefetch(Link *aElement,
nsAutoString hostname;
aElement->GetHostname(hostname);
return CancelPrefetch(hostname, flags, aReason);
Element* element = aElement->GetElement();
NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
return CancelPrefetch(hostname,
element->NodePrincipal()
->OriginAttributesRef(),
flags, aReason);
}
nsresult
nsHTMLDNSPrefetch::CancelPrefetch(const nsAString &hostname,
const OriginAttributes &aOriginAttributes,
uint16_t flags,
nsresult aReason)
{
@ -198,7 +212,9 @@ nsHTMLDNSPrefetch::CancelPrefetch(const nsAString &hostname,
net_IsValidHostName(NS_ConvertUTF16toUTF8(hostname))) {
// during shutdown gNeckoChild might be null
if (gNeckoChild) {
gNeckoChild->SendCancelHTMLDNSPrefetch(nsString(hostname), flags,
gNeckoChild->SendCancelHTMLDNSPrefetch(nsString(hostname),
aOriginAttributes,
flags,
aReason);
}
}
@ -209,10 +225,10 @@ nsHTMLDNSPrefetch::CancelPrefetch(const nsAString &hostname,
return NS_ERROR_NOT_AVAILABLE;
// Forward cancellation to DNS service
return sDNSService->CancelAsyncResolve(NS_ConvertUTF16toUTF8(hostname),
flags
| nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, aReason);
return sDNSService->CancelAsyncResolveNative(NS_ConvertUTF16toUTF8(hostname),
flags
| nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, aReason, aOriginAttributes);
}
nsresult
@ -223,9 +239,11 @@ nsHTMLDNSPrefetch::CancelPrefetchLow(Link *aElement, nsresult aReason)
}
nsresult
nsHTMLDNSPrefetch::CancelPrefetchLow(const nsAString &hostname, nsresult aReason)
nsHTMLDNSPrefetch::CancelPrefetchLow(const nsAString &hostname,
const OriginAttributes &aOriginAttributes,
nsresult aReason)
{
return CancelPrefetch(hostname, nsIDNSService::RESOLVE_PRIORITY_LOW,
return CancelPrefetch(hostname, aOriginAttributes, nsIDNSService::RESOLVE_PRIORITY_LOW,
aReason);
}
@ -318,6 +336,7 @@ nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
nsCOMPtr<nsIURI> hrefURI(link ? link->GetURI() : nullptr);
bool isLocalResource = false;
nsresult rv = NS_OK;
Element* element = link->GetElement();
hostName.Truncate();
if (hrefURI) {
@ -327,21 +346,26 @@ nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
&isLocalResource);
}
if (!hostName.IsEmpty() && NS_SUCCEEDED(rv) && !isLocalResource) {
if (!hostName.IsEmpty() && NS_SUCCEEDED(rv) && !isLocalResource &&
element) {
if (IsNeckoChild()) {
// during shutdown gNeckoChild might be null
if (gNeckoChild) {
gNeckoChild->SendHTMLDNSPrefetch(NS_ConvertUTF8toUTF16(hostName),
element->NodePrincipal()
->OriginAttributesRef(),
mEntries[mTail].mFlags);
}
} else {
nsCOMPtr<nsICancelable> tmpOutstanding;
rv = sDNSService->AsyncResolve(hostName,
mEntries[mTail].mFlags
| nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, nullptr,
getter_AddRefs(tmpOutstanding));
rv = sDNSService->AsyncResolveNative(hostName,
mEntries[mTail].mFlags
| nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, nullptr,
element->NodePrincipal()
->OriginAttributesRef(),
getter_AddRefs(tmpOutstanding));
// Tell link that deferred prefetch was requested
if (NS_SUCCEEDED(rv))
link->OnDNSPrefetchRequested();
@ -349,11 +373,11 @@ nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
}
}
}
mEntries[mTail].mElement = nullptr;
mTail = (mTail + 1) & sMaxDeferredMask;
}
if (mTimerArmed) {
mTimerArmed = false;
mTimer->Cancel();

View File

@ -51,17 +51,25 @@ public:
static nsresult PrefetchHigh(mozilla::dom::Link *aElement);
static nsresult PrefetchMedium(mozilla::dom::Link *aElement);
static nsresult PrefetchLow(mozilla::dom::Link *aElement);
static nsresult PrefetchHigh(const nsAString &host);
static nsresult PrefetchMedium(const nsAString &host);
static nsresult PrefetchLow(const nsAString &host);
static nsresult CancelPrefetchLow(const nsAString &host, nsresult aReason);
static nsresult PrefetchHigh(const nsAString &host,
const mozilla::OriginAttributes &aOriginAttributes);
static nsresult PrefetchMedium(const nsAString &host,
const mozilla::OriginAttributes &aOriginAttributes);
static nsresult PrefetchLow(const nsAString &host,
const mozilla::OriginAttributes &aOriginAttributes);
static nsresult CancelPrefetchLow(const nsAString &host,
const mozilla::OriginAttributes &aOriginAttributes,
nsresult aReason);
static nsresult CancelPrefetchLow(mozilla::dom::Link *aElement,
nsresult aReason);
private:
static nsresult Prefetch(const nsAString &host, uint16_t flags);
static nsresult Prefetch(const nsAString &host,
const mozilla::OriginAttributes &aOriginAttributes,
uint16_t flags);
static nsresult Prefetch(mozilla::dom::Link *aElement, uint16_t flags);
static nsresult CancelPrefetch(const nsAString &hostname,
const mozilla::OriginAttributes &aOriginAttributes,
uint16_t flags,
nsresult aReason);
static nsresult CancelPrefetch(mozilla::dom::Link *aElement,

View File

@ -960,7 +960,8 @@ NetworkManager.prototype = {
0,
aNetId,
onLookupComplete,
Services.tm.mainThread);
Services.tm.mainThread,
{});
});
};

View File

@ -119,9 +119,11 @@ MakeSN(const char *principal, nsCString &result)
// resolver might not have enough information to satisfy the request from
// its cache. This is not an issue in versions of Windows up to WinXP.
nsCOMPtr<nsIDNSRecord> record;
rv = dns->Resolve(Substring(buf, index + 1),
nsIDNSService::RESOLVE_CANONICAL_NAME,
getter_AddRefs(record));
mozilla::OriginAttributes attrs;
rv = dns->ResolveNative(Substring(buf, index + 1),
nsIDNSService::RESOLVE_CANONICAL_NAME,
attrs,
getter_AddRefs(record));
if (NS_FAILED(rv))
return rv;

View File

@ -151,6 +151,7 @@ int NrIceResolver::resolve(nr_resolver_resource *resource,
ASSERT_ON_THREAD(sts_thread_);
RefPtr<PendingResolution> pr;
uint32_t resolve_flags = 0;
OriginAttributes attrs;
if (resource->transport_protocol != IPPROTO_UDP &&
resource->transport_protocol != IPPROTO_TCP) {
@ -175,9 +176,10 @@ int NrIceResolver::resolve(nr_resolver_resource *resource,
ABORT(R_BAD_ARGS);
}
if (NS_FAILED(dns_->AsyncResolve(nsAutoCString(resource->domain_name),
resolve_flags, pr,
sts_thread_, getter_AddRefs(pr->request_)))) {
if (NS_FAILED(dns_->AsyncResolveNative(nsAutoCString(resource->domain_name),
resolve_flags, pr,
sts_thread_, attrs,
getter_AddRefs(pr->request_)))) {
MOZ_MTLOG(ML_ERROR, "AsyncResolve failed.");
ABORT(R_NOT_FOUND);
}

View File

@ -690,7 +690,7 @@ NeckoParent::RecvHTMLDNSPrefetch(const nsString& hostname,
const OriginAttributes& aOriginAttributes,
const uint16_t& flags)
{
nsHTMLDNSPrefetch::Prefetch(hostname, flags);
nsHTMLDNSPrefetch::Prefetch(hostname, aOriginAttributes, flags);
return IPC_OK();
}
@ -700,7 +700,7 @@ NeckoParent::RecvCancelHTMLDNSPrefetch(const nsString& hostname,
const uint16_t& flags,
const nsresult& reason)
{
nsHTMLDNSPrefetch::CancelPrefetch(hostname, flags, reason);
nsHTMLDNSPrefetch::CancelPrefetch(hostname, aOriginAttributes, flags, reason);
return IPC_OK();
}