Bug 1602318 - Simplify DocumentChannelParent construction so that everything happens in Init. r=jya,necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D72111
This commit is contained in:
Matt Woodrow 2020-04-26 00:53:37 +00:00
parent 69baeef355
commit 382b007694
3 changed files with 10 additions and 21 deletions

View File

@ -18,27 +18,23 @@ using namespace mozilla::dom;
namespace mozilla {
namespace net {
DocumentChannelParent::DocumentChannelParent(
CanonicalBrowsingContext* aContext) {
DocumentChannelParent::DocumentChannelParent() {
LOG(("DocumentChannelParent ctor [this=%p]", this));
// Sometime we can get this called without a BrowsingContext, so that we have
// an actor to call SendFailedAsyncOpen on.
if (aContext) {
mParent = new DocumentLoadListener(aContext, this);
}
}
DocumentChannelParent::~DocumentChannelParent() {
LOG(("DocumentChannelParent dtor [this=%p]", this));
}
bool DocumentChannelParent::Init(const DocumentChannelCreationArgs& aArgs) {
MOZ_ASSERT(mParent);
bool DocumentChannelParent::Init(dom::CanonicalBrowsingContext* aContext,
const DocumentChannelCreationArgs& aArgs) {
RefPtr<nsDocShellLoadState> loadState =
new nsDocShellLoadState(aArgs.loadState());
LOG(("DocumentChannelParent Init [this=%p, uri=%s]", this,
loadState->URI()->GetSpecOrDefault().get()));
mParent = new DocumentLoadListener(aContext, this);
Maybe<ClientInfo> clientInfo;
if (aArgs.initialClientInfo().isSome()) {
clientInfo.emplace(ClientInfo(aArgs.initialClientInfo().ref()));

View File

@ -26,9 +26,10 @@ class DocumentChannelParent final : public ADocumentChannelBridge,
public:
NS_INLINE_DECL_REFCOUNTING(DocumentChannelParent, override);
explicit DocumentChannelParent(dom::CanonicalBrowsingContext* aContext);
explicit DocumentChannelParent();
bool Init(const DocumentChannelCreationArgs& aArgs);
bool Init(dom::CanonicalBrowsingContext* aContext,
const DocumentChannelCreationArgs& aArgs);
// PDocumentChannelParent
bool RecvCancel(const nsresult& aStatus) {

View File

@ -402,15 +402,7 @@ already_AddRefed<PDocumentChannelParent>
NeckoParent::AllocPDocumentChannelParent(
const MaybeDiscarded<BrowsingContext>& aContext,
const DocumentChannelCreationArgs& args) {
// We still create the actor even if the BrowsingContext isn't available,
// so that we can send the reject message using it from
// RecvPDocumentChannelConstructor
CanonicalBrowsingContext* context = nullptr;
if (!aContext.IsNullOrDiscarded()) {
context = aContext.get_canonical();
}
RefPtr<DocumentChannelParent> p = new DocumentChannelParent(context);
RefPtr<DocumentChannelParent> p = new DocumentChannelParent();
return p.forget();
}
@ -425,7 +417,7 @@ mozilla::ipc::IPCResult NeckoParent::RecvPDocumentChannelConstructor(
return IPC_OK();
}
if (!p->Init(aArgs)) {
if (!p->Init(aContext.get_canonical(), aArgs)) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();