| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 guest_crashed_(false), | 120 guest_crashed_(false), |
| 121 auto_size_ack_pending_(false), | 121 auto_size_ack_pending_(false), |
| 122 persist_storage_(false), | 122 persist_storage_(false), |
| 123 valid_partition_id_(true), | 123 valid_partition_id_(true), |
| 124 content_window_routing_id_(MSG_ROUTING_NONE), | 124 content_window_routing_id_(MSG_ROUTING_NONE), |
| 125 plugin_focused_(false), | 125 plugin_focused_(false), |
| 126 visible_(true), | 126 visible_(true), |
| 127 size_changed_in_flight_(false), | 127 size_changed_in_flight_(false), |
| 128 before_first_navigation_(true), | 128 before_first_navigation_(true), |
| 129 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 129 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
| 130 current_nav_entry_index_(0), | |
| 131 nav_entry_count_(0), | |
| 132 compositing_enabled_(false), | 130 compositing_enabled_(false), |
| 133 weak_ptr_factory_(this) { | 131 weak_ptr_factory_(this) { |
| 134 } | 132 } |
| 135 | 133 |
| 136 BrowserPlugin::~BrowserPlugin() { | 134 BrowserPlugin::~BrowserPlugin() { |
| 137 // If the BrowserPlugin has never navigated then the browser process and | 135 // If the BrowserPlugin has never navigated then the browser process and |
| 138 // BrowserPluginManager don't know about it and so there is nothing to do | 136 // BrowserPluginManager don't know about it and so there is nothing to do |
| 139 // here. | 137 // here. |
| 140 if (!HasGuestInstanceID()) | 138 if (!HasGuestInstanceID()) |
| 141 return; | 139 return; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 576 } |
| 579 | 577 |
| 580 void BrowserPlugin::OnLoadCommit( | 578 void BrowserPlugin::OnLoadCommit( |
| 581 int guest_instance_id, | 579 int guest_instance_id, |
| 582 const BrowserPluginMsg_LoadCommit_Params& params) { | 580 const BrowserPluginMsg_LoadCommit_Params& params) { |
| 583 // If the guest has just committed a new navigation then it is no longer | 581 // If the guest has just committed a new navigation then it is no longer |
| 584 // crashed. | 582 // crashed. |
| 585 guest_crashed_ = false; | 583 guest_crashed_ = false; |
| 586 if (params.is_top_level) | 584 if (params.is_top_level) |
| 587 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); | 585 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); |
| 588 | |
| 589 current_nav_entry_index_ = params.current_entry_index; | |
| 590 nav_entry_count_ = params.entry_count; | |
| 591 } | 586 } |
| 592 | 587 |
| 593 void BrowserPlugin::OnLoadHandlerCalled(int guest_instance_id) { | 588 void BrowserPlugin::OnLoadHandlerCalled(int guest_instance_id) { |
| 594 TriggerEvent(browser_plugin::kEventContentLoad, NULL); | 589 TriggerEvent(browser_plugin::kEventContentLoad, NULL); |
| 595 } | 590 } |
| 596 | 591 |
| 597 void BrowserPlugin::OnLoadRedirect(int guest_instance_id, | 592 void BrowserPlugin::OnLoadRedirect(int guest_instance_id, |
| 598 const GURL& old_url, | 593 const GURL& old_url, |
| 599 const GURL& new_url, | 594 const GURL& new_url, |
| 600 bool is_top_level) { | 595 bool is_top_level) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 } | 877 } |
| 883 | 878 |
| 884 bool BrowserPlugin::HasNavigated() const { | 879 bool BrowserPlugin::HasNavigated() const { |
| 885 return !before_first_navigation_; | 880 return !before_first_navigation_; |
| 886 } | 881 } |
| 887 | 882 |
| 888 bool BrowserPlugin::HasGuestInstanceID() const { | 883 bool BrowserPlugin::HasGuestInstanceID() const { |
| 889 return guest_instance_id_ != browser_plugin::kInstanceIDNone; | 884 return guest_instance_id_ != browser_plugin::kInstanceIDNone; |
| 890 } | 885 } |
| 891 | 886 |
| 892 bool BrowserPlugin::CanGoBack() const { | |
| 893 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; | |
| 894 } | |
| 895 | |
| 896 bool BrowserPlugin::CanGoForward() const { | |
| 897 return current_nav_entry_index_ >= 0 && | |
| 898 current_nav_entry_index_ < (nav_entry_count_ - 1); | |
| 899 } | |
| 900 | |
| 901 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { | 887 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { |
| 902 if (HasNavigated()) { | 888 if (HasNavigated()) { |
| 903 *error_message = browser_plugin::kErrorAlreadyNavigated; | 889 *error_message = browser_plugin::kErrorAlreadyNavigated; |
| 904 return false; | 890 return false; |
| 905 } | 891 } |
| 906 | 892 |
| 907 std::string input = GetPartitionAttribute(); | 893 std::string input = GetPartitionAttribute(); |
| 908 | 894 |
| 909 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | 895 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
| 910 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | 896 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 // Note that we are using weak pointer for the following PostTask, so we | 1045 // Note that we are using weak pointer for the following PostTask, so we |
| 1060 // don't need to worry about BrowserPlugin going away. | 1046 // don't need to worry about BrowserPlugin going away. |
| 1061 base::MessageLoop::current()->PostTask( | 1047 base::MessageLoop::current()->PostTask( |
| 1062 FROM_HERE, | 1048 FROM_HERE, |
| 1063 base::Bind(&BrowserPlugin::OnRequestObjectGarbageCollected, | 1049 base::Bind(&BrowserPlugin::OnRequestObjectGarbageCollected, |
| 1064 plugin, | 1050 plugin, |
| 1065 request_id)); | 1051 request_id)); |
| 1066 } | 1052 } |
| 1067 } | 1053 } |
| 1068 | 1054 |
| 1069 void BrowserPlugin::Back() { | |
| 1070 if (!HasGuestInstanceID()) | |
| 1071 return; | |
| 1072 browser_plugin_manager()->Send( | |
| 1073 new BrowserPluginHostMsg_Go(render_view_routing_id_, | |
| 1074 guest_instance_id_, -1)); | |
| 1075 } | |
| 1076 | |
| 1077 void BrowserPlugin::Forward() { | |
| 1078 if (!HasGuestInstanceID()) | |
| 1079 return; | |
| 1080 browser_plugin_manager()->Send( | |
| 1081 new BrowserPluginHostMsg_Go(render_view_routing_id_, | |
| 1082 guest_instance_id_, 1)); | |
| 1083 } | |
| 1084 | |
| 1085 void BrowserPlugin::Go(int relative_index) { | |
| 1086 if (!HasGuestInstanceID()) | |
| 1087 return; | |
| 1088 browser_plugin_manager()->Send( | |
| 1089 new BrowserPluginHostMsg_Go(render_view_routing_id_, | |
| 1090 guest_instance_id_, | |
| 1091 relative_index)); | |
| 1092 } | |
| 1093 | |
| 1094 void BrowserPlugin::TerminateGuest() { | 1055 void BrowserPlugin::TerminateGuest() { |
| 1095 if (!HasGuestInstanceID() || guest_crashed_) | 1056 if (!HasGuestInstanceID() || guest_crashed_) |
| 1096 return; | 1057 return; |
| 1097 browser_plugin_manager()->Send( | 1058 browser_plugin_manager()->Send( |
| 1098 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, | 1059 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, |
| 1099 guest_instance_id_)); | 1060 guest_instance_id_)); |
| 1100 } | 1061 } |
| 1101 | 1062 |
| 1102 void BrowserPlugin::Stop() { | 1063 void BrowserPlugin::Stop() { |
| 1103 if (!HasGuestInstanceID()) | 1064 if (!HasGuestInstanceID()) |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 const WebKit::WebMouseEvent& event) { | 1598 const WebKit::WebMouseEvent& event) { |
| 1638 browser_plugin_manager()->Send( | 1599 browser_plugin_manager()->Send( |
| 1639 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1600 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1640 guest_instance_id_, | 1601 guest_instance_id_, |
| 1641 plugin_rect_, | 1602 plugin_rect_, |
| 1642 &event)); | 1603 &event)); |
| 1643 return true; | 1604 return true; |
| 1644 } | 1605 } |
| 1645 | 1606 |
| 1646 } // namespace content | 1607 } // namespace content |
| OLD | NEW |