зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337893 - Part 2: Making the DNS cache be aware of originAttributes. r=valentin
MozReview-Commit-ID: EroJiwwkGHa --HG-- extra : rebase_source : 409730ef008b02373cc547a890224371806fbf4c
This commit is contained in:
Родитель
a36759a331
Коммит
defed589eb
|
@ -57,12 +57,18 @@ ChildDNSService::~ChildDNSService()
|
|||
|
||||
void
|
||||
ChildDNSService::GetDNSRecordHashKey(const nsACString &aHost,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener* aListener,
|
||||
nsACString &aHashKey)
|
||||
{
|
||||
aHashKey.Assign(aHost);
|
||||
|
||||
nsAutoCString originSuffix;
|
||||
aOriginAttributes.CreateSuffix(originSuffix);
|
||||
aHashKey.Assign(originSuffix);
|
||||
|
||||
aHashKey.AppendInt(aFlags);
|
||||
if (!aNetworkInterface.IsEmpty()) {
|
||||
aHashKey.Append(aNetworkInterface);
|
||||
|
@ -79,19 +85,71 @@ ChildDNSService::AsyncResolve(const nsACString &hostname,
|
|||
uint32_t flags,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc,
|
||||
nsICancelable **result)
|
||||
{
|
||||
return AsyncResolveExtended(hostname, flags, EmptyCString(), listener,
|
||||
target_, result);
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return AsyncResolveExtendedNative(hostname, flags, EmptyCString(),
|
||||
listener, target_, attrs,
|
||||
result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::AsyncResolveExtended(const nsACString &hostname,
|
||||
ChildDNSService::AsyncResolveNative(const nsACString &hostname,
|
||||
uint32_t flags,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsICancelable **result)
|
||||
{
|
||||
return AsyncResolveExtendedNative(hostname, flags, EmptyCString(),
|
||||
listener, target_, aOriginAttributes,
|
||||
result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::AsyncResolveExtended(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc,
|
||||
nsICancelable **result)
|
||||
{
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return AsyncResolveExtendedNative(aHostname, flags, aNetworkInterface,
|
||||
listener, target_, attrs,
|
||||
result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::AsyncResolveExtendedNative(const nsACString &hostname,
|
||||
uint32_t flags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsICancelable **result)
|
||||
{
|
||||
NS_ENSURE_TRUE(gNeckoChild != nullptr, NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -126,14 +184,16 @@ ChildDNSService::AsyncResolveExtended(const nsACString &hostname,
|
|||
}
|
||||
|
||||
RefPtr<DNSRequestChild> childReq =
|
||||
new DNSRequestChild(nsCString(hostname), flags,
|
||||
new DNSRequestChild(nsCString(hostname),
|
||||
aOriginAttributes,
|
||||
flags,
|
||||
nsCString(aNetworkInterface),
|
||||
listener, target);
|
||||
|
||||
{
|
||||
MutexAutoLock lock(mPendingRequestsLock);
|
||||
nsCString key;
|
||||
GetDNSRecordHashKey(hostname, originalFlags, aNetworkInterface,
|
||||
GetDNSRecordHashKey(hostname, aOriginAttributes, originalFlags, aNetworkInterface,
|
||||
originalListener, key);
|
||||
nsTArray<RefPtr<DNSRequestChild>> *hashEntry;
|
||||
if (mPendingRequests.Get(key, &hashEntry)) {
|
||||
|
@ -155,10 +215,33 @@ NS_IMETHODIMP
|
|||
ChildDNSService::CancelAsyncResolve(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason)
|
||||
nsresult aReason,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc)
|
||||
{
|
||||
return CancelAsyncResolveExtended(aHostname, aFlags, EmptyCString(),
|
||||
aListener, aReason);
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return CancelAsyncResolveExtendedNative(aHostname, aFlags, EmptyCString(),
|
||||
aListener, aReason, attrs);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::CancelAsyncResolveNative(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason,
|
||||
const OriginAttributes &aOriginAttributes)
|
||||
{
|
||||
return CancelAsyncResolveExtendedNative(aHostname, aFlags, EmptyCString(),
|
||||
aListener, aReason, aOriginAttributes);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -166,7 +249,31 @@ ChildDNSService::CancelAsyncResolveExtended(const nsACString &aHostname,
|
|||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason)
|
||||
nsresult aReason,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc)
|
||||
{
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return CancelAsyncResolveExtendedNative(aHostname, aFlags, aNetworkInterface,
|
||||
aListener, aReason, attrs);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::CancelAsyncResolveExtendedNative(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason,
|
||||
const OriginAttributes &aOriginAttributes)
|
||||
{
|
||||
if (mDisablePrefetch && (aFlags & RESOLVE_SPECULATE)) {
|
||||
return NS_ERROR_DNS_LOOKUP_QUEUE_FULL;
|
||||
|
@ -175,7 +282,8 @@ ChildDNSService::CancelAsyncResolveExtended(const nsACString &aHostname,
|
|||
MutexAutoLock lock(mPendingRequestsLock);
|
||||
nsTArray<RefPtr<DNSRequestChild>> *hashEntry;
|
||||
nsCString key;
|
||||
GetDNSRecordHashKey(aHostname, aFlags, aNetworkInterface, aListener, key);
|
||||
GetDNSRecordHashKey(aHostname, aOriginAttributes, aFlags,
|
||||
aNetworkInterface, aListener, key);
|
||||
if (mPendingRequests.Get(key, &hashEntry)) {
|
||||
// We cancel just one.
|
||||
hashEntry->ElementAt(0)->Cancel(aReason);
|
||||
|
@ -187,12 +295,25 @@ ChildDNSService::CancelAsyncResolveExtended(const nsACString &aHostname,
|
|||
NS_IMETHODIMP
|
||||
ChildDNSService::Resolve(const nsACString &hostname,
|
||||
uint32_t flags,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
// not planning to ever support this, since sync IPDL is evil.
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::ResolveNative(const nsACString &hostname,
|
||||
uint32_t flags,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
// not planning to ever support this, since sync IPDL is evil.
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChildDNSService::GetDNSCacheEntries(nsTArray<mozilla::net::DNSCacheEntries> *args)
|
||||
{
|
||||
|
@ -227,7 +348,7 @@ ChildDNSService::NotifyRequestDone(DNSRequestChild *aDnsRequest)
|
|||
MutexAutoLock lock(mPendingRequestsLock);
|
||||
|
||||
nsCString key;
|
||||
GetDNSRecordHashKey(aDnsRequest->mHost, originalFlags,
|
||||
GetDNSRecordHashKey(aDnsRequest->mHost, aDnsRequest->mOriginAttributes, originalFlags,
|
||||
aDnsRequest->mNetworkInterface, originalListener, key);
|
||||
|
||||
nsTArray<RefPtr<DNSRequestChild>> *hashEntry;
|
||||
|
|
|
@ -41,6 +41,7 @@ private:
|
|||
virtual ~ChildDNSService();
|
||||
|
||||
void MOZ_ALWAYS_INLINE GetDNSRecordHashKey(const nsACString &aHost,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener* aListener,
|
||||
|
|
|
@ -171,7 +171,9 @@ public:
|
|||
{
|
||||
if (mDnsRequest->mIPCOpen) {
|
||||
// Send request to Parent process.
|
||||
mDnsRequest->SendCancelDNSRequest(mDnsRequest->mHost, mDnsRequest->mFlags,
|
||||
mDnsRequest->SendCancelDNSRequest(mDnsRequest->mHost,
|
||||
mDnsRequest->mOriginAttributes,
|
||||
mDnsRequest->mFlags,
|
||||
mDnsRequest->mNetworkInterface,
|
||||
mReasonForCancel);
|
||||
}
|
||||
|
@ -187,6 +189,7 @@ private:
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
DNSRequestChild::DNSRequestChild(const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface,
|
||||
nsIDNSListener *aListener,
|
||||
|
@ -195,6 +198,7 @@ DNSRequestChild::DNSRequestChild(const nsCString& aHost,
|
|||
, mTarget(target)
|
||||
, mResultStatus(NS_OK)
|
||||
, mHost(aHost)
|
||||
, mOriginAttributes(aOriginAttributes)
|
||||
, mFlags(aFlags)
|
||||
, mNetworkInterface(aNetworkInterface)
|
||||
, mIPCOpen(false)
|
||||
|
@ -212,8 +216,8 @@ DNSRequestChild::StartRequest()
|
|||
}
|
||||
|
||||
// Send request to Parent process.
|
||||
gNeckoChild->SendPDNSRequestConstructor(this, mHost, mFlags,
|
||||
mNetworkInterface);
|
||||
gNeckoChild->SendPDNSRequestConstructor(this, mHost, mOriginAttributes,
|
||||
mFlags, mNetworkInterface);
|
||||
mIPCOpen = true;
|
||||
|
||||
// IPDL holds a reference until IPDL channel gets destroyed
|
||||
|
|
|
@ -24,7 +24,9 @@ public:
|
|||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSICANCELABLE
|
||||
|
||||
DNSRequestChild(const nsCString& aHost, const uint32_t& aFlags,
|
||||
DNSRequestChild(const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface,
|
||||
nsIDNSListener *aListener, nsIEventTarget *target);
|
||||
|
||||
|
@ -50,6 +52,7 @@ protected:
|
|||
nsCOMPtr<nsIDNSRecord> mResultRecord;
|
||||
nsresult mResultStatus;
|
||||
nsCString mHost;
|
||||
const OriginAttributes mOriginAttributes;
|
||||
uint16_t mFlags;
|
||||
nsCString mNetworkInterface;
|
||||
bool mIPCOpen;
|
||||
|
|
|
@ -32,7 +32,9 @@ DNSRequestParent::~DNSRequestParent()
|
|||
}
|
||||
|
||||
void
|
||||
DNSRequestParent::DoAsyncResolve(const nsACString &hostname, uint32_t flags,
|
||||
DNSRequestParent::DoAsyncResolve(const nsACString &hostname,
|
||||
const OriginAttributes &originAttributes,
|
||||
uint32_t flags,
|
||||
const nsACString &networkInterface)
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -41,8 +43,10 @@ DNSRequestParent::DoAsyncResolve(const nsACString &hostname, uint32_t flags,
|
|||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
|
||||
nsCOMPtr<nsICancelable> unused;
|
||||
rv = dns->AsyncResolveExtended(hostname, flags, networkInterface, this,
|
||||
mainThread, getter_AddRefs(unused));
|
||||
rv = dns->AsyncResolveExtendedNative(hostname, flags,
|
||||
networkInterface, this,
|
||||
mainThread, originAttributes,
|
||||
getter_AddRefs(unused));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv) && !mIPCClosed) {
|
||||
|
@ -53,6 +57,7 @@ DNSRequestParent::DoAsyncResolve(const nsACString &hostname, uint32_t flags,
|
|||
|
||||
mozilla::ipc::IPCResult
|
||||
DNSRequestParent::RecvCancelDNSRequest(const nsCString& hostName,
|
||||
const OriginAttributes& originAttributes,
|
||||
const uint32_t& flags,
|
||||
const nsCString& networkInterface,
|
||||
const nsresult& reason)
|
||||
|
@ -60,8 +65,10 @@ DNSRequestParent::RecvCancelDNSRequest(const nsCString& hostName,
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = dns->CancelAsyncResolveExtended(hostName, flags, networkInterface,
|
||||
this, reason);
|
||||
rv = dns->CancelAsyncResolveExtendedNative(hostName, flags,
|
||||
networkInterface,
|
||||
this, reason,
|
||||
originAttributes);
|
||||
}
|
||||
return IPC_OK();
|
||||
}
|
||||
|
|
|
@ -24,12 +24,15 @@ public:
|
|||
|
||||
DNSRequestParent();
|
||||
|
||||
void DoAsyncResolve(const nsACString &hostname, uint32_t flags,
|
||||
void DoAsyncResolve(const nsACString &hostname,
|
||||
const OriginAttributes &originAttributes,
|
||||
uint32_t flags,
|
||||
const nsACString &networkInterface);
|
||||
|
||||
// Pass args here rather than storing them in the parent; they are only
|
||||
// needed if the request is to be canceled.
|
||||
mozilla::ipc::IPCResult RecvCancelDNSRequest(const nsCString& hostName,
|
||||
const OriginAttributes& originAttributes,
|
||||
const uint32_t& flags,
|
||||
const nsCString& networkInterface,
|
||||
const nsresult& reason) override;
|
||||
|
|
|
@ -302,12 +302,14 @@ public:
|
|||
|
||||
nsDNSAsyncRequest(nsHostResolver *res,
|
||||
const nsACString &host,
|
||||
const OriginAttributes &attrs,
|
||||
nsIDNSListener *listener,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const nsACString &netInterface)
|
||||
: mResolver(res)
|
||||
, mHost(host)
|
||||
, mOriginAttributes(attrs)
|
||||
, mListener(listener)
|
||||
, mFlags(flags)
|
||||
, mAF(af)
|
||||
|
@ -323,6 +325,7 @@ public:
|
|||
|
||||
RefPtr<nsHostResolver> mResolver;
|
||||
nsCString mHost; // hostname we're resolving
|
||||
const OriginAttributes mOriginAttributes; // The originAttributes for this resolving
|
||||
nsCOMPtr<nsIDNSListener> mListener;
|
||||
uint16_t mFlags;
|
||||
uint16_t mAF;
|
||||
|
@ -382,8 +385,8 @@ NS_IMETHODIMP
|
|||
nsDNSAsyncRequest::Cancel(nsresult reason)
|
||||
{
|
||||
NS_ENSURE_ARG(NS_FAILED(reason));
|
||||
mResolver->DetachCallback(mHost.get(), mFlags, mAF, mNetworkInterface.get(),
|
||||
this, reason);
|
||||
mResolver->DetachCallback(mHost.get(), mOriginAttributes, mFlags, mAF,
|
||||
mNetworkInterface.get(), this, reason);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -719,10 +722,36 @@ nsDNSService::AsyncResolve(const nsACString &aHostname,
|
|||
uint32_t flags,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc,
|
||||
nsICancelable **result)
|
||||
{
|
||||
return AsyncResolveExtended(aHostname, flags, EmptyCString(), listener, target_,
|
||||
result);
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return AsyncResolveExtendedNative(aHostname, flags, EmptyCString(),
|
||||
listener, target_, attrs,
|
||||
result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::AsyncResolveNative(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsICancelable **result)
|
||||
{
|
||||
return AsyncResolveExtendedNative(aHostname, flags, EmptyCString(),
|
||||
listener, target_, aOriginAttributes,
|
||||
result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -731,7 +760,33 @@ nsDNSService::AsyncResolveExtended(const nsACString &aHostname,
|
|||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc,
|
||||
nsICancelable **result)
|
||||
{
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return AsyncResolveExtendedNative(aHostname, flags, aNetworkInterface,
|
||||
listener, target_, attrs,
|
||||
result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::AsyncResolveExtendedNative(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *listener,
|
||||
nsIEventTarget *target_,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsICancelable **result)
|
||||
{
|
||||
// grab reference to global host resolver and IDN service. beware
|
||||
// simultaneous shutdown!!
|
||||
|
@ -783,7 +838,7 @@ nsDNSService::AsyncResolveExtended(const nsACString &aHostname,
|
|||
uint16_t af = GetAFForLookup(hostname, flags);
|
||||
|
||||
auto *req =
|
||||
new nsDNSAsyncRequest(res, hostname, listener, flags, af,
|
||||
new nsDNSAsyncRequest(res, hostname, aOriginAttributes, listener, flags, af,
|
||||
aNetworkInterface);
|
||||
if (!req)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -791,7 +846,7 @@ nsDNSService::AsyncResolveExtended(const nsACString &aHostname,
|
|||
|
||||
// addref for resolver; will be released when OnLookupComplete is called.
|
||||
NS_ADDREF(req);
|
||||
rv = res->ResolveHost(req->mHost.get(), flags, af,
|
||||
rv = res->ResolveHost(req->mHost.get(), req->mOriginAttributes, flags, af,
|
||||
req->mNetworkInterface.get(), req);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(req);
|
||||
|
@ -801,21 +856,68 @@ nsDNSService::AsyncResolveExtended(const nsACString &aHostname,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::CancelAsyncResolve(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason)
|
||||
nsDNSService::CancelAsyncResolve(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc)
|
||||
{
|
||||
return CancelAsyncResolveExtended(aHostname, aFlags, EmptyCString(), aListener,
|
||||
aReason);
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return CancelAsyncResolveExtendedNative(aHostname, aFlags, EmptyCString(),
|
||||
aListener, aReason, attrs);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::CancelAsyncResolveExtended(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason)
|
||||
nsDNSService::CancelAsyncResolveNative(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason,
|
||||
const OriginAttributes &aOriginAttributes)
|
||||
{
|
||||
return CancelAsyncResolveExtendedNative(aHostname, aFlags, EmptyCString(),
|
||||
aListener, aReason, aOriginAttributes);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::CancelAsyncResolveExtended(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc)
|
||||
{
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return CancelAsyncResolveExtendedNative(aHostname, aFlags, aNetworkInterface,
|
||||
aListener, aReason, attrs);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::CancelAsyncResolveExtendedNative(const nsACString &aHostname,
|
||||
uint32_t aFlags,
|
||||
const nsACString &aNetworkInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult aReason,
|
||||
const OriginAttributes &aOriginAttributes)
|
||||
{
|
||||
// grab reference to global host resolver and IDN service. beware
|
||||
// simultaneous shutdown!!
|
||||
|
@ -843,16 +945,37 @@ nsDNSService::CancelAsyncResolveExtended(const nsACString &aHostname,
|
|||
|
||||
uint16_t af = GetAFForLookup(hostname, aFlags);
|
||||
|
||||
res->CancelAsyncRequest(hostname.get(), aFlags, af,
|
||||
res->CancelAsyncRequest(hostname.get(), aOriginAttributes, aFlags, af,
|
||||
nsPromiseFlatCString(aNetworkInterface).get(), aListener,
|
||||
aReason);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::Resolve(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
nsIDNSRecord **result)
|
||||
nsDNSService::Resolve(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
JS::HandleValue aOriginAttributes,
|
||||
JSContext *aCx,
|
||||
uint8_t aArgc,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
OriginAttributes attrs;
|
||||
|
||||
if (aArgc == 1) {
|
||||
if (!aOriginAttributes.isObject() ||
|
||||
!attrs.Init(aCx, aOriginAttributes)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return ResolveNative(aHostname, flags, attrs, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSService::ResolveNative(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
// grab reference to global host resolver and IDN service. beware
|
||||
// simultaneous shutdown!!
|
||||
|
@ -900,7 +1023,7 @@ nsDNSService::Resolve(const nsACString &aHostname,
|
|||
|
||||
uint16_t af = GetAFForLookup(hostname, flags);
|
||||
|
||||
rv = res->ResolveHost(hostname.get(), flags, af, "", &syncReq);
|
||||
rv = res->ResolveHost(hostname.get(), aOriginAttributes, flags, af, "", &syncReq);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// wait for result
|
||||
while (!syncReq.mDone)
|
||||
|
|
|
@ -185,6 +185,9 @@ nsHostRecord::nsHostRecord(const nsHostKey *key)
|
|||
netInterface = host + strlen(key->host) + 1;
|
||||
memcpy((char *) netInterface, key->netInterface,
|
||||
strlen(key->netInterface) + 1);
|
||||
originSuffix = netInterface + strlen(key->netInterface) + 1;
|
||||
memcpy((char *) originSuffix, key->originSuffix,
|
||||
strlen(key->originSuffix) + 1);
|
||||
PR_INIT_CLIST(this);
|
||||
PR_INIT_CLIST(&callbacks);
|
||||
}
|
||||
|
@ -194,10 +197,11 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
|
|||
{
|
||||
size_t hostLen = strlen(key->host) + 1;
|
||||
size_t netInterfaceLen = strlen(key->netInterface) + 1;
|
||||
size_t size = hostLen + netInterfaceLen + sizeof(nsHostRecord);
|
||||
size_t originSuffixLen = strlen(key->originSuffix) + 1;
|
||||
size_t size = hostLen + netInterfaceLen + originSuffixLen + sizeof(nsHostRecord);
|
||||
|
||||
// Use placement new to create the object with room for the hostname and
|
||||
// network interface name allocated after it.
|
||||
// Use placement new to create the object with room for the hostname,
|
||||
// network interface name and originSuffix allocated after it.
|
||||
void *place = ::operator new(size);
|
||||
*result = new(place) nsHostRecord(key);
|
||||
NS_ADDREF(*result);
|
||||
|
@ -403,7 +407,7 @@ HostDB_HashKey(const void *key)
|
|||
{
|
||||
const nsHostKey *hk = static_cast<const nsHostKey *>(key);
|
||||
return AddToHash(HashString(hk->host), RES_KEY_FLAGS(hk->flags), hk->af,
|
||||
HashString(hk->netInterface));
|
||||
HashString(hk->netInterface), HashString(hk->originSuffix));
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -417,7 +421,8 @@ HostDB_MatchEntry(const PLDHashEntryHdr *entry,
|
|||
hk->host ? hk->host : "") &&
|
||||
RES_KEY_FLAGS (he->rec->flags) == RES_KEY_FLAGS(hk->flags) &&
|
||||
he->rec->af == hk->af &&
|
||||
!strcmp(he->rec->netInterface, hk->netInterface);
|
||||
!strcmp(he->rec->netInterface, hk->netInterface) &&
|
||||
!strcmp(he->rec->originSuffix, hk->originSuffix);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -722,11 +727,12 @@ nsHostResolver::MoveQueue(nsHostRecord *aRec, PRCList &aDestQ)
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsHostResolver::ResolveHost(const char *host,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback)
|
||||
nsHostResolver::ResolveHost(const char *host,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback)
|
||||
{
|
||||
NS_ENSURE_TRUE(host && *host, NS_ERROR_UNEXPECTED);
|
||||
NS_ENSURE_TRUE(netInterface, NS_ERROR_UNEXPECTED);
|
||||
|
@ -761,8 +767,10 @@ nsHostResolver::ResolveHost(const char *host,
|
|||
// any pending callbacks, then add to pending callbacks queue,
|
||||
// and return. otherwise, add ourselves as first pending
|
||||
// callback, and proceed to do the lookup.
|
||||
nsAutoCString originSuffix;
|
||||
aOriginAttributes.CreateSuffix(originSuffix);
|
||||
|
||||
nsHostKey key = { host, flags, af, netInterface };
|
||||
nsHostKey key = { host, flags, af, netInterface, originSuffix.get() };
|
||||
auto he = static_cast<nsHostDBEnt*>(mDB.Add(&key, fallible));
|
||||
|
||||
// if the record is null, the hash table OOM'd.
|
||||
|
@ -840,7 +848,7 @@ nsHostResolver::ResolveHost(const char *host,
|
|||
((af == PR_AF_INET) || (af == PR_AF_INET6))) {
|
||||
// First, search for an entry with AF_UNSPEC
|
||||
const nsHostKey unspecKey = { host, flags, PR_AF_UNSPEC,
|
||||
netInterface };
|
||||
netInterface, originSuffix.get() };
|
||||
auto unspecHe =
|
||||
static_cast<nsHostDBEnt*>(mDB.Search(&unspecKey));
|
||||
NS_ASSERTION(!unspecHe ||
|
||||
|
@ -968,18 +976,22 @@ nsHostResolver::ResolveHost(const char *host,
|
|||
}
|
||||
|
||||
void
|
||||
nsHostResolver::DetachCallback(const char *host,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback,
|
||||
nsresult status)
|
||||
nsHostResolver::DetachCallback(const char *host,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback,
|
||||
nsresult status)
|
||||
{
|
||||
RefPtr<nsHostRecord> rec;
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
nsHostKey key = { host, flags, af, netInterface };
|
||||
nsAutoCString originSuffix;
|
||||
aOriginAttributes.CreateSuffix(originSuffix);
|
||||
|
||||
nsHostKey key = { host, flags, af, netInterface, originSuffix.get() };
|
||||
auto he = static_cast<nsHostDBEnt*>(mDB.Search(&key));
|
||||
if (he) {
|
||||
// walk list looking for |callback|... we cannot assume
|
||||
|
@ -1371,18 +1383,22 @@ nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, AddrInfo* n
|
|||
}
|
||||
|
||||
void
|
||||
nsHostResolver::CancelAsyncRequest(const char *host,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult status)
|
||||
nsHostResolver::CancelAsyncRequest(const char *host,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult status)
|
||||
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
nsAutoCString originSuffix;
|
||||
aOriginAttributes.CreateSuffix(originSuffix);
|
||||
|
||||
// Lookup the host record associated with host, flags & address family
|
||||
nsHostKey key = { host, flags, af, netInterface };
|
||||
nsHostKey key = { host, flags, af, netInterface, originSuffix.get() };
|
||||
auto he = static_cast<nsHostDBEnt*>(mDB.Search(&key));
|
||||
if (he) {
|
||||
nsHostRecord* recPtr = nullptr;
|
||||
|
|
|
@ -39,6 +39,7 @@ struct nsHostKey
|
|||
uint16_t flags;
|
||||
uint16_t af;
|
||||
const char *netInterface;
|
||||
const char *originSuffix;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -234,44 +235,47 @@ public:
|
|||
void Shutdown();
|
||||
|
||||
/**
|
||||
* resolve the given hostname asynchronously. the caller can synthesize
|
||||
* a synchronous host lookup using a lock and a cvar. as noted above
|
||||
* the callback will occur re-entrantly from an unspecified thread. the
|
||||
* host lookup cannot be canceled (cancelation can be layered above this
|
||||
* by having the callback implementation return without doing anything).
|
||||
* resolve the given hostname and originAttributes asynchronously. the caller
|
||||
* can synthesize a synchronous host lookup using a lock and a cvar. as noted
|
||||
* above the callback will occur re-entrantly from an unspecified thread. the
|
||||
* host lookup cannot be canceled (cancelation can be layered above this by
|
||||
* having the callback implementation return without doing anything).
|
||||
*/
|
||||
nsresult ResolveHost(const char *hostname,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback);
|
||||
nsresult ResolveHost(const char *hostname,
|
||||
const mozilla::OriginAttributes &aOriginAttributes,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback);
|
||||
|
||||
/**
|
||||
* removes the specified callback from the nsHostRecord for the given
|
||||
* hostname, flags, and address family. these parameters should correspond
|
||||
* to the parameters passed to ResolveHost. this function executes the
|
||||
* callback if the callback is still pending with the given status.
|
||||
* hostname, originAttributes, flags, and address family. these parameters
|
||||
* should correspond to the parameters passed to ResolveHost. this function
|
||||
* executes the callback if the callback is still pending with the given status.
|
||||
*/
|
||||
void DetachCallback(const char *hostname,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback,
|
||||
nsresult status);
|
||||
void DetachCallback(const char *hostname,
|
||||
const mozilla::OriginAttributes &aOriginAttributes,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsResolveHostCallback *callback,
|
||||
nsresult status);
|
||||
|
||||
/**
|
||||
* Cancels an async request associated with the hostname, flags,
|
||||
* Cancels an async request associated with the hostname, originAttributes, flags,
|
||||
* address family and listener. Cancels first callback found which matches
|
||||
* these criteria. These parameters should correspond to the parameters
|
||||
* passed to ResolveHost. If this is the last callback associated with the
|
||||
* host record, it is removed from any request queues it might be on.
|
||||
*/
|
||||
void CancelAsyncRequest(const char *host,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult status);
|
||||
void CancelAsyncRequest(const char *host,
|
||||
const mozilla::OriginAttributes &aOriginAttributes,
|
||||
uint16_t flags,
|
||||
uint16_t af,
|
||||
const char *netInterface,
|
||||
nsIDNSListener *aListener,
|
||||
nsresult status);
|
||||
/**
|
||||
* values for the flags parameter passed to ResolveHost and DetachCallback
|
||||
* that may be bitwise OR'd together.
|
||||
|
|
|
@ -298,6 +298,7 @@ NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child)
|
|||
|
||||
PDNSRequestChild*
|
||||
NeckoChild::AllocPDNSRequestChild(const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface)
|
||||
{
|
||||
|
|
|
@ -59,6 +59,7 @@ protected:
|
|||
const nsCString& aFilter) override;
|
||||
virtual bool DeallocPUDPSocketChild(PUDPSocketChild*) override;
|
||||
virtual PDNSRequestChild* AllocPDNSRequestChild(const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface) override;
|
||||
virtual bool DeallocPDNSRequestChild(PDNSRequestChild*) override;
|
||||
|
|
|
@ -635,6 +635,7 @@ NeckoParent::DeallocPUDPSocketParent(PUDPSocketParent* actor)
|
|||
|
||||
PDNSRequestParent*
|
||||
NeckoParent::AllocPDNSRequestParent(const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface)
|
||||
{
|
||||
|
@ -646,10 +647,13 @@ NeckoParent::AllocPDNSRequestParent(const nsCString& aHost,
|
|||
mozilla::ipc::IPCResult
|
||||
NeckoParent::RecvPDNSRequestConstructor(PDNSRequestParent* aActor,
|
||||
const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface)
|
||||
{
|
||||
static_cast<DNSRequestParent*>(aActor)->DoAsyncResolve(aHost, aFlags,
|
||||
static_cast<DNSRequestParent*>(aActor)->DoAsyncResolve(aHost,
|
||||
aOriginAttributes,
|
||||
aFlags,
|
||||
aNetworkInterface);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
|
|
@ -149,10 +149,12 @@ protected:
|
|||
const nsCString& aFilter) override;
|
||||
virtual bool DeallocPUDPSocketParent(PUDPSocketParent*) override;
|
||||
virtual PDNSRequestParent* AllocPDNSRequestParent(const nsCString& aHost,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& aFlags,
|
||||
const nsCString& aNetworkInterface) override;
|
||||
virtual mozilla::ipc::IPCResult RecvPDNSRequestConstructor(PDNSRequestParent* actor,
|
||||
const nsCString& hostName,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const uint32_t& flags,
|
||||
const nsCString& aNetworkInterface) override;
|
||||
virtual bool DeallocPDNSRequestParent(PDNSRequestParent*) override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче