[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
| 6 | #define CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 7 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 11 | #include <queue> |
asvitkine | 92c1a93 | 2016-11-24 19:51:22 | [diff] [blame] | 12 | #include <string> |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 13 | #include <vector> |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 14 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 15 | #include "base/files/file_path.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | ec3cbea1 | 2012-06-04 22:29:44 | [diff] [blame] | 17 | #include "base/memory/ref_counted.h" |
[email protected] | fa20e00 | 2013-07-23 21:20:54 | [diff] [blame] | 18 | #include "base/process/process.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 19 | #include "base/strings/string16.h" |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 20 | #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
[email protected] | 2ddef57 | 2012-07-03 19:56:00 | [diff] [blame] | 21 | #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 22 | #include "content/public/browser/browser_child_process_host_delegate.h" |
| 23 | #include "content/public/browser/browser_child_process_host_iterator.h" |
[email protected] | d84effeb | 2012-06-25 17:03:10 | [diff] [blame] | 24 | #include "ipc/ipc_sender.h" |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 25 | #include "ppapi/shared_impl/ppapi_permissions.h" |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 26 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 27 | namespace content { |
| 28 | class BrowserChildProcessHostImpl; |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 29 | struct PepperPluginInfo; |
| 30 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 31 | // Process host for PPAPI plugin and broker processes. |
| 32 | // When used for the broker, interpret all references to "plugin" with "broker". |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 33 | class PpapiPluginProcessHost : public BrowserChildProcessHostDelegate, |
[email protected] | d84effeb | 2012-06-25 17:03:10 | [diff] [blame] | 34 | public IPC::Sender { |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 35 | public: |
| 36 | class Client { |
| 37 | public: |
| 38 | // Gets the information about the renderer that's requesting the channel. |
yzshen | 92cad45 | 2016-06-17 20:40:09 | [diff] [blame] | 39 | // If |renderer_handle| is base::kNullProcessHandle, this channel is used by |
| 40 | // the browser itself. |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 41 | virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle, |
| 42 | int* renderer_id) = 0; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 43 | |
| 44 | // Called when the channel is asynchronously opened to the plugin or on |
| 45 | // error. On error, the parameters should be: |
| 46 | // base::kNullProcessHandle |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 47 | // IPC::ChannelHandle(), |
| 48 | // 0 |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 49 | virtual void OnPpapiChannelOpened( |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 50 | const IPC::ChannelHandle& channel_handle, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 51 | base::ProcessId plugin_pid, |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 52 | int plugin_child_id) = 0; |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 53 | |
chili | 59caaddf | 2016-09-09 18:51:56 | [diff] [blame] | 54 | // Returns true if the current connection is incognito. |
| 55 | virtual bool Incognito() = 0; |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 56 | |
| 57 | protected: |
| 58 | virtual ~Client() {} |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 59 | }; |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 60 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 61 | class PluginClient : public Client { |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 62 | protected: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 63 | ~PluginClient() override {} |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 64 | }; |
| 65 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 66 | class BrokerClient : public Client { |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 67 | protected: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 68 | ~BrokerClient() override {} |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 69 | }; |
| 70 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 71 | ~PpapiPluginProcessHost() override; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 72 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 73 | static PpapiPluginProcessHost* CreatePluginHost( |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 74 | const PepperPluginInfo& info, |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 75 | const base::FilePath& profile_data_directory); |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 76 | static PpapiPluginProcessHost* CreateBrokerHost( |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 77 | const PepperPluginInfo& info); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 78 | |
[email protected] | 83d12c8d | 2012-12-10 19:28:46 | [diff] [blame] | 79 | // Notification that a PP_Instance has been created and the associated |
| 80 | // renderer related data including the RenderView/Process pair for the given |
| 81 | // plugin. This is necessary so that when the plugin calls us with a |
| 82 | // PP_Instance we can find the RenderView associated with it without trusting |
| 83 | // the plugin. |
| 84 | static void DidCreateOutOfProcessInstance( |
| 85 | int plugin_process_id, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 86 | int32_t pp_instance, |
[email protected] | 83d12c8d | 2012-12-10 19:28:46 | [diff] [blame] | 87 | const PepperRendererInstanceData& instance_data); |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 88 | |
| 89 | // The opposite of DIdCreate... above. |
| 90 | static void DidDeleteOutOfProcessInstance(int plugin_process_id, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 91 | int32_t pp_instance); |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 92 | |
tommycli | c7634dec | 2015-02-19 01:46:20 | [diff] [blame] | 93 | // Notification that a Plugin instance has been throttled or unthrottled. |
| 94 | static void OnPluginInstanceThrottleStateChange(int plugin_process_id, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 95 | int32_t pp_instance, |
tommycli | c7634dec | 2015-02-19 01:46:20 | [diff] [blame] | 96 | bool is_throttled); |
| 97 | |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 98 | // Returns the instances that match the specified process name. |
| 99 | // It can only be called on the IO thread. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 100 | static void FindByName(const base::string16& name, |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 101 | std::vector<PpapiPluginProcessHost*>* hosts); |
| 102 | |
[email protected] | d84effeb | 2012-06-25 17:03:10 | [diff] [blame] | 103 | // IPC::Sender implementation: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 104 | bool Send(IPC::Message* message) override; |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 105 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 106 | // Opens a new channel to the plugin. The client will be notified when the |
| 107 | // channel is ready or if there's an error. |
| 108 | void OpenChannelToPlugin(Client* client); |
| 109 | |
[email protected] | c542557 | 2013-06-07 22:15:25 | [diff] [blame] | 110 | BrowserPpapiHostImpl* host_impl() { return host_impl_.get(); } |
| 111 | const BrowserChildProcessHostImpl* process() { return process_.get(); } |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 112 | const base::FilePath& plugin_path() const { return plugin_path_; } |
| 113 | const base::FilePath& profile_data_directory() const { |
[email protected] | 3f2b288 | 2012-06-05 20:46:29 | [diff] [blame] | 114 | return profile_data_directory_; |
| 115 | } |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 116 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 117 | // The client pointer must remain valid until its callback is issued. |
| 118 | |
| 119 | private: |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 120 | class PluginNetworkObserver; |
| 121 | |
| 122 | // Constructors for plugin and broker process hosts, respectively. |
| 123 | // You must call Init before doing anything else. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 124 | PpapiPluginProcessHost(const PepperPluginInfo& info, |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 125 | const base::FilePath& profile_data_directory); |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 126 | PpapiPluginProcessHost(); |
| 127 | |
| 128 | // Actually launches the process with the given plugin info. Returns true |
| 129 | // on success (the process was spawned). |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 130 | bool Init(const PepperPluginInfo& info); |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 131 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 132 | void RequestPluginChannel(Client* client); |
| 133 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 134 | void OnProcessLaunched() override; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 135 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 136 | void OnProcessCrashed(int exit_code) override; |
| 137 | bool OnMessageReceived(const IPC::Message& msg) override; |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 138 | void OnChannelConnected(int32_t peer_pid) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 139 | void OnChannelError() override; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 140 | |
| 141 | void CancelRequests(); |
| 142 | |
| 143 | // IPC message handlers. |
| 144 | void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 145 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 146 | // Handles most requests from the plugin. May be NULL. |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 147 | scoped_refptr<PepperMessageFilter> filter_; |
| 148 | |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 149 | ppapi::PpapiPermissions permissions_; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 150 | std::unique_ptr<BrowserPpapiHostImpl> host_impl_; |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 151 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 152 | // Observes network changes. May be NULL. |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 153 | std::unique_ptr<PluginNetworkObserver> network_observer_; |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 154 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 155 | // Channel requests that we are waiting to send to the plugin process once |
| 156 | // the channel is opened. |
| 157 | std::vector<Client*> pending_requests_; |
| 158 | |
| 159 | // Channel requests that we have already sent to the plugin process, but |
| 160 | // haven't heard back about yet. |
| 161 | std::queue<Client*> sent_requests_; |
| 162 | |
| 163 | // Path to the plugin library. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 164 | base::FilePath plugin_path_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 165 | |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 166 | // Path to the top-level plugin data directory (differs based upon profile). |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 167 | base::FilePath profile_data_directory_; |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 168 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 169 | const bool is_broker_; |
| 170 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 171 | std::unique_ptr<BrowserChildProcessHostImpl> process_; |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 172 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 173 | DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost); |
| 174 | }; |
| 175 | |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 176 | class PpapiPluginProcessHostIterator |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 177 | : public BrowserChildProcessHostTypeIterator< |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 178 | PpapiPluginProcessHost> { |
| 179 | public: |
| 180 | PpapiPluginProcessHostIterator() |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 181 | : BrowserChildProcessHostTypeIterator< |
| 182 | PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_PLUGIN) {} |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | class PpapiBrokerProcessHostIterator |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 186 | : public BrowserChildProcessHostTypeIterator< |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 187 | PpapiPluginProcessHost> { |
| 188 | public: |
| 189 | PpapiBrokerProcessHostIterator() |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 190 | : BrowserChildProcessHostTypeIterator< |
| 191 | PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_BROKER) {} |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 192 | }; |
| 193 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 194 | } // namespace content |
| 195 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 196 | #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
| 197 | |