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 90c3f9ba7183580e8f0c07d6736c85feda4421e8..54a1e06b0b69b470e12b3139c7d3ec1bb813b8a0 100644 |
--- a/components/plugins/renderer/loadable_plugin_placeholder.cc |
+++ b/components/plugins/renderer/loadable_plugin_placeholder.cc |
@@ -9,7 +9,6 @@ |
#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" |
@@ -28,24 +27,13 @@ |
#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" |
using base::UserMetricsAction; |
-using blink::WebElement; |
-using blink::WebLocalFrame; |
-using blink::WebMouseEvent; |
-using blink::WebNode; |
-using blink::WebPlugin; |
-using blink::WebPluginContainer; |
-using blink::WebPluginParams; |
-using blink::WebScriptSource; |
-using blink::WebURLRequest; |
using content::PluginInstanceThrottler; |
using content::RenderThread; |
namespace plugins { |
-#if defined(ENABLE_PLUGINS) |
void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { |
DCHECK(!is_blocked_for_power_saver_poster_); |
is_blocked_for_power_saver_poster_ = true; |
@@ -63,26 +51,19 @@ void LoadablePluginPlaceholder::SetPremadePlugin( |
DCHECK(!premade_throttler_); |
premade_throttler_ = throttler; |
} |
-#endif |
LoadablePluginPlaceholder::LoadablePluginPlaceholder( |
content::RenderFrame* render_frame, |
- WebLocalFrame* frame, |
- const WebPluginParams& params, |
- const std::string& html_data, |
- GURL placeholderDataUrl) |
- : PluginPlaceholder(render_frame, |
- frame, |
- params, |
- html_data, |
- placeholderDataUrl), |
+ blink::WebLocalFrame* frame, |
+ const blink::WebPluginParams& params, |
+ const std::string& html_data) |
+ : PluginPlaceholder(render_frame, frame, params, html_data), |
is_blocked_for_background_tab_(false), |
is_blocked_for_prerendering_(false), |
is_blocked_for_power_saver_poster_(false), |
power_saver_enabled_(false), |
premade_throttler_(nullptr), |
- allow_loading_(false), |
- hidden_(false), |
+ allow_loading_(true), |
finished_loading_(false), |
weak_factory_(this) { |
} |
@@ -90,7 +71,6 @@ LoadablePluginPlaceholder::LoadablePluginPlaceholder( |
LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { |
} |
-#if defined(ENABLE_PLUGINS) |
void LoadablePluginPlaceholder::MarkPluginEssential( |
PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { |
if (!power_saver_enabled_) |
@@ -109,39 +89,25 @@ void LoadablePluginPlaceholder::MarkPluginEssential( |
LoadPlugin(); |
} |
} |
-#endif |
- |
-void LoadablePluginPlaceholder::BindWebFrame(blink::WebFrame* frame) { |
- v8::Isolate* isolate = blink::mainThreadIsolate(); |
- v8::HandleScope handle_scope(isolate); |
- v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
- DCHECK(!context.IsEmpty()); |
- |
- v8::Context::Scope context_scope(context); |
- v8::Local<v8::Object> global = context->Global(); |
- global->Set(gin::StringToV8(isolate, "plugin"), |
- gin::CreateHandle(isolate, this).ToV8()); |
-} |
gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( |
v8::Isolate* isolate) { |
- return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) |
+ return PluginPlaceholder::GetObjectTemplateBuilder(isolate) |
.SetMethod("load", &LoadablePluginPlaceholder::LoadCallback) |
- .SetMethod("hide", &LoadablePluginPlaceholder::HideCallback) |
.SetMethod("didFinishLoading", |
&LoadablePluginPlaceholder::DidFinishLoadingCallback); |
} |
-void LoadablePluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { |
+void LoadablePluginPlaceholder::ReplacePlugin(blink::WebPlugin* new_plugin) { |
CHECK(plugin()); |
if (!new_plugin) |
return; |
- WebPluginContainer* container = plugin()->container(); |
+ blink::WebPluginContainer* container = plugin()->container(); |
// Set the new plugin on the container before initializing it. |
container->setPlugin(new_plugin); |
// Save the element in case the plugin is removed from the page during |
// initialization. |
- WebElement element = container->element(); |
+ blink::WebElement element = container->element(); |
bool plugin_needs_initialization = |
!premade_throttler_ || new_plugin != premade_throttler_->GetWebPlugin(); |
if (plugin_needs_initialization && !new_plugin->initialize(container)) { |
@@ -169,54 +135,6 @@ void LoadablePluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { |
plugin()->destroy(); |
} |
-void LoadablePluginPlaceholder::HidePlugin() { |
- hidden_ = true; |
- if (!plugin()) |
- return; |
- WebPluginContainer* container = plugin()->container(); |
- WebElement element = container->element(); |
- element.setAttribute("style", "display: none;"); |
- // If we have a width and height, search for a parent (often <div>) with the |
- // same dimensions. If we find such a parent, hide that as well. |
- // This makes much more uncovered page content usable (including clickable) |
- // as opposed to merely visible. |
- // TODO(cevans) -- it's a foul heuristic but we're going to tolerate it for |
- // now for these reasons: |
- // 1) Makes the user experience better. |
- // 2) Foulness is encapsulated within this single function. |
- // 3) Confidence in no fasle positives. |
- // 4) Seems to have a good / low false negative rate at this time. |
- if (element.hasAttribute("width") && element.hasAttribute("height")) { |
- std::string width_str("width:[\\s]*"); |
- width_str += element.getAttribute("width").utf8().data(); |
- if (EndsWith(width_str, "px", false)) { |
- width_str = width_str.substr(0, width_str.length() - 2); |
- } |
- base::TrimWhitespace(width_str, base::TRIM_TRAILING, &width_str); |
- width_str += "[\\s]*px"; |
- std::string height_str("height:[\\s]*"); |
- height_str += element.getAttribute("height").utf8().data(); |
- if (EndsWith(height_str, "px", false)) { |
- height_str = height_str.substr(0, height_str.length() - 2); |
- } |
- base::TrimWhitespace(height_str, base::TRIM_TRAILING, &height_str); |
- height_str += "[\\s]*px"; |
- WebNode parent = element; |
- while (!parent.parentNode().isNull()) { |
- parent = parent.parentNode(); |
- if (!parent.isElementNode()) |
- continue; |
- element = parent.toConst<WebElement>(); |
- if (element.hasAttribute("style")) { |
- std::string style_str = element.getAttribute("style").utf8(); |
- if (RE2::PartialMatch(style_str, width_str) && |
- RE2::PartialMatch(style_str, height_str)) |
- element.setAttribute("style", "display: none;"); |
- } |
- } |
- } |
-} |
- |
void LoadablePluginPlaceholder::SetMessage(const base::string16& message) { |
message_ = message; |
if (finished_loading_) |
@@ -229,11 +147,10 @@ void LoadablePluginPlaceholder::UpdateMessage() { |
std::string script = |
"window.setMessage(" + base::GetQuotedJSONString(message_) + ")"; |
plugin()->web_view()->mainFrame()->executeScript( |
- WebScriptSource(base::UTF8ToUTF16(script))); |
+ blink::WebScriptSource(base::UTF8ToUTF16(script))); |
} |
void LoadablePluginPlaceholder::PluginDestroyed() { |
-#if defined(ENABLE_PLUGINS) |
if (power_saver_enabled_) { |
if (premade_throttler_) { |
// Since the premade plugin has been detached from the container, it will |
@@ -249,19 +166,16 @@ void LoadablePluginPlaceholder::PluginDestroyed() { |
// Prevent processing subsequent calls to MarkPluginEssential. |
power_saver_enabled_ = false; |
} |
-#endif |
PluginPlaceholder::PluginDestroyed(); |
} |
v8::Local<v8::Object> LoadablePluginPlaceholder::GetV8ScriptableObject( |
v8::Isolate* isolate) const { |
-#if defined(ENABLE_PLUGINS) |
// Pass through JavaScript access to the underlying throttled plugin. |
if (premade_throttler_ && premade_throttler_->GetWebPlugin()) { |
return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate); |
} |
-#endif |
return v8::Local<v8::Object>(); |
} |
@@ -296,7 +210,7 @@ void LoadablePluginPlaceholder::OnSetIsPrerendering(bool is_prerendering) { |
void LoadablePluginPlaceholder::LoadPlugin() { |
// This is not strictly necessary but is an important defense in case the |
// event propagation changes between "close" vs. "click-to-play". |
- if (hidden_) |
+ if (hidden()) |
return; |
if (!plugin()) |
return; |
@@ -316,19 +230,12 @@ void LoadablePluginPlaceholder::LoadPlugin() { |
void LoadablePluginPlaceholder::LoadCallback() { |
RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); |
-#if defined(ENABLE_PLUGINS) |
// If the user specifically clicks on the plugin content's placeholder, |
// disable power saver throttling for this instance. |
MarkPluginEssential(PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK); |
-#endif |
LoadPlugin(); |
} |
-void LoadablePluginPlaceholder::HideCallback() { |
- RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click")); |
- HidePlugin(); |
-} |
- |
void LoadablePluginPlaceholder::DidFinishLoadingCallback() { |
finished_loading_ = true; |
if (message_.length() > 0) |
@@ -343,7 +250,7 @@ void LoadablePluginPlaceholder::DidFinishLoadingCallback() { |
// placeholder to be ready to receive simulated user input. |
if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
switches::kEnablePluginPlaceholderTesting)) { |
- WebElement element = plugin()->container()->element(); |
+ blink::WebElement element = plugin()->container()->element(); |
element.setAttribute("placeholderLoaded", "true"); |
scoped_ptr<content::V8ValueConverter> converter( |