blob: 5623114187ae340dbe5761a1729e9c237c510eb2 [file] [log] [blame]
[email protected]f0ecb552012-05-11 22:09:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a0421732011-02-23 03:55:402// 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]a0421732011-02-23 03:55:407
avib7348942015-12-25 20:57:108#include <stdint.h>
9
dcheng59716272016-04-09 05:19:0810#include <memory>
[email protected]a0421732011-02-23 03:55:4011#include <queue>
asvitkine92c1a932016-11-24 19:51:2212#include <string>
[email protected]029bd942013-01-22 08:30:3313#include <vector>
[email protected]a0421732011-02-23 03:55:4014
[email protected]57999812013-02-24 05:40:5215#include "base/files/file_path.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
[email protected]ec3cbea12012-06-04 22:29:4417#include "base/memory/ref_counted.h"
[email protected]fa20e002013-07-23 21:20:5418#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5119#include "base/strings/string16.h"
[email protected]93df81e2012-08-10 22:22:4620#include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
[email protected]2ddef572012-07-03 19:56:0021#include "content/browser/renderer_host/pepper/pepper_message_filter.h"
[email protected]4967f792012-01-20 22:14:4022#include "content/public/browser/browser_child_process_host_delegate.h"
23#include "content/public/browser/browser_child_process_host_iterator.h"
[email protected]d84effeb2012-06-25 17:03:1024#include "ipc/ipc_sender.h"
[email protected]195d4cde2012-10-02 18:12:4125#include "ppapi/shared_impl/ppapi_permissions.h"
[email protected]4967f792012-01-20 22:14:4026
[email protected]130757672012-10-24 00:26:1927namespace content {
28class BrowserChildProcessHostImpl;
[email protected]130757672012-10-24 00:26:1929struct PepperPluginInfo;
30
[email protected]a50432d2011-09-30 16:32:1431// Process host for PPAPI plugin and broker processes.
32// When used for the broker, interpret all references to "plugin" with "broker".
[email protected]130757672012-10-24 00:26:1933class PpapiPluginProcessHost : public BrowserChildProcessHostDelegate,
[email protected]d84effeb2012-06-25 17:03:1034 public IPC::Sender {
[email protected]a0421732011-02-23 03:55:4035 public:
36 class Client {
37 public:
38 // Gets the information about the renderer that's requesting the channel.
yzshen92cad452016-06-17 20:40:0939 // If |renderer_handle| is base::kNullProcessHandle, this channel is used by
40 // the browser itself.
[email protected]1bf0fb22012-04-12 21:44:1641 virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle,
42 int* renderer_id) = 0;
[email protected]a0421732011-02-23 03:55:4043
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]8be45842012-04-13 19:49:2947 // IPC::ChannelHandle(),
48 // 0
[email protected]1bf0fb22012-04-12 21:44:1649 virtual void OnPpapiChannelOpened(
[email protected]8be45842012-04-13 19:49:2950 const IPC::ChannelHandle& channel_handle,
[email protected]108fd342013-01-04 20:46:5451 base::ProcessId plugin_pid,
[email protected]8be45842012-04-13 19:49:2952 int plugin_child_id) = 0;
[email protected]bc2eeb42012-05-02 22:35:5353
chili59caaddf2016-09-09 18:51:5654 // Returns true if the current connection is incognito.
55 virtual bool Incognito() = 0;
[email protected]512d03f2012-06-26 01:06:0656
57 protected:
58 virtual ~Client() {}
[email protected]a50432d2011-09-30 16:32:1459 };
[email protected]d259a8e2011-05-18 22:31:0960
[email protected]a50432d2011-09-30 16:32:1461 class PluginClient : public Client {
[email protected]512d03f2012-06-26 01:06:0662 protected:
dchengc2282aa2014-10-21 12:07:5863 ~PluginClient() override {}
[email protected]a0421732011-02-23 03:55:4064 };
65
[email protected]a50432d2011-09-30 16:32:1466 class BrokerClient : public Client {
[email protected]512d03f2012-06-26 01:06:0667 protected:
dchengc2282aa2014-10-21 12:07:5868 ~BrokerClient() override {}
[email protected]a50432d2011-09-30 16:32:1469 };
70
dchengc2282aa2014-10-21 12:07:5871 ~PpapiPluginProcessHost() override;
[email protected]a0421732011-02-23 03:55:4072
[email protected]a50432d2011-09-30 16:32:1473 static PpapiPluginProcessHost* CreatePluginHost(
[email protected]130757672012-10-24 00:26:1974 const PepperPluginInfo& info,
[email protected]8522332e2013-08-28 19:42:5975 const base::FilePath& profile_data_directory);
[email protected]738a7212011-10-21 17:33:5276 static PpapiPluginProcessHost* CreateBrokerHost(
[email protected]130757672012-10-24 00:26:1977 const PepperPluginInfo& info);
[email protected]a0421732011-02-23 03:55:4078
[email protected]83d12c8d2012-12-10 19:28:4679 // 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,
avib7348942015-12-25 20:57:1086 int32_t pp_instance,
[email protected]83d12c8d2012-12-10 19:28:4687 const PepperRendererInstanceData& instance_data);
[email protected]b7631cc2012-09-15 05:08:3888
89 // The opposite of DIdCreate... above.
90 static void DidDeleteOutOfProcessInstance(int plugin_process_id,
avib7348942015-12-25 20:57:1091 int32_t pp_instance);
[email protected]b7631cc2012-09-15 05:08:3892
tommyclic7634dec2015-02-19 01:46:2093 // Notification that a Plugin instance has been throttled or unthrottled.
94 static void OnPluginInstanceThrottleStateChange(int plugin_process_id,
avib7348942015-12-25 20:57:1095 int32_t pp_instance,
tommyclic7634dec2015-02-19 01:46:2096 bool is_throttled);
97
[email protected]029bd942013-01-22 08:30:3398 // Returns the instances that match the specified process name.
99 // It can only be called on the IO thread.
[email protected]fcf75d42013-12-03 20:11:26100 static void FindByName(const base::string16& name,
[email protected]029bd942013-01-22 08:30:33101 std::vector<PpapiPluginProcessHost*>* hosts);
102
[email protected]d84effeb2012-06-25 17:03:10103 // IPC::Sender implementation:
dchengc2282aa2014-10-21 12:07:58104 bool Send(IPC::Message* message) override;
[email protected]4967f792012-01-20 22:14:40105
[email protected]a0421732011-02-23 03:55:40106 // 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]c5425572013-06-07 22:15:25110 BrowserPpapiHostImpl* host_impl() { return host_impl_.get(); }
111 const BrowserChildProcessHostImpl* process() { return process_.get(); }
[email protected]2dec8ec2013-02-07 19:20:34112 const base::FilePath& plugin_path() const { return plugin_path_; }
113 const base::FilePath& profile_data_directory() const {
[email protected]3f2b2882012-06-05 20:46:29114 return profile_data_directory_;
115 }
[email protected]a0421732011-02-23 03:55:40116
[email protected]a0421732011-02-23 03:55:40117 // The client pointer must remain valid until its callback is issued.
118
119 private:
[email protected]a50432d2011-09-30 16:32:14120 class PluginNetworkObserver;
121
122 // Constructors for plugin and broker process hosts, respectively.
123 // You must call Init before doing anything else.
[email protected]130757672012-10-24 00:26:19124 PpapiPluginProcessHost(const PepperPluginInfo& info,
[email protected]8522332e2013-08-28 19:42:59125 const base::FilePath& profile_data_directory);
[email protected]a50432d2011-09-30 16:32:14126 PpapiPluginProcessHost();
127
128 // Actually launches the process with the given plugin info. Returns true
129 // on success (the process was spawned).
[email protected]130757672012-10-24 00:26:19130 bool Init(const PepperPluginInfo& info);
[email protected]a50432d2011-09-30 16:32:14131
[email protected]a0421732011-02-23 03:55:40132 void RequestPluginChannel(Client* client);
133
dchengc2282aa2014-10-21 12:07:58134 void OnProcessLaunched() override;
[email protected]a0421732011-02-23 03:55:40135
dchengc2282aa2014-10-21 12:07:58136 void OnProcessCrashed(int exit_code) override;
137 bool OnMessageReceived(const IPC::Message& msg) override;
avib7348942015-12-25 20:57:10138 void OnChannelConnected(int32_t peer_pid) override;
dchengc2282aa2014-10-21 12:07:58139 void OnChannelError() override;
[email protected]a0421732011-02-23 03:55:40140
141 void CancelRequests();
142
143 // IPC message handlers.
144 void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle);
[email protected]a0421732011-02-23 03:55:40145
[email protected]a50432d2011-09-30 16:32:14146 // Handles most requests from the plugin. May be NULL.
[email protected]d259a8e2011-05-18 22:31:09147 scoped_refptr<PepperMessageFilter> filter_;
148
[email protected]195d4cde2012-10-02 18:12:41149 ppapi::PpapiPermissions permissions_;
dcheng59716272016-04-09 05:19:08150 std::unique_ptr<BrowserPpapiHostImpl> host_impl_;
[email protected]93df81e2012-08-10 22:22:46151
[email protected]a50432d2011-09-30 16:32:14152 // Observes network changes. May be NULL.
dcheng59716272016-04-09 05:19:08153 std::unique_ptr<PluginNetworkObserver> network_observer_;
[email protected]a50432d2011-09-30 16:32:14154
[email protected]a0421732011-02-23 03:55:40155 // 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]2dec8ec2013-02-07 19:20:34164 base::FilePath plugin_path_;
[email protected]a0421732011-02-23 03:55:40165
[email protected]dd9a0952012-05-31 20:11:31166 // Path to the top-level plugin data directory (differs based upon profile).
[email protected]2dec8ec2013-02-07 19:20:34167 base::FilePath profile_data_directory_;
[email protected]dd9a0952012-05-31 20:11:31168
[email protected]a50432d2011-09-30 16:32:14169 const bool is_broker_;
170
dcheng59716272016-04-09 05:19:08171 std::unique_ptr<BrowserChildProcessHostImpl> process_;
[email protected]4967f792012-01-20 22:14:40172
[email protected]a0421732011-02-23 03:55:40173 DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost);
174};
175
[email protected]4967f792012-01-20 22:14:40176class PpapiPluginProcessHostIterator
[email protected]130757672012-10-24 00:26:19177 : public BrowserChildProcessHostTypeIterator<
[email protected]4967f792012-01-20 22:14:40178 PpapiPluginProcessHost> {
179 public:
180 PpapiPluginProcessHostIterator()
[email protected]130757672012-10-24 00:26:19181 : BrowserChildProcessHostTypeIterator<
182 PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_PLUGIN) {}
[email protected]4967f792012-01-20 22:14:40183};
184
185class PpapiBrokerProcessHostIterator
[email protected]130757672012-10-24 00:26:19186 : public BrowserChildProcessHostTypeIterator<
[email protected]4967f792012-01-20 22:14:40187 PpapiPluginProcessHost> {
188 public:
189 PpapiBrokerProcessHostIterator()
[email protected]130757672012-10-24 00:26:19190 : BrowserChildProcessHostTypeIterator<
191 PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_BROKER) {}
[email protected]4967f792012-01-20 22:14:40192};
193
[email protected]130757672012-10-24 00:26:19194} // namespace content
195
[email protected]a0421732011-02-23 03:55:40196#endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_
197