OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
6 #define CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/memory/ref_counted.h" |
13 #include "content/browser/browser_child_process_host.h" | 14 #include "content/browser/browser_child_process_host.h" |
| 15 #include "content/browser/renderer_host/pepper_message_filter.h" |
14 | 16 |
15 struct PepperPluginInfo; | 17 struct PepperPluginInfo; |
16 | 18 |
| 19 namespace content { |
| 20 class ResourceContext; |
| 21 } |
| 22 |
| 23 namespace net { |
| 24 class HostResolver; |
| 25 } |
| 26 |
17 class PpapiPluginProcessHost : public BrowserChildProcessHost { | 27 class PpapiPluginProcessHost : public BrowserChildProcessHost { |
18 public: | 28 public: |
19 class Client { | 29 class Client { |
20 public: | 30 public: |
21 // Gets the information about the renderer that's requesting the channel. | 31 // Gets the information about the renderer that's requesting the channel. |
22 virtual void GetChannelInfo(base::ProcessHandle* renderer_handle, | 32 virtual void GetChannelInfo(base::ProcessHandle* renderer_handle, |
23 int* renderer_id) = 0; | 33 int* renderer_id) = 0; |
24 | 34 |
25 // Called when the channel is asynchronously opened to the plugin or on | 35 // Called when the channel is asynchronously opened to the plugin or on |
26 // error. On error, the parameters should be: | 36 // error. On error, the parameters should be: |
27 // base::kNullProcessHandle | 37 // base::kNullProcessHandle |
28 // IPC::ChannelHandle() | 38 // IPC::ChannelHandle() |
29 virtual void OnChannelOpened(base::ProcessHandle plugin_process_handle, | 39 virtual void OnChannelOpened(base::ProcessHandle plugin_process_handle, |
30 const IPC::ChannelHandle& channel_handle) = 0; | 40 const IPC::ChannelHandle& channel_handle) = 0; |
| 41 |
| 42 // Returns the resource context for the renderer requesting the channel. |
| 43 virtual const content::ResourceContext* GetResourceContext() = 0; |
31 }; | 44 }; |
32 | 45 |
33 // You must call Init before doing anything else. | 46 // You must call Init before doing anything else. |
34 PpapiPluginProcessHost(); | 47 PpapiPluginProcessHost(net::HostResolver* host_resolver); |
35 virtual ~PpapiPluginProcessHost(); | 48 virtual ~PpapiPluginProcessHost(); |
36 | 49 |
37 // Actually launches the process with the given plugin info. Returns true | 50 // Actually launches the process with the given plugin info. Returns true |
38 // on success (the process was spawned). | 51 // on success (the process was spawned). |
39 bool Init(const PepperPluginInfo& info); | 52 bool Init(const PepperPluginInfo& info); |
40 | 53 |
41 // Opens a new channel to the plugin. The client will be notified when the | 54 // Opens a new channel to the plugin. The client will be notified when the |
42 // channel is ready or if there's an error. | 55 // channel is ready or if there's an error. |
43 void OpenChannelToPlugin(Client* client); | 56 void OpenChannelToPlugin(Client* client); |
44 | 57 |
45 const FilePath& plugin_path() const { return plugin_path_; } | 58 const FilePath& plugin_path() const { return plugin_path_; } |
46 | 59 |
47 // The client pointer must remain valid until its callback is issued. | 60 // The client pointer must remain valid until its callback is issued. |
48 | 61 |
49 private: | 62 private: |
50 | |
51 void RequestPluginChannel(Client* client); | 63 void RequestPluginChannel(Client* client); |
52 | 64 |
53 virtual bool CanShutdown(); | 65 virtual bool CanShutdown(); |
54 virtual void OnProcessLaunched(); | 66 virtual void OnProcessLaunched(); |
55 | 67 |
56 virtual bool OnMessageReceived(const IPC::Message& msg); | 68 virtual bool OnMessageReceived(const IPC::Message& msg); |
57 virtual void OnChannelConnected(int32 peer_pid); | 69 virtual void OnChannelConnected(int32 peer_pid); |
58 virtual void OnChannelError(); | 70 virtual void OnChannelError(); |
59 | 71 |
60 void CancelRequests(); | 72 void CancelRequests(); |
61 | 73 |
62 // IPC message handlers. | 74 // IPC message handlers. |
63 void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle); | 75 void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle); |
64 | 76 |
| 77 // Handles most requests from the plugin. |
| 78 scoped_refptr<PepperMessageFilter> filter_; |
| 79 |
65 // Channel requests that we are waiting to send to the plugin process once | 80 // Channel requests that we are waiting to send to the plugin process once |
66 // the channel is opened. | 81 // the channel is opened. |
67 std::vector<Client*> pending_requests_; | 82 std::vector<Client*> pending_requests_; |
68 | 83 |
69 // Channel requests that we have already sent to the plugin process, but | 84 // Channel requests that we have already sent to the plugin process, but |
70 // haven't heard back about yet. | 85 // haven't heard back about yet. |
71 std::queue<Client*> sent_requests_; | 86 std::queue<Client*> sent_requests_; |
72 | 87 |
73 // Path to the plugin library. | 88 // Path to the plugin library. |
74 FilePath plugin_path_; | 89 FilePath plugin_path_; |
75 | 90 |
76 DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost); | 91 DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost); |
77 }; | 92 }; |
78 | 93 |
79 #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ | 94 #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
80 | 95 |
OLD | NEW |