Bug 1269162 - part 5 - Merge XMLHttpRequestUploadWorker and XMLHttpRequestUpload, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 27 Jun 2016 19:13:41 +0200
changeset 342797 ddb3b5ac04aff12d9b18c2504477cb5bc00abad1
parent 342796 e03db893b8da2247b1a5ed9aafc968ff2d874c90
child 342798 155012d3d3731e10e085ae0841d308ca0515a35c
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1269162
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1269162 - part 5 - Merge XMLHttpRequestUploadWorker and XMLHttpRequestUpload, r=smaug
dom/bindings/Bindings.conf
dom/xhr/XMLHttpRequestUpload.cpp
dom/xhr/XMLHttpRequestUpload.h
dom/xhr/XMLHttpRequestUploadWorker.cpp
dom/xhr/XMLHttpRequestUploadWorker.h
dom/xhr/XMLHttpRequestWorker.cpp
dom/xhr/XMLHttpRequestWorker.h
dom/xhr/moz.build
dom/xhr/nsXMLHttpRequest.cpp
dom/xhr/nsXMLHttpRequest.h
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1587,27 +1587,16 @@ DOMInterfaces = {
     'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequestWorker.h',
     'workers': True,
 }],
 
 'XMLHttpRequestEventTarget': {
     'concrete': False
 },
 
-'XMLHttpRequestUpload': [
-{
-    'nativeType': 'nsXMLHttpRequestUpload',
-    'headerFile': 'nsXMLHttpRequest.h'
-},
-{
-    'nativeType': 'mozilla::dom::workers::XMLHttpRequestUploadWorker',
-    'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequestUploadWorker.h',
-    'workers': True,
-}],
-
 'XMLSerializer': {
     'nativeType': 'nsDOMSerializer',
 },
 
 'XPathEvaluator': {
     'wrapperCache': False
 },
 
