Bug 1053650 - Part 1: Add attribute 'networkInterfaceId' to XMLHttpRequest. r=bz
authorHenry Chang <hchang@mozilla.com>
Tue, 03 Mar 2015 09:09:07 +0800
changeset 237852 d7d77d26136d1ac6fb3ac9b1ab2e7cc3bf38f218
parent 237851 7ec555c68f6654621ca75d3d85e904649506a01a
child 237853 15eb3e502463bdaa5c7716d58d8652598f8a4920
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs1053650
milestone40.0a1
Bug 1053650 - Part 1: Add attribute 'networkInterfaceId' to XMLHttpRequest. r=bz
dom/base/nsXMLHttpRequest.cpp
dom/base/nsXMLHttpRequest.h
dom/webidl/XMLHttpRequest.webidl
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -1790,16 +1790,29 @@ nsXMLHttpRequest::Open(const nsACString&
     }
   }
 
   ChangeState(XML_HTTP_REQUEST_OPENED);
 
   return rv;
 }
 
+void
+nsXMLHttpRequest::PopulateNetworkInterfaceId()
+{
+  if (mNetworkInterfaceId.IsEmpty()) {
+    return;
+  }
+  nsCOMPtr<nsIHttpChannelInternal> channel(do_QueryInterface(mChannel));
+  if (!channel) {
+    return;
+  }
+  channel->SetNetworkInterfaceId(mNetworkInterfaceId);
+}
+
 /*
  * "Copy" from a stream.
  */
 NS_METHOD
 nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
                                    void* closure,
                                    const char* fromRawSegment,
                                    uint32_t toOffset,
@@ -2607,16 +2620,18 @@ nsXMLHttpRequest::Send(nsIVariant *aBody
   return Send(aBody, Nullable<RequestBody>());
 }
 
 nsresult
 nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable<RequestBody>& aBody)
 {
   NS_ENSURE_TRUE(mPrincipal, NS_ERROR_NOT_INITIALIZED);
 
+  PopulateNetworkInterfaceId();
+
   nsresult rv = CheckInnerWindowCorrectness();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Return error if we're already processing a request
   if (XML_HTTP_REQUEST_SENT & mState) {
     return NS_ERROR_FAILURE;
   }
 
--- a/dom/base/nsXMLHttpRequest.h
+++ b/dom/base/nsXMLHttpRequest.h
@@ -423,16 +423,21 @@ private:
   }
   nsresult Send(const RequestBody& aBody)
   {
     return Send(Nullable<RequestBody>(aBody));
   }
 
   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)
   {
     aRv = Send(Nullable<RequestBody>());
   }
   void Send(JSContext* /*aCx*/,
             const mozilla::dom::ArrayBuffer& aArrayBuffer,
             ErrorResult& aRv)
@@ -533,16 +538,26 @@ public:
   bool MozAnon();
   bool MozSystem();
 
   nsIChannel* GetChannel()
   {
     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<JS::Value> aRetval, ErrorResult& aRv);
 
   // This creates a trusted readystatechange event, which is not cancelable and
   // doesn't bubble.
   nsresult CreateReadystatechangeEvent(nsIDOMEvent** aDOMEvent);
   void DispatchProgressEvent(mozilla::DOMEventTargetHelper* aTarget,
@@ -757,16 +772,20 @@ protected:
   // Ordering of OnProgress and OnDataAvailable is undefined.
   int64_t mLoadTransferred;
   nsCOMPtr<nsITimer> mProgressNotifier;
   void HandleProgressTimerCallback();
 
   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.
    *
    * @param aType The progress event type.
    * @param aFlag A XML_HTTP_REQUEST_* state flag defined in
    *              nsXMLHttpRequest.cpp.
    */
--- a/dom/webidl/XMLHttpRequest.webidl
+++ b/dom/webidl/XMLHttpRequest.webidl
@@ -135,14 +135,19 @@ interface XMLHttpRequest : XMLHttpReques
   // Mozilla-specific stuff
 
   [ChromeOnly, SetterThrows=Workers]
   attribute boolean mozBackgroundRequest;
 
   [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);
 
   readonly attribute boolean mozAnon;
   readonly attribute boolean mozSystem;
 };