summaryrefslogtreecommitdiffstats
path: root/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp')
-rw-r--r--embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp b/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp
new file mode 100644
index 000000000..2f76ffb33
--- /dev/null
+++ b/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp
@@ -0,0 +1,90 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * 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 "WebBrowserPersistSerializeParent.h"
+
+#include "nsReadableUtils.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
+
+WebBrowserPersistSerializeParent::WebBrowserPersistSerializeParent(
+ nsIWebBrowserPersistDocument* aDocument,
+ nsIOutputStream* aStream,
+ nsIWebBrowserPersistWriteCompletion* aFinish)
+: mDocument(aDocument)
+, mStream(aStream)
+, mFinish(aFinish)
+, mOutputError(NS_OK)
+{
+ MOZ_ASSERT(aDocument);
+ MOZ_ASSERT(aStream);
+ MOZ_ASSERT(aFinish);
+}
+
+WebBrowserPersistSerializeParent::~WebBrowserPersistSerializeParent()
+{
+}
+
+bool
+WebBrowserPersistSerializeParent::RecvWriteData(nsTArray<uint8_t>&& aData)
+{
+ if (NS_FAILED(mOutputError)) {
+ return true;
+ }
+
+ uint32_t written = 0;
+ static_assert(sizeof(char) == sizeof(uint8_t),
+ "char must be (at least?) 8 bits");
+ const char* data = reinterpret_cast<const char*>(aData.Elements());
+ // nsIOutputStream::Write is allowed to return short writes.
+ while (written < aData.Length()) {
+ uint32_t writeReturn;
+ nsresult rv = mStream->Write(data + written,
+ aData.Length() - written,
+ &writeReturn);
+ if (NS_FAILED(rv)) {
+ mOutputError = rv;
+ return true;
+ }
+ written += writeReturn;
+ }
+ return true;
+}
+
+bool
+WebBrowserPersistSerializeParent::Recv__delete__(const nsCString& aContentType,
+ const nsresult& aStatus)
+{
+ if (NS_SUCCEEDED(mOutputError)) {
+ mOutputError = aStatus;
+ }
+ mFinish->OnFinish(mDocument,
+ mStream,
+ aContentType,
+ mOutputError);
+ mFinish = nullptr;
+ return true;
+}
+
+void
+WebBrowserPersistSerializeParent::ActorDestroy(ActorDestroyReason aWhy)
+{
+ if (mFinish) {
+ MOZ_ASSERT(aWhy != Deletion);
+ // See comment in WebBrowserPersistDocumentParent::ActorDestroy
+ // (or bug 1202887) for why this is deferred.
+ nsCOMPtr<nsIRunnable> errorLater = NewRunnableMethod
+ <nsCOMPtr<nsIWebBrowserPersistDocument>, nsCOMPtr<nsIOutputStream>,
+ nsCString, nsresult>
+ (mFinish, &nsIWebBrowserPersistWriteCompletion::OnFinish,
+ mDocument, mStream, EmptyCString(), NS_ERROR_FAILURE);
+ NS_DispatchToCurrentThread(errorLater);
+ mFinish = nullptr;
+ }
+}
+
+} // namespace mozilla