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 | |
582 std::string input; | |
583 if (auto_navigate_) | |
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) { | |
613 if (HasGuestInstanceID()) | |
614 *error_message = browser_plugin::kErrorCannotRemovePartition; | |
615 return !HasGuestInstanceID(); | |
616 } | |
617 | |
618 void BrowserPlugin::ShowSadGraphic() { | 477 void BrowserPlugin::ShowSadGraphic() { |
619 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 478 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
620 // NULL so we shouldn't attempt to access it. | 479 // NULL so we shouldn't attempt to access it. |
621 if (container_) | 480 if (container_) |
622 container_->invalidate(); | 481 container_->invalidate(); |
623 } | 482 } |
624 | 483 |
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 { | 484 float BrowserPlugin::GetDeviceScaleFactor() const { |
636 if (!render_view_.get()) | 485 if (!render_view_.get()) |
637 return 1.0f; | 486 return 1.0f; |
638 return render_view_->GetWebView()->deviceScaleFactor(); | 487 return render_view_->GetWebView()->deviceScaleFactor(); |
639 } | 488 } |
640 | 489 |
641 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { | 490 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { |
642 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) | 491 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) |
643 return; | 492 return; |
644 | 493 |
645 BrowserPluginHostMsg_ResizeGuest_Params params; | 494 BrowserPluginHostMsg_ResizeGuest_Params params; |
646 PopulateResizeGuestParameters(¶ms, plugin_rect(), false); | 495 PopulateResizeGuestParameters(¶ms, plugin_rect(), false); |
647 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 496 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
648 render_view_routing_id_, | 497 render_view_routing_id_, |
649 guest_instance_id_, | 498 guest_instance_id_, |
650 params)); | 499 params)); |
651 } | 500 } |
652 | 501 |
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() { | 502 void BrowserPlugin::UpdateGuestFocusState() { |
699 if (!HasGuestInstanceID()) | 503 if (!HasGuestInstanceID()) |
700 return; | 504 return; |
701 bool should_be_focused = ShouldGuestBeFocused(); | 505 bool should_be_focused = ShouldGuestBeFocused(); |
702 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 506 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
703 render_view_routing_id_, | 507 render_view_routing_id_, |
704 guest_instance_id_, | 508 guest_instance_id_, |
705 should_be_focused)); | 509 should_be_focused)); |
706 } | 510 } |
707 | 511 |
(...skipping 16 matching lines...) Expand all Loading... |
724 !auto_navigate_) | 528 !auto_navigate_) |
725 return false; | 529 return false; |
726 | 530 |
727 // Tell |container| to allow this plugin to use script objects. | 531 // Tell |container| to allow this plugin to use script objects. |
728 npp_.reset(new NPP_t); | 532 npp_.reset(new NPP_t); |
729 container->allowScriptObjects(); | 533 container->allowScriptObjects(); |
730 | 534 |
731 bindings_.reset(new BrowserPluginBindings(this)); | 535 bindings_.reset(new BrowserPluginBindings(this)); |
732 container_ = container; | 536 container_ = container; |
733 container_->setWantsWheelEvents(true); | 537 container_->setWantsWheelEvents(true); |
734 ParseAttributes(); | |
735 return true; | 538 return true; |
736 } | 539 } |
737 | 540 |
738 void BrowserPlugin::EnableCompositing(bool enable) { | 541 void BrowserPlugin::EnableCompositing(bool enable) { |
739 bool enabled = !!compositing_helper_; | 542 bool enabled = !!compositing_helper_; |
740 if (enabled == enable) | 543 if (enabled == enable) |
741 return; | 544 return; |
742 | 545 |
743 if (enable) { | 546 if (enable) { |
744 DCHECK(!compositing_helper_.get()); | 547 DCHECK(!compositing_helper_.get()); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 | 844 |
1042 void BrowserPlugin::didReceiveData(const char* data, int data_length) { | 845 void BrowserPlugin::didReceiveData(const char* data, int data_length) { |
1043 if (auto_navigate_) { | 846 if (auto_navigate_) { |
1044 std::string value(data, data_length); | 847 std::string value(data, data_length); |
1045 html_string_ += value; | 848 html_string_ += value; |
1046 } | 849 } |
1047 } | 850 } |
1048 | 851 |
1049 void BrowserPlugin::didFinishLoading() { | 852 void BrowserPlugin::didFinishLoading() { |
1050 if (auto_navigate_) { | 853 if (auto_navigate_) { |
| 854 // TODO(lazyboy): Make |auto_navigate_| stuff work. |
1051 UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_); | 855 UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_); |
1052 ParseAttributes(); | |
1053 } | 856 } |
1054 } | 857 } |
1055 | 858 |
1056 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { | 859 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { |
1057 } | 860 } |
1058 | 861 |
1059 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, | 862 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, |
1060 void* notify_data) { | 863 void* notify_data) { |
1061 } | 864 } |
1062 | 865 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 const blink::WebMouseEvent& event) { | 953 const blink::WebMouseEvent& event) { |
1151 browser_plugin_manager()->Send( | 954 browser_plugin_manager()->Send( |
1152 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 955 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
1153 guest_instance_id_, | 956 guest_instance_id_, |
1154 plugin_rect_, | 957 plugin_rect_, |
1155 &event)); | 958 &event)); |
1156 return true; | 959 return true; |
1157 } | 960 } |
1158 | 961 |
1159 } // namespace content | 962 } // namespace content |
OLD | NEW |