[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / browser / ppapi_plugin_process_host.h
blob6b50856aa2eda223a206a33c08256f137c9f77ed
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_
6 #define CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_
8 #include <string>
9 #include <queue>
11 #include "base/basictypes.h"
12 #include "base/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
16 #include "content/browser/renderer_host/pepper/pepper_message_filter.h"
17 #include "content/public/browser/browser_child_process_host_delegate.h"
18 #include "content/public/browser/browser_child_process_host_iterator.h"
19 #include "ipc/ipc_sender.h"
20 #include "ppapi/shared_impl/ppapi_permissions.h"
22 namespace net {
23 class HostResolver;
26 namespace content {
27 class BrowserChildProcessHostImpl;
28 class ResourceContext;
29 struct PepperPluginInfo;
31 // Process host for PPAPI plugin and broker processes.
32 // When used for the broker, interpret all references to "plugin" with "broker".
33 class PpapiPluginProcessHost : public BrowserChildProcessHostDelegate,
34 public IPC::Sender {
35 public:
36 class Client {
37 public:
38 // Gets the information about the renderer that's requesting the channel.
39 virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle,
40 int* renderer_id) = 0;
42 // Called when the channel is asynchronously opened to the plugin or on
43 // error. On error, the parameters should be:
44 // base::kNullProcessHandle
45 // IPC::ChannelHandle(),
46 // 0
47 virtual void OnPpapiChannelOpened(
48 const IPC::ChannelHandle& channel_handle,
49 int plugin_child_id) = 0;
51 // Returns true if the current connection is off-the-record.
52 virtual bool OffTheRecord() = 0;
54 protected:
55 virtual ~Client() {}
58 class PluginClient : public Client {
59 public:
60 // Returns the resource context for the renderer requesting the channel.
61 virtual ResourceContext* GetResourceContext() = 0;
63 protected:
64 virtual ~PluginClient() {}
67 class BrokerClient : public Client {
68 protected:
69 virtual ~BrokerClient() {}
72 virtual ~PpapiPluginProcessHost();
74 static PpapiPluginProcessHost* CreatePluginHost(
75 const PepperPluginInfo& info,
76 const FilePath& profile_data_directory,
77 net::HostResolver* host_resolver);
78 static PpapiPluginProcessHost* CreateBrokerHost(
79 const PepperPluginInfo& info);
81 // Notification that a PP_Instance has been created and the associated
82 // renderer related data including the RenderView/Process pair for the given
83 // plugin. This is necessary so that when the plugin calls us with a
84 // PP_Instance we can find the RenderView associated with it without trusting
85 // the plugin.
86 static void DidCreateOutOfProcessInstance(
87 int plugin_process_id,
88 int32 pp_instance,
89 const PepperRendererInstanceData& instance_data);
91 // The opposite of DIdCreate... above.
92 static void DidDeleteOutOfProcessInstance(int plugin_process_id,
93 int32 pp_instance);
95 // IPC::Sender implementation:
96 virtual bool Send(IPC::Message* message) OVERRIDE;
98 // Opens a new channel to the plugin. The client will be notified when the
99 // channel is ready or if there's an error.
100 void OpenChannelToPlugin(Client* client);
102 const FilePath& plugin_path() const { return plugin_path_; }
103 const FilePath& profile_data_directory() const {
104 return profile_data_directory_;
107 // The client pointer must remain valid until its callback is issued.
109 private:
110 class PluginNetworkObserver;
112 // Constructors for plugin and broker process hosts, respectively.
113 // You must call Init before doing anything else.
114 PpapiPluginProcessHost(const PepperPluginInfo& info,
115 const FilePath& profile_data_directory,
116 net::HostResolver* host_resolver);
117 PpapiPluginProcessHost();
119 // Actually launches the process with the given plugin info. Returns true
120 // on success (the process was spawned).
121 bool Init(const PepperPluginInfo& info);
123 void RequestPluginChannel(Client* client);
125 virtual void OnProcessLaunched() OVERRIDE;
127 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
128 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
129 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
130 virtual void OnChannelError() OVERRIDE;
132 void CancelRequests();
134 // IPC message handlers.
135 void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle);
137 // Handles most requests from the plugin. May be NULL.
138 scoped_refptr<PepperMessageFilter> filter_;
140 ppapi::PpapiPermissions permissions_;
141 scoped_ptr<BrowserPpapiHostImpl> host_impl_;
143 // Observes network changes. May be NULL.
144 scoped_ptr<PluginNetworkObserver> network_observer_;
146 // Channel requests that we are waiting to send to the plugin process once
147 // the channel is opened.
148 std::vector<Client*> pending_requests_;
150 // Channel requests that we have already sent to the plugin process, but
151 // haven't heard back about yet.
152 std::queue<Client*> sent_requests_;
154 // Path to the plugin library.
155 FilePath plugin_path_;
157 // Path to the top-level plugin data directory (differs based upon profile).
158 FilePath profile_data_directory_;
160 const bool is_broker_;
162 scoped_ptr<BrowserChildProcessHostImpl> process_;
164 DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost);
167 class PpapiPluginProcessHostIterator
168 : public BrowserChildProcessHostTypeIterator<
169 PpapiPluginProcessHost> {
170 public:
171 PpapiPluginProcessHostIterator()
172 : BrowserChildProcessHostTypeIterator<
173 PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_PLUGIN) {}
176 class PpapiBrokerProcessHostIterator
177 : public BrowserChildProcessHostTypeIterator<
178 PpapiPluginProcessHost> {
179 public:
180 PpapiBrokerProcessHostIterator()
181 : BrowserChildProcessHostTypeIterator<
182 PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_BROKER) {}
185 } // namespace content
187 #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_