new file mode 100644
--- /dev/null
+++ b/dom/xhr/XMLHttpRequestUpload.cpp
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XMLHttpRequestUpload.h"
+#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_INTERFACE_MAP_BEGIN(XMLHttpRequestUpload)
+  NS_INTERFACE_MAP_ENTRY(nsIXMLHttpRequestUpload)
+NS_INTERFACE_MAP_END_INHERITING(XMLHttpRequestEventTarget)
+
+NS_IMPL_ADDREF_INHERITED(XMLHttpRequestUpload, XMLHttpRequestEventTarget)
+NS_IMPL_RELEASE_INHERITED(XMLHttpRequestUpload, XMLHttpRequestEventTarget)
+
+/* virtual */ JSObject*
+XMLHttpRequestUpload::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+  return XMLHttpRequestUploadBinding::Wrap(aCx, this, aGivenProto);
+}
+
+} // dom namespace
+} // mozilla namespace
new file mode 100644
--- /dev/null
+++ b/dom/xhr/XMLHttpRequestUpload.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_XMLHttpRequestUpload_h
+#define mozilla_dom_XMLHttpRequestUpload_h
+
+#include "mozilla/dom/XMLHttpRequestEventTarget.h"
+#include "nsIXMLHttpRequest.h"
+
+namespace mozilla {
+namespace dom {
+
+namespace workers {
+class XMLHttpRequestWorker;
+}
+
+class XMLHttpRequestUpload final : public XMLHttpRequestEventTarget,
+                                   public nsIXMLHttpRequestUpload
+{
+public:
+  explicit XMLHttpRequestUpload(DOMEventTargetHelper* aOwner)
+    : XMLHttpRequestEventTarget(aOwner)
+  {}
+
+  explicit XMLHttpRequestUpload()
+  {}
+
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(XMLHttpRequestEventTarget::)
+  NS_REALLY_FORWARD_NSIDOMEVENTTARGET(XMLHttpRequestEventTarget)
+  NS_DECL_NSIXMLHTTPREQUESTUPLOAD
+
+  virtual JSObject*
+  WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
+
+  bool HasListeners()
+  {
+    return mListenerManager && mListenerManager->HasListeners();
+  }
+
+private:
+  virtual ~XMLHttpRequestUpload()
+  {}
+};
+
+
+} // dom namespace
+} // mozilla namespace
+
+#endif // mozilla_dom_XMLHttpRequestUpload_h
+
deleted file mode 100644
--- a/dom/xhr/XMLHttpRequestUploadWorker.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "XMLHttpRequestUploadWorker.h"
-
-#include "XMLHttpRequestWorker.h"
-
-#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
-
-USING_WORKERS_NAMESPACE
-
-XMLHttpRequestUploadWorker::XMLHttpRequestUploadWorker(XMLHttpRequestWorker* aXHR)
-: mXHR(aXHR)
-{
-}
-
-XMLHttpRequestUploadWorker::~XMLHttpRequestUploadWorker()
-{
-}
-
-NS_IMPL_ADDREF_INHERITED(XMLHttpRequestUploadWorker, XMLHttpRequestEventTarget)
-NS_IMPL_RELEASE_INHERITED(XMLHttpRequestUploadWorker, XMLHttpRequestEventTarget)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(XMLHttpRequestUploadWorker)
-NS_INTERFACE_MAP_END_INHERITING(XMLHttpRequestEventTarget)
-
-NS_IMPL_CYCLE_COLLECTION_INHERITED(XMLHttpRequestUploadWorker, XMLHttpRequestEventTarget,
-                                   mXHR)
-
-JSObject*
-XMLHttpRequestUploadWorker::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return XMLHttpRequestUploadBinding_workers::Wrap(aCx, this, aGivenProto);
-}
-
-// static
-already_AddRefed<XMLHttpRequestUploadWorker>
-XMLHttpRequestUploadWorker::Create(XMLHttpRequestWorker* aXHR)
-{
-  RefPtr<XMLHttpRequestUploadWorker> upload = new XMLHttpRequestUploadWorker(aXHR);
-  return upload.forget();
-}
deleted file mode 100644
--- a/dom/xhr/XMLHttpRequestUploadWorker.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_workers_xmlhttprequestupload_h__
-#define mozilla_dom_workers_xmlhttprequestupload_h__
-
-#include "mozilla/dom/XMLHttpRequestEventTarget.h"
-
-BEGIN_WORKERS_NAMESPACE
-
-class XMLHttpRequestWorker;
-
-class XMLHttpRequestUploadWorker final : public XMLHttpRequestEventTarget
-{
-  RefPtr<XMLHttpRequestWorker> mXHR;
-
-  explicit XMLHttpRequestUploadWorker(XMLHttpRequestWorker* aXHR);
-
-  ~XMLHttpRequestUploadWorker();
-
-public:
-  virtual JSObject*
-  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
-  static already_AddRefed<XMLHttpRequestUploadWorker>
-  Create(XMLHttpRequestWorker* aXHR);
-
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XMLHttpRequestUploadWorker, XMLHttpRequestEventTarget)
-
-  NS_DECL_ISUPPORTS_INHERITED
-
-  nsISupports*
-  GetParentObject() const
-  {
-    // There's only one global on a worker, so we don't need to specify.
-    return nullptr;
-  }
-
-  bool
-  HasListeners()
-  {
-    return mListenerManager && mListenerManager->HasListeners();
-  }
-};
-
-END_WORKERS_NAMESPACE
-
-#endif // mozilla_dom_workers_xmlhttprequestupload_h__
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -27,17 +27,17 @@
 #include "nsJSUtils.h"
 #include "nsThreadUtils.h"
 #include "nsVariant.h"
 
 #include "RuntimeService.h"
 #include "WorkerScope.h"
 #include "WorkerPrivate.h"
 #include "WorkerRunnable.h"
-#include "XMLHttpRequestUploadWorker.h"
+#include "XMLHttpRequestUpload.h"
 
 #include "mozilla/UniquePtr.h"
 
 using namespace mozilla;
 
 using namespace mozilla::dom;
 USING_WORKERS_NAMESPACE
 
