TestShellParent.h (1880B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: sw=2 ts=8 et : 3 */ 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef ipc_testshell_TestShellParent_h 9 #define ipc_testshell_TestShellParent_h 1 10 11 #include "mozilla/ipc/PTestShellParent.h" 12 #include "mozilla/ipc/PTestShellCommandParent.h" 13 14 #include "js/RootingAPI.h" 15 #include "js/Value.h" 16 #include "nsString.h" 17 18 namespace mozilla { 19 20 namespace ipc { 21 22 class TestShellCommandParent; 23 24 class TestShellParent : public PTestShellParent { 25 friend class PTestShellParent; 26 27 public: 28 NS_INLINE_DECL_REFCOUNTING(TestShellParent, override) 29 30 virtual void ActorDestroy(ActorDestroyReason aWhy) override; 31 32 PTestShellCommandParent* AllocPTestShellCommandParent( 33 const nsAString& aCommand); 34 35 bool DeallocPTestShellCommandParent(PTestShellCommandParent* aActor); 36 37 bool CommandDone(TestShellCommandParent* aActor, const nsAString& aResponse); 38 39 private: 40 ~TestShellParent() = default; 41 }; 42 43 class TestShellCommandParent : public PTestShellCommandParent { 44 friend class PTestShellCommandParent; 45 46 public: 47 TestShellCommandParent() = default; 48 49 bool SetCallback(JSContext* aCx, const JS::Value& aCallback); 50 51 bool RunCallback(const nsAString& aResponse); 52 53 void ReleaseCallback(); 54 55 protected: 56 bool ExecuteCallback(const nsAString& aResponse); 57 58 void ActorDestroy(ActorDestroyReason why) override; 59 60 mozilla::ipc::IPCResult Recv__delete__(const nsAString& aResponse) { 61 if (!ExecuteCallback(aResponse)) { 62 return IPC_FAIL_NO_REASON(this); 63 } 64 return IPC_OK(); 65 } 66 67 private: 68 JS::PersistentRooted<JS::Value> mCallback; 69 }; 70 71 } /* namespace ipc */ 72 } /* namespace mozilla */ 73 74 #endif /* ipc_testshell_TestShellParent_h */