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 | |
lazyboy
2013/01/17 17:39:25
Do we have a test that destroys BrowserPlugin befo
Fady Samuel
2013/01/17 18:40:38
Done. Added a test.
| |
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 if (!allocate_instance_id_in_flight_) { |
lazyboy
2013/01/17 17:39:25
I'd put a short version of your CL description as
Fady Samuel
2013/01/17 18:40:38
Done.
Fady Samuel
2013/01/17 18:40:38
Done.
Fady Samuel
2013/01/17 18:40:38
Done.
| |
227 create_guest_params.storage_partition_id = storage_partition_id_; | 237 browser_plugin_manager()->AllocateInstanceID(this); |
228 create_guest_params.persist_storage = persist_storage_; | 238 allocate_instance_id_in_flight_ = true; |
lazyboy
2013/01/17 17:39:25
more state booleans. possible cleanup opportunitie
Fady Samuel
2013/01/17 18:40:38
Agreed, there's room for cleanup here. mthiesse@ i
| |
229 create_guest_params.focused = ShouldGuestBeFocused(); | 239 } |
230 create_guest_params.visible = visible_; | 240 return true; |
231 create_guest_params.name = name_; | |
232 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | |
233 &create_guest_params.resize_guest_params); | |
234 browser_plugin_manager()->Send( | |
235 new BrowserPluginHostMsg_CreateGuest( | |
236 render_view_routing_id_, | |
237 instance_id_, | |
238 create_guest_params)); | |
239 } | 241 } |
240 | 242 |
241 browser_plugin_manager()->Send( | 243 browser_plugin_manager()->Send( |
242 new BrowserPluginHostMsg_NavigateGuest( | 244 new BrowserPluginHostMsg_NavigateGuest( |
243 render_view_routing_id_, | 245 render_view_routing_id_, |
244 instance_id_, | 246 instance_id_, |
245 src)); | 247 src)); |
246 // Record that we sent a NavigateGuest message to embedder. | |
lazyboy
2013/01/17 17:39:25
Keep this comment in OnAllocateInstanceIDResponse(
Fady Samuel
2013/01/17 18:40:38
Done.
| |
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; | 248 return true; |
252 } | 249 } |
253 | 250 |
254 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { | 251 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { |
255 if (auto_size_ == auto_size) | 252 if (auto_size_ == auto_size) |
256 return; | 253 return; |
257 auto_size_ = auto_size; | 254 auto_size_ = auto_size; |
258 last_view_size_ = plugin_rect_.size(); | 255 last_view_size_ = plugin_rect_.size(); |
259 UpdateGuestAutoSizeState(); | 256 UpdateGuestAutoSizeState(); |
260 } | 257 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 return params.damage_buffer_sequence_id != 0; | 304 return params.damage_buffer_sequence_id != 0; |
308 } | 305 } |
309 | 306 |
310 bool BrowserPlugin::UsesPendingDamageBuffer( | 307 bool BrowserPlugin::UsesPendingDamageBuffer( |
311 const BrowserPluginMsg_UpdateRect_Params& params) { | 308 const BrowserPluginMsg_UpdateRect_Params& params) { |
312 if (!pending_damage_buffer_.get()) | 309 if (!pending_damage_buffer_.get()) |
313 return false; | 310 return false; |
314 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; | 311 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
315 } | 312 } |
316 | 313 |
314 void BrowserPlugin::OnAllocateInstanceIDResponse(int request_id, | |
315 int instance_id) { | |
316 instance_id_ = instance_id; | |
317 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | |
318 | |
319 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | |
320 create_guest_params.storage_partition_id = storage_partition_id_; | |
321 create_guest_params.persist_storage = persist_storage_; | |
322 create_guest_params.focused = ShouldGuestBeFocused(); | |
323 create_guest_params.visible = visible_; | |
324 create_guest_params.name = name_; | |
325 create_guest_params.src = src_; | |
326 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | |
327 &create_guest_params.resize_guest_params); | |
328 browser_plugin_manager()->Send( | |
329 new BrowserPluginHostMsg_CreateGuest( | |
330 render_view_routing_id_, | |
331 instance_id_, | |
332 create_guest_params)); | |
333 | |
334 navigate_src_sent_ = true; | |
335 } | |
336 | |
317 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { | 337 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { |
318 DCHECK(render_view_); | 338 DCHECK(render_view_); |
319 render_view_->GetWebView()->advanceFocus(reverse); | 339 render_view_->GetWebView()->advanceFocus(reverse); |
320 } | 340 } |
321 | 341 |
322 void BrowserPlugin::OnBuffersSwapped(int instance_id, | 342 void BrowserPlugin::OnBuffersSwapped(int instance_id, |
323 const gfx::Size& size, | 343 const gfx::Size& size, |
324 std::string mailbox_name, | 344 std::string mailbox_name, |
325 int gpu_route_id, | 345 int gpu_route_id, |
326 int gpu_host_id) { | 346 int gpu_host_id) { |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 void* notify_data) { | 1106 void* notify_data) { |
1087 } | 1107 } |
1088 | 1108 |
1089 void BrowserPlugin::didFailLoadingFrameRequest( | 1109 void BrowserPlugin::didFailLoadingFrameRequest( |
1090 const WebKit::WebURL& url, | 1110 const WebKit::WebURL& url, |
1091 void* notify_data, | 1111 void* notify_data, |
1092 const WebKit::WebURLError& error) { | 1112 const WebKit::WebURLError& error) { |
1093 } | 1113 } |
1094 | 1114 |
1095 } // namespace content | 1115 } // namespace content |
OLD | NEW |