| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 const char kEventLoadCommit[] = "loadcommit"; | 53 const char kEventLoadCommit[] = "loadcommit"; |
| 54 const char kEventLoadRedirect[] = "loadredirect"; | 54 const char kEventLoadRedirect[] = "loadredirect"; |
| 55 const char kEventLoadStart[] = "loadstart"; | 55 const char kEventLoadStart[] = "loadstart"; |
| 56 const char kEventLoadStop[] = "loadstop"; | 56 const char kEventLoadStop[] = "loadstop"; |
| 57 const char kEventResponsive[] = "responsive"; | 57 const char kEventResponsive[] = "responsive"; |
| 58 const char kEventSizeChanged[] = "sizechanged"; | 58 const char kEventSizeChanged[] = "sizechanged"; |
| 59 const char kEventUnresponsive[] = "unresponsive"; | 59 const char kEventUnresponsive[] = "unresponsive"; |
| 60 | 60 |
| 61 // Parameters/properties on events. | 61 // Parameters/properties on events. |
| 62 const char kIsTopLevel[] = "isTopLevel"; | 62 const char kIsTopLevel[] = "isTopLevel"; |
| 63 const char kName[] = "name"; |
| 63 const char kNewURL[] = "newUrl"; | 64 const char kNewURL[] = "newUrl"; |
| 64 const char kNewHeight[] = "newHeight"; | 65 const char kNewHeight[] = "newHeight"; |
| 65 const char kNewWidth[] = "newWidth"; | 66 const char kNewWidth[] = "newWidth"; |
| 66 const char kOldURL[] = "oldUrl"; | 67 const char kOldURL[] = "oldUrl"; |
| 67 const char kOldHeight[] = "oldHeight"; | 68 const char kOldHeight[] = "oldHeight"; |
| 68 const char kOldWidth[] = "oldWidth"; | 69 const char kOldWidth[] = "oldWidth"; |
| 69 const char kPartition[] = "partition"; | 70 const char kPartition[] = "partition"; |
| 70 const char kPersistPrefix[] = "persist:"; | 71 const char kPersistPrefix[] = "persist:"; |
| 71 const char kProcessId[] = "processId"; | 72 const char kProcessId[] = "processId"; |
| 72 const char kReason[] = "reason"; | 73 const char kReason[] = "reason"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 instance_id_)); | 146 instance_id_)); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void BrowserPlugin::Cleanup() { | 149 void BrowserPlugin::Cleanup() { |
| 149 if (current_damage_buffer_) | 150 if (current_damage_buffer_) |
| 150 FreeDamageBuffer(¤t_damage_buffer_); | 151 FreeDamageBuffer(¤t_damage_buffer_); |
| 151 if (pending_damage_buffer_) | 152 if (pending_damage_buffer_) |
| 152 FreeDamageBuffer(&pending_damage_buffer_); | 153 FreeDamageBuffer(&pending_damage_buffer_); |
| 153 } | 154 } |
| 154 | 155 |
| 156 void BrowserPlugin::UpdateDOMAttribute( |
| 157 const std::string& attribute_name, |
| 158 const std::string& attribute_value) { |
| 159 if (!container()) |
| 160 return; |
| 161 |
| 162 WebKit::WebElement element = container()->element(); |
| 163 WebKit::WebString web_attribute_name = |
| 164 WebKit::WebString::fromUTF8(attribute_name); |
| 165 std::string current_value(element.getAttribute(web_attribute_name).utf8()); |
| 166 if (current_value == attribute_value) |
| 167 return; |
| 168 |
| 169 if (attribute_value.empty()) { |
| 170 element.removeAttribute(web_attribute_name); |
| 171 } else { |
| 172 element.setAttribute(web_attribute_name, |
| 173 WebKit::WebString::fromUTF8(attribute_value)); |
| 174 } |
| 175 } |
| 176 |
| 177 void BrowserPlugin::SetNameAttribute(const std::string& name) { |
| 178 if (name_ == name) |
| 179 return; |
| 180 |
| 181 name_ = name; |
| 182 if (!navigate_src_sent_) |
| 183 return; |
| 184 |
| 185 browser_plugin_manager()->Send( |
| 186 new BrowserPluginHostMsg_SetName( |
| 187 render_view_routing_id_, |
| 188 instance_id_, |
| 189 name)); |
| 190 } |
| 191 |
| 155 bool BrowserPlugin::SetSrcAttribute(const std::string& src, | 192 bool BrowserPlugin::SetSrcAttribute(const std::string& src, |
| 156 std::string* error_message) { | 193 std::string* error_message) { |
| 157 if (!valid_partition_id_) { | 194 if (!valid_partition_id_) { |
| 158 *error_message = kErrorInvalidPartition; | 195 *error_message = kErrorInvalidPartition; |
| 159 return false; | 196 return false; |
| 160 } | 197 } |
| 161 | 198 |
| 162 if (src.empty() || (src == src_ && !guest_crashed_)) | 199 if (src.empty() || (src == src_ && !guest_crashed_)) |
| 163 return true; | 200 return true; |
| 164 | 201 |
| 165 // If we haven't created the guest yet, do so now. We will navigate it right | 202 // If we haven't created the guest yet, do so now. We will navigate it right |
| 166 // after creation. If |src| is empty, we can delay the creation until we | 203 // after creation. If |src| is empty, we can delay the creation until we |
| 167 // acutally need it. | 204 // acutally need it. |
| 168 if (!navigate_src_sent_) { | 205 if (!navigate_src_sent_) { |
| 169 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 206 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; |
| 170 create_guest_params.storage_partition_id = storage_partition_id_; | 207 create_guest_params.storage_partition_id = storage_partition_id_; |
| 171 create_guest_params.persist_storage = persist_storage_; | 208 create_guest_params.persist_storage = persist_storage_; |
| 172 create_guest_params.focused = ShouldGuestBeFocused(); | 209 create_guest_params.focused = ShouldGuestBeFocused(); |
| 173 create_guest_params.visible = visible_; | 210 create_guest_params.visible = visible_; |
| 211 create_guest_params.name = name_; |
| 174 pending_damage_buffer_ = | 212 pending_damage_buffer_ = |
| 175 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 213 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, |
| 176 &create_guest_params.resize_guest_params); | 214 &create_guest_params.resize_guest_params); |
| 177 browser_plugin_manager()->Send( | 215 browser_plugin_manager()->Send( |
| 178 new BrowserPluginHostMsg_CreateGuest( | 216 new BrowserPluginHostMsg_CreateGuest( |
| 179 render_view_routing_id_, | 217 render_view_routing_id_, |
| 180 instance_id_, | 218 instance_id_, |
| 181 create_guest_params)); | 219 create_guest_params)); |
| 182 } | 220 } |
| 183 | 221 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 #else | 293 #else |
| 256 bool BrowserPlugin::DamageBufferMatches( | 294 bool BrowserPlugin::DamageBufferMatches( |
| 257 const TransportDIB* damage_buffer, | 295 const TransportDIB* damage_buffer, |
| 258 const TransportDIB::Handle& other_damage_buffer_handle) { | 296 const TransportDIB::Handle& other_damage_buffer_handle) { |
| 259 if (!damage_buffer) | 297 if (!damage_buffer) |
| 260 return false; | 298 return false; |
| 261 return damage_buffer->handle() == other_damage_buffer_handle; | 299 return damage_buffer->handle() == other_damage_buffer_handle; |
| 262 } | 300 } |
| 263 #endif | 301 #endif |
| 264 | 302 |
| 265 void BrowserPlugin::UpdateDOMAttribute( | |
| 266 const std::string& attribute_name, | |
| 267 const std::string& attribute_value) { | |
| 268 if (!container()) | |
| 269 return; | |
| 270 | |
| 271 WebKit::WebElement element = container()->element(); | |
| 272 WebKit::WebString web_attribute_name = | |
| 273 WebKit::WebString::fromUTF8(attribute_name); | |
| 274 std::string current_value(element.getAttribute(web_attribute_name).utf8()); | |
| 275 if (current_value == attribute_value) | |
| 276 return; | |
| 277 | |
| 278 if (attribute_value.empty()) { | |
| 279 element.removeAttribute(web_attribute_name); | |
| 280 } else { | |
| 281 element.setAttribute(web_attribute_name, | |
| 282 WebKit::WebString::fromUTF8(attribute_value)); | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { | 303 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { |
| 287 if (max_height_ == max_height) | 304 if (max_height_ == max_height) |
| 288 return; | 305 return; |
| 289 max_height_ = max_height; | 306 max_height_ = max_height; |
| 290 if (!auto_size_) | 307 if (!auto_size_) |
| 291 return; | 308 return; |
| 292 UpdateGuestAutoSizeState(); | 309 UpdateGuestAutoSizeState(); |
| 293 } | 310 } |
| 294 | 311 |
| 295 void BrowserPlugin::SetMaxWidthAttribute(int max_width) { | 312 void BrowserPlugin::SetMaxWidthAttribute(int max_width) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 std::string src; | 406 std::string src; |
| 390 | 407 |
| 391 // Get the src attribute from the attributes vector | 408 // Get the src attribute from the attributes vector |
| 392 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { | 409 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { |
| 393 std::string attributeName = params.attributeNames[i].utf8(); | 410 std::string attributeName = params.attributeNames[i].utf8(); |
| 394 if (LowerCaseEqualsASCII(attributeName, kSrc)) { | 411 if (LowerCaseEqualsASCII(attributeName, kSrc)) { |
| 395 src = params.attributeValues[i].utf8(); | 412 src = params.attributeValues[i].utf8(); |
| 396 } else if (LowerCaseEqualsASCII(attributeName, kPartition)) { | 413 } else if (LowerCaseEqualsASCII(attributeName, kPartition)) { |
| 397 std::string error; | 414 std::string error; |
| 398 SetPartitionAttribute(params.attributeValues[i].utf8(), &error); | 415 SetPartitionAttribute(params.attributeValues[i].utf8(), &error); |
| 416 } else if (LowerCaseEqualsASCII(attributeName, kName)) { |
| 417 SetNameAttribute(params.attributeValues[i].utf8()); |
| 399 } | 418 } |
| 400 } | 419 } |
| 401 | 420 |
| 402 // Set the 'src' attribute last, as it will set the has_navigated_ flag to | 421 // Set the 'src' attribute last, as it will set the has_navigated_ flag to |
| 403 // true, which prevents changing the 'partition' attribute. | 422 // true, which prevents changing the 'partition' attribute. |
| 404 std::string error; | 423 std::string error; |
| 405 SetSrcAttribute(src, &error); | 424 SetSrcAttribute(src, &error); |
| 406 } | 425 } |
| 407 | 426 |
| 408 float BrowserPlugin::GetDeviceScaleFactor() const { | 427 float BrowserPlugin::GetDeviceScaleFactor() const { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 void BrowserPlugin::LoadRedirect(const GURL& old_url, | 700 void BrowserPlugin::LoadRedirect(const GURL& old_url, |
| 682 const GURL& new_url, | 701 const GURL& new_url, |
| 683 bool is_top_level) { | 702 bool is_top_level) { |
| 684 std::map<std::string, base::Value*> props; | 703 std::map<std::string, base::Value*> props; |
| 685 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); | 704 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); |
| 686 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); | 705 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); |
| 687 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | 706 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 688 TriggerEvent(kEventLoadRedirect, &props); | 707 TriggerEvent(kEventLoadRedirect, &props); |
| 689 } | 708 } |
| 690 | 709 |
| 710 void BrowserPlugin::UpdatedName(const std::string& name) { |
| 711 name_ = name; |
| 712 UpdateDOMAttribute(kName, name); |
| 713 } |
| 714 |
| 691 void BrowserPlugin::AdvanceFocus(bool reverse) { | 715 void BrowserPlugin::AdvanceFocus(bool reverse) { |
| 692 DCHECK(render_view_); | 716 DCHECK(render_view_); |
| 693 render_view_->GetWebView()->advanceFocus(reverse); | 717 render_view_->GetWebView()->advanceFocus(reverse); |
| 694 } | 718 } |
| 695 | 719 |
| 696 void BrowserPlugin::SetEmbedderFocus(bool focused) { | 720 void BrowserPlugin::SetEmbedderFocus(bool focused) { |
| 697 if (embedder_focused_ == focused) | 721 if (embedder_focused_ == focused) |
| 698 return; | 722 return; |
| 699 | 723 |
| 700 bool old_guest_focus_state = ShouldGuestBeFocused(); | 724 bool old_guest_focus_state = ShouldGuestBeFocused(); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 void* notify_data) { | 1040 void* notify_data) { |
| 1017 } | 1041 } |
| 1018 | 1042 |
| 1019 void BrowserPlugin::didFailLoadingFrameRequest( | 1043 void BrowserPlugin::didFailLoadingFrameRequest( |
| 1020 const WebKit::WebURL& url, | 1044 const WebKit::WebURL& url, |
| 1021 void* notify_data, | 1045 void* notify_data, |
| 1022 const WebKit::WebURLError& error) { | 1046 const WebKit::WebURLError& error) { |
| 1023 } | 1047 } |
| 1024 | 1048 |
| 1025 } // namespace content | 1049 } // namespace content |
| OLD | NEW |