@@ -2022,28 +2022,28 @@ XMLHttpRequestWorker::SetMozBackgroundRe
   }
 
   RefPtr<SetBackgroundRequestRunnable> runnable =
     new SetBackgroundRequestRunnable(mWorkerPrivate, mProxy,
                                      aBackgroundRequest);
   runnable->Dispatch(aRv);
 }
 
-XMLHttpRequestUploadWorker*
+XMLHttpRequestUpload*
 XMLHttpRequestWorker::GetUpload(ErrorResult& aRv)
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
   if (mCanceled) {
     aRv.ThrowUncatchableException();
     return nullptr;
   }
 
   if (!mUpload) {
-    mUpload = XMLHttpRequestUploadWorker::Create(this);
+    mUpload = new XMLHttpRequestUpload();
 
     if (!mUpload) {
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
   }
 
   return mUpload;
--- a/dom/xhr/XMLHttpRequestWorker.h
+++ b/dom/xhr/XMLHttpRequestWorker.h
@@ -14,24 +14,24 @@
 
 #include "mozilla/dom/TypedArray.h"
 
 #include "nsXMLHttpRequest.h"
 
 namespace mozilla {
 namespace dom {
 class Blob;
+class XMLHttpRequestUpload;
 } // namespace dom
 } // namespace mozilla
 
 BEGIN_WORKERS_NAMESPACE
 
 class Proxy;
 class SendRunnable;
-class XMLHttpRequestUploadWorker;
 class WorkerPrivate;
 
 class XMLHttpRequestWorker final : public XMLHttpRequestEventTarget,
                                    public WorkerHolder
 {
 public:
   struct StateData
   {
@@ -50,17 +50,17 @@ public:
       mResponseTextResult(NS_OK), mStatusResult(NS_OK),
       mResponseResult(NS_OK)
     { }
 
     void trace(JSTracer* trc);
   };
 
 private:
-  RefPtr<XMLHttpRequestUploadWorker> mUpload;
+  RefPtr<XMLHttpRequestUpload> mUpload;
   WorkerPrivate* mWorkerPrivate;
   RefPtr<Proxy> mProxy;
   XMLHttpRequestResponseType mResponseType;
   StateData mStateData;
 
   uint32_t mTimeout;
 
   bool mRooted;
@@ -155,17 +155,17 @@ public:
   MozBackgroundRequest() const
   {
     return mBackgroundRequest;
   }
 
   void
   SetMozBackgroundRequest(bool aBackgroundRequest, ErrorResult& aRv);
 
-  XMLHttpRequestUploadWorker*
+  XMLHttpRequestUpload*
   GetUpload(ErrorResult& aRv);
 
   void
   Send(ErrorResult& aRv);
 
   void
   Send(const nsAString& aBody, ErrorResult& aRv);
 
@@ -234,17 +234,17 @@ public:
 
   void
   GetInterface(JSContext* cx, JS::Handle<JSObject*> aIID,
                JS::MutableHandle<JS::Value> aRetval, ErrorResult& aRv)
   {
     aRv.Throw(NS_ERROR_FAILURE);
   }
 
-  XMLHttpRequestUploadWorker*
+  XMLHttpRequestUpload*
   GetUploadObjectNoCreate() const
   {
     return mUpload;
   }
 
   void
   UpdateState(const StateData& aStateData, bool aUseCachedArrayBufferResponse);
 
--- a/dom/xhr/moz.build
+++ b/dom/xhr/moz.build
@@ -7,32 +7,32 @@
 XPIDL_SOURCES += [
     'nsIXMLHttpRequest.idl',
 ]
 
 XPIDL_MODULE = 'dom_xhr'
 
 # Stuff needed for the bindings, not really public though.
 EXPORTS.mozilla.dom.workers.bindings += [
-    'XMLHttpRequestUploadWorker.h',
     'XMLHttpRequestWorker.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'XMLHttpRequestEventTarget.h',
+    'XMLHttpRequestUpload.h',
 ]
 
 EXPORTS += [
     'nsXMLHttpRequest.h',
 ]
 
 UNIFIED_SOURCES += [
     'nsXMLHttpRequest.cpp',
     'XMLHttpRequestEventTarget.cpp',
-    'XMLHttpRequestUploadWorker.cpp',
+    'XMLHttpRequestUpload.cpp',
     'XMLHttpRequestWorker.cpp',
 ]
 
 LOCAL_INCLUDES += [
     '/dom/base',
     '/dom/workers',
     '/netwerk/base',
 ]
--- a/dom/xhr/nsXMLHttpRequest.cpp
+++ b/dom/xhr/nsXMLHttpRequest.cpp
@@ -10,17 +10,16 @@
 #include <unistd.h>
 #endif
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/dom/BlobSet.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/FetchUtil.h"
 #include "mozilla/dom/FormData.h"
-#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/LoadInfo.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsIDOMDocument.h"
 #include "mozilla/dom/ProgressEvent.h"
 #include "nsIJARChannel.h"
 #include "nsIJARURI.h"
@@ -75,16 +74,17 @@
 #include "nsCharSeparatedTokenizer.h"
 #include "nsStreamListenerWrapper.h"
 #include "xpcjsid.h"
 #include "nsITimedChannel.h"
 #include "nsWrapperCacheInlines.h"
 #include "nsZipArchive.h"
 #include "mozilla/Preferences.h"
 #include "private/pprio.h"
+#include "XMLHttpRequestUpload.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::net;
 
 // Maximum size that we'll grow an ArrayBuffer instead of doubling,
 // once doubling reaches this threshold
 #define XML_HTTP_REQUEST_ARRAYBUFFER_MAX_GROWTH (32*1024*1024)
@@ -174,31 +174,16 @@ static void AddLoadFlags(nsIRequest *req
 {
   nsLoadFlags flags;
   request->GetLoadFlags(&flags);
   flags |= newFlags;
   request->SetLoadFlags(flags);
 }
 
 /////////////////////////////////////////////
-
-NS_INTERFACE_MAP_BEGIN(nsXMLHttpRequestUpload)
-  NS_INTERFACE_MAP_ENTRY(nsIXMLHttpRequestUpload)
-NS_INTERFACE_MAP_END_INHERITING(XMLHttpRequestEventTarget)
-
-NS_IMPL_ADDREF_INHERITED(nsXMLHttpRequestUpload, XMLHttpRequestEventTarget)
-NS_IMPL_RELEASE_INHERITED(nsXMLHttpRequestUpload, XMLHttpRequestEventTarget)
-
-/* virtual */ JSObject*
-nsXMLHttpRequestUpload::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return XMLHttpRequestUploadBinding::Wrap(aCx, this, aGivenProto);
-}
-
-/////////////////////////////////////////////
 //
 //
 /////////////////////////////////////////////
 
 bool
 nsXMLHttpRequest::sDontWarnAboutSyncXHR = false;
 
 nsXMLHttpRequest::nsXMLHttpRequest()
@@ -3483,29 +3468,29 @@ nsXMLHttpRequest::GetInterface(const nsI
 void
 nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSID* aIID,
                                JS::MutableHandle<JS::Value> aRetval,
                                ErrorResult& aRv)
 {
   dom::GetInterface(aCx, this, aIID, aRetval, aRv);
 }
 
-nsXMLHttpRequestUpload*
+XMLHttpRequestUpload*
 nsXMLHttpRequest::Upload()
 {
   if (!mUpload) {
-    mUpload = new nsXMLHttpRequestUpload(this);
+    mUpload = new XMLHttpRequestUpload(this);
   }
   return mUpload;
 }
 
 NS_IMETHODIMP
 nsXMLHttpRequest::GetUpload(nsIXMLHttpRequestUpload** aUpload)
 {
-  RefPtr<nsXMLHttpRequestUpload> upload = Upload();
+  RefPtr<XMLHttpRequestUpload> upload = Upload();
   upload.forget(aUpload);
   return NS_OK;
 }
 
 bool
 nsXMLHttpRequest::MozAnon()
 {
   return mIsAnon;
--- a/dom/xhr/nsXMLHttpRequest.h
+++ b/dom/xhr/nsXMLHttpRequest.h
@@ -50,16 +50,17 @@ class nsIUnicodeDecoder;
 class nsIJSID;
 
 namespace mozilla {
 
 namespace dom {
 class Blob;
 class BlobSet;
 class FormData;
+class XMLHttpRequestUpload;
 } // namespace dom
 
 // A helper for building up an ArrayBuffer object's data
 // before creating the ArrayBuffer itself.  Will do doubling
 // based reallocation, up to an optional maximum growth given.
 //
 // When all the data has been appended, call getArrayBuffer,
 // passing in the JSContext* for which the ArrayBuffer object
@@ -105,45 +106,16 @@ public:
 
 protected:
   static bool areOverlappingRegions(const uint8_t* aStart1, uint32_t aLength1,
                                     const uint8_t* aStart2, uint32_t aLength2);
 };
 
 } // namespace mozilla
 
-class nsXMLHttpRequestUpload final : public mozilla::dom::XMLHttpRequestEventTarget,
-                                     public nsIXMLHttpRequestUpload
-{
-public:
-  explicit nsXMLHttpRequestUpload(mozilla::DOMEventTargetHelper* aOwner)
-    : XMLHttpRequestEventTarget(aOwner)
-  {
-  }
-
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(XMLHttpRequestEventTarget::)
-  NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::dom::XMLHttpRequestEventTarget)
-  NS_DECL_NSIXMLHTTPREQUESTUPLOAD
-
-  virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
-  nsISupports* GetParentObject()
-  {
-    return GetOwner();
-  }
-
-  bool HasListeners()
-  {
-    return mListenerManager && mListenerManager->HasListeners();
-  }
-
-private:
-  virtual ~nsXMLHttpRequestUpload() {}
-};
-
 class nsXMLHttpRequestXPCOMifier;
 
 // Make sure that any non-DOM interfaces added here are also added to
 // nsXMLHttpRequestXPCOMifier.
 class nsXMLHttpRequest final : public mozilla::dom::XMLHttpRequestEventTarget,
                                public nsIXMLHttpRequest,
                                public nsIJSXMLHttpRequest,
                                public nsIStreamListener,
@@ -291,17 +263,17 @@ public:
   }
   uint32_t Timeout()
   {
     return mTimeoutMilliseconds;
   }
   void SetTimeout(uint32_t aTimeout, mozilla::ErrorResult& aRv);
   bool WithCredentials();
   void SetWithCredentials(bool aWithCredentials, mozilla::ErrorResult& aRv);
-  nsXMLHttpRequestUpload* Upload();
+  mozilla::dom::XMLHttpRequestUpload* Upload();
 
 private:
   virtual ~nsXMLHttpRequest();
 
   class RequestBody
   {
   public:
     RequestBody() : mType(Uninitialized)
@@ -690,17 +662,17 @@ protected:
 
   nsIRequestObserver* mRequestObserver;
 
   nsCOMPtr<nsIURI> mBaseURI;
   nsCOMPtr<nsILoadGroup> mLoadGroup;
 
   uint32_t mState;
 
-  RefPtr<nsXMLHttpRequestUpload> mUpload;
+  RefPtr<mozilla::dom::XMLHttpRequestUpload> mUpload;
   int64_t mUploadTransferred;
   int64_t mUploadTotal;
   bool mUploadLengthComputable;
   bool mUploadComplete;
   bool mProgressSinceLastProgressEvent;
 
   // Timeout support
   PRTime mRequestSentTime;