Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: components/plugins/renderer/loadable_plugin_placeholder.cc

Issue 1132873002: Plugin Power Saver: Fix poster-click flaky test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0275-plugin-power-saver-preserve-js-access-for-throttled-plugins
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/plugins/renderer/loadable_plugin_placeholder.cc
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.cc b/components/plugins/renderer/loadable_plugin_placeholder.cc
index 8bb9d4ad28c264a74fdd314c32694b839b04689b..90c3f9ba7183580e8f0c07d6736c85feda4421e8 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.cc
+++ b/components/plugins/renderer/loadable_plugin_placeholder.cc
@@ -6,20 +6,27 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/command_line.h"
#include "base/json/string_escape.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "content/public/child/v8_value_converter.h"
+#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
+#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
+#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
+#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/re2/re2/re2.h"
@@ -331,6 +338,32 @@ void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
// This is necessary to prevent a flicker.
if (premade_throttler_ && power_saver_enabled_)
premade_throttler_->SetHiddenForPlaceholder(true /* hidden */);
+
+ // Set an attribute and post an event, so browser tests can wait for the
+ // placeholder to be ready to receive simulated user input.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnablePluginPlaceholderTesting)) {
+ WebElement element = plugin()->container()->element();
+ element.setAttribute("placeholderLoaded", "true");
+
+ scoped_ptr<content::V8ValueConverter> converter(
+ content::V8ValueConverter::create());
+ base::StringValue value("placeholderLoaded");
+ blink::WebSerializedScriptValue message_data =
+ blink::WebSerializedScriptValue::serialize(converter->ToV8Value(
+ &value, element.document().frame()->mainWorldScriptContext()));
+
+ blink::WebDOMEvent event = element.document().createEvent("MessageEvent");
+ blink::WebDOMMessageEvent msg_event = event.to<blink::WebDOMMessageEvent>();
+ msg_event.initMessageEvent("message", // type
+ false, // canBubble
+ false, // cancelable
+ message_data, // data
+ "", // origin [*]
+ NULL, // source [*]
+ ""); // lastEventId
+ element.dispatchEvent(msg_event);
+ }
}
void LoadablePluginPlaceholder::SetPluginInfo(

Powered by Google App Engine
This is Rietveld 408576698