| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 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 "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" | 15 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
| 16 #include "content/browser/renderer_host/pepper/pepper_file_message_filter.h" | 16 #include "content/browser/renderer_host/pepper/pepper_file_message_filter.h" |
| 17 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" | 17 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
| 18 #include "content/public/browser/browser_child_process_host_delegate.h" | 18 #include "content/public/browser/browser_child_process_host_delegate.h" |
| 19 #include "content/public/browser/browser_child_process_host_iterator.h" | 19 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 20 #include "ipc/ipc_sender.h" | 20 #include "ipc/ipc_sender.h" |
| 21 #include "ppapi/shared_impl/ppapi_permissions.h" | 21 #include "ppapi/shared_impl/ppapi_permissions.h" |
| 22 | 22 |
| 23 class BrowserChildProcessHostImpl; | |
| 24 | |
| 25 namespace content { | |
| 26 struct PepperPluginInfo; | |
| 27 class ResourceContext; | |
| 28 } | |
| 29 | |
| 30 namespace net { | 23 namespace net { |
| 31 class HostResolver; | 24 class HostResolver; |
| 32 } | 25 } |
| 33 | 26 |
| 27 namespace content { |
| 28 class BrowserChildProcessHostImpl; |
| 29 class ResourceContext; |
| 30 struct PepperPluginInfo; |
| 31 |
| 34 // Process host for PPAPI plugin and broker processes. | 32 // Process host for PPAPI plugin and broker processes. |
| 35 // When used for the broker, interpret all references to "plugin" with "broker". | 33 // When used for the broker, interpret all references to "plugin" with "broker". |
| 36 class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate, | 34 class PpapiPluginProcessHost : public BrowserChildProcessHostDelegate, |
| 37 public IPC::Sender { | 35 public IPC::Sender { |
| 38 public: | 36 public: |
| 39 class Client { | 37 class Client { |
| 40 public: | 38 public: |
| 41 // Gets the information about the renderer that's requesting the channel. | 39 // Gets the information about the renderer that's requesting the channel. |
| 42 virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle, | 40 virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle, |
| 43 int* renderer_id) = 0; | 41 int* renderer_id) = 0; |
| 44 | 42 |
| 45 // Called when the channel is asynchronously opened to the plugin or on | 43 // Called when the channel is asynchronously opened to the plugin or on |
| 46 // error. On error, the parameters should be: | 44 // error. On error, the parameters should be: |
| 47 // base::kNullProcessHandle | 45 // base::kNullProcessHandle |
| 48 // IPC::ChannelHandle(), | 46 // IPC::ChannelHandle(), |
| 49 // 0 | 47 // 0 |
| 50 virtual void OnPpapiChannelOpened( | 48 virtual void OnPpapiChannelOpened( |
| 51 const IPC::ChannelHandle& channel_handle, | 49 const IPC::ChannelHandle& channel_handle, |
| 52 int plugin_child_id) = 0; | 50 int plugin_child_id) = 0; |
| 53 | 51 |
| 54 // Returns true if the current connection is off-the-record. | 52 // Returns true if the current connection is off-the-record. |
| 55 virtual bool OffTheRecord() = 0; | 53 virtual bool OffTheRecord() = 0; |
| 56 | 54 |
| 57 protected: | 55 protected: |
| 58 virtual ~Client() {} | 56 virtual ~Client() {} |
| 59 }; | 57 }; |
| 60 | 58 |
| 61 class PluginClient : public Client { | 59 class PluginClient : public Client { |
| 62 public: | 60 public: |
| 63 // Returns the resource context for the renderer requesting the channel. | 61 // Returns the resource context for the renderer requesting the channel. |
| 64 virtual content::ResourceContext* GetResourceContext() = 0; | 62 virtual ResourceContext* GetResourceContext() = 0; |
| 65 | 63 |
| 66 protected: | 64 protected: |
| 67 virtual ~PluginClient() {} | 65 virtual ~PluginClient() {} |
| 68 }; | 66 }; |
| 69 | 67 |
| 70 class BrokerClient : public Client { | 68 class BrokerClient : public Client { |
| 71 protected: | 69 protected: |
| 72 virtual ~BrokerClient() {} | 70 virtual ~BrokerClient() {} |
| 73 }; | 71 }; |
| 74 | 72 |
| 75 virtual ~PpapiPluginProcessHost(); | 73 virtual ~PpapiPluginProcessHost(); |
| 76 | 74 |
| 77 static PpapiPluginProcessHost* CreatePluginHost( | 75 static PpapiPluginProcessHost* CreatePluginHost( |
| 78 const content::PepperPluginInfo& info, | 76 const PepperPluginInfo& info, |
| 79 const FilePath& profile_data_directory, | 77 const FilePath& profile_data_directory, |
| 80 net::HostResolver* host_resolver); | 78 net::HostResolver* host_resolver); |
| 81 static PpapiPluginProcessHost* CreateBrokerHost( | 79 static PpapiPluginProcessHost* CreateBrokerHost( |
| 82 const content::PepperPluginInfo& info); | 80 const PepperPluginInfo& info); |
| 83 | 81 |
| 84 // Notification that a PP_Instance has been created for the given | 82 // Notification that a PP_Instance has been created for the given |
| 85 // RenderView/Process pair for the given plugin. This is necessary so that | 83 // RenderView/Process pair for the given plugin. This is necessary so that |
| 86 // when the plugin calls us with a PP_Instance we can find the RenderView | 84 // when the plugin calls us with a PP_Instance we can find the RenderView |
| 87 // associated with it without trusting the plugin. | 85 // associated with it without trusting the plugin. |
| 88 static void DidCreateOutOfProcessInstance(int plugin_process_id, | 86 static void DidCreateOutOfProcessInstance(int plugin_process_id, |
| 89 int32 pp_instance, | 87 int32 pp_instance, |
| 90 int render_process_id, | 88 int render_process_id, |
| 91 int render_view_id); | 89 int render_view_id); |
| 92 | 90 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 106 return profile_data_directory_; | 104 return profile_data_directory_; |
| 107 } | 105 } |
| 108 | 106 |
| 109 // The client pointer must remain valid until its callback is issued. | 107 // The client pointer must remain valid until its callback is issued. |
| 110 | 108 |
| 111 private: | 109 private: |
| 112 class PluginNetworkObserver; | 110 class PluginNetworkObserver; |
| 113 | 111 |
| 114 // Constructors for plugin and broker process hosts, respectively. | 112 // Constructors for plugin and broker process hosts, respectively. |
| 115 // You must call Init before doing anything else. | 113 // You must call Init before doing anything else. |
| 116 PpapiPluginProcessHost(const content::PepperPluginInfo& info, | 114 PpapiPluginProcessHost(const PepperPluginInfo& info, |
| 117 const FilePath& profile_data_directory, | 115 const FilePath& profile_data_directory, |
| 118 net::HostResolver* host_resolver); | 116 net::HostResolver* host_resolver); |
| 119 PpapiPluginProcessHost(); | 117 PpapiPluginProcessHost(); |
| 120 | 118 |
| 121 // Actually launches the process with the given plugin info. Returns true | 119 // Actually launches the process with the given plugin info. Returns true |
| 122 // on success (the process was spawned). | 120 // on success (the process was spawned). |
| 123 bool Init(const content::PepperPluginInfo& info); | 121 bool Init(const PepperPluginInfo& info); |
| 124 | 122 |
| 125 void RequestPluginChannel(Client* client); | 123 void RequestPluginChannel(Client* client); |
| 126 | 124 |
| 127 virtual void OnProcessLaunched() OVERRIDE; | 125 virtual void OnProcessLaunched() OVERRIDE; |
| 128 | 126 |
| 129 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 127 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
| 130 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 128 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 131 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 129 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 132 virtual void OnChannelError() OVERRIDE; | 130 virtual void OnChannelError() OVERRIDE; |
| 133 | 131 |
| 134 void CancelRequests(); | 132 void CancelRequests(); |
| 135 | 133 |
| 136 // IPC message handlers. | 134 // IPC message handlers. |
| 137 void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle); | 135 void OnRendererPluginChannelCreated(const IPC::ChannelHandle& handle); |
| 138 | 136 |
| 139 // Handles most requests from the plugin. May be NULL. | 137 // Handles most requests from the plugin. May be NULL. |
| 140 scoped_refptr<PepperMessageFilter> filter_; | 138 scoped_refptr<PepperMessageFilter> filter_; |
| 141 | 139 |
| 142 ppapi::PpapiPermissions permissions_; | 140 ppapi::PpapiPermissions permissions_; |
| 143 scoped_refptr<content::BrowserPpapiHostImpl> host_impl_; | 141 scoped_refptr<BrowserPpapiHostImpl> host_impl_; |
| 144 | 142 |
| 145 // Handles filesystem requests from flash plugins. May be NULL. | 143 // Handles filesystem requests from flash plugins. May be NULL. |
| 146 scoped_refptr<PepperFileMessageFilter> file_filter_; | 144 scoped_refptr<PepperFileMessageFilter> file_filter_; |
| 147 | 145 |
| 148 // Observes network changes. May be NULL. | 146 // Observes network changes. May be NULL. |
| 149 scoped_ptr<PluginNetworkObserver> network_observer_; | 147 scoped_ptr<PluginNetworkObserver> network_observer_; |
| 150 | 148 |
| 151 // Channel requests that we are waiting to send to the plugin process once | 149 // Channel requests that we are waiting to send to the plugin process once |
| 152 // the channel is opened. | 150 // the channel is opened. |
| 153 std::vector<Client*> pending_requests_; | 151 std::vector<Client*> pending_requests_; |
| 154 | 152 |
| 155 // Channel requests that we have already sent to the plugin process, but | 153 // Channel requests that we have already sent to the plugin process, but |
| 156 // haven't heard back about yet. | 154 // haven't heard back about yet. |
| 157 std::queue<Client*> sent_requests_; | 155 std::queue<Client*> sent_requests_; |
| 158 | 156 |
| 159 // Path to the plugin library. | 157 // Path to the plugin library. |
| 160 FilePath plugin_path_; | 158 FilePath plugin_path_; |
| 161 | 159 |
| 162 // Path to the top-level plugin data directory (differs based upon profile). | 160 // Path to the top-level plugin data directory (differs based upon profile). |
| 163 FilePath profile_data_directory_; | 161 FilePath profile_data_directory_; |
| 164 | 162 |
| 165 const bool is_broker_; | 163 const bool is_broker_; |
| 166 | 164 |
| 167 scoped_ptr<BrowserChildProcessHostImpl> process_; | 165 scoped_ptr<BrowserChildProcessHostImpl> process_; |
| 168 | 166 |
| 169 DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost); | 167 DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost); |
| 170 }; | 168 }; |
| 171 | 169 |
| 172 class PpapiPluginProcessHostIterator | 170 class PpapiPluginProcessHostIterator |
| 173 : public content::BrowserChildProcessHostTypeIterator< | 171 : public BrowserChildProcessHostTypeIterator< |
| 174 PpapiPluginProcessHost> { | 172 PpapiPluginProcessHost> { |
| 175 public: | 173 public: |
| 176 PpapiPluginProcessHostIterator() | 174 PpapiPluginProcessHostIterator() |
| 177 : content::BrowserChildProcessHostTypeIterator< | 175 : BrowserChildProcessHostTypeIterator< |
| 178 PpapiPluginProcessHost>(content::PROCESS_TYPE_PPAPI_PLUGIN) {} | 176 PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_PLUGIN) {} |
| 179 }; | 177 }; |
| 180 | 178 |
| 181 class PpapiBrokerProcessHostIterator | 179 class PpapiBrokerProcessHostIterator |
| 182 : public content::BrowserChildProcessHostTypeIterator< | 180 : public BrowserChildProcessHostTypeIterator< |
| 183 PpapiPluginProcessHost> { | 181 PpapiPluginProcessHost> { |
| 184 public: | 182 public: |
| 185 PpapiBrokerProcessHostIterator() | 183 PpapiBrokerProcessHostIterator() |
| 186 : content::BrowserChildProcessHostTypeIterator< | 184 : BrowserChildProcessHostTypeIterator< |
| 187 PpapiPluginProcessHost>(content::PROCESS_TYPE_PPAPI_BROKER) {} | 185 PpapiPluginProcessHost>(PROCESS_TYPE_PPAPI_BROKER) {} |
| 188 }; | 186 }; |
| 189 | 187 |
| 188 } // namespace content |
| 189 |
| 190 #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ | 190 #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ |
| 191 | 191 |
| OLD | NEW |