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_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/containers/scoped_ptr_hash_map.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto
ry.h" | 17 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto
ry.h" |
17 #include "content/browser/renderer_host/pepper/ssl_context_helper.h" | 18 #include "content/browser/renderer_host/pepper/ssl_context_helper.h" |
18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
19 #include "content/common/pepper_renderer_instance_data.h" | 20 #include "content/common/pepper_renderer_instance_data.h" |
20 #include "content/public/browser/browser_ppapi_host.h" | 21 #include "content/public/browser/browser_ppapi_host.h" |
21 #include "content/public/common/process_type.h" | 22 #include "content/public/common/process_type.h" |
22 #include "ipc/message_filter.h" | 23 #include "ipc/message_filter.h" |
23 #include "ppapi/host/ppapi_host.h" | 24 #include "ppapi/host/ppapi_host.h" |
24 | 25 |
25 #if !defined(ENABLE_PLUGINS) | 26 #if !defined(ENABLE_PLUGINS) |
26 #error "Plugins should be enabled" | 27 #error "Plugins should be enabled" |
27 #endif | 28 #endif |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 | 31 |
| 32 class BrowserMessageFilter; |
| 33 class BrowserPpapiHostImpl; |
| 34 class PendingHostCreator { |
| 35 public: |
| 36 PendingHostCreator(int routing_id, |
| 37 int sequence_id, |
| 38 size_t nested_msgs_size); |
| 39 ~PendingHostCreator(); |
| 40 |
| 41 // Adds the given resource host as a pending one. The host is remembered as |
| 42 // host number |index|, and will ultimately be sent to the plugin to be |
| 43 // attached to a real resource. |
| 44 void AddPendingResourceHost(size_t index, int host_id); |
| 45 |
| 46 bool finished() const { |
| 47 return completed_so_far_ == host_ids_.size(); |
| 48 } |
| 49 |
| 50 int routing_id() const { return routing_id_; } |
| 51 int sequence_id() const { return sequence_id_; } |
| 52 const std::vector<int>& host_ids() const { return host_ids_; } |
| 53 |
| 54 // Swap host_ids with host_ids_, to avoid copying. |
| 55 void TakePendingResourceHostIdsAndReset(std::vector<int>* host_ids); |
| 56 |
| 57 private: |
| 58 int routing_id_; |
| 59 int sequence_id_; |
| 60 std::vector<int> host_ids_; |
| 61 size_t completed_so_far_; |
| 62 }; |
| 63 |
| 64 // TODO(dmichael) Rename and move this to its own file. |
| 65 class InstanceData { |
| 66 public: |
| 67 explicit InstanceData(PP_Instance instance, |
| 68 BrowserPpapiHostImpl* host, |
| 69 IPC::Sender* renderer_sender, |
| 70 PepperRendererInstanceData renderer_data); |
| 71 InstanceData(const InstanceData& instance_data); |
| 72 ~InstanceData(); |
| 73 |
| 74 const PepperRendererInstanceData& renderer_data() const { |
| 75 return renderer_data_; |
| 76 } |
| 77 |
| 78 void CreateResourceHostsFromHost( |
| 79 int routing_id, |
| 80 const ppapi::proxy::ResourceMessageCallParams& params, |
| 81 const std::vector<IPC::Message>& nested_msgs); |
| 82 void GetAllPendingResourceHosts(scoped_ptr<IPC::Message> reply_msg); |
| 83 void RendererDidReceiveHosts(int sequence); |
| 84 private: |
| 85 typedef base::ScopedPtrHashMap<int, PendingHostCreator> HostCreatorMap; |
| 86 |
| 87 void SendCompletedResourceHosts(const PendingHostCreator& creator); |
| 88 void SendSyncReplyIfNecessary(); |
| 89 void AddPendingResourceHost(PendingHostCreator* creator, |
| 90 int sequence, |
| 91 size_t index, |
| 92 scoped_ptr<ppapi::host::ResourceHost> host); |
| 93 PP_Instance instance_; |
| 94 |
| 95 // Weak; host_ owns the InstanceData. |
| 96 BrowserPpapiHostImpl* host_; |
| 97 |
| 98 IPC::Sender* renderer_sender_; |
| 99 |
| 100 // Maps sequence number to PendingHostCreator. |
| 101 HostCreatorMap host_creator_map_; |
| 102 size_t finished_creators_; |
| 103 // Valid if we are building up a reply to a sync request for this instance. |
| 104 // If null, we are in "normal" mode, where we send created hosts |
| 105 // asynchronously. If valid, this is the reply message to send back to the |
| 106 // renderer to unblock it. Note we only need 1, because the renderer will |
| 107 // be blocked and unable to make another sync request until after we are |
| 108 // finished servicing this one. |
| 109 scoped_ptr<IPC::Message> reply_for_sync_request_; |
| 110 PepperRendererInstanceData renderer_data_; |
| 111 |
| 112 base::WeakPtrFactory<InstanceData> weak_ptr_factory_; |
| 113 }; |
| 114 |
31 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost { | 115 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost { |
32 public: | 116 public: |
33 // The creator is responsible for calling set_plugin_process_handle as soon | 117 // The creator is responsible for calling set_plugin_process_handle as soon |
34 // as it is known (we start the process asynchronously so it won't be known | 118 // as it is known (we start the process asynchronously so it won't be known |
35 // when this object is created). | 119 // when this object is created). |
36 // |external_plugin| signfies that this is a proxy created for an embedder's | 120 // |external_plugin| signfies that this is a proxy created for an embedder's |
37 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess. | 121 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess. |
38 BrowserPpapiHostImpl(IPC::Sender* sender, | 122 BrowserPpapiHostImpl(IPC::Sender* sender, |
39 const ppapi::PpapiPermissions& permissions, | 123 const ppapi::PpapiPermissions& permissions, |
40 const std::string& plugin_name, | 124 const std::string& plugin_name, |
(...skipping 21 matching lines...) Expand all Loading... |
62 void set_plugin_process_handle(base::ProcessHandle handle) { | 146 void set_plugin_process_handle(base::ProcessHandle handle) { |
63 plugin_process_handle_ = handle; | 147 plugin_process_handle_ = handle; |
64 } | 148 } |
65 | 149 |
66 bool external_plugin() const { return external_plugin_; } | 150 bool external_plugin() const { return external_plugin_; } |
67 | 151 |
68 // These two functions are notifications that an instance has been created | 152 // These two functions are notifications that an instance has been created |
69 // or destroyed. They allow us to maintain a mapping of PP_Instance to data | 153 // or destroyed. They allow us to maintain a mapping of PP_Instance to data |
70 // associated with the instance including view IDs in the browser process. | 154 // associated with the instance including view IDs in the browser process. |
71 void AddInstance(PP_Instance instance, | 155 void AddInstance(PP_Instance instance, |
72 const PepperRendererInstanceData& instance_data); | 156 const PepperRendererInstanceData& instance_data, |
| 157 IPC::Sender* renderer_sender); |
73 void DeleteInstance(PP_Instance instance); | 158 void DeleteInstance(PP_Instance instance); |
74 | 159 |
| 160 void CreateResourceHostsFromHost( |
| 161 int routing_id, |
| 162 const ppapi::proxy::ResourceMessageCallParams& params, |
| 163 PP_Instance instance, |
| 164 const std::vector<IPC::Message>& nested_msgs); |
| 165 void RendererDidReceiveHosts(PP_Instance instance, int sequence); |
| 166 bool GetAllPendingResourceHosts( |
| 167 PP_Instance instance, |
| 168 scoped_ptr<IPC::Message> reply_msg); |
| 169 |
75 scoped_refptr<IPC::MessageFilter> message_filter() { | 170 scoped_refptr<IPC::MessageFilter> message_filter() { |
76 return message_filter_; | 171 return message_filter_; |
77 } | 172 } |
78 | 173 |
79 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const { | 174 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const { |
80 return ssl_context_helper_; | 175 return ssl_context_helper_; |
81 } | 176 } |
82 | 177 |
83 private: | 178 private: |
84 friend class BrowserPpapiHostTest; | 179 friend class BrowserPpapiHostTest; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 213 |
119 // If true, this refers to a plugin running in the renderer process. | 214 // If true, this refers to a plugin running in the renderer process. |
120 bool in_process_; | 215 bool in_process_; |
121 | 216 |
122 // If true, this is an external plugin, i.e. created by the embedder using | 217 // If true, this is an external plugin, i.e. created by the embedder using |
123 // BrowserPpapiHost::CreateExternalPluginProcess. | 218 // BrowserPpapiHost::CreateExternalPluginProcess. |
124 bool external_plugin_; | 219 bool external_plugin_; |
125 | 220 |
126 scoped_refptr<SSLContextHelper> ssl_context_helper_; | 221 scoped_refptr<SSLContextHelper> ssl_context_helper_; |
127 | 222 |
| 223 // PendingHostCreator keeps track of a set of hosts that are being created |
| 224 // for a single request message from the renderer. See the body for its |
| 225 // definition. |
| 226 class PendingHostCreator; |
| 227 |
128 // Tracks all PP_Instances in this plugin and associated renderer-related | 228 // Tracks all PP_Instances in this plugin and associated renderer-related |
129 // data. | 229 // data. |
130 typedef std::map<PP_Instance, PepperRendererInstanceData> InstanceMap; | 230 typedef std::map<PP_Instance, InstanceData> InstanceMap; |
131 InstanceMap instance_map_; | 231 InstanceMap instance_map_; |
132 | 232 |
133 scoped_refptr<HostMessageFilter> message_filter_; | 233 scoped_refptr<HostMessageFilter> message_filter_; |
134 | 234 |
135 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_; | 235 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_; |
136 | 236 |
137 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); | 237 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); |
138 }; | 238 }; |
139 | 239 |
140 } // namespace content | 240 } // namespace content |
141 | 241 |
142 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ | 242 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ |
OLD | NEW |