diff --git a/dom/base/moz.build b/dom/base/moz.build index 464a6a6147c..c3ba9c10684 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -403,7 +403,6 @@ LOCAL_INCLUDES += [ '/dom/xslt/xpath', '/dom/xul', '/image/src', - '/js/ipc', '/js/xpconnect/src', '/js/xpconnect/wrappers', '/layout/base', diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index d782137e512..13e7f23897c 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -80,6 +80,7 @@ #include "mozilla/Preferences.h" #include "mozilla/unused.h" #include "mozilla/dom/Element.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/layout/RenderFrameParent.h" #include "nsIAppsService.h" #include "GeckoProfiler.h" @@ -88,7 +89,6 @@ #include "mozilla/dom/HTMLIFrameElement.h" #include "mozilla/dom/SVGIFrameElement.h" #include "nsSandboxFlags.h" -#include "JavaScriptParent.h" #include "mozilla/layers/CompositorChild.h" #include "mozilla/dom/StructuredCloneUtils.h" diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index a72893e154b..0559468b889 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -37,9 +37,8 @@ #include "mozilla/dom/StructuredCloneUtils.h" #include "mozilla/dom/ipc/BlobChild.h" #include "mozilla/dom/ipc/BlobParent.h" -#include "JavaScriptChild.h" -#include "JavaScriptParent.h" #include "mozilla/dom/DOMStringList.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "nsPrintfCString.h" #include "nsXULAppAPI.h" #include @@ -927,7 +926,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, const nsAString& aMessage, bool aIsSync, const StructuredCloneData* aCloneData, - CpowHolder* aCpows, + mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal, InfallibleTArray* aJSONRetVal) { diff --git a/dom/base/nsFrameMessageManager.h b/dom/base/nsFrameMessageManager.h index 758643459bc..30708cf534f 100644 --- a/dom/base/nsFrameMessageManager.h +++ b/dom/base/nsFrameMessageManager.h @@ -28,6 +28,7 @@ #include "js/RootingAPI.h" #include "nsTObserverArray.h" #include "mozilla/dom/StructuredCloneUtils.h" +#include "mozilla/jsipc/CpowHolder.h" namespace mozilla { namespace dom { @@ -134,13 +135,8 @@ struct nsMessageListenerInfo nsWeakPtr mWeakListener; }; -class CpowHolder -{ -public: - virtual bool ToObject(JSContext* cx, JS::MutableHandle objp) = 0; -}; -class MOZ_STACK_CLASS SameProcessCpowHolder : public CpowHolder +class MOZ_STACK_CLASS SameProcessCpowHolder : public mozilla::jsipc::CpowHolder { public: SameProcessCpowHolder(JSRuntime *aRuntime, JS::Handle aObj) @@ -230,7 +226,7 @@ public: nsresult ReceiveMessage(nsISupports* aTarget, const nsAString& aMessage, bool aIsSync, const StructuredCloneData* aCloneData, - CpowHolder* aCpows, nsIPrincipal* aPrincipal, + mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal, InfallibleTArray* aJSONRetVal); void AddChildManager(nsFrameMessageManager* aManager); diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 39fe8fd0844..c4a21f28a00 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -9,8 +9,6 @@ #include #include -#include "JavaScriptParent.h" - #include "mozilla/DebugOnly.h" #include "mozilla/FloatingPoint.h" #include "mozilla/Assertions.h" @@ -44,6 +42,7 @@ #include "mozilla/dom/HTMLEmbedElementBinding.h" #include "mozilla/dom/HTMLAppletElementBinding.h" #include "mozilla/dom/Promise.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "WorkerPrivate.h" #include "nsDOMClassInfo.h" diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index 6e1c5db2b71..747fec2a7ee 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -58,7 +58,6 @@ LOCAL_INCLUDES += [ '/dom/xslt/base', '/dom/xslt/xpath', '/dom/xul', - '/js/ipc', '/js/xpconnect/src', '/js/xpconnect/wrappers', '/layout/style', diff --git a/dom/ipc/CPOWManagerGetter.h b/dom/ipc/CPOWManagerGetter.h index ad16cda3475..c58d355843e 100644 --- a/dom/ipc/CPOWManagerGetter.h +++ b/dom/ipc/CPOWManagerGetter.h @@ -10,14 +10,14 @@ namespace mozilla { namespace jsipc { -class JavaScriptShared; +class CPOWManager; } /* namespace jsipc */ namespace dom { class CPOWManagerGetter { public: - virtual mozilla::jsipc::JavaScriptShared* GetCPOWManager() = 0; + virtual mozilla::jsipc::CPOWManager* GetCPOWManager() = 0; }; } /* namespace dom */ diff --git a/dom/ipc/ContentBridgeChild.cpp b/dom/ipc/ContentBridgeChild.cpp index b3ea951cb52..16077c97489 100644 --- a/dom/ipc/ContentBridgeChild.cpp +++ b/dom/ipc/ContentBridgeChild.cpp @@ -10,8 +10,8 @@ #include "mozilla/dom/StructuredCloneUtils.h" #include "mozilla/dom/TabChild.h" #include "mozilla/dom/ipc/BlobChild.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/ipc/InputStreamUtils.h" -#include "JavaScriptChild.h" using namespace base; using namespace mozilla::ipc; @@ -100,14 +100,13 @@ ContentBridgeChild::SendPBrowserConstructor(PBrowserChild* aActor, // This implementation is identical to ContentChild::GetCPOWManager but we can't // move it to nsIContentChild because it calls ManagedPJavaScriptChild() which // only exists in PContentChild and PContentBridgeChild. -jsipc::JavaScriptShared* +jsipc::CPOWManager* ContentBridgeChild::GetCPOWManager() { if (ManagedPJavaScriptChild().Length()) { - return static_cast(ManagedPJavaScriptChild()[0]); + return CPOWManagerFor(ManagedPJavaScriptChild()[0]); } - JavaScriptChild* actor = static_cast(SendPJavaScriptConstructor()); - return actor; + return CPOWManagerFor(SendPJavaScriptConstructor()); } mozilla::jsipc::PJavaScriptChild * diff --git a/dom/ipc/ContentBridgeChild.h b/dom/ipc/ContentBridgeChild.h index ede302fae4c..1e7844cf8f2 100644 --- a/dom/ipc/ContentBridgeChild.h +++ b/dom/ipc/ContentBridgeChild.h @@ -36,7 +36,7 @@ public: SendPBlobConstructor(PBlobChild* actor, const BlobConstructorParams& aParams) MOZ_OVERRIDE; - jsipc::JavaScriptShared* GetCPOWManager() MOZ_OVERRIDE; + jsipc::CPOWManager* GetCPOWManager() MOZ_OVERRIDE; virtual bool SendPBrowserConstructor(PBrowserChild* aActor, const TabId& aTabId, diff --git a/dom/ipc/ContentBridgeParent.cpp b/dom/ipc/ContentBridgeParent.cpp index 2d98c9710a9..216dde0f9bf 100644 --- a/dom/ipc/ContentBridgeParent.cpp +++ b/dom/ipc/ContentBridgeParent.cpp @@ -6,7 +6,7 @@ #include "mozilla/dom/ContentBridgeParent.h" #include "mozilla/dom/TabParent.h" -#include "JavaScriptParent.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "nsXULAppAPI.h" using namespace base; @@ -154,14 +154,13 @@ ContentBridgeParent::DeallocPBrowserParent(PBrowserParent* aParent) // This implementation is identical to ContentParent::GetCPOWManager but we can't // move it to nsIContentParent because it calls ManagedPJavaScriptParent() which // only exists in PContentParent and PContentBridgeParent. -jsipc::JavaScriptShared* +jsipc::CPOWManager* ContentBridgeParent::GetCPOWManager() { if (ManagedPJavaScriptParent().Length()) { - return static_cast(ManagedPJavaScriptParent()[0]); + return CPOWManagerFor(ManagedPJavaScriptParent()[0]); } - JavaScriptParent* actor = static_cast(SendPJavaScriptConstructor()); - return actor; + return CPOWManagerFor(SendPJavaScriptConstructor()); } } // namespace dom diff --git a/dom/ipc/ContentBridgeParent.h b/dom/ipc/ContentBridgeParent.h index e9d3e9a2194..4dc784afe1f 100644 --- a/dom/ipc/ContentBridgeParent.h +++ b/dom/ipc/ContentBridgeParent.h @@ -41,7 +41,7 @@ public: const bool& aIsForApp, const bool& aIsForBrowser) MOZ_OVERRIDE; - jsipc::JavaScriptShared* GetCPOWManager() MOZ_OVERRIDE; + jsipc::CPOWManager* GetCPOWManager() MOZ_OVERRIDE; virtual ContentParentId ChildID() MOZ_OVERRIDE { diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 4df3de57377..6cc156fc801 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -41,6 +41,7 @@ #include "mozilla/ipc/FileDescriptorUtils.h" #include "mozilla/ipc/GeckoChildProcessHost.h" #include "mozilla/ipc/TestShellChild.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/layers/CompositorChild.h" #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/PCompositorChild.h" @@ -163,7 +164,6 @@ #include "nsIPrincipal.h" #include "nsDeviceStorage.h" #include "AudioChannelService.h" -#include "JavaScriptChild.h" #include "mozilla/dom/DataStoreService.h" #include "mozilla/dom/telephony/PTelephonyChild.h" #include "mozilla/dom/time/DateCacheCleaner.h" @@ -1403,14 +1403,13 @@ ContentChild::DeallocPTestShellChild(PTestShellChild* shell) return true; } -jsipc::JavaScriptShared* +jsipc::CPOWManager* ContentChild::GetCPOWManager() { if (ManagedPJavaScriptChild().Length()) { - return static_cast(ManagedPJavaScriptChild()[0]); + return CPOWManagerFor(ManagedPJavaScriptChild()[0]); } - JavaScriptChild* actor = static_cast(SendPJavaScriptConstructor()); - return actor; + return CPOWManagerFor(SendPJavaScriptConstructor()); } bool diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 0e76e01059c..cf9b7e7434b 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -209,7 +209,7 @@ public: virtual PTestShellChild* AllocPTestShellChild() MOZ_OVERRIDE; virtual bool DeallocPTestShellChild(PTestShellChild*) MOZ_OVERRIDE; virtual bool RecvPTestShellConstructor(PTestShellChild*) MOZ_OVERRIDE; - jsipc::JavaScriptShared* GetCPOWManager() MOZ_OVERRIDE; + jsipc::CPOWManager* GetCPOWManager() MOZ_OVERRIDE; PMobileConnectionChild* SendPMobileConnectionConstructor(PMobileConnectionChild* aActor, diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 7ecbf3c5fb3..77e0a0f80bc 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -67,6 +67,7 @@ #include "mozilla/ipc/PFileDescriptorSetParent.h" #include "mozilla/ipc/TestShellParent.h" #include "mozilla/ipc/InputStreamUtils.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/layers/CompositorParent.h" #include "mozilla/layers/ImageBridgeParent.h" #include "mozilla/layers/SharedBufferManagerParent.h" @@ -178,8 +179,6 @@ using namespace mozilla::system; #include "BluetoothService.h" #endif -#include "JavaScriptParent.h" - #include "mozilla/RemoteSpellCheckEngineParent.h" #ifdef MOZ_B2G_FM @@ -1996,11 +1995,11 @@ ContentParent::NotifyTabDestroyed(PBrowserParent* aTab, } } -jsipc::JavaScriptShared* +jsipc::CPOWManager* ContentParent::GetCPOWManager() { if (ManagedPJavaScriptParent().Length()) { - return static_cast(ManagedPJavaScriptParent()[0]); + return CPOWManagerFor(ManagedPJavaScriptParent()[0]); } return nullptr; } diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index c2bb0570586..7e486f7c671 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -189,7 +189,7 @@ public: TestShellParent* CreateTestShell(); bool DestroyTestShell(TestShellParent* aTestShell); TestShellParent* GetTestShellSingleton(); - jsipc::JavaScriptShared* GetCPOWManager() MOZ_OVERRIDE; + jsipc::CPOWManager* GetCPOWManager() MOZ_OVERRIDE; static TabId AllocateTabId(const TabId& aOpenerTabId, diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 6fc26e3eff8..1a281cef24a 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -75,7 +75,6 @@ #include "PuppetWidget.h" #include "StructuredCloneUtils.h" #include "nsViewportInfo.h" -#include "JavaScriptChild.h" #include "nsILoadContext.h" #include "ipc/nsGUIEventIPC.h" #include "mozilla/gfx/Matrix.h" diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index def22ab56c4..9e860dfb9ad 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -18,6 +18,7 @@ #include "mozilla/EventStateManager.h" #include "mozilla/Hal.h" #include "mozilla/ipc/DocumentRendererParent.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/layers/CompositorParent.h" #include "mozilla/layers/InputAPZContext.h" #include "mozilla/layout/RenderFrameParent.h" @@ -65,7 +66,6 @@ #include "PermissionMessageUtils.h" #include "StructuredCloneUtils.h" #include "ColorPickerParent.h" -#include "JavaScriptParent.h" #include "FilePickerParent.h" #include "TabChild.h" #include "LoadContext.h" diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index b516291dbe4..044f1eaa28c 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -29,11 +29,14 @@ class nsIPrincipal; class nsIURI; class nsIWidget; class nsILoadContext; -class CpowHolder; class nsIDocShell; namespace mozilla { +namespace jsipc { +class CpowHolder; +} + namespace layers { struct FrameMetrics; struct TextureFactoryIdentifier; @@ -363,7 +366,7 @@ protected: bool ReceiveMessage(const nsString& aMessage, bool aSync, const StructuredCloneData* aCloneData, - CpowHolder* aCpows, + mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal, InfallibleTArray* aJSONRetVal = nullptr); diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 9ed23bb8ec0..15ccd291fbe 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -130,7 +130,6 @@ LOCAL_INCLUDES += [ '/extensions/cookie', '/extensions/spellcheck/src', '/hal/sandbox', - '/js/ipc', '/layout/base', '/netwerk/base', '/toolkit/xre', diff --git a/dom/ipc/nsIContentChild.cpp b/dom/ipc/nsIContentChild.cpp index bcbedc01803..afcd7f2baa1 100644 --- a/dom/ipc/nsIContentChild.cpp +++ b/dom/ipc/nsIContentChild.cpp @@ -15,7 +15,6 @@ #include "mozilla/dom/ipc/BlobChild.h" #include "mozilla/ipc/InputStreamUtils.h" -#include "JavaScriptChild.h" #include "nsIJSRuntimeService.h" #include "nsPrintfCString.h" @@ -35,17 +34,13 @@ nsIContentChild::AllocPJavaScriptChild() svc->GetRuntime(&rt); NS_ENSURE_TRUE(svc, nullptr); - nsAutoPtr child(new JavaScriptChild(rt)); - if (!child->init()) { - return nullptr; - } - return child.forget(); + return NewJavaScriptChild(rt); } bool nsIContentChild::DeallocPJavaScriptChild(PJavaScriptChild* aChild) { - static_cast(aChild)->decref(); + ReleaseJavaScriptChild(aChild); return true; } diff --git a/dom/ipc/nsIContentParent.cpp b/dom/ipc/nsIContentParent.cpp index 93e567875de..8fcbafb882c 100644 --- a/dom/ipc/nsIContentParent.cpp +++ b/dom/ipc/nsIContentParent.cpp @@ -15,9 +15,9 @@ #include "mozilla/dom/StructuredCloneUtils.h" #include "mozilla/dom/TabParent.h" #include "mozilla/dom/ipc/BlobParent.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/unused.h" -#include "JavaScriptParent.h" #include "nsFrameMessageManager.h" #include "nsIJSRuntimeService.h" #include "nsPrintfCString.h" @@ -57,17 +57,13 @@ nsIContentParent::AllocPJavaScriptParent() svc->GetRuntime(&rt); NS_ENSURE_TRUE(svc, nullptr); - nsAutoPtr parent(new JavaScriptParent(rt)); - if (!parent->init()) { - return nullptr; - } - return parent.forget(); + return NewJavaScriptParent(rt); } bool nsIContentParent::DeallocPJavaScriptParent(PJavaScriptParent* aParent) { - static_cast(aParent)->decref(); + ReleaseJavaScriptParent(aParent); return true; } diff --git a/js/ipc/CpowHolder.h b/js/ipc/CpowHolder.h new file mode 100644 index 00000000000..2be878f3908 --- /dev/null +++ b/js/ipc/CpowHolder.h @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et 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_jsipc_CpowHolder_h__ +#define mozilla_jsipc_CpowHolder_h__ + +#include "js/TypeDecls.h" + +namespace mozilla { +namespace jsipc { + +class CpowHolder +{ + public: + virtual bool ToObject(JSContext* cx, JS::MutableHandle objp) = 0; +}; + +} // namespace jsipc +} // namespace mozilla + +#endif // mozilla_jsipc_CpowHolder_h__ diff --git a/js/ipc/CrossProcessObjectWrappers.h b/js/ipc/CrossProcessObjectWrappers.h new file mode 100644 index 00000000000..da083693946 --- /dev/null +++ b/js/ipc/CrossProcessObjectWrappers.h @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et 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_jsipc_CrossProcessObjectWrappers_h__ +#define mozilla_jsipc_CrossProcessObjectWrappers_h__ + +#include "js/TypeDecls.h" +#include "mozilla/jsipc/CpowHolder.h" +#include "mozilla/jsipc/JavaScriptTypes.h" +#include "nsID.h" +#include "nsString.h" +#include "nsTArray.h" + +#ifdef XP_WIN +#undef GetClassName +#undef GetClassInfo +#endif + +namespace mozilla { + +namespace dom { +class CPOWManagerGetter; +} + +namespace jsipc { + +class PJavaScriptParent; +class PJavaScriptChild; + +class CPOWManager +{ + public: + virtual bool Unwrap(JSContext *cx, + const InfallibleTArray &aCpows, + JS::MutableHandleObject objp) = 0; + + virtual bool Wrap(JSContext *cx, + JS::HandleObject aObj, + InfallibleTArray *outCpows) = 0; +}; + +class CpowIdHolder : public CpowHolder +{ + public: + CpowIdHolder(dom::CPOWManagerGetter *managerGetter, const InfallibleTArray &cpows); + + bool ToObject(JSContext *cx, JS::MutableHandleObject objp); + + private: + CPOWManager *js_; + const InfallibleTArray &cpows_; +}; + +CPOWManager* +CPOWManagerFor(PJavaScriptParent* aParent); + +CPOWManager* +CPOWManagerFor(PJavaScriptChild* aChild); + +bool +IsCPOW(JSObject *obj); + +bool +IsWrappedCPOW(JSObject *obj); + +nsresult +InstanceOf(JSObject *obj, const nsID *id, bool *bp); + +bool +DOMInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp); + +void +GetWrappedCPOWTag(JSObject *obj, nsACString &out); + +PJavaScriptParent * +NewJavaScriptParent(JSRuntime *rt); + +void +ReleaseJavaScriptParent(PJavaScriptParent *parent); + +PJavaScriptChild * +NewJavaScriptChild(JSRuntime *rt); + +void +ReleaseJavaScriptChild(PJavaScriptChild *child); + +} // namespace jsipc +} // namespace mozilla + +#endif // mozilla_jsipc_CrossProcessObjectWrappers_h__ diff --git a/js/ipc/JavaScriptChild.cpp b/js/ipc/JavaScriptChild.cpp index 1ed45d1f1db..1a8f6d53b71 100644 --- a/js/ipc/JavaScriptChild.cpp +++ b/js/ipc/JavaScriptChild.cpp @@ -64,3 +64,20 @@ JavaScriptChild::scopeForTargetObjects() // scope so that they can benefit from XrayWrappers in the child. return xpc::PrivilegedJunkScope(); } + +PJavaScriptChild * +mozilla::jsipc::NewJavaScriptChild(JSRuntime *rt) +{ + JavaScriptChild *child = new JavaScriptChild(rt); + if (!child->init()) { + delete child; + return nullptr; + } + return child; +} + +void +mozilla::jsipc::ReleaseJavaScriptChild(PJavaScriptChild *child) +{ + static_cast(child)->decref(); +} diff --git a/js/ipc/JavaScriptParent.cpp b/js/ipc/JavaScriptParent.cpp index 3411c537bc5..b1b1f39d47d 100644 --- a/js/ipc/JavaScriptParent.cpp +++ b/js/ipc/JavaScriptParent.cpp @@ -76,3 +76,20 @@ JavaScriptParent::CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx) } return actor.forget(); } + +PJavaScriptParent * +mozilla::jsipc::NewJavaScriptParent(JSRuntime *rt) +{ + JavaScriptParent *parent = new JavaScriptParent(rt); + if (!parent->init()) { + delete parent; + return nullptr; + } + return parent; +} + +void +mozilla::jsipc::ReleaseJavaScriptParent(PJavaScriptParent *parent) +{ + static_cast(parent)->decref(); +} diff --git a/js/ipc/JavaScriptShared.cpp b/js/ipc/JavaScriptShared.cpp index 147f28fcfd5..e7e14b7d773 100644 --- a/js/ipc/JavaScriptShared.cpp +++ b/js/ipc/JavaScriptShared.cpp @@ -757,3 +757,15 @@ JavaScriptShared::Wrap(JSContext *cx, HandleObject aObj, InfallibleTArray(aParent); +} + +CPOWManager* +mozilla::jsipc::CPOWManagerFor(PJavaScriptChild* aChild) +{ + return static_cast(aChild); +} diff --git a/js/ipc/JavaScriptShared.h b/js/ipc/JavaScriptShared.h index fb381680b94..77c71c0083e 100644 --- a/js/ipc/JavaScriptShared.h +++ b/js/ipc/JavaScriptShared.h @@ -9,9 +9,9 @@ #define mozilla_jsipc_JavaScriptShared_h__ #include "mozilla/dom/DOMTypes.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/jsipc/PJavaScript.h" #include "nsJSUtils.h" -#include "nsFrameMessageManager.h" namespace mozilla { @@ -65,18 +65,6 @@ class ObjectId { class JavaScriptShared; -class CpowIdHolder : public CpowHolder -{ - public: - CpowIdHolder(dom::CPOWManagerGetter *managerGetter, const InfallibleTArray &cpows); - - bool ToObject(JSContext *cx, JS::MutableHandleObject objp); - - private: - JavaScriptShared *js_; - const InfallibleTArray &cpows_; -}; - // DefaultHasher requires that T coerce to an integral type. We could make // ObjectId do that, but doing so would weaken our type invariants, so we just // reimplement it manually. @@ -144,7 +132,7 @@ class ObjectToIdMap class Logging; -class JavaScriptShared +class JavaScriptShared : public CPOWManager { public: explicit JavaScriptShared(JSRuntime *rt); diff --git a/js/ipc/WrapperOwner.h b/js/ipc/WrapperOwner.h index d95b1d9a2cf..db8a778a230 100644 --- a/js/ipc/WrapperOwner.h +++ b/js/ipc/WrapperOwner.h @@ -10,14 +10,10 @@ #include "JavaScriptShared.h" #include "mozilla/ipc/ProtocolUtils.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "js/Class.h" #include "jsproxy.h" -#ifdef XP_WIN -#undef GetClassName -#undef GetClassInfo -#endif - namespace mozilla { namespace jsipc { @@ -149,21 +145,6 @@ class WrapperOwner : public virtual JavaScriptShared ReturnStatus *rs, bool *instanceof) = 0; }; -bool -IsCPOW(JSObject *obj); - -bool -IsWrappedCPOW(JSObject *obj); - -nsresult -InstanceOf(JSObject *obj, const nsID *id, bool *bp); - -bool -DOMInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp); - -void -GetWrappedCPOWTag(JSObject *obj, nsACString &out); - } // jsipc } // mozilla diff --git a/js/ipc/moz.build b/js/ipc/moz.build index 404795f9d66..7a8a2231914 100644 --- a/js/ipc/moz.build +++ b/js/ipc/moz.build @@ -26,6 +26,11 @@ FINAL_LIBRARY = 'xul' DEFINES['BIN_SUFFIX'] = '"%s"' % CONFIG['BIN_SUFFIX'] +EXPORTS.mozilla.jsipc = [ + 'CpowHolder.h', + 'CrossProcessObjectWrappers.h', +] + LOCAL_INCLUDES += [ '/dom/base', '/js/ipc', diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 2273f8aac0a..f981562caef 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -13,10 +13,10 @@ #include "nsJSUtils.h" #include "mozJSComponentLoader.h" #include "nsContentUtils.h" -#include "JavaScriptParent.h" #include "jsfriendapi.h" #include "js/StructuredClone.h" #include "mozilla/Attributes.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/Preferences.h" #include "nsJSEnvironment.h" #include "mozilla/TimeStamp.h" diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 40379f9b199..1d0d48edb47 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -21,11 +21,11 @@ #include "jsfriendapi.h" #include "js/CharacterEncoding.h" #include "jsprf.h" -#include "JavaScriptParent.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DOMException.h" #include "mozilla/dom/PrimitiveConversions.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" using namespace xpc; using namespace mozilla; diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index a8d7d24bd5c..71e018da10e 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -9,7 +9,7 @@ #include "xpcprivate.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/Attributes.h" -#include "JavaScriptParent.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/StaticPtr.h" using namespace mozilla::dom; diff --git a/js/xpconnect/src/XPCWrappedJS.cpp b/js/xpconnect/src/XPCWrappedJS.cpp index f4d569e8bcd..ba5386a3eb8 100644 --- a/js/xpconnect/src/XPCWrappedJS.cpp +++ b/js/xpconnect/src/XPCWrappedJS.cpp @@ -8,10 +8,10 @@ #include "xpcprivate.h" #include "jsprf.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "nsCCUncollectableMarker.h" #include "nsContentUtils.h" #include "nsThreadUtils.h" -#include "JavaScriptParent.h" using namespace mozilla; diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 1474aec1302..5f5db108314 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -13,11 +13,11 @@ #include "nsWrapperCache.h" #include "AccessCheck.h" #include "nsJSUtils.h" -#include "JavaScriptParent.h" #include "mozilla/Attributes.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMExceptionBinding.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "jsapi.h" #include "jsfriendapi.h" diff --git a/js/xpconnect/src/moz.build b/js/xpconnect/src/moz.build index bcb089b1d60..4afe4dd15c7 100644 --- a/js/xpconnect/src/moz.build +++ b/js/xpconnect/src/moz.build @@ -66,7 +66,6 @@ LOCAL_INCLUDES += [ '/dom/html', '/dom/svg', '/dom/workers', - '/js/ipc', '/layout/base', '/layout/style', '/xpcom/reflect/xptinfo', diff --git a/js/xpconnect/wrappers/AccessCheck.cpp b/js/xpconnect/wrappers/AccessCheck.cpp index 7cd922a4c41..4e0ae7151cf 100644 --- a/js/xpconnect/wrappers/AccessCheck.cpp +++ b/js/xpconnect/wrappers/AccessCheck.cpp @@ -8,7 +8,6 @@ #include "nsJSPrincipals.h" #include "nsGlobalWindow.h" -#include "JavaScriptParent.h" #include "XPCWrapper.h" #include "XrayWrapper.h" @@ -17,6 +16,7 @@ #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/LocationBinding.h" #include "mozilla/dom/WindowBinding.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "nsIDOMWindowCollection.h" #include "nsJSUtils.h" diff --git a/js/xpconnect/wrappers/WrapperFactory.cpp b/js/xpconnect/wrappers/WrapperFactory.cpp index 0d8eee539c7..9768f669f7f 100644 --- a/js/xpconnect/wrappers/WrapperFactory.cpp +++ b/js/xpconnect/wrappers/WrapperFactory.cpp @@ -16,8 +16,8 @@ #include "xpcprivate.h" #include "XPCMaps.h" #include "mozilla/dom/BindingUtils.h" -#include "JavaScriptParent.h" #include "jsfriendapi.h" +#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/Likely.h" #include "nsContentUtils.h" #include "nsXULAppAPI.h" diff --git a/js/xpconnect/wrappers/moz.build b/js/xpconnect/wrappers/moz.build index 33bb86edff8..d6a8c1c2e9f 100644 --- a/js/xpconnect/wrappers/moz.build +++ b/js/xpconnect/wrappers/moz.build @@ -39,6 +39,5 @@ FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '../../../dom/base', '../src', - '/js/ipc', ]