| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 150 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
| 150 OnGuestContentWindowReady) | 151 OnGuestContentWindowReady) |
| 151 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 152 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
| 152 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | 153 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
| 153 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) | 154 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) |
| 154 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | 155 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
| 155 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | 156 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
| 156 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) | 157 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) |
| 157 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) | 158 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) |
| 158 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) | 159 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) |
| 160 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
| 159 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
| 160 OnShouldAcceptTouchEvents) | 162 OnShouldAcceptTouchEvents) |
| 161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 163 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
| 162 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | 164 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
| 163 IPC_MESSAGE_UNHANDLED(handled = false) | 165 IPC_MESSAGE_UNHANDLED(handled = false) |
| 164 IPC_END_MESSAGE_MAP() | 166 IPC_END_MESSAGE_MAP() |
| 165 return handled; | 167 return handled; |
| 166 } | 168 } |
| 167 | 169 |
| 168 void BrowserPlugin::UpdateDOMAttribute( | 170 void BrowserPlugin::UpdateDOMAttribute( |
| 169 const std::string& attribute_name, | 171 const std::string& attribute_name, |
| 170 const std::string& attribute_value) { | 172 const std::string& attribute_value) { |
| 171 if (!container()) | 173 if (!container()) |
| 172 return; | 174 return; |
| 173 | 175 |
| 174 WebKit::WebElement element = container()->element(); | 176 WebKit::WebElement element = container()->element(); |
| 175 WebKit::WebString web_attribute_name = | 177 WebKit::WebString web_attribute_name = |
| 176 WebKit::WebString::fromUTF8(attribute_name); | 178 WebKit::WebString::fromUTF8(attribute_name); |
| 177 std::string current_value(element.getAttribute(web_attribute_name).utf8()); | 179 std::string current_value(element.getAttribute(web_attribute_name).utf8()); |
| 178 if (current_value == attribute_value) | 180 if (current_value == attribute_value) |
| 179 return; | 181 return; |
| 180 | 182 |
| 181 if (attribute_value.empty()) { | 183 if (attribute_value.empty()) { |
| 182 element.removeAttribute(web_attribute_name); | 184 element.removeAttribute(web_attribute_name); |
| 183 } else { | 185 } else { |
| 184 element.setAttribute(web_attribute_name, | 186 element.setAttribute(web_attribute_name, |
| 185 WebKit::WebString::fromUTF8(attribute_value)); | 187 WebKit::WebString::fromUTF8(attribute_value)); |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 | 190 |
| 191 void BrowserPlugin::SetNameAttribute(const std::string& name) { |
| 192 if (name_ == name) |
| 193 return; |
| 194 |
| 195 name_ = name; |
| 196 if (!navigate_src_sent_) |
| 197 return; |
| 198 |
| 199 browser_plugin_manager()->Send( |
| 200 new BrowserPluginHostMsg_SetName( |
| 201 render_view_routing_id_, |
| 202 instance_id_, |
| 203 name)); |
| 204 } |
| 205 |
| 189 bool BrowserPlugin::SetSrcAttribute(const std::string& src, | 206 bool BrowserPlugin::SetSrcAttribute(const std::string& src, |
| 190 std::string* error_message) { | 207 std::string* error_message) { |
| 191 if (!valid_partition_id_) { | 208 if (!valid_partition_id_) { |
| 192 *error_message = kErrorInvalidPartition; | 209 *error_message = kErrorInvalidPartition; |
| 193 return false; | 210 return false; |
| 194 } | 211 } |
| 195 | 212 |
| 196 if (src.empty() || (src == src_ && !guest_crashed_)) | 213 if (src.empty() || (src == src_ && !guest_crashed_)) |
| 197 return true; | 214 return true; |
| 198 | 215 |
| 199 // If we haven't created the guest yet, do so now. We will navigate it right | 216 // If we haven't created the guest yet, do so now. We will navigate it right |
| 200 // after creation. If |src| is empty, we can delay the creation until we | 217 // after creation. If |src| is empty, we can delay the creation until we |
| 201 // actually need it. | 218 // actually need it. |
| 202 if (!navigate_src_sent_) { | 219 if (!navigate_src_sent_) { |
| 203 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 220 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; |
| 204 create_guest_params.storage_partition_id = storage_partition_id_; | 221 create_guest_params.storage_partition_id = storage_partition_id_; |
| 205 create_guest_params.persist_storage = persist_storage_; | 222 create_guest_params.persist_storage = persist_storage_; |
| 206 create_guest_params.focused = ShouldGuestBeFocused(); | 223 create_guest_params.focused = ShouldGuestBeFocused(); |
| 207 create_guest_params.visible = visible_; | 224 create_guest_params.visible = visible_; |
| 225 create_guest_params.name = name_; |
| 208 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 226 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, |
| 209 &create_guest_params.resize_guest_params); | 227 &create_guest_params.resize_guest_params); |
| 210 browser_plugin_manager()->Send( | 228 browser_plugin_manager()->Send( |
| 211 new BrowserPluginHostMsg_CreateGuest( | 229 new BrowserPluginHostMsg_CreateGuest( |
| 212 render_view_routing_id_, | 230 render_view_routing_id_, |
| 213 instance_id_, | 231 instance_id_, |
| 214 create_guest_params)); | 232 create_guest_params)); |
| 215 } | 233 } |
| 216 | 234 |
| 217 browser_plugin_manager()->Send( | 235 browser_plugin_manager()->Send( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 417 } |
| 400 | 418 |
| 401 void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { | 419 void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { |
| 402 if (container()) { | 420 if (container()) { |
| 403 container()->requestTouchEventType(accept ? | 421 container()->requestTouchEventType(accept ? |
| 404 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 422 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
| 405 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 423 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
| 406 } | 424 } |
| 407 } | 425 } |
| 408 | 426 |
| 427 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { |
| 428 name_ = name; |
| 429 UpdateDOMAttribute(kName, name); |
| 430 } |
| 431 |
| 409 void BrowserPlugin::OnUpdateRect( | 432 void BrowserPlugin::OnUpdateRect( |
| 410 int instance_id, | 433 int instance_id, |
| 411 const BrowserPluginMsg_UpdateRect_Params& params) { | 434 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 412 bool use_new_damage_buffer = !backing_store_; | 435 bool use_new_damage_buffer = !backing_store_; |
| 413 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 436 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 414 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 437 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 415 // If we have a pending damage buffer, and the guest has begun to use the | 438 // If we have a pending damage buffer, and the guest has begun to use the |
| 416 // damage buffer then we know the guest will no longer use the current | 439 // damage buffer then we know the guest will no longer use the current |
| 417 // damage buffer. At this point, we drop the current damage buffer, and | 440 // damage buffer. At this point, we drop the current damage buffer, and |
| 418 // mark the pending damage buffer as the current damage buffer. | 441 // mark the pending damage buffer as the current damage buffer. |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 void* notify_data) { | 1062 void* notify_data) { |
| 1040 } | 1063 } |
| 1041 | 1064 |
| 1042 void BrowserPlugin::didFailLoadingFrameRequest( | 1065 void BrowserPlugin::didFailLoadingFrameRequest( |
| 1043 const WebKit::WebURL& url, | 1066 const WebKit::WebURL& url, |
| 1044 void* notify_data, | 1067 void* notify_data, |
| 1045 const WebKit::WebURLError& error) { | 1068 const WebKit::WebURLError& error) { |
| 1046 } | 1069 } |
| 1047 | 1070 |
| 1048 } // namespace content | 1071 } // namespace content |
| OLD | NEW |