2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2015-08-06 00:25:39 +03:00
|
|
|
*
|
|
|
|
* 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 "WebBrowserPersistDocumentParent.h"
|
|
|
|
|
2017-03-09 16:09:11 +03:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
2016-12-13 23:09:21 +03:00
|
|
|
#include "mozilla/dom/PContentParent.h"
|
2015-08-06 00:25:39 +03:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "WebBrowserPersistResourcesParent.h"
|
|
|
|
#include "WebBrowserPersistSerializeParent.h"
|
|
|
|
#include "WebBrowserPersistRemoteDocument.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
WebBrowserPersistDocumentParent::WebBrowserPersistDocumentParent()
|
|
|
|
: mReflection(nullptr) {}
|
|
|
|
|
|
|
|
void WebBrowserPersistDocumentParent::SetOnReady(
|
|
|
|
nsIWebBrowserPersistDocumentReceiver* aOnReady) {
|
|
|
|
MOZ_ASSERT(aOnReady);
|
|
|
|
MOZ_ASSERT(!mOnReady);
|
|
|
|
MOZ_ASSERT(!mReflection);
|
|
|
|
mOnReady = aOnReady;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebBrowserPersistDocumentParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
if (mReflection) {
|
|
|
|
mReflection->ActorDestroy();
|
|
|
|
mReflection = nullptr;
|
|
|
|
}
|
|
|
|
if (mOnReady) {
|
2015-09-14 21:18:28 +03:00
|
|
|
// Bug 1202887: If this is part of a subtree destruction, then
|
|
|
|
// anything which could cause another actor in that subtree to
|
|
|
|
// be Send__delete__()ed will cause use-after-free -- such as
|
|
|
|
// dropping the last reference to another document's
|
|
|
|
// WebBrowserPersistRemoteDocument. To avoid that, defer the
|
|
|
|
// callback until after the entire subtree is destroyed.
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> errorLater = NewRunnableMethod<nsresult>(
|
|
|
|
"nsIWebBrowserPersistDocumentReceiver::OnError", mOnReady,
|
|
|
|
&nsIWebBrowserPersistDocumentReceiver::OnError, NS_ERROR_FAILURE);
|
2015-09-14 21:18:28 +03:00
|
|
|
NS_DispatchToCurrentThread(errorLater);
|
2015-08-06 00:25:39 +03:00
|
|
|
mOnReady = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebBrowserPersistDocumentParent::~WebBrowserPersistDocumentParent() {
|
|
|
|
MOZ_RELEASE_ASSERT(!mReflection);
|
|
|
|
MOZ_ASSERT(!mOnReady);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult WebBrowserPersistDocumentParent::RecvAttributes(
|
2019-02-22 21:46:14 +03:00
|
|
|
const Attrs& aAttrs, const Maybe<IPCStream>& aPostStream) {
|
2015-08-06 00:25:39 +03:00
|
|
|
// Deserialize the postData unconditionally so that fds aren't leaked.
|
2017-03-09 16:09:11 +03:00
|
|
|
nsCOMPtr<nsIInputStream> postData =
|
|
|
|
mozilla::ipc::DeserializeIPCStream(aPostStream);
|
2015-08-06 00:25:39 +03:00
|
|
|
if (!mOnReady || mReflection) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
mReflection = new WebBrowserPersistRemoteDocument(this, aAttrs, postData);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebBrowserPersistRemoteDocument> reflection = mReflection;
|
2015-08-06 00:25:39 +03:00
|
|
|
mOnReady->OnDocumentReady(reflection);
|
|
|
|
mOnReady = nullptr;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult WebBrowserPersistDocumentParent::RecvInitFailure(
|
|
|
|
const nsresult& aFailure) {
|
|
|
|
if (!mOnReady || mReflection) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
mOnReady->OnError(aFailure);
|
|
|
|
mOnReady = nullptr;
|
|
|
|
// Warning: Send__delete__ deallocates this object.
|
2016-12-13 23:09:21 +03:00
|
|
|
IProtocol* mgr = Manager();
|
2016-11-15 06:26:00 +03:00
|
|
|
if (!Send__delete__(this)) {
|
2016-12-13 23:09:21 +03:00
|
|
|
return IPC_FAIL_NO_REASON(mgr);
|
2016-11-15 06:26:00 +03:00
|
|
|
}
|
|
|
|
return IPC_OK();
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PWebBrowserPersistResourcesParent*
|
|
|
|
WebBrowserPersistDocumentParent::AllocPWebBrowserPersistResourcesParent() {
|
|
|
|
MOZ_CRASH("Don't use this; construct the actor directly and AddRef.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebBrowserPersistDocumentParent::DeallocPWebBrowserPersistResourcesParent(
|
|
|
|
PWebBrowserPersistResourcesParent* aActor) {
|
|
|
|
// Turn the ref held by IPC back into an nsRefPtr.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebBrowserPersistResourcesParent> actor =
|
2015-08-06 00:25:39 +03:00
|
|
|
already_AddRefed<WebBrowserPersistResourcesParent>(
|
|
|
|
static_cast<WebBrowserPersistResourcesParent*>(aActor));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PWebBrowserPersistSerializeParent*
|
|
|
|
WebBrowserPersistDocumentParent::AllocPWebBrowserPersistSerializeParent(
|
|
|
|
const WebBrowserPersistURIMap& aMap, const nsCString& aRequestedContentType,
|
|
|
|
const uint32_t& aEncoderFlags, const uint32_t& aWrapColumn) {
|
|
|
|
MOZ_CRASH("Don't use this; construct the actor directly.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebBrowserPersistDocumentParent::DeallocPWebBrowserPersistSerializeParent(
|
|
|
|
PWebBrowserPersistSerializeParent* aActor) {
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|