gecko-dev/dom/ipc/jsactor/JSWindowActorChild.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 строки
2.3 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_JSWindowActorChild_h
#define mozilla_dom_JSWindowActorChild_h
#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/JSActor.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "nsIDOMProcessChild.h"
namespace mozilla {
namespace dom {
template <typename>
struct Nullable;
class Document;
class WindowGlobalChild;
class WindowProxyHolder;
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace dom {
class JSWindowActorChild final : public JSActor {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(JSWindowActorChild,
JSActor)
explicit JSWindowActorChild(nsISupports* aGlobal = nullptr)
: JSActor(aGlobal) {}
Bug 1541557: Part 1 - Use correct globals for JSWindowActors not in the shared JSM global. r=nika The current JSWindowActor code assumes that all actors will be created in the shared JSM global. This has a few problems: 1) For actors in other scopes, it enters the wrong compartment before decoding messages, which leads to a compartment checker error when trying to call message handlers. That could be fixed by just wrapping the result for the caller, but that would lead to other problems. Aside from the efficiency concerns of having to deal with cross-compartment wrappers, SpecialPowers in particular would not be able to pass the resulting objects to unprivileged scopes, since only SpecialPowers compartments have permissive CCWs enabled. 2) It also leads to the prototype objects for the actor instances being created in the shared JSM scope, even when the actors themselves are defined in other compartments. Again, aside from CCW efficiency issues, this prevents the SpecialPowers instances from being accessed by the unprivileged scopes that they're exposed to, since the prototype objects live in privileged scopes which don't have permissive CCWs enabled. This patch changes child actors to always create their objects in the global of their constructors. The parent objects are still created in the shared JSM global, but they now wrap values for the appropriate compartment before trying to call message handlers. Differential Revision: https://phabricator.services.mozilla.com/D35051 --HG-- extra : rebase_source : 436ce516080812680d1433bf3ecbd12f91d88165 extra : source : 61fa2745733f3631488a3ecccc144823683b7b6d
2019-06-13 02:06:40 +03:00
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<JSWindowActorChild> Constructor(
GlobalObject& aGlobal) {
return MakeAndAddRef<JSWindowActorChild>(aGlobal.GetAsSupports());
}
WindowGlobalChild* GetManager() const;
void Init(const nsACString& aName, WindowGlobalChild* aManager);
void ClearManager() override;
Document* GetDocument(ErrorResult& aRv);
BrowsingContext* GetBrowsingContext(ErrorResult& aRv);
nsIDocShell* GetDocShell(ErrorResult& aRv);
Nullable<WindowProxyHolder> GetContentWindow(ErrorResult& aRv);
protected:
void SendRawMessage(const JSActorMessageMeta& aMeta,
Maybe<ipc::StructuredCloneData>&& aData,
Maybe<ipc::StructuredCloneData>&& aStack,
ErrorResult& aRv) override;
private:
~JSWindowActorChild();
RefPtr<WindowGlobalChild> mManager;
Bug 1541557: Part 1 - Use correct globals for JSWindowActors not in the shared JSM global. r=nika The current JSWindowActor code assumes that all actors will be created in the shared JSM global. This has a few problems: 1) For actors in other scopes, it enters the wrong compartment before decoding messages, which leads to a compartment checker error when trying to call message handlers. That could be fixed by just wrapping the result for the caller, but that would lead to other problems. Aside from the efficiency concerns of having to deal with cross-compartment wrappers, SpecialPowers in particular would not be able to pass the resulting objects to unprivileged scopes, since only SpecialPowers compartments have permissive CCWs enabled. 2) It also leads to the prototype objects for the actor instances being created in the shared JSM scope, even when the actors themselves are defined in other compartments. Again, aside from CCW efficiency issues, this prevents the SpecialPowers instances from being accessed by the unprivileged scopes that they're exposed to, since the prototype objects live in privileged scopes which don't have permissive CCWs enabled. This patch changes child actors to always create their objects in the global of their constructors. The parent objects are still created in the shared JSM global, but they now wrap values for the appropriate compartment before trying to call message handlers. Differential Revision: https://phabricator.services.mozilla.com/D35051 --HG-- extra : rebase_source : 436ce516080812680d1433bf3ecbd12f91d88165 extra : source : 61fa2745733f3631488a3ecccc144823683b7b6d
2019-06-13 02:06:40 +03:00
nsCOMPtr<nsIGlobalObject> mGlobal;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSWindowActorChild_h