summaryrefslogtreecommitdiffstats
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-04-23 16:48:48 +0000
committerMoonchild <moonchild@palemoon.org>2020-04-23 16:48:48 +0000
commit13eacee0ab3ad5a3120e7e732f6c4850f9a7bff7 (patch)
treec34a0709eb57fc6420d4460ca429cb2ead5004c6 /dom
parent4b7155deb57d554dca6eefb9bc873aaedb0ba777 (diff)
downloadUXP-13eacee0ab3ad5a3120e7e732f6c4850f9a7bff7.tar
UXP-13eacee0ab3ad5a3120e7e732f6c4850f9a7bff7.tar.gz
UXP-13eacee0ab3ad5a3120e7e732f6c4850f9a7bff7.tar.lz
UXP-13eacee0ab3ad5a3120e7e732f6c4850f9a7bff7.tar.xz
UXP-13eacee0ab3ad5a3120e7e732f6c4850f9a7bff7.zip
Issue #80 - De-unify dom/xhr
Diffstat (limited to 'dom')
-rw-r--r--dom/xhr/XMLHttpRequestString.cpp91
-rw-r--r--dom/xhr/XMLHttpRequestString.h95
-rw-r--r--dom/xhr/XMLHttpRequestWorker.cpp2
-rw-r--r--dom/xhr/moz.build2
4 files changed, 98 insertions, 92 deletions
diff --git a/dom/xhr/XMLHttpRequestString.cpp b/dom/xhr/XMLHttpRequestString.cpp
index c668b94f6..c2bde5e0e 100644
--- a/dom/xhr/XMLHttpRequestString.cpp
+++ b/dom/xhr/XMLHttpRequestString.cpp
@@ -12,97 +12,6 @@
namespace mozilla {
namespace dom {
-class XMLHttpRequestStringBuffer final
-{
- friend class XMLHttpRequestStringWriterHelper;
- friend class XMLHttpRequestStringSnapshotReaderHelper;
-
-public:
- NS_INLINE_DECL_THREADSAFE_REFCOUNTING(XMLHttpRequestStringBuffer)
- NS_DECL_OWNINGTHREAD
-
- XMLHttpRequestStringBuffer()
- : mMutex("XMLHttpRequestStringBuffer::mMutex")
- {
- }
-
- uint32_t
- Length()
- {
- MutexAutoLock lock(mMutex);
- return mData.Length();
- }
-
- uint32_t
- UnsafeLength() const
- {
- return mData.Length();
- }
-
- void
- Append(const nsAString& aString)
- {
- NS_ASSERT_OWNINGTHREAD(XMLHttpRequestStringBuffer);
-
- MutexAutoLock lock(mMutex);
- mData.Append(aString);
- }
-
- MOZ_MUST_USE bool
- GetAsString(nsAString& aString)
- {
- MutexAutoLock lock(mMutex);
- return aString.Assign(mData, mozilla::fallible);
- }
-
- size_t
- SizeOfThis(MallocSizeOf aMallocSizeOf) const
- {
- return mData.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
- }
-
- MOZ_MUST_USE bool
- GetAsString(DOMString& aString, uint32_t aLength)
- {
- MutexAutoLock lock(mMutex);
- MOZ_ASSERT(aLength <= mData.Length());
- nsStringBuffer* buf = nsStringBuffer::FromString(mData);
- if (buf) {
- // We have to use SetEphemeralStringBuffer, because once we release our
- // mutex mData can get mutated from some other thread while the DOMString
- // is still alive.
- aString.SetEphemeralStringBuffer(buf, aLength);
- return true;
- }
-
- // We can get here if mData is empty. In that case it won't have an
- // nsStringBuffer....
- MOZ_ASSERT(mData.IsEmpty());
- return aString.AsAString().Assign(mData.BeginReading(), aLength,
- mozilla::fallible);
- }
-
- void
- CreateSnapshot(XMLHttpRequestStringSnapshot& aSnapshot)
- {
- MutexAutoLock lock(mMutex);
- aSnapshot.Set(this, mData.Length());
- }
-
-private:
- ~XMLHttpRequestStringBuffer()
- {}
-
- nsString& UnsafeData()
- {
- return mData;
- }
-
- Mutex mMutex;
-
- // The following member variable is protected by mutex.
- nsString mData;
-};
// ---------------------------------------------------------------------------
// XMLHttpRequestString
diff --git a/dom/xhr/XMLHttpRequestString.h b/dom/xhr/XMLHttpRequestString.h
index b6b12483f..5709c1aa2 100644
--- a/dom/xhr/XMLHttpRequestString.h
+++ b/dom/xhr/XMLHttpRequestString.h
@@ -7,6 +7,9 @@
#ifndef mozilla_dom_XMLHttpRequestString_h
#define mozilla_dom_XMLHttpRequestString_h
+#include "mozilla/Mutex.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/dom/DOMString.h"
#include "nsString.h"
namespace mozilla {
@@ -155,6 +158,98 @@ private:
MutexAutoLock mLock;
};
+class XMLHttpRequestStringBuffer final
+{
+ friend class XMLHttpRequestStringWriterHelper;
+ friend class XMLHttpRequestStringSnapshotReaderHelper;
+
+public:
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(XMLHttpRequestStringBuffer)
+ NS_DECL_OWNINGTHREAD
+
+ XMLHttpRequestStringBuffer()
+ : mMutex("XMLHttpRequestStringBuffer::mMutex")
+ {
+ }
+
+ uint32_t
+ Length()
+ {
+ MutexAutoLock lock(mMutex);
+ return mData.Length();
+ }
+
+ uint32_t
+ UnsafeLength() const
+ {
+ return mData.Length();
+ }
+
+ void
+ Append(const nsAString& aString)
+ {
+ NS_ASSERT_OWNINGTHREAD(XMLHttpRequestStringBuffer);
+
+ MutexAutoLock lock(mMutex);
+ mData.Append(aString);
+ }
+
+ MOZ_MUST_USE bool
+ GetAsString(nsAString& aString)
+ {
+ MutexAutoLock lock(mMutex);
+ return aString.Assign(mData, mozilla::fallible);
+ }
+
+ size_t
+ SizeOfThis(MallocSizeOf aMallocSizeOf) const
+ {
+ return mData.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+ }
+
+ MOZ_MUST_USE bool
+ GetAsString(DOMString& aString, uint32_t aLength)
+ {
+ MutexAutoLock lock(mMutex);
+ MOZ_ASSERT(aLength <= mData.Length());
+ nsStringBuffer* buf = nsStringBuffer::FromString(mData);
+ if (buf) {
+ // We have to use SetEphemeralStringBuffer, because once we release our
+ // mutex mData can get mutated from some other thread while the DOMString
+ // is still alive.
+ aString.SetEphemeralStringBuffer(buf, aLength);
+ return true;
+ }
+
+ // We can get here if mData is empty. In that case it won't have an
+ // nsStringBuffer....
+ MOZ_ASSERT(mData.IsEmpty());
+ return aString.AsAString().Assign(mData.BeginReading(), aLength,
+ mozilla::fallible);
+ }
+
+ void
+ CreateSnapshot(XMLHttpRequestStringSnapshot& aSnapshot)
+ {
+ MutexAutoLock lock(mMutex);
+ aSnapshot.Set(this, mData.Length());
+ }
+
+private:
+ ~XMLHttpRequestStringBuffer()
+ {}
+
+ nsString& UnsafeData()
+ {
+ return mData;
+ }
+
+ Mutex mMutex;
+
+ // The following member variable is protected by mutex.
+ nsString mData;
+};
+
} // dom namespace
} // mozilla namespace
diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp
index 2af61bd7d..7bec379aa 100644
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -33,6 +33,8 @@
#include "WorkerScope.h"
#include "WorkerPrivate.h"
#include "WorkerRunnable.h"
+#include "XMLHttpRequestMainThread.h"
+#include "XMLHttpRequestString.h"
#include "XMLHttpRequestUpload.h"
#include "mozilla/UniquePtr.h"
diff --git a/dom/xhr/moz.build b/dom/xhr/moz.build
index 4ad91deea..d4803015f 100644
--- a/dom/xhr/moz.build
+++ b/dom/xhr/moz.build
@@ -18,7 +18,7 @@ EXPORTS.mozilla.dom += [
'XMLHttpRequestUpload.h',
]
-UNIFIED_SOURCES += [
+SOURCES += [
'XMLHttpRequest.cpp',
'XMLHttpRequestEventTarget.cpp',
'XMLHttpRequestMainThread.cpp',