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

Unified Diff: chrome/renderer/blocked_plugin.cc

Issue 6114004: When hiding a plug-in element, also hide same-sized parent elements (such as... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/blocked_plugin.cc
===================================================================
--- chrome/renderer/blocked_plugin.cc (revision 70986)
+++ chrome/renderer/blocked_plugin.cc (working copy)
@@ -20,6 +20,8 @@
#include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebTextCaseSensitivity.h"
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webpreferences.h"
@@ -27,12 +29,15 @@
#include "webkit/plugins/npapi/webview_plugin.h"
using WebKit::WebContextMenuData;
+using WebKit::WebElement;
using WebKit::WebFrame;
using WebKit::WebMenuItemInfo;
+using WebKit::WebNode;
using WebKit::WebPlugin;
using WebKit::WebPluginContainer;
using WebKit::WebPluginParams;
using WebKit::WebPoint;
+using WebKit::WebRegularExpression;
using WebKit::WebString;
using WebKit::WebVector;
@@ -162,6 +167,42 @@
void BlockedPlugin::HidePlugin() {
CHECK(plugin_);
WebPluginContainer* container = plugin_->container();
- container->element().setAttribute("style", "display: none;");
+ 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 heurisitc 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();
+ width_str += "[\\s]*px";
+ WebRegularExpression width_regex(WebString::fromUTF8(width_str.c_str()),
+ WebKit::WebTextCaseSensitive);
+ std::string height_str("height:[\\s]*");
+ height_str += element.getAttribute("height").utf8().data();
+ height_str += "[\\s]*px";
+ WebRegularExpression height_regex(WebString::fromUTF8(height_str.c_str()),
+ WebKit::WebTextCaseSensitive);
+ WebNode parent = element;
+ while (!parent.parentNode().isNull()) {
+ parent = parent.parentNode();
+ if (!parent.isElementNode())
+ continue;
+ element = parent.toConst<WebElement>();
+ if (element.hasAttribute("style")) {
+ WebString style_str = element.getAttribute("style");
+ if (width_regex.match(style_str) >= 0 &&
+ height_regex.match(style_str) >= 0)
+ element.setAttribute("style", "display: none;");
+ }
+ }
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698