2015-08-05 21:25:39 +00:00
|
|
|
/* -*- 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 "WebBrowserPersistDocumentParent.h"
|
|
|
|
|
2017-03-09 13:09:11 +00:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
2016-12-13 20:09:21 +00:00
|
|
|
#include "mozilla/dom/PContentParent.h"
|
2015-08-05 21:25:39 +00: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 18:18:28 +00: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 19:34:10 +00:00
|
|
|
nsCOMPtr<nsIRunnable> errorLater = NewRunnableMethod<nsresult>(
|
|
|
|
"nsIWebBrowserPersistDocumentReceiver::OnError",
|
|
|
|
mOnReady,
|
|
|
|
&nsIWebBrowserPersistDocumentReceiver::OnError,
|
|
|
|
NS_ERROR_FAILURE);
|
2015-09-14 18:18:28 +00:00
|
|
|
NS_DispatchToCurrentThread(errorLater);
|
2015-08-05 21:25:39 +00:00
|
|
|
mOnReady = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebBrowserPersistDocumentParent::~WebBrowserPersistDocumentParent()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!mReflection);
|
|
|
|
MOZ_ASSERT(!mOnReady);
|
|
|
|
}
|
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
mozilla::ipc::IPCResult
|
2015-08-05 21:25:39 +00:00
|
|
|
WebBrowserPersistDocumentParent::RecvAttributes(const Attrs& aAttrs,
|
2017-03-09 13:09:11 +00:00
|
|
|
const OptionalIPCStream& aPostStream)
|
2015-08-05 21:25:39 +00:00
|
|
|
{
|
|
|
|
// Deserialize the postData unconditionally so that fds aren't leaked.
|
2017-03-09 13:09:11 +00:00
|
|
|
nsCOMPtr<nsIInputStream> postData = mozilla::ipc::DeserializeIPCStream(aPostStream);
|
2015-08-05 21:25:39 +00:00
|
|
|
if (!mOnReady || mReflection) {
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2015-08-05 21:25:39 +00:00
|
|
|
}
|
|
|
|
mReflection = new WebBrowserPersistRemoteDocument(this, aAttrs, postData);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WebBrowserPersistRemoteDocument> reflection = mReflection;
|
2015-08-05 21:25:39 +00:00
|
|
|
mOnReady->OnDocumentReady(reflection);
|
|
|
|
mOnReady = nullptr;
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-08-05 21:25:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
mozilla::ipc::IPCResult
|
2015-08-05 21:25:39 +00:00
|
|
|
WebBrowserPersistDocumentParent::RecvInitFailure(const nsresult& aFailure)
|
|
|
|
{
|
|
|
|
if (!mOnReady || mReflection) {
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2015-08-05 21:25:39 +00:00
|
|
|
}
|
|
|
|
mOnReady->OnError(aFailure);
|
|
|
|
mOnReady = nullptr;
|
|
|
|
// Warning: Send__delete__ deallocates this object.
|
2016-12-13 20:09:21 +00:00
|
|
|
IProtocol* mgr = Manager();
|
2016-11-15 03:26:00 +00:00
|
|
|
if (!Send__delete__(this)) {
|
2016-12-13 20:09:21 +00:00
|
|
|
return IPC_FAIL_NO_REASON(mgr);
|
2016-11-15 03:26:00 +00:00
|
|
|
}
|
|
|
|
return IPC_OK();
|
2015-08-05 21:25:39 +00: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 05:24:48 +00:00
|
|
|
RefPtr<WebBrowserPersistResourcesParent> actor =
|
2015-08-05 21:25:39 +00: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
|