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

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

Issue 1161923004: Reland: Plugin Placeholders: Refactor for platforms that don't support plugins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove some enable_plugins that are no longer needed Created 5 years, 6 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
« no previous file with comments | « components/plugins/renderer/plugin_placeholder.h ('k') | components/plugins/renderer/webview_plugin.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/plugins/renderer/plugin_placeholder.cc
diff --git a/components/plugins/renderer/plugin_placeholder.cc b/components/plugins/renderer/plugin_placeholder.cc
index 180e913896646407dc8590222d78ebaa3d795805..98fc8cb9d7901a3f4ff432104dd85c82b0ac0ef5 100644
--- a/components/plugins/renderer/plugin_placeholder.cc
+++ b/components/plugins/renderer/plugin_placeholder.cc
@@ -4,18 +4,26 @@
#include "components/plugins/renderer/plugin_placeholder.h"
+#include "base/strings/string_util.h"
#include "content/public/common/web_preferences.h"
#include "content/public/renderer/render_frame.h"
+#include "content/public/renderer/render_thread.h"
+#include "gin/object_template_builder.h"
+#include "third_party/WebKit/public/web/WebElement.h"
+#include "third_party/WebKit/public/web/WebPluginContainer.h"
+#include "third_party/re2/re2/re2.h"
namespace plugins {
-gin::WrapperInfo PluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin};
+// The placeholder is loaded in normal web renderer processes, so it should not
+// have a chrome:// scheme that might let it be confused with a WebUI page.
+const char kPluginPlaceholderDataURL[] = "data:text/html,pluginplaceholderdata";
-PluginPlaceholder::PluginPlaceholder(content::RenderFrame* render_frame,
- blink::WebLocalFrame* frame,
- const blink::WebPluginParams& params,
- const std::string& html_data,
- GURL placeholderDataUrl)
+PluginPlaceholderBase::PluginPlaceholderBase(
+ content::RenderFrame* render_frame,
+ blink::WebLocalFrame* frame,
+ const blink::WebPluginParams& params,
+ const std::string& html_data)
: content::RenderFrameObserver(render_frame),
frame_(frame),
plugin_params_(params),
@@ -24,36 +32,116 @@ PluginPlaceholder::PluginPlaceholder(content::RenderFrame* render_frame,
? render_frame->GetWebkitPreferences()
: content::WebPreferences(),
html_data,
- placeholderDataUrl)) {
- DCHECK(placeholderDataUrl.is_valid())
- << "Blink requires the placeholder to have a valid URL.";
+ GURL(kPluginPlaceholderDataURL))),
+ hidden_(false) {
}
-PluginPlaceholder::~PluginPlaceholder() {}
+PluginPlaceholderBase::~PluginPlaceholderBase() {
+}
-const blink::WebPluginParams& PluginPlaceholder::GetPluginParams() const {
+const blink::WebPluginParams& PluginPlaceholderBase::GetPluginParams() const {
return plugin_params_;
}
-void PluginPlaceholder::ShowContextMenu(const blink::WebMouseEvent& event) {
+void PluginPlaceholderBase::ShowContextMenu(const blink::WebMouseEvent& event) {
// Does nothing by default. Will be overridden if a specific browser wants
// a context menu.
return;
}
-void PluginPlaceholder::PluginDestroyed() {
+void PluginPlaceholderBase::PluginDestroyed() {
plugin_ = NULL;
}
-v8::Local<v8::Object> PluginPlaceholder::GetV8ScriptableObject(
+v8::Local<v8::Object> PluginPlaceholderBase::GetV8ScriptableObject(
v8::Isolate* isolate) const {
return v8::Local<v8::Object>();
}
-void PluginPlaceholder::OnDestruct() {
+void PluginPlaceholderBase::HidePlugin() {
+ hidden_ = true;
+ if (!plugin())
+ return;
+ blink::WebPluginContainer* container = plugin()->container();
+ blink::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";
+ blink::WebNode parent = element;
+ while (!parent.parentNode().isNull()) {
+ parent = parent.parentNode();
+ if (!parent.isElementNode())
+ continue;
+ element = parent.toConst<blink::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 PluginPlaceholderBase::HideCallback() {
+ content::RenderThread::Get()->RecordAction(
+ base::UserMetricsAction("Plugin_Hide_Click"));
+ HidePlugin();
+}
+
+void PluginPlaceholderBase::OnDestruct() {
frame_ = NULL;
}
-blink::WebLocalFrame* PluginPlaceholder::GetFrame() { return frame_; }
+blink::WebLocalFrame* PluginPlaceholderBase::GetFrame() {
+ return frame_;
+}
+
+// static
+gin::WrapperInfo PluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin};
+
+PluginPlaceholder::PluginPlaceholder(content::RenderFrame* render_frame,
+ blink::WebLocalFrame* frame,
+ const blink::WebPluginParams& params,
+ const std::string& html_data)
+ : PluginPlaceholderBase(render_frame, frame, params, html_data) {
+}
+
+PluginPlaceholder::~PluginPlaceholder() {
+}
+
+v8::Local<v8::Value> PluginPlaceholder::GetV8Handle(v8::Isolate* isolate) {
+ return gin::CreateHandle(isolate, this).ToV8();
+}
+
+gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder(
+ v8::Isolate* isolate) {
+ return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate)
+ .SetMethod<void (plugins::PluginPlaceholder::*)()>(
+ "hide", &PluginPlaceholder::HideCallback);
+}
} // namespace plugins
« no previous file with comments | « components/plugins/renderer/plugin_placeholder.h ('k') | components/plugins/renderer/webview_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698