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 #include "content/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 using WebKit::WebPluginParams; | 41 using WebKit::WebPluginParams; |
42 using WebKit::WebPoint; | 42 using WebKit::WebPoint; |
43 using WebKit::WebRect; | 43 using WebKit::WebRect; |
44 using WebKit::WebURL; | 44 using WebKit::WebURL; |
45 using WebKit::WebVector; | 45 using WebKit::WebVector; |
46 | 46 |
47 namespace content { | 47 namespace content { |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 const int INSTANCE_ID_NONE = 0; | |
52 | |
51 // Events. | 53 // Events. |
52 const char kEventExit[] = "exit"; | 54 const char kEventExit[] = "exit"; |
53 const char kEventLoadAbort[] = "loadabort"; | 55 const char kEventLoadAbort[] = "loadabort"; |
54 const char kEventLoadCommit[] = "loadcommit"; | 56 const char kEventLoadCommit[] = "loadcommit"; |
55 const char kEventLoadRedirect[] = "loadredirect"; | 57 const char kEventLoadRedirect[] = "loadredirect"; |
56 const char kEventLoadStart[] = "loadstart"; | 58 const char kEventLoadStart[] = "loadstart"; |
57 const char kEventLoadStop[] = "loadstop"; | 59 const char kEventLoadStop[] = "loadstop"; |
58 const char kEventResponsive[] = "responsive"; | 60 const char kEventResponsive[] = "responsive"; |
59 const char kEventSizeChanged[] = "sizechanged"; | 61 const char kEventSizeChanged[] = "sizechanged"; |
60 const char kEventUnresponsive[] = "unresponsive"; | 62 const char kEventUnresponsive[] = "unresponsive"; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 NOTREACHED() << "Unknown Termination Status."; | 100 NOTREACHED() << "Unknown Termination Status."; |
99 return "unknown"; | 101 return "unknown"; |
100 } | 102 } |
101 | 103 |
102 static std::string GetInternalEventName(const char* event_name) { | 104 static std::string GetInternalEventName(const char* event_name) { |
103 return base::StringPrintf("-internal-%s", event_name); | 105 return base::StringPrintf("-internal-%s", event_name); |
104 } | 106 } |
105 } | 107 } |
106 | 108 |
107 BrowserPlugin::BrowserPlugin( | 109 BrowserPlugin::BrowserPlugin( |
108 int instance_id, | |
109 RenderViewImpl* render_view, | 110 RenderViewImpl* render_view, |
110 WebKit::WebFrame* frame, | 111 WebKit::WebFrame* frame, |
111 const WebPluginParams& params) | 112 const WebPluginParams& params) |
112 : instance_id_(instance_id), | 113 : instance_id_(INSTANCE_ID_NONE), |
113 render_view_(render_view->AsWeakPtr()), | 114 render_view_(render_view->AsWeakPtr()), |
114 render_view_routing_id_(render_view->GetRoutingID()), | 115 render_view_routing_id_(render_view->GetRoutingID()), |
115 container_(NULL), | 116 container_(NULL), |
116 damage_buffer_sequence_id_(0), | 117 damage_buffer_sequence_id_(0), |
117 resize_ack_received_(true), | 118 resize_ack_received_(true), |
118 sad_guest_(NULL), | 119 sad_guest_(NULL), |
119 guest_crashed_(false), | 120 guest_crashed_(false), |
120 navigate_src_sent_(false), | 121 navigate_src_sent_(false), |
121 auto_size_(false), | 122 auto_size_(false), |
122 max_height_(0), | 123 max_height_(0), |
123 max_width_(0), | 124 max_width_(0), |
124 min_height_(0), | 125 min_height_(0), |
125 min_width_(0), | 126 min_width_(0), |
126 process_id_(-1), | 127 process_id_(-1), |
127 persist_storage_(false), | 128 persist_storage_(false), |
128 valid_partition_id_(true), | 129 valid_partition_id_(true), |
129 content_window_routing_id_(MSG_ROUTING_NONE), | 130 content_window_routing_id_(MSG_ROUTING_NONE), |
130 plugin_focused_(false), | 131 plugin_focused_(false), |
131 visible_(true), | 132 visible_(true), |
132 size_changed_in_flight_(false), | 133 size_changed_in_flight_(false), |
134 allocate_instance_id_in_flight_(false), | |
133 browser_plugin_manager_(render_view->browser_plugin_manager()), | 135 browser_plugin_manager_(render_view->browser_plugin_manager()), |
134 current_nav_entry_index_(0), | 136 current_nav_entry_index_(0), |
135 nav_entry_count_(0), | 137 nav_entry_count_(0), |
136 compositing_enabled_(false) { | 138 compositing_enabled_(false) { |
137 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | |
138 bindings_.reset(new BrowserPluginBindings(this)); | 139 bindings_.reset(new BrowserPluginBindings(this)); |
139 | 140 |
140 ParseAttributes(params); | 141 ParseAttributes(params); |
141 } | 142 } |
142 | 143 |
143 BrowserPlugin::~BrowserPlugin() { | 144 BrowserPlugin::~BrowserPlugin() { |
145 // If the BrowserPlugin has never navigated then the browser process, and | |
Charlie Reis
2013/01/18 01:54:31
nit: no comma
Fady Samuel
2013/01/18 02:23:10
Done.
| |
146 // BrowserPluginManager don't know about it and so there is nothing to do | |
147 // here. | |
148 if (!navigate_src_sent_) | |
149 return; | |
144 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); | 150 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); |
145 browser_plugin_manager()->Send( | 151 browser_plugin_manager()->Send( |
146 new BrowserPluginHostMsg_PluginDestroyed( | 152 new BrowserPluginHostMsg_PluginDestroyed( |
147 render_view_routing_id_, | 153 render_view_routing_id_, |
148 instance_id_)); | 154 instance_id_)); |
149 } | 155 } |
150 | 156 |
151 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 157 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
152 bool handled = true; | 158 bool handled = true; |
153 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 159 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
154 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 160 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AllocateInstanceIDResponse, | |
162 OnAllocateInstanceIDResponse) | |
155 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 163 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
156 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 164 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
157 OnGuestContentWindowReady) | 165 OnGuestContentWindowReady) |
158 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 166 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
159 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | 167 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
160 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) | 168 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) |
161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | 169 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
162 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | 170 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
163 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) | 171 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) |
164 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) | 172 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 bool BrowserPlugin::SetSrcAttribute(const std::string& src, | 220 bool BrowserPlugin::SetSrcAttribute(const std::string& src, |
213 std::string* error_message) { | 221 std::string* error_message) { |
214 if (!valid_partition_id_) { | 222 if (!valid_partition_id_) { |
215 *error_message = kErrorInvalidPartition; | 223 *error_message = kErrorInvalidPartition; |
216 return false; | 224 return false; |
217 } | 225 } |
218 | 226 |
219 if (src.empty() || (src == src_ && !guest_crashed_)) | 227 if (src.empty() || (src == src_ && !guest_crashed_)) |
220 return true; | 228 return true; |
221 | 229 |
230 src_ = src; | |
231 | |
222 // If we haven't created the guest yet, do so now. We will navigate it right | 232 // If we haven't created the guest yet, do so now. We will navigate it right |
223 // after creation. If |src| is empty, we can delay the creation until we | 233 // after creation. If |src| is empty, we can delay the creation until we |
224 // actually need it. | 234 // actually need it. |
225 if (!navigate_src_sent_) { | 235 if (!navigate_src_sent_) { |
226 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 236 // On initial navigation, we request an instance ID from the browser |
227 create_guest_params.storage_partition_id = storage_partition_id_; | 237 // process. We essentially ignore all subsequent calls to SetSrcAttribute |
228 create_guest_params.persist_storage = persist_storage_; | 238 // until we receive an instance ID. |allocate_instance_id_in_flight_| |
229 create_guest_params.focused = ShouldGuestBeFocused(); | 239 // prevents BrowserPlugin from allocating more than one instance ID. |
230 create_guest_params.visible = visible_; | 240 // Upon receiving an instance ID from the browser process, we continue |
231 create_guest_params.name = name_; | 241 // the process of navigation by populating the |
232 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 242 // BrowserPluginHostMsg_CreateGuest_Params with the current state of |
233 &create_guest_params.resize_guest_params); | 243 // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the |
234 browser_plugin_manager()->Send( | 244 // browser process in order to create a new guest. |
235 new BrowserPluginHostMsg_CreateGuest( | 245 if (!allocate_instance_id_in_flight_) { |
236 render_view_routing_id_, | 246 browser_plugin_manager()->AllocateInstanceID(this); |
237 instance_id_, | 247 allocate_instance_id_in_flight_ = true; |
238 create_guest_params)); | 248 } |
249 return true; | |
239 } | 250 } |
240 | 251 |
241 browser_plugin_manager()->Send( | 252 browser_plugin_manager()->Send( |
242 new BrowserPluginHostMsg_NavigateGuest( | 253 new BrowserPluginHostMsg_NavigateGuest( |
243 render_view_routing_id_, | 254 render_view_routing_id_, |
244 instance_id_, | 255 instance_id_, |
245 src)); | 256 src)); |
246 // Record that we sent a NavigateGuest message to embedder. | |
247 // Once this instance has navigated, the storage partition cannot be changed, | |
248 // so this value is used for enforcing this. | |
249 navigate_src_sent_ = true; | |
250 src_ = src; | |
251 return true; | 257 return true; |
252 } | 258 } |
253 | 259 |
254 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { | 260 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { |
255 if (auto_size_ == auto_size) | 261 if (auto_size_ == auto_size) |
256 return; | 262 return; |
257 auto_size_ = auto_size; | 263 auto_size_ = auto_size; |
258 last_view_size_ = plugin_rect_.size(); | 264 last_view_size_ = plugin_rect_.size(); |
259 UpdateGuestAutoSizeState(); | 265 UpdateGuestAutoSizeState(); |
260 } | 266 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 return params.damage_buffer_sequence_id != 0; | 313 return params.damage_buffer_sequence_id != 0; |
308 } | 314 } |
309 | 315 |
310 bool BrowserPlugin::UsesPendingDamageBuffer( | 316 bool BrowserPlugin::UsesPendingDamageBuffer( |
311 const BrowserPluginMsg_UpdateRect_Params& params) { | 317 const BrowserPluginMsg_UpdateRect_Params& params) { |
312 if (!pending_damage_buffer_.get()) | 318 if (!pending_damage_buffer_.get()) |
313 return false; | 319 return false; |
314 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; | 320 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
315 } | 321 } |
316 | 322 |
323 void BrowserPlugin::OnAllocateInstanceIDResponse(int request_id, | |
324 int instance_id) { | |
325 instance_id_ = instance_id; | |
Charlie Reis
2013/01/18 01:54:31
Perhaps we should CHECK() that it isn't INSTANCE_I
Fady Samuel
2013/01/18 02:23:10
Done.
| |
326 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | |
327 | |
328 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | |
329 create_guest_params.storage_partition_id = storage_partition_id_; | |
330 create_guest_params.persist_storage = persist_storage_; | |
331 create_guest_params.focused = ShouldGuestBeFocused(); | |
332 create_guest_params.visible = visible_; | |
333 create_guest_params.name = name_; | |
334 create_guest_params.src = src_; | |
335 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | |
336 &create_guest_params.resize_guest_params); | |
337 browser_plugin_manager()->Send( | |
338 new BrowserPluginHostMsg_CreateGuest( | |
339 render_view_routing_id_, | |
340 instance_id_, | |
341 create_guest_params)); | |
342 | |
343 // Record that we sent a navigation request to the browser process. | |
344 // Once this instance has navigated, the storage partition cannot be changed, | |
345 // so this value is used for enforcing this. | |
346 navigate_src_sent_ = true; | |
347 } | |
348 | |
317 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { | 349 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { |
318 DCHECK(render_view_); | 350 DCHECK(render_view_); |
319 render_view_->GetWebView()->advanceFocus(reverse); | 351 render_view_->GetWebView()->advanceFocus(reverse); |
320 } | 352 } |
321 | 353 |
322 void BrowserPlugin::OnBuffersSwapped(int instance_id, | 354 void BrowserPlugin::OnBuffersSwapped(int instance_id, |
323 const gfx::Size& size, | 355 const gfx::Size& size, |
324 std::string mailbox_name, | 356 std::string mailbox_name, |
325 int gpu_route_id, | 357 int gpu_route_id, |
326 int gpu_host_id) { | 358 int gpu_host_id) { |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 void* notify_data) { | 1122 void* notify_data) { |
1091 } | 1123 } |
1092 | 1124 |
1093 void BrowserPlugin::didFailLoadingFrameRequest( | 1125 void BrowserPlugin::didFailLoadingFrameRequest( |
1094 const WebKit::WebURL& url, | 1126 const WebKit::WebURL& url, |
1095 void* notify_data, | 1127 void* notify_data, |
1096 const WebKit::WebURLError& error) { | 1128 const WebKit::WebURLError& error) { |
1097 } | 1129 } |
1098 | 1130 |
1099 } // namespace content | 1131 } // namespace content |
OLD | NEW |