/work/obj-fuzz/dist/include/mozilla/plugins/PluginProcessParent.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 | | * vim: sw=4 ts=4 et : |
3 | | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef dom_plugins_PluginProcessParent_h |
8 | | #define dom_plugins_PluginProcessParent_h 1 |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "base/basictypes.h" |
12 | | |
13 | | #include "base/file_path.h" |
14 | | #include "base/task.h" |
15 | | #include "base/thread.h" |
16 | | #include "chrome/common/child_process_host.h" |
17 | | |
18 | | #include "mozilla/ipc/GeckoChildProcessHost.h" |
19 | | #include "mozilla/ipc/TaskFactory.h" |
20 | | #include "mozilla/UniquePtr.h" |
21 | | #include "nsCOMPtr.h" |
22 | | #include "nsIRunnable.h" |
23 | | #include "nsTHashtable.h" |
24 | | #include "nsHashKeys.h" |
25 | | |
26 | | namespace mozilla { |
27 | | namespace plugins { |
28 | | |
29 | | class LaunchCompleteTask : public Runnable |
30 | | { |
31 | | public: |
32 | | LaunchCompleteTask() |
33 | | : Runnable("plugins::LaunchCompleteTask") |
34 | | , mLaunchSucceeded(false) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | 0 | void SetLaunchSucceeded() { mLaunchSucceeded = true; } |
39 | | |
40 | | protected: |
41 | | bool mLaunchSucceeded; |
42 | | }; |
43 | | |
44 | | class PluginProcessParent : public mozilla::ipc::GeckoChildProcessHost |
45 | | { |
46 | | public: |
47 | | explicit PluginProcessParent(const std::string& aPluginFilePath); |
48 | | ~PluginProcessParent(); |
49 | | |
50 | | /** |
51 | | * Launch the plugin process. If the process fails to launch, |
52 | | * this method will return false. |
53 | | * |
54 | | * @param aLaunchCompleteTask Task that is executed on the main |
55 | | * thread once the asynchonous launch has completed. |
56 | | * @param aSandboxLevel Determines the strength of the sandbox. |
57 | | * <= 0 means no sandbox. |
58 | | * @param aIsSandboxLoggingEnabled Indicates if sandbox violation |
59 | | * logging should be enabled for the plugin process. |
60 | | */ |
61 | | bool Launch(UniquePtr<LaunchCompleteTask> aLaunchCompleteTask = UniquePtr<LaunchCompleteTask>(), |
62 | | int32_t aSandboxLevel = 0, |
63 | | bool aIsSandboxLoggingEnabled = false); |
64 | | |
65 | | void Delete(); |
66 | | |
67 | | virtual bool CanShutdown() override |
68 | 0 | { |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | 0 | const std::string& GetPluginFilePath() { return mPluginFilePath; } |
73 | | |
74 | | using mozilla::ipc::GeckoChildProcessHost::GetChannel; |
75 | | |
76 | | virtual bool WaitUntilConnected(int32_t aTimeoutMs = 0) override; |
77 | | |
78 | | virtual void OnChannelConnected(int32_t peer_pid) override; |
79 | | virtual void OnChannelError() override; |
80 | | |
81 | | bool IsConnected(); |
82 | | |
83 | | static bool IsPluginProcessId(base::ProcessId procId); |
84 | | |
85 | | private: |
86 | | void RunLaunchCompleteTask(); |
87 | | |
88 | | std::string mPluginFilePath; |
89 | | ipc::TaskFactory<PluginProcessParent> mTaskFactory; |
90 | | UniquePtr<LaunchCompleteTask> mLaunchCompleteTask; |
91 | | MessageLoop* mMainMsgLoop; |
92 | | #ifdef XP_WIN |
93 | | typedef nsTHashtable<nsUint32HashKey> PidSet; |
94 | | // Set of PIDs for all plugin child processes or NULL if empty. |
95 | | static PidSet* sPidSet; |
96 | | uint32_t mChildPid; |
97 | | #endif |
98 | | |
99 | | DISALLOW_EVIL_CONSTRUCTORS(PluginProcessParent); |
100 | | }; |
101 | | |
102 | | |
103 | | } // namespace plugins |
104 | | } // namespace mozilla |
105 | | |
106 | | #endif // ifndef dom_plugins_PluginProcessParent_h |