From de2b2e4d23a118a8a501b4e226e1f8da2486110e Mon Sep 17 00:00:00 2001 From: Henry Chang Date: Tue, 3 Mar 2015 09:09:07 +0800 Subject: [PATCH] Bug 1053650 - Part 1: Add attribute 'networkInterfaceId' to XMLHttpRequest. r=bz --- dom/base/nsXMLHttpRequest.cpp | 15 +++++++++++++++ dom/base/nsXMLHttpRequest.h | 19 +++++++++++++++++++ dom/webidl/XMLHttpRequest.webidl | 5 +++++ 3 files changed, 39 insertions(+) diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index 0ccd4eb90d2..489b85b9548 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -1795,6 +1795,19 @@ nsXMLHttpRequest::Open(const nsACString& inMethod, const nsACString& url, return rv; } +void +nsXMLHttpRequest::PopulateNetworkInterfaceId() +{ + if (mNetworkInterfaceId.IsEmpty()) { + return; + } + nsCOMPtr channel(do_QueryInterface(mChannel)); + if (!channel) { + return; + } + channel->SetNetworkInterfaceId(mNetworkInterfaceId); +} + /* * "Copy" from a stream. */ @@ -2612,6 +2625,8 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable& aBody) { NS_ENSURE_TRUE(mPrincipal, NS_ERROR_NOT_INITIALIZED); + PopulateNetworkInterfaceId(); + nsresult rv = CheckInnerWindowCorrectness(); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/base/nsXMLHttpRequest.h b/dom/base/nsXMLHttpRequest.h index ca37a7c45ac..ce71cc7c44e 100644 --- a/dom/base/nsXMLHttpRequest.h +++ b/dom/base/nsXMLHttpRequest.h @@ -428,6 +428,11 @@ private: bool IsDeniedCrossSiteRequest(); + // Tell our channel what network interface ID we were told to use. + // If it's an HTTP channel and we were told to use a non-default + // interface ID. + void PopulateNetworkInterfaceId(); + public: void Send(JSContext* /*aCx*/, ErrorResult& aRv) { @@ -538,6 +543,16 @@ public: return mChannel; } + void GetNetworkInterfaceId(nsACString& aId) const + { + aId = mNetworkInterfaceId; + } + + void SetNetworkInterfaceId(const nsACString& aId) + { + mNetworkInterfaceId = aId; + } + // We need a GetInterface callable from JS for chrome JS void GetInterface(JSContext* aCx, nsIJSID* aIID, JS::MutableHandle aRetval, ErrorResult& aRv); @@ -762,6 +777,10 @@ protected: bool mIsSystem; bool mIsAnon; + // A platform-specific identifer to represent the network interface + // that this request is associated with. + nsCString mNetworkInterfaceId; + /** * Close the XMLHttpRequest's channels and dispatch appropriate progress * events. diff --git a/dom/webidl/XMLHttpRequest.webidl b/dom/webidl/XMLHttpRequest.webidl index b00319d07ff..d5cf4962cbe 100644 --- a/dom/webidl/XMLHttpRequest.webidl +++ b/dom/webidl/XMLHttpRequest.webidl @@ -140,6 +140,11 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget { [ChromeOnly, Exposed=Window] readonly attribute MozChannel? channel; + // A platform-specific identifer to represent the network interface + // which the HTTP request would occur on. + [ChromeOnly, Exposed=Window] + attribute ByteString? networkInterfaceId; + [Throws, ChromeOnly, Exposed=Window] any getInterface(IID iid);