| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 565 } |
| 568 | 566 |
| 569 void BrowserPlugin::OnLoadCommit( | 567 void BrowserPlugin::OnLoadCommit( |
| 570 int guest_instance_id, | 568 int guest_instance_id, |
| 571 const BrowserPluginMsg_LoadCommit_Params& params) { | 569 const BrowserPluginMsg_LoadCommit_Params& params) { |
| 572 // If the guest has just committed a new navigation then it is no longer | 570 // If the guest has just committed a new navigation then it is no longer |
| 573 // crashed. | 571 // crashed. |
| 574 guest_crashed_ = false; | 572 guest_crashed_ = false; |
| 575 if (params.is_top_level) | 573 if (params.is_top_level) |
| 576 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); | 574 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); |
| 577 | |
| 578 current_nav_entry_index_ = params.current_entry_index; | |
| 579 nav_entry_count_ = params.entry_count; | |
| 580 } | 575 } |
| 581 | 576 |
| 582 void BrowserPlugin::OnLoadHandlerCalled(int guest_instance_id) { | 577 void BrowserPlugin::OnLoadHandlerCalled(int guest_instance_id) { |
| 583 TriggerEvent(browser_plugin::kEventContentLoad, NULL); | 578 TriggerEvent(browser_plugin::kEventContentLoad, NULL); |
| 584 } | 579 } |
| 585 | 580 |
| 586 void BrowserPlugin::OnLoadRedirect(int guest_instance_id, | 581 void BrowserPlugin::OnLoadRedirect(int guest_instance_id, |
| 587 const GURL& old_url, | 582 const GURL& old_url, |
| 588 const GURL& new_url, | 583 const GURL& new_url, |
| 589 bool is_top_level) { | 584 bool is_top_level) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 } | 866 } |
| 872 | 867 |
| 873 bool BrowserPlugin::HasNavigated() const { | 868 bool BrowserPlugin::HasNavigated() const { |
| 874 return !before_first_navigation_; | 869 return !before_first_navigation_; |
| 875 } | 870 } |
| 876 | 871 |
| 877 bool BrowserPlugin::HasGuestInstanceID() const { | 872 bool BrowserPlugin::HasGuestInstanceID() const { |
| 878 return guest_instance_id_ != browser_plugin::kInstanceIDNone; | 873 return guest_instance_id_ != browser_plugin::kInstanceIDNone; |
| 879 } | 874 } |
| 880 | 875 |
| 881 bool BrowserPlugin::CanGoBack() const { | |
| 882 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; | |
| 883 } | |
| 884 | |
| 885 bool BrowserPlugin::CanGoForward() const { | |
| 886 return current_nav_entry_index_ >= 0 && | |
| 887 current_nav_entry_index_ < (nav_entry_count_ - 1); | |
| 888 } | |
| 889 | |
| 890 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { | 876 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { |
| 891 if (HasNavigated()) { | 877 if (HasNavigated()) { |
| 892 *error_message = browser_plugin::kErrorAlreadyNavigated; | 878 *error_message = browser_plugin::kErrorAlreadyNavigated; |
| 893 return false; | 879 return false; |
| 894 } | 880 } |
| 895 | 881 |
| 896 std::string input = GetPartitionAttribute(); | 882 std::string input = GetPartitionAttribute(); |
| 897 | 883 |
| 898 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | 884 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
| 899 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | 885 // 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... |
| 1048 // Note that we are using weak pointer for the following PostTask, so we | 1034 // Note that we are using weak pointer for the following PostTask, so we |
| 1049 // don't need to worry about BrowserPlugin going away. | 1035 // don't need to worry about BrowserPlugin going away. |
| 1050 base::MessageLoop::current()->PostTask( | 1036 base::MessageLoop::current()->PostTask( |
| 1051 FROM_HERE, | 1037 FROM_HERE, |
| 1052 base::Bind(&BrowserPlugin::OnRequestObjectGarbageCollected, | 1038 base::Bind(&BrowserPlugin::OnRequestObjectGarbageCollected, |
| 1053 plugin, | 1039 plugin, |
| 1054 request_id)); | 1040 request_id)); |
| 1055 } | 1041 } |
| 1056 } | 1042 } |
| 1057 | 1043 |
| 1058 void BrowserPlugin::Back() { | |
| 1059 if (!HasGuestInstanceID()) | |
| 1060 return; | |
| 1061 browser_plugin_manager()->Send( | |
| 1062 new BrowserPluginHostMsg_Go(render_view_routing_id_, | |
| 1063 guest_instance_id_, -1)); | |
| 1064 } | |
| 1065 | |
| 1066 void BrowserPlugin::Forward() { | |
| 1067 if (!HasGuestInstanceID()) | |
| 1068 return; | |
| 1069 browser_plugin_manager()->Send( | |
| 1070 new BrowserPluginHostMsg_Go(render_view_routing_id_, | |
| 1071 guest_instance_id_, 1)); | |
| 1072 } | |
| 1073 | |
| 1074 void BrowserPlugin::Go(int relative_index) { | |
| 1075 if (!HasGuestInstanceID()) | |
| 1076 return; | |
| 1077 browser_plugin_manager()->Send( | |
| 1078 new BrowserPluginHostMsg_Go(render_view_routing_id_, | |
| 1079 guest_instance_id_, | |
| 1080 relative_index)); | |
| 1081 } | |
| 1082 | |
| 1083 void BrowserPlugin::TerminateGuest() { | 1044 void BrowserPlugin::TerminateGuest() { |
| 1084 if (!HasGuestInstanceID() || guest_crashed_) | 1045 if (!HasGuestInstanceID() || guest_crashed_) |
| 1085 return; | 1046 return; |
| 1086 browser_plugin_manager()->Send( | 1047 browser_plugin_manager()->Send( |
| 1087 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, | 1048 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, |
| 1088 guest_instance_id_)); | 1049 guest_instance_id_)); |
| 1089 } | 1050 } |
| 1090 | 1051 |
| 1091 void BrowserPlugin::Stop() { | 1052 void BrowserPlugin::Stop() { |
| 1092 if (!HasGuestInstanceID()) | 1053 if (!HasGuestInstanceID()) |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 const WebKit::WebMouseEvent& event) { | 1587 const WebKit::WebMouseEvent& event) { |
| 1627 browser_plugin_manager()->Send( | 1588 browser_plugin_manager()->Send( |
| 1628 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1589 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1629 guest_instance_id_, | 1590 guest_instance_id_, |
| 1630 plugin_rect_, | 1591 plugin_rect_, |
| 1631 &event)); | 1592 &event)); |
| 1632 return true; | 1593 return true; |
| 1633 } | 1594 } |
| 1634 | 1595 |
| 1635 } // namespace content | 1596 } // namespace content |
| OLD | NEW |