| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 guest_crashed_(false), | 134 guest_crashed_(false), |
| 135 auto_size_ack_pending_(false), | 135 auto_size_ack_pending_(false), |
| 136 guest_process_id_(-1), | 136 guest_process_id_(-1), |
| 137 guest_route_id_(-1), | 137 guest_route_id_(-1), |
| 138 persist_storage_(false), | 138 persist_storage_(false), |
| 139 valid_partition_id_(true), | 139 valid_partition_id_(true), |
| 140 content_window_routing_id_(MSG_ROUTING_NONE), | 140 content_window_routing_id_(MSG_ROUTING_NONE), |
| 141 plugin_focused_(false), | 141 plugin_focused_(false), |
| 142 visible_(true), | 142 visible_(true), |
| 143 size_changed_in_flight_(false), | 143 size_changed_in_flight_(false), |
| 144 allocate_instance_id_sent_(false), | 144 before_first_navigation_(true), |
| 145 browser_plugin_manager_(render_view->browser_plugin_manager()), | 145 browser_plugin_manager_(render_view->browser_plugin_manager()), |
| 146 current_nav_entry_index_(0), | 146 current_nav_entry_index_(0), |
| 147 nav_entry_count_(0), | 147 nav_entry_count_(0), |
| 148 compositing_enabled_(false), | 148 compositing_enabled_(false), |
| 149 ALLOW_THIS_IN_INITIALIZER_LIST( | 149 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 150 weak_ptr_factory_(this)) { | 150 weak_ptr_factory_(this)) { |
| 151 } | 151 } |
| 152 | 152 |
| 153 BrowserPlugin::~BrowserPlugin() { | 153 BrowserPlugin::~BrowserPlugin() { |
| 154 // If the BrowserPlugin has never navigated then the browser process and | 154 // If the BrowserPlugin has never navigated then the browser process and |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 WebKit::WebPluginContainer* container) { | 167 WebKit::WebPluginContainer* container) { |
| 168 PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer(); | 168 PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer(); |
| 169 PluginContainerMap::iterator it = browser_plugins->find(container); | 169 PluginContainerMap::iterator it = browser_plugins->find(container); |
| 170 return it == browser_plugins->end() ? NULL : it->second; | 170 return it == browser_plugins->end() ? NULL : it->second; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 173 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
| 174 bool handled = true; | 174 bool handled = true; |
| 175 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 175 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
| 176 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 176 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
| 177 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) |
| 177 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 178 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
| 178 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, | 179 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, |
| 179 OnCompositorFrameSwapped(message)) | 180 OnCompositorFrameSwapped(message)) |
| 180 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 181 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
| 181 OnGuestContentWindowReady) | 182 OnGuestContentWindowReady) |
| 182 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 183 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
| 183 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | 184 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
| 184 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) | 185 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) |
| 185 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | 186 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
| 186 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | 187 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 std::string src = GetSrcAttribute(); | 330 std::string src = GetSrcAttribute(); |
| 330 if (src.empty()) | 331 if (src.empty()) |
| 331 return true; | 332 return true; |
| 332 | 333 |
| 333 // If we haven't created the guest yet, do so now. We will navigate it right | 334 // If we haven't created the guest yet, do so now. We will navigate it right |
| 334 // after creation. If |src| is empty, we can delay the creation until we | 335 // after creation. If |src| is empty, we can delay the creation until we |
| 335 // actually need it. | 336 // actually need it. |
| 336 if (!HasGuest()) { | 337 if (!HasGuest()) { |
| 337 // On initial navigation, we request an instance ID from the browser | 338 // On initial navigation, we request an instance ID from the browser |
| 338 // process. We essentially ignore all subsequent calls to SetSrcAttribute | 339 // process. We essentially ignore all subsequent calls to SetSrcAttribute |
| 339 // until we receive an instance ID. |allocate_instance_id_sent_| | 340 // until we receive an instance ID. |before_first_navigation_| |
| 340 // prevents BrowserPlugin from allocating more than one instance ID. | 341 // prevents BrowserPlugin from allocating more than one instance ID. |
| 341 // Upon receiving an instance ID from the browser process, we continue | 342 // Upon receiving an instance ID from the browser process, we continue |
| 342 // the process of navigation by populating the | 343 // the process of navigation by populating the |
| 343 // BrowserPluginHostMsg_CreateGuest_Params with the current state of | 344 // BrowserPluginHostMsg_CreateGuest_Params with the current state of |
| 344 // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the | 345 // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the |
| 345 // browser process in order to create a new guest. | 346 // browser process in order to create a new guest. |
| 346 if (!allocate_instance_id_sent_) { | 347 if (before_first_navigation_) { |
| 347 browser_plugin_manager()->AllocateInstanceID(this); | 348 browser_plugin_manager()->AllocateInstanceID(this); |
| 348 allocate_instance_id_sent_ = true; | 349 before_first_navigation_ = false; |
| 349 } | 350 } |
| 350 return true; | 351 return true; |
| 351 } | 352 } |
| 352 | 353 |
| 353 browser_plugin_manager()->Send( | 354 browser_plugin_manager()->Send( |
| 354 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, | 355 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, |
| 355 instance_id_, | 356 instance_id_, |
| 356 src)); | 357 src)); |
| 357 return true; | 358 return true; |
| 358 } | 359 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 418 |
| 418 bool BrowserPlugin::UsesPendingDamageBuffer( | 419 bool BrowserPlugin::UsesPendingDamageBuffer( |
| 419 const BrowserPluginMsg_UpdateRect_Params& params) { | 420 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 420 if (!pending_damage_buffer_.get()) | 421 if (!pending_damage_buffer_.get()) |
| 421 return false; | 422 return false; |
| 422 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; | 423 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
| 423 } | 424 } |
| 424 | 425 |
| 425 void BrowserPlugin::SetInstanceID(int instance_id, bool new_guest) { | 426 void BrowserPlugin::SetInstanceID(int instance_id, bool new_guest) { |
| 426 CHECK(instance_id != browser_plugin::kInstanceIDNone); | 427 CHECK(instance_id != browser_plugin::kInstanceIDNone); |
| 428 before_first_navigation_ = false; |
| 427 instance_id_ = instance_id; | 429 instance_id_ = instance_id; |
| 428 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | 430 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); |
| 429 | 431 |
| 430 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 432 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; |
| 431 create_guest_params.focused = ShouldGuestBeFocused(); | 433 create_guest_params.focused = ShouldGuestBeFocused(); |
| 432 create_guest_params.visible = visible_; | 434 create_guest_params.visible = visible_; |
| 433 create_guest_params.name = GetNameAttribute(); | 435 create_guest_params.name = GetNameAttribute(); |
| 434 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 436 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, |
| 435 &create_guest_params.resize_guest_params); | 437 &create_guest_params.resize_guest_params); |
| 436 | 438 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 453 void BrowserPlugin::DidCommitCompositorFrame() { | 455 void BrowserPlugin::DidCommitCompositorFrame() { |
| 454 if (compositing_helper_) | 456 if (compositing_helper_) |
| 455 compositing_helper_->DidCommitCompositorFrame(); | 457 compositing_helper_->DidCommitCompositorFrame(); |
| 456 } | 458 } |
| 457 | 459 |
| 458 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { | 460 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { |
| 459 DCHECK(render_view_); | 461 DCHECK(render_view_); |
| 460 render_view_->GetWebView()->advanceFocus(reverse); | 462 render_view_->GetWebView()->advanceFocus(reverse); |
| 461 } | 463 } |
| 462 | 464 |
| 465 void BrowserPlugin::OnAttachACK( |
| 466 int instance_id, |
| 467 const BrowserPluginMsg_Attach_ACK_Params& params) { |
| 468 // Update BrowserPlugin attributes to match the state of the guest. |
| 469 if (!params.name.empty()) |
| 470 OnUpdatedName(instance_id, params.name); |
| 471 if (!params.storage_partition_id.empty()) { |
| 472 std::string partition_name = |
| 473 (params.persist_storage ? browser_plugin::kPersistPrefix : "") + |
| 474 params.storage_partition_id; |
| 475 UpdateDOMAttribute(browser_plugin::kAttributePartition, partition_name); |
| 476 } |
| 477 } |
| 478 |
| 463 void BrowserPlugin::OnBuffersSwapped(int instance_id, | 479 void BrowserPlugin::OnBuffersSwapped(int instance_id, |
| 464 const gfx::Size& size, | 480 const gfx::Size& size, |
| 465 std::string mailbox_name, | 481 std::string mailbox_name, |
| 466 int gpu_route_id, | 482 int gpu_route_id, |
| 467 int gpu_host_id) { | 483 int gpu_host_id) { |
| 468 DCHECK(instance_id == instance_id_); | 484 DCHECK(instance_id == instance_id_); |
| 469 EnableCompositing(true); | 485 EnableCompositing(true); |
| 470 | 486 |
| 471 compositing_helper_->OnBuffersSwapped(size, | 487 compositing_helper_->OnBuffersSwapped(size, |
| 472 mailbox_name, | 488 mailbox_name, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 bool BrowserPlugin::CanGoBack() const { | 859 bool BrowserPlugin::CanGoBack() const { |
| 844 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; | 860 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; |
| 845 } | 861 } |
| 846 | 862 |
| 847 bool BrowserPlugin::CanGoForward() const { | 863 bool BrowserPlugin::CanGoForward() const { |
| 848 return current_nav_entry_index_ >= 0 && | 864 return current_nav_entry_index_ >= 0 && |
| 849 current_nav_entry_index_ < (nav_entry_count_ - 1); | 865 current_nav_entry_index_ < (nav_entry_count_ - 1); |
| 850 } | 866 } |
| 851 | 867 |
| 852 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { | 868 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { |
| 853 if (allocate_instance_id_sent_) { | 869 if (!before_first_navigation_) { |
| 854 *error_message = browser_plugin::kErrorAlreadyNavigated; | 870 *error_message = browser_plugin::kErrorAlreadyNavigated; |
| 855 return false; | 871 return false; |
| 856 } | 872 } |
| 857 | 873 |
| 858 std::string input = GetPartitionAttribute(); | 874 std::string input = GetPartitionAttribute(); |
| 859 | 875 |
| 860 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | 876 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
| 861 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | 877 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely |
| 862 // remove the prefix without splicing in the middle of a multi-byte codepoint. | 878 // remove the prefix without splicing in the middle of a multi-byte codepoint. |
| 863 // We can use the rest of the string as UTF-8 encoded one. | 879 // We can use the rest of the string as UTF-8 encoded one. |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 if (container_) | 1254 if (container_) |
| 1239 return container_->windowToLocalPoint(WebKit::WebPoint(point)); | 1255 return container_->windowToLocalPoint(WebKit::WebPoint(point)); |
| 1240 return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); | 1256 return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); |
| 1241 } | 1257 } |
| 1242 | 1258 |
| 1243 // static | 1259 // static |
| 1244 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 1260 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
| 1245 const IPC::Message& message) { | 1261 const IPC::Message& message) { |
| 1246 switch (message.type()) { | 1262 switch (message.type()) { |
| 1247 case BrowserPluginMsg_AdvanceFocus::ID: | 1263 case BrowserPluginMsg_AdvanceFocus::ID: |
| 1264 case BrowserPluginMsg_Attach_ACK::ID: |
| 1248 case BrowserPluginMsg_BuffersSwapped::ID: | 1265 case BrowserPluginMsg_BuffersSwapped::ID: |
| 1249 case BrowserPluginMsg_CompositorFrameSwapped::ID: | 1266 case BrowserPluginMsg_CompositorFrameSwapped::ID: |
| 1250 case BrowserPluginMsg_GuestContentWindowReady::ID: | 1267 case BrowserPluginMsg_GuestContentWindowReady::ID: |
| 1251 case BrowserPluginMsg_GuestGone::ID: | 1268 case BrowserPluginMsg_GuestGone::ID: |
| 1252 case BrowserPluginMsg_GuestResponsive::ID: | 1269 case BrowserPluginMsg_GuestResponsive::ID: |
| 1253 case BrowserPluginMsg_GuestUnresponsive::ID: | 1270 case BrowserPluginMsg_GuestUnresponsive::ID: |
| 1254 case BrowserPluginMsg_LoadAbort::ID: | 1271 case BrowserPluginMsg_LoadAbort::ID: |
| 1255 case BrowserPluginMsg_LoadCommit::ID: | 1272 case BrowserPluginMsg_LoadCommit::ID: |
| 1256 case BrowserPluginMsg_LoadRedirect::ID: | 1273 case BrowserPluginMsg_LoadRedirect::ID: |
| 1257 case BrowserPluginMsg_LoadStart::ID: | 1274 case BrowserPluginMsg_LoadStart::ID: |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 const WebKit::WebMouseEvent& event) { | 1536 const WebKit::WebMouseEvent& event) { |
| 1520 browser_plugin_manager()->Send( | 1537 browser_plugin_manager()->Send( |
| 1521 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1538 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1522 instance_id_, | 1539 instance_id_, |
| 1523 plugin_rect_, | 1540 plugin_rect_, |
| 1524 &event)); | 1541 &event)); |
| 1525 return true; | 1542 return true; |
| 1526 } | 1543 } |
| 1527 | 1544 |
| 1528 } // namespace content | 1545 } // namespace content |
| OLD | NEW |