| 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" | |
| 9 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/common/browser_plugin/browser_plugin_constants.h" | 11 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 14 #include "content/common/browser_plugin/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 15 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 16 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/renderer/content_renderer_client.h" | 16 #include "content/public/renderer/content_renderer_client.h" |
| 19 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
| 20 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 21 #include "content/renderer/child_frame_compositing_helper.h" | 19 #include "content/renderer/child_frame_compositing_helper.h" |
| 22 #include "content/renderer/cursor_utils.h" | 20 #include "content/renderer/cursor_utils.h" |
| 23 #include "content/renderer/drop_data_builder.h" | 21 #include "content/renderer/drop_data_builder.h" |
| 24 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 25 #include "content/renderer/sad_plugin.h" | 23 #include "content/renderer/sad_plugin.h" |
| 26 #include "content/renderer/v8_value_converter_impl.h" | |
| 27 #include "third_party/WebKit/public/platform/WebRect.h" | 24 #include "third_party/WebKit/public/platform/WebRect.h" |
| 28 #include "third_party/WebKit/public/web/WebBindings.h" | 25 #include "third_party/WebKit/public/web/WebBindings.h" |
| 29 #include "third_party/WebKit/public/web/WebDOMCustomEvent.h" | |
| 30 #include "third_party/WebKit/public/web/WebDocument.h" | 26 #include "third_party/WebKit/public/web/WebDocument.h" |
| 31 #include "third_party/WebKit/public/web/WebElement.h" | 27 #include "third_party/WebKit/public/web/WebElement.h" |
| 32 #include "third_party/WebKit/public/web/WebInputEvent.h" | 28 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 34 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 29 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 35 #include "third_party/WebKit/public/web/WebPluginParams.h" | 30 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 36 #include "third_party/WebKit/public/web/WebScriptSource.h" | |
| 37 #include "third_party/WebKit/public/web/WebView.h" | 31 #include "third_party/WebKit/public/web/WebView.h" |
| 38 #include "third_party/skia/include/core/SkCanvas.h" | 32 #include "third_party/skia/include/core/SkCanvas.h" |
| 39 #include "ui/events/keycodes/keyboard_codes.h" | 33 #include "ui/events/keycodes/keyboard_codes.h" |
| 40 | 34 |
| 41 #if defined (OS_WIN) | |
| 42 #include "base/sys_info.h" | |
| 43 #endif | |
| 44 | |
| 45 using blink::WebCanvas; | 35 using blink::WebCanvas; |
| 46 using blink::WebPluginContainer; | 36 using blink::WebPluginContainer; |
| 47 using blink::WebPluginParams; | 37 using blink::WebPluginParams; |
| 48 using blink::WebPoint; | 38 using blink::WebPoint; |
| 49 using blink::WebRect; | 39 using blink::WebRect; |
| 50 using blink::WebURL; | 40 using blink::WebURL; |
| 51 using blink::WebVector; | 41 using blink::WebVector; |
| 52 | 42 |
| 53 namespace content { | 43 namespace content { |
| 54 | 44 |
| 55 namespace { | |
| 56 | |
| 57 const char* kCustomPersistPartition = "persist:custom_plugin"; | |
| 58 | |
| 59 static std::string GetInternalEventName(const char* event_name) { | |
| 60 return base::StringPrintf("-internal-%s", event_name); | |
| 61 } | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, | 45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, |
| 66 blink::WebFrame* frame, | 46 blink::WebFrame* frame, |
| 67 bool auto_navigate) | 47 bool auto_navigate) |
| 68 : guest_instance_id_(browser_plugin::kInstanceIDNone), | 48 : guest_instance_id_(browser_plugin::kInstanceIDNone), |
| 69 attached_(false), | 49 attached_(false), |
| 70 render_view_(render_view->AsWeakPtr()), | 50 render_view_(render_view->AsWeakPtr()), |
| 71 render_view_routing_id_(render_view->GetRoutingID()), | 51 render_view_routing_id_(render_view->GetRoutingID()), |
| 72 container_(NULL), | 52 container_(NULL), |
| 73 paint_ack_received_(true), | 53 paint_ack_received_(true), |
| 74 last_device_scale_factor_(1.0f), | 54 last_device_scale_factor_(1.0f), |
| 75 sad_guest_(NULL), | 55 sad_guest_(NULL), |
| 76 guest_crashed_(false), | 56 guest_crashed_(false), |
| 77 is_auto_size_state_dirty_(false), | 57 is_auto_size_state_dirty_(false), |
| 78 persist_storage_(false), | |
| 79 valid_partition_id_(true), | |
| 80 content_window_routing_id_(MSG_ROUTING_NONE), | 58 content_window_routing_id_(MSG_ROUTING_NONE), |
| 81 plugin_focused_(false), | 59 plugin_focused_(false), |
| 82 visible_(true), | 60 visible_(true), |
| 83 auto_navigate_(auto_navigate), | 61 auto_navigate_(auto_navigate), |
| 84 before_first_navigation_(true), | |
| 85 mouse_locked_(false), | 62 mouse_locked_(false), |
| 86 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 63 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
| 87 embedder_frame_url_(frame->document().url()), | 64 embedder_frame_url_(frame->document().url()), |
| 88 weak_ptr_factory_(this) { | 65 weak_ptr_factory_(this) { |
| 89 } | 66 } |
| 90 | 67 |
| 91 BrowserPlugin::~BrowserPlugin() { | 68 BrowserPlugin::~BrowserPlugin() { |
| 92 // If the BrowserPlugin has never navigated then the browser process and | 69 // If the BrowserPlugin has never navigated then the browser process and |
| 93 // BrowserPluginManager don't know about it and so there is nothing to do | 70 // BrowserPluginManager don't know about it and so there is nothing to do |
| 94 // here. | 71 // here. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return false; | 138 return false; |
| 162 | 139 |
| 163 return container()->element().hasAttribute( | 140 return container()->element().hasAttribute( |
| 164 blink::WebString::fromUTF8(attribute_name)); | 141 blink::WebString::fromUTF8(attribute_name)); |
| 165 } | 142 } |
| 166 | 143 |
| 167 bool BrowserPlugin::GetAllowTransparencyAttribute() const { | 144 bool BrowserPlugin::GetAllowTransparencyAttribute() const { |
| 168 return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency); | 145 return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency); |
| 169 } | 146 } |
| 170 | 147 |
| 171 std::string BrowserPlugin::GetSrcAttribute() const { | |
| 172 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); | |
| 173 } | |
| 174 | |
| 175 bool BrowserPlugin::GetAutoSizeAttribute() const { | 148 bool BrowserPlugin::GetAutoSizeAttribute() const { |
| 176 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); | 149 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); |
| 177 } | 150 } |
| 178 | 151 |
| 179 int BrowserPlugin::GetMaxHeightAttribute() const { | 152 int BrowserPlugin::GetMaxHeightAttribute() const { |
| 180 int max_height; | 153 int max_height; |
| 181 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), | 154 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), |
| 182 &max_height); | 155 &max_height); |
| 183 return max_height; | 156 return max_height; |
| 184 } | 157 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 198 |
| 226 int BrowserPlugin::GetAdjustedMinWidth() const { | 199 int BrowserPlugin::GetAdjustedMinWidth() const { |
| 227 int min_width = GetMinWidthAttribute(); | 200 int min_width = GetMinWidthAttribute(); |
| 228 // FrameView.cpp does not allow this value to be <= 0, so when the value is | 201 // FrameView.cpp does not allow this value to be <= 0, so when the value is |
| 229 // unset (or set to 0), we set it to the container size. | 202 // unset (or set to 0), we set it to the container size. |
| 230 min_width = min_width ? min_width : width(); | 203 min_width = min_width ? min_width : width(); |
| 231 // For autosize, minWidth should not be bigger than maxWidth. | 204 // For autosize, minWidth should not be bigger than maxWidth. |
| 232 return std::min(min_width, GetAdjustedMaxWidth()); | 205 return std::min(min_width, GetAdjustedMaxWidth()); |
| 233 } | 206 } |
| 234 | 207 |
| 235 std::string BrowserPlugin::GetPartitionAttribute() const { | |
| 236 return GetDOMAttributeValue(browser_plugin::kAttributePartition); | |
| 237 } | |
| 238 | |
| 239 void BrowserPlugin::ParseAllowTransparencyAttribute() { | 208 void BrowserPlugin::ParseAllowTransparencyAttribute() { |
| 240 if (!HasGuestInstanceID()) | 209 if (!HasGuestInstanceID()) |
| 241 return; | 210 return; |
| 242 | 211 |
| 243 bool opaque = !GetAllowTransparencyAttribute(); | 212 bool opaque = !GetAllowTransparencyAttribute(); |
| 244 | 213 |
| 245 if (compositing_helper_) | 214 if (compositing_helper_) |
| 246 compositing_helper_->SetContentsOpaque(opaque); | 215 compositing_helper_->SetContentsOpaque(opaque); |
| 247 | 216 |
| 248 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( | 217 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( |
| 249 render_view_routing_id_, | 218 render_view_routing_id_, |
| 250 guest_instance_id_, | 219 guest_instance_id_, |
| 251 opaque)); | 220 opaque)); |
| 252 } | 221 } |
| 253 | 222 |
| 254 bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { | |
| 255 if (!valid_partition_id_) { | |
| 256 *error_message = browser_plugin::kErrorInvalidPartition; | |
| 257 return false; | |
| 258 } | |
| 259 std::string src = GetSrcAttribute(); | |
| 260 if (src.empty()) | |
| 261 return true; | |
| 262 | |
| 263 // If we haven't created the guest yet, do so now. We will navigate it right | |
| 264 // after creation. If |src| is empty, we can delay the creation until we | |
| 265 // actually need it. | |
| 266 if (!HasGuestInstanceID()) { | |
| 267 // On initial navigation, we request an instance ID from the browser | |
| 268 // process. We essentially ignore all subsequent calls to SetSrcAttribute | |
| 269 // until we receive an instance ID. |before_first_navigation_| | |
| 270 // prevents BrowserPlugin from allocating more than one instance ID. | |
| 271 // Upon receiving an instance ID from the browser process, we continue | |
| 272 // the process of navigation by populating the | |
| 273 // BrowserPluginHostMsg_Attach_Params with the current state of | |
| 274 // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the | |
| 275 // browser process in order to create a new guest. | |
| 276 if (before_first_navigation_) { | |
| 277 browser_plugin_manager()->AllocateInstanceID( | |
| 278 weak_ptr_factory_.GetWeakPtr()); | |
| 279 before_first_navigation_ = false; | |
| 280 } | |
| 281 return true; | |
| 282 } | |
| 283 | |
| 284 browser_plugin_manager()->Send( | |
| 285 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, | |
| 286 guest_instance_id_, | |
| 287 src)); | |
| 288 return true; | |
| 289 } | |
| 290 | |
| 291 void BrowserPlugin::ParseAutoSizeAttribute() { | 223 void BrowserPlugin::ParseAutoSizeAttribute() { |
| 292 last_view_size_ = plugin_rect_.size(); | 224 last_view_size_ = plugin_rect_.size(); |
| 293 is_auto_size_state_dirty_ = true; | 225 is_auto_size_state_dirty_ = true; |
| 294 UpdateGuestAutoSizeState(GetAutoSizeAttribute()); | 226 UpdateGuestAutoSizeState(GetAutoSizeAttribute()); |
| 295 } | 227 } |
| 296 | 228 |
| 297 void BrowserPlugin::PopulateAutoSizeParameters( | 229 void BrowserPlugin::PopulateAutoSizeParameters( |
| 298 BrowserPluginHostMsg_AutoSize_Params* params, bool auto_size_enabled) { | 230 BrowserPluginHostMsg_AutoSize_Params* params, bool auto_size_enabled) { |
| 299 params->enable = auto_size_enabled; | 231 params->enable = auto_size_enabled; |
| 300 // No need to populate the params if autosize is off. | 232 // No need to populate the params if autosize is off. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 326 GetSizeParams(NULL, &resize_guest_params, true); | 258 GetSizeParams(NULL, &resize_guest_params, true); |
| 327 } | 259 } |
| 328 paint_ack_received_ = false; | 260 paint_ack_received_ = false; |
| 329 browser_plugin_manager()->Send( | 261 browser_plugin_manager()->Send( |
| 330 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, | 262 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, |
| 331 guest_instance_id_, | 263 guest_instance_id_, |
| 332 auto_size_params, | 264 auto_size_params, |
| 333 resize_guest_params)); | 265 resize_guest_params)); |
| 334 } | 266 } |
| 335 | 267 |
| 336 void BrowserPlugin::OnInstanceIDAllocated(int guest_instance_id) { | |
| 337 CHECK(guest_instance_id != browser_plugin::kInstanceIDNone); | |
| 338 | |
| 339 if (auto_navigate_) { | |
| 340 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | |
| 341 Attach(guest_instance_id, params.Pass()); | |
| 342 return; | |
| 343 } | |
| 344 | |
| 345 std::map<std::string, base::Value*> props; | |
| 346 props[browser_plugin::kWindowID] = | |
| 347 new base::FundamentalValue(guest_instance_id); | |
| 348 TriggerEvent(browser_plugin::kEventInternalInstanceIDAllocated, &props); | |
| 349 } | |
| 350 | |
| 351 void BrowserPlugin::Attach(int guest_instance_id, | 268 void BrowserPlugin::Attach(int guest_instance_id, |
| 352 scoped_ptr<base::DictionaryValue> extra_params) { | 269 scoped_ptr<base::DictionaryValue> extra_params) { |
| 353 CHECK(guest_instance_id != browser_plugin::kInstanceIDNone); | 270 CHECK(guest_instance_id != browser_plugin::kInstanceIDNone); |
| 354 | 271 |
| 355 // If this BrowserPlugin is already attached to a guest, then do nothing. | 272 // If this BrowserPlugin is already attached to a guest, then do nothing. |
| 356 if (HasGuestInstanceID()) | 273 if (HasGuestInstanceID()) |
| 357 return; | 274 return; |
| 358 | 275 |
| 359 // This API may be called directly without setting the src attribute. | 276 // This API may be called directly without setting the src attribute. |
| 360 // In that case, we need to make sure we don't allocate another instance ID. | 277 // In that case, we need to make sure we don't allocate another instance ID. |
| 361 before_first_navigation_ = false; | |
| 362 guest_instance_id_ = guest_instance_id; | 278 guest_instance_id_ = guest_instance_id; |
| 363 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this); | 279 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this); |
| 364 | 280 |
| 365 BrowserPluginHostMsg_Attach_Params attach_params; | 281 BrowserPluginHostMsg_Attach_Params attach_params; |
| 366 attach_params.focused = ShouldGuestBeFocused(); | 282 attach_params.focused = ShouldGuestBeFocused(); |
| 367 attach_params.visible = visible_; | 283 attach_params.visible = visible_; |
| 368 attach_params.opaque = !GetAllowTransparencyAttribute(); | 284 attach_params.opaque = !GetAllowTransparencyAttribute(); |
| 369 attach_params.storage_partition_id = storage_partition_id_; | |
| 370 attach_params.persist_storage = persist_storage_; | |
| 371 attach_params.src = GetSrcAttribute(); | |
| 372 attach_params.embedder_frame_url = embedder_frame_url_; | 285 attach_params.embedder_frame_url = embedder_frame_url_; |
| 373 GetSizeParams(&attach_params.auto_size_params, | 286 GetSizeParams(&attach_params.auto_size_params, |
| 374 &attach_params.resize_guest_params, | 287 &attach_params.resize_guest_params, |
| 375 false); | 288 false); |
| 376 | 289 |
| 377 browser_plugin_manager()->Send( | 290 browser_plugin_manager()->Send( |
| 378 new BrowserPluginHostMsg_Attach(render_view_routing_id_, | 291 new BrowserPluginHostMsg_Attach(render_view_routing_id_, |
| 379 guest_instance_id_, attach_params, | 292 guest_instance_id_, attach_params, |
| 380 *extra_params)); | 293 *extra_params)); |
| 381 } | 294 } |
| 382 | 295 |
| 383 void BrowserPlugin::DidCommitCompositorFrame() { | 296 void BrowserPlugin::DidCommitCompositorFrame() { |
| 384 if (compositing_helper_.get()) | 297 if (compositing_helper_.get()) |
| 385 compositing_helper_->DidCommitCompositorFrame(); | 298 compositing_helper_->DidCommitCompositorFrame(); |
| 386 } | 299 } |
| 387 | 300 |
| 388 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { | 301 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { |
| 389 DCHECK(render_view_.get()); | 302 DCHECK(render_view_.get()); |
| 390 render_view_->GetWebView()->advanceFocus(reverse); | 303 render_view_->GetWebView()->advanceFocus(reverse); |
| 391 } | 304 } |
| 392 | 305 |
| 393 void BrowserPlugin::OnAttachACK( | 306 void BrowserPlugin::OnAttachACK(int guest_instance_id) { |
| 394 int guest_instance_id, | |
| 395 const BrowserPluginMsg_Attach_ACK_Params& params) { | |
| 396 if (!params.storage_partition_id.empty()) { | |
| 397 std::string partition_name = | |
| 398 (params.persist_storage ? browser_plugin::kPersistPrefix : "") + | |
| 399 params.storage_partition_id; | |
| 400 UpdateDOMAttribute(browser_plugin::kAttributePartition, partition_name); | |
| 401 } | |
| 402 attached_ = true; | 307 attached_ = true; |
| 403 } | 308 } |
| 404 | 309 |
| 405 void BrowserPlugin::OnBuffersSwapped( | 310 void BrowserPlugin::OnBuffersSwapped( |
| 406 int instance_id, | 311 int instance_id, |
| 407 const FrameMsg_BuffersSwapped_Params& params) { | 312 const FrameMsg_BuffersSwapped_Params& params) { |
| 408 EnableCompositing(true); | 313 EnableCompositing(true); |
| 409 | 314 |
| 410 compositing_helper_->OnBuffersSwapped(params.size, | 315 compositing_helper_->OnBuffersSwapped(params.size, |
| 411 params.mailbox, | 316 params.mailbox, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 463 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
| 559 return NULL; | 464 return NULL; |
| 560 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( | 465 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( |
| 561 content_window_routing_id_); | 466 content_window_routing_id_); |
| 562 if (!guest_render_view) | 467 if (!guest_render_view) |
| 563 return NULL; | 468 return NULL; |
| 564 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 469 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
| 565 return guest_frame->windowObject(); | 470 return guest_frame->windowObject(); |
| 566 } | 471 } |
| 567 | 472 |
| 568 bool BrowserPlugin::HasNavigated() const { | |
| 569 return !before_first_navigation_; | |
| 570 } | |
| 571 | |
| 572 bool BrowserPlugin::HasGuestInstanceID() const { | 473 bool BrowserPlugin::HasGuestInstanceID() const { |
| 573 return guest_instance_id_ != browser_plugin::kInstanceIDNone; | 474 return guest_instance_id_ != browser_plugin::kInstanceIDNone; |
| 574 } | 475 } |
| 575 | 476 |
| 576 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { | |
| 577 if (HasNavigated()) { | |
| 578 *error_message = browser_plugin::kErrorAlreadyNavigated; | |
| 579 return false; | |
| 580 } | |
| 581 | 477 |
| 582 std::string input; | 478 // TODO(lazyboy): Need equivalent in web_view.js |
| 583 if (auto_navigate_) | 479 // Also write test. |
| 584 input = kCustomPersistPartition; | |
| 585 else | |
| 586 input = GetPartitionAttribute(); | |
| 587 | |
| 588 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | |
| 589 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | |
| 590 // remove the prefix without splicing in the middle of a multi-byte codepoint. | |
| 591 // We can use the rest of the string as UTF-8 encoded one. | |
| 592 if (StartsWithASCII(input, browser_plugin::kPersistPrefix, true)) { | |
| 593 size_t index = input.find(":"); | |
| 594 CHECK(index != std::string::npos); | |
| 595 // It is safe to do index + 1, since we tested for the full prefix above. | |
| 596 input = input.substr(index + 1); | |
| 597 if (input.empty()) { | |
| 598 valid_partition_id_ = false; | |
| 599 *error_message = browser_plugin::kErrorInvalidPartition; | |
| 600 return false; | |
| 601 } | |
| 602 persist_storage_ = true; | |
| 603 } else { | |
| 604 persist_storage_ = false; | |
| 605 } | |
| 606 | |
| 607 valid_partition_id_ = true; | |
| 608 storage_partition_id_ = input; | |
| 609 return true; | |
| 610 } | |
| 611 | |
| 612 bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) { | 480 bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) { |
| 613 if (HasGuestInstanceID()) | 481 if (HasGuestInstanceID()) |
| 614 *error_message = browser_plugin::kErrorCannotRemovePartition; | 482 *error_message = browser_plugin::kErrorCannotRemovePartition; |
| 615 return !HasGuestInstanceID(); | 483 return !HasGuestInstanceID(); |
| 616 } | 484 } |
| 617 | 485 |
| 618 void BrowserPlugin::ShowSadGraphic() { | 486 void BrowserPlugin::ShowSadGraphic() { |
| 619 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 487 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 620 // NULL so we shouldn't attempt to access it. | 488 // NULL so we shouldn't attempt to access it. |
| 621 if (container_) | 489 if (container_) |
| 622 container_->invalidate(); | 490 container_->invalidate(); |
| 623 } | 491 } |
| 624 | 492 |
| 625 void BrowserPlugin::ParseAttributes() { | |
| 626 // TODO(mthiesse): Handle errors here? | |
| 627 std::string error; | |
| 628 ParsePartitionAttribute(&error); | |
| 629 | |
| 630 // Parse the 'src' attribute last, as it will set the has_navigated_ flag to | |
| 631 // true, which prevents changing the 'partition' attribute. | |
| 632 ParseSrcAttribute(&error); | |
| 633 } | |
| 634 | |
| 635 float BrowserPlugin::GetDeviceScaleFactor() const { | 493 float BrowserPlugin::GetDeviceScaleFactor() const { |
| 636 if (!render_view_.get()) | 494 if (!render_view_.get()) |
| 637 return 1.0f; | 495 return 1.0f; |
| 638 return render_view_->GetWebView()->deviceScaleFactor(); | 496 return render_view_->GetWebView()->deviceScaleFactor(); |
| 639 } | 497 } |
| 640 | 498 |
| 641 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { | 499 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { |
| 642 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) | 500 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) |
| 643 return; | 501 return; |
| 644 | 502 |
| 645 BrowserPluginHostMsg_ResizeGuest_Params params; | 503 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 646 PopulateResizeGuestParameters(¶ms, plugin_rect(), false); | 504 PopulateResizeGuestParameters(¶ms, plugin_rect(), false); |
| 647 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 505 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 648 render_view_routing_id_, | 506 render_view_routing_id_, |
| 649 guest_instance_id_, | 507 guest_instance_id_, |
| 650 params)); | 508 params)); |
| 651 } | 509 } |
| 652 | 510 |
| 653 void BrowserPlugin::TriggerEvent(const std::string& event_name, | |
| 654 std::map<std::string, base::Value*>* props) { | |
| 655 if (!container()) | |
| 656 return; | |
| 657 | |
| 658 blink::WebLocalFrame* frame = container()->element().document().frame(); | |
| 659 if (!frame) | |
| 660 return; | |
| 661 | |
| 662 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | |
| 663 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | |
| 664 v8::Context::Scope context_scope(context); | |
| 665 | |
| 666 std::string json_string; | |
| 667 if (props) { | |
| 668 base::DictionaryValue dict; | |
| 669 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), | |
| 670 end = props->end(); iter != end; ++iter) { | |
| 671 dict.Set(iter->first, iter->second); | |
| 672 } | |
| 673 | |
| 674 JSONStringValueSerializer serializer(&json_string); | |
| 675 if (!serializer.Serialize(dict)) | |
| 676 return; | |
| 677 } | |
| 678 | |
| 679 blink::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); | |
| 680 blink::WebDOMCustomEvent event = dom_event.to<blink::WebDOMCustomEvent>(); | |
| 681 | |
| 682 // The events triggered directly from the plugin <object> are internal events | |
| 683 // whose implementation details can (and likely will) change over time. The | |
| 684 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a | |
| 685 // more appropriate (and stable) event to the consumers as part of the API. | |
| 686 event.initCustomEvent( | |
| 687 blink::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), | |
| 688 false, | |
| 689 false, | |
| 690 blink::WebSerializedScriptValue::serialize( | |
| 691 v8::String::NewFromUtf8(context->GetIsolate(), | |
| 692 json_string.c_str(), | |
| 693 v8::String::kNormalString, | |
| 694 json_string.size()))); | |
| 695 container()->element().dispatchEvent(event); | |
| 696 } | |
| 697 | |
| 698 void BrowserPlugin::UpdateGuestFocusState() { | 511 void BrowserPlugin::UpdateGuestFocusState() { |
| 699 if (!HasGuestInstanceID()) | 512 if (!HasGuestInstanceID()) |
| 700 return; | 513 return; |
| 701 bool should_be_focused = ShouldGuestBeFocused(); | 514 bool should_be_focused = ShouldGuestBeFocused(); |
| 702 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 515 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
| 703 render_view_routing_id_, | 516 render_view_routing_id_, |
| 704 guest_instance_id_, | 517 guest_instance_id_, |
| 705 should_be_focused)); | 518 should_be_focused)); |
| 706 } | 519 } |
| 707 | 520 |
| 708 bool BrowserPlugin::ShouldGuestBeFocused() const { | 521 bool BrowserPlugin::ShouldGuestBeFocused() const { |
| 709 bool embedder_focused = false; | 522 bool embedder_focused = false; |
| 710 if (render_view_.get()) | 523 if (render_view_.get()) |
| 711 embedder_focused = render_view_->has_focus(); | 524 embedder_focused = render_view_->has_focus(); |
| 712 return plugin_focused_ && embedder_focused; | 525 return plugin_focused_ && embedder_focused; |
| 713 } | 526 } |
| 714 | 527 |
| 715 blink::WebPluginContainer* BrowserPlugin::container() const { | 528 blink::WebPluginContainer* BrowserPlugin::container() const { |
| 716 return container_; | 529 return container_; |
| 717 } | 530 } |
| 718 | 531 |
| 719 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 532 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 533 printf("BP::initialize()\n"); |
| 720 if (!container) | 534 if (!container) |
| 721 return false; | 535 return false; |
| 722 | 536 |
| 723 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container) && | 537 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container) && |
| 724 !auto_navigate_) | 538 !auto_navigate_) |
| 725 return false; | 539 return false; |
| 726 | 540 |
| 727 // Tell |container| to allow this plugin to use script objects. | 541 // Tell |container| to allow this plugin to use script objects. |
| 728 npp_.reset(new NPP_t); | 542 npp_.reset(new NPP_t); |
| 729 container->allowScriptObjects(); | 543 container->allowScriptObjects(); |
| 730 | 544 |
| 731 bindings_.reset(new BrowserPluginBindings(this)); | 545 bindings_.reset(new BrowserPluginBindings(this)); |
| 732 container_ = container; | 546 container_ = container; |
| 733 container_->setWantsWheelEvents(true); | 547 container_->setWantsWheelEvents(true); |
| 734 ParseAttributes(); | |
| 735 return true; | 548 return true; |
| 736 } | 549 } |
| 737 | 550 |
| 738 void BrowserPlugin::EnableCompositing(bool enable) { | 551 void BrowserPlugin::EnableCompositing(bool enable) { |
| 739 bool enabled = !!compositing_helper_; | 552 bool enabled = !!compositing_helper_; |
| 740 if (enabled == enable) | 553 if (enabled == enable) |
| 741 return; | 554 return; |
| 742 | 555 |
| 743 if (enable) { | 556 if (enable) { |
| 744 DCHECK(!compositing_helper_.get()); | 557 DCHECK(!compositing_helper_.get()); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 } | 853 } |
| 1041 | 854 |
| 1042 void BrowserPlugin::didReceiveData(const char* data, int data_length) { | 855 void BrowserPlugin::didReceiveData(const char* data, int data_length) { |
| 1043 if (auto_navigate_) { | 856 if (auto_navigate_) { |
| 1044 std::string value(data, data_length); | 857 std::string value(data, data_length); |
| 1045 html_string_ += value; | 858 html_string_ += value; |
| 1046 } | 859 } |
| 1047 } | 860 } |
| 1048 | 861 |
| 1049 void BrowserPlugin::didFinishLoading() { | 862 void BrowserPlugin::didFinishLoading() { |
| 863 printf("BP::didFinishLoading(), will update partition attr.\n"); |
| 1050 if (auto_navigate_) { | 864 if (auto_navigate_) { |
| 865 // web_view.js should pick this mutation. |
| 1051 UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_); | 866 UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_); |
| 1052 ParseAttributes(); | |
| 1053 } | 867 } |
| 1054 } | 868 } |
| 1055 | 869 |
| 1056 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { | 870 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { |
| 1057 } | 871 } |
| 1058 | 872 |
| 1059 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, | 873 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, |
| 1060 void* notify_data) { | 874 void* notify_data) { |
| 1061 } | 875 } |
| 1062 | 876 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 const blink::WebMouseEvent& event) { | 964 const blink::WebMouseEvent& event) { |
| 1151 browser_plugin_manager()->Send( | 965 browser_plugin_manager()->Send( |
| 1152 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 966 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1153 guest_instance_id_, | 967 guest_instance_id_, |
| 1154 plugin_rect_, | 968 plugin_rect_, |
| 1155 &event)); | 969 &event)); |
| 1156 return true; | 970 return true; |
| 1157 } | 971 } |
| 1158 | 972 |
| 1159 } // namespace content | 973 } // namespace content |
| OLD | NEW |