OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/plugins/renderer/loadable_plugin_placeholder.h" | 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" |
9 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
10 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" |
| 15 #include "content/public/child/v8_value_converter.h" |
| 16 #include "content/public/common/content_switches.h" |
13 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
14 #include "content/public/renderer/render_thread.h" | 18 #include "content/public/renderer/render_thread.h" |
15 #include "gin/handle.h" | 19 #include "gin/handle.h" |
16 #include "gin/object_template_builder.h" | 20 #include "gin/object_template_builder.h" |
| 21 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" |
17 #include "third_party/WebKit/public/web/WebElement.h" | 23 #include "third_party/WebKit/public/web/WebElement.h" |
18 #include "third_party/WebKit/public/web/WebInputEvent.h" | 24 #include "third_party/WebKit/public/web/WebInputEvent.h" |
19 #include "third_party/WebKit/public/web/WebKit.h" | 25 #include "third_party/WebKit/public/web/WebKit.h" |
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
21 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 27 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
22 #include "third_party/WebKit/public/web/WebScriptSource.h" | 28 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 29 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
23 #include "third_party/WebKit/public/web/WebView.h" | 30 #include "third_party/WebKit/public/web/WebView.h" |
24 #include "third_party/re2/re2/re2.h" | 31 #include "third_party/re2/re2/re2.h" |
25 | 32 |
26 using base::UserMetricsAction; | 33 using base::UserMetricsAction; |
27 using blink::WebElement; | 34 using blink::WebElement; |
28 using blink::WebLocalFrame; | 35 using blink::WebLocalFrame; |
29 using blink::WebMouseEvent; | 36 using blink::WebMouseEvent; |
30 using blink::WebNode; | 37 using blink::WebNode; |
31 using blink::WebPlugin; | 38 using blink::WebPlugin; |
32 using blink::WebPluginContainer; | 39 using blink::WebPluginContainer; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 331 |
325 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { | 332 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { |
326 finished_loading_ = true; | 333 finished_loading_ = true; |
327 if (message_.length() > 0) | 334 if (message_.length() > 0) |
328 UpdateMessage(); | 335 UpdateMessage(); |
329 | 336 |
330 // Wait for the placeholder to finish loading to hide the premade plugin. | 337 // Wait for the placeholder to finish loading to hide the premade plugin. |
331 // This is necessary to prevent a flicker. | 338 // This is necessary to prevent a flicker. |
332 if (premade_throttler_ && power_saver_enabled_) | 339 if (premade_throttler_ && power_saver_enabled_) |
333 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */); | 340 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */); |
| 341 |
| 342 // Set an attribute and post an event, so browser tests can wait for the |
| 343 // placeholder to be ready to receive simulated user input. |
| 344 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 345 switches::kEnablePluginPlaceholderTesting)) { |
| 346 WebElement element = plugin()->container()->element(); |
| 347 element.setAttribute("placeholderLoaded", "true"); |
| 348 |
| 349 scoped_ptr<content::V8ValueConverter> converter( |
| 350 content::V8ValueConverter::create()); |
| 351 base::StringValue value("placeholderLoaded"); |
| 352 blink::WebSerializedScriptValue message_data = |
| 353 blink::WebSerializedScriptValue::serialize(converter->ToV8Value( |
| 354 &value, element.document().frame()->mainWorldScriptContext())); |
| 355 |
| 356 blink::WebDOMEvent event = element.document().createEvent("MessageEvent"); |
| 357 blink::WebDOMMessageEvent msg_event = event.to<blink::WebDOMMessageEvent>(); |
| 358 msg_event.initMessageEvent("message", // type |
| 359 false, // canBubble |
| 360 false, // cancelable |
| 361 message_data, // data |
| 362 "", // origin [*] |
| 363 NULL, // source [*] |
| 364 ""); // lastEventId |
| 365 element.dispatchEvent(msg_event); |
| 366 } |
334 } | 367 } |
335 | 368 |
336 void LoadablePluginPlaceholder::SetPluginInfo( | 369 void LoadablePluginPlaceholder::SetPluginInfo( |
337 const content::WebPluginInfo& plugin_info) { | 370 const content::WebPluginInfo& plugin_info) { |
338 plugin_info_ = plugin_info; | 371 plugin_info_ = plugin_info; |
339 } | 372 } |
340 | 373 |
341 const content::WebPluginInfo& LoadablePluginPlaceholder::GetPluginInfo() const { | 374 const content::WebPluginInfo& LoadablePluginPlaceholder::GetPluginInfo() const { |
342 return plugin_info_; | 375 return plugin_info_; |
343 } | 376 } |
344 | 377 |
345 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) { | 378 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) { |
346 identifier_ = identifier; | 379 identifier_ = identifier; |
347 } | 380 } |
348 | 381 |
349 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { | 382 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { |
350 return identifier_; | 383 return identifier_; |
351 } | 384 } |
352 | 385 |
353 bool LoadablePluginPlaceholder::LoadingBlocked() const { | 386 bool LoadablePluginPlaceholder::LoadingBlocked() const { |
354 DCHECK(allow_loading_); | 387 DCHECK(allow_loading_); |
355 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 388 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
356 is_blocked_for_prerendering_; | 389 is_blocked_for_prerendering_; |
357 } | 390 } |
358 | 391 |
359 } // namespace plugins | 392 } // namespace plugins |
OLD | NEW |