ContentBridgeChild.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/dom/ContentBridgeChild.h"
  6. #include "mozilla/dom/ContentChild.h"
  7. #include "mozilla/dom/File.h"
  8. #include "mozilla/dom/TabChild.h"
  9. #include "mozilla/dom/ipc/BlobChild.h"
  10. #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
  11. #include "mozilla/ipc/InputStreamUtils.h"
  12. #include "base/task.h"
  13. using namespace mozilla::ipc;
  14. using namespace mozilla::jsipc;
  15. namespace mozilla {
  16. namespace dom {
  17. NS_IMPL_ISUPPORTS(ContentBridgeChild,
  18. nsIContentChild)
  19. ContentBridgeChild::ContentBridgeChild(Transport* aTransport)
  20. : mTransport(aTransport)
  21. {}
  22. ContentBridgeChild::~ContentBridgeChild()
  23. {
  24. }
  25. void
  26. ContentBridgeChild::ActorDestroy(ActorDestroyReason aWhy)
  27. {
  28. MessageLoop::current()->PostTask(NewRunnableMethod(this, &ContentBridgeChild::DeferredDestroy));
  29. }
  30. /*static*/ ContentBridgeChild*
  31. ContentBridgeChild::Create(Transport* aTransport, ProcessId aOtherPid)
  32. {
  33. RefPtr<ContentBridgeChild> bridge =
  34. new ContentBridgeChild(aTransport);
  35. bridge->mSelfRef = bridge;
  36. DebugOnly<bool> ok = bridge->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop());
  37. MOZ_ASSERT(ok);
  38. return bridge;
  39. }
  40. void
  41. ContentBridgeChild::DeferredDestroy()
  42. {
  43. mSelfRef = nullptr;
  44. // |this| was just destroyed, hands off
  45. }
  46. bool
  47. ContentBridgeChild::RecvAsyncMessage(const nsString& aMsg,
  48. InfallibleTArray<jsipc::CpowEntry>&& aCpows,
  49. const IPC::Principal& aPrincipal,
  50. const ClonedMessageData& aData)
  51. {
  52. return nsIContentChild::RecvAsyncMessage(aMsg, Move(aCpows), aPrincipal, aData);
  53. }
  54. PBlobChild*
  55. ContentBridgeChild::SendPBlobConstructor(PBlobChild* actor,
  56. const BlobConstructorParams& params)
  57. {
  58. return PContentBridgeChild::SendPBlobConstructor(actor, params);
  59. }
  60. bool
  61. ContentBridgeChild::SendPBrowserConstructor(PBrowserChild* aActor,
  62. const TabId& aTabId,
  63. const IPCTabContext& aContext,
  64. const uint32_t& aChromeFlags,
  65. const ContentParentId& aCpID,
  66. const bool& aIsForApp,
  67. const bool& aIsForBrowser)
  68. {
  69. return PContentBridgeChild::SendPBrowserConstructor(aActor,
  70. aTabId,
  71. aContext,
  72. aChromeFlags,
  73. aCpID,
  74. aIsForApp,
  75. aIsForBrowser);
  76. }
  77. PFileDescriptorSetChild*
  78. ContentBridgeChild::SendPFileDescriptorSetConstructor(const FileDescriptor& aFD)
  79. {
  80. return PContentBridgeChild::SendPFileDescriptorSetConstructor(aFD);
  81. }
  82. PSendStreamChild*
  83. ContentBridgeChild::SendPSendStreamConstructor(PSendStreamChild* aActor)
  84. {
  85. return PContentBridgeChild::SendPSendStreamConstructor(aActor);
  86. }
  87. // This implementation is identical to ContentChild::GetCPOWManager but we can't
  88. // move it to nsIContentChild because it calls ManagedPJavaScriptChild() which
  89. // only exists in PContentChild and PContentBridgeChild.
  90. jsipc::CPOWManager*
  91. ContentBridgeChild::GetCPOWManager()
  92. {
  93. if (PJavaScriptChild* c = LoneManagedOrNullAsserts(ManagedPJavaScriptChild())) {
  94. return CPOWManagerFor(c);
  95. }
  96. return CPOWManagerFor(SendPJavaScriptConstructor());
  97. }
  98. mozilla::jsipc::PJavaScriptChild *
  99. ContentBridgeChild::AllocPJavaScriptChild()
  100. {
  101. return nsIContentChild::AllocPJavaScriptChild();
  102. }
  103. bool
  104. ContentBridgeChild::DeallocPJavaScriptChild(PJavaScriptChild *child)
  105. {
  106. return nsIContentChild::DeallocPJavaScriptChild(child);
  107. }
  108. PBrowserChild*
  109. ContentBridgeChild::AllocPBrowserChild(const TabId& aTabId,
  110. const IPCTabContext &aContext,
  111. const uint32_t& aChromeFlags,
  112. const ContentParentId& aCpID,
  113. const bool& aIsForApp,
  114. const bool& aIsForBrowser)
  115. {
  116. return nsIContentChild::AllocPBrowserChild(aTabId,
  117. aContext,
  118. aChromeFlags,
  119. aCpID,
  120. aIsForApp,
  121. aIsForBrowser);
  122. }
  123. bool
  124. ContentBridgeChild::DeallocPBrowserChild(PBrowserChild* aChild)
  125. {
  126. return nsIContentChild::DeallocPBrowserChild(aChild);
  127. }
  128. bool
  129. ContentBridgeChild::RecvPBrowserConstructor(PBrowserChild* aActor,
  130. const TabId& aTabId,
  131. const IPCTabContext& aContext,
  132. const uint32_t& aChromeFlags,
  133. const ContentParentId& aCpID,
  134. const bool& aIsForApp,
  135. const bool& aIsForBrowser)
  136. {
  137. return ContentChild::GetSingleton()->RecvPBrowserConstructor(aActor,
  138. aTabId,
  139. aContext,
  140. aChromeFlags,
  141. aCpID,
  142. aIsForApp,
  143. aIsForBrowser);
  144. }
  145. PBlobChild*
  146. ContentBridgeChild::AllocPBlobChild(const BlobConstructorParams& aParams)
  147. {
  148. return nsIContentChild::AllocPBlobChild(aParams);
  149. }
  150. bool
  151. ContentBridgeChild::DeallocPBlobChild(PBlobChild* aActor)
  152. {
  153. return nsIContentChild::DeallocPBlobChild(aActor);
  154. }
  155. PSendStreamChild*
  156. ContentBridgeChild::AllocPSendStreamChild()
  157. {
  158. return nsIContentChild::AllocPSendStreamChild();
  159. }
  160. bool
  161. ContentBridgeChild::DeallocPSendStreamChild(PSendStreamChild* aActor)
  162. {
  163. return nsIContentChild::DeallocPSendStreamChild(aActor);
  164. }
  165. PFileDescriptorSetChild*
  166. ContentBridgeChild::AllocPFileDescriptorSetChild(const FileDescriptor& aFD)
  167. {
  168. return nsIContentChild::AllocPFileDescriptorSetChild(aFD);
  169. }
  170. bool
  171. ContentBridgeChild::DeallocPFileDescriptorSetChild(PFileDescriptorSetChild* aActor)
  172. {
  173. return nsIContentChild::DeallocPFileDescriptorSetChild(aActor);
  174. }
  175. } // namespace dom
  176. } // namespace mozilla