OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/blocked_plugin.h" | 5 #include "chrome/renderer/blocked_plugin.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/jstemplate_builder.h" | 11 #include "chrome/common/jstemplate_builder.h" |
12 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/renderer/render_view.h" | 14 #include "chrome/renderer/render_view.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/renderer_resources.h" | 16 #include "grit/renderer_resources.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" |
19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
20 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h" |
21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
22 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebTextCaseSensitivity.h" |
23 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
24 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 26 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
25 #include "webkit/glue/webpreferences.h" | 27 #include "webkit/glue/webpreferences.h" |
26 #include "webkit/plugins/npapi/plugin_group.h" | 28 #include "webkit/plugins/npapi/plugin_group.h" |
27 #include "webkit/plugins/npapi/webview_plugin.h" | 29 #include "webkit/plugins/npapi/webview_plugin.h" |
28 | 30 |
29 using WebKit::WebContextMenuData; | 31 using WebKit::WebContextMenuData; |
| 32 using WebKit::WebElement; |
30 using WebKit::WebFrame; | 33 using WebKit::WebFrame; |
31 using WebKit::WebMenuItemInfo; | 34 using WebKit::WebMenuItemInfo; |
| 35 using WebKit::WebNode; |
32 using WebKit::WebPlugin; | 36 using WebKit::WebPlugin; |
33 using WebKit::WebPluginContainer; | 37 using WebKit::WebPluginContainer; |
34 using WebKit::WebPluginParams; | 38 using WebKit::WebPluginParams; |
35 using WebKit::WebPoint; | 39 using WebKit::WebPoint; |
| 40 using WebKit::WebRegularExpression; |
36 using WebKit::WebString; | 41 using WebKit::WebString; |
37 using WebKit::WebVector; | 42 using WebKit::WebVector; |
38 | 43 |
39 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; | 44 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; |
40 static const unsigned kMenuActionLoad = 1; | 45 static const unsigned kMenuActionLoad = 1; |
41 static const unsigned kMenuActionRemove = 2; | 46 static const unsigned kMenuActionRemove = 2; |
42 | 47 |
43 BlockedPlugin::BlockedPlugin(RenderView* render_view, | 48 BlockedPlugin::BlockedPlugin(RenderView* render_view, |
44 WebFrame* frame, | 49 WebFrame* frame, |
45 const webkit::npapi::PluginGroup& info, | 50 const webkit::npapi::PluginGroup& info, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 container->invalidate(); | 160 container->invalidate(); |
156 container->reportGeometry(); | 161 container->reportGeometry(); |
157 plugin_->ReplayReceivedData(new_plugin); | 162 plugin_->ReplayReceivedData(new_plugin); |
158 plugin_->destroy(); | 163 plugin_->destroy(); |
159 } | 164 } |
160 } | 165 } |
161 | 166 |
162 void BlockedPlugin::HidePlugin() { | 167 void BlockedPlugin::HidePlugin() { |
163 CHECK(plugin_); | 168 CHECK(plugin_); |
164 WebPluginContainer* container = plugin_->container(); | 169 WebPluginContainer* container = plugin_->container(); |
165 container->element().setAttribute("style", "display: none;"); | 170 WebElement element = container->element(); |
| 171 element.setAttribute("style", "display: none;"); |
| 172 // If we have a width and height, search for a parent (often <div>) with the |
| 173 // same dimensions. If we find such a parent, hide that as well. |
| 174 // This makes much more uncovered page content usable (including clickable) |
| 175 // as opposed to merely visible. |
| 176 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for |
| 177 // now for these reasons: |
| 178 // 1) Makes the user experience better. |
| 179 // 2) Foulness is encapsulated within this single function. |
| 180 // 3) Confidence in no fasle positives. |
| 181 // 4) Seems to have a good / low false negative rate at this time. |
| 182 if (element.hasAttribute("width") && element.hasAttribute("height")) { |
| 183 std::string width_str("width:[\\s]*"); |
| 184 width_str += element.getAttribute("width").utf8().data(); |
| 185 width_str += "[\\s]*px"; |
| 186 WebRegularExpression width_regex(WebString::fromUTF8(width_str.c_str()), |
| 187 WebKit::WebTextCaseSensitive); |
| 188 std::string height_str("height:[\\s]*"); |
| 189 height_str += element.getAttribute("height").utf8().data(); |
| 190 height_str += "[\\s]*px"; |
| 191 WebRegularExpression height_regex(WebString::fromUTF8(height_str.c_str()), |
| 192 WebKit::WebTextCaseSensitive); |
| 193 WebNode parent = element; |
| 194 while (!parent.parentNode().isNull()) { |
| 195 parent = parent.parentNode(); |
| 196 if (!parent.isElementNode()) |
| 197 continue; |
| 198 element = parent.toConst<WebElement>(); |
| 199 if (element.hasAttribute("style")) { |
| 200 WebString style_str = element.getAttribute("style"); |
| 201 if (width_regex.match(style_str) >= 0 && |
| 202 height_regex.match(style_str) >= 0) |
| 203 element.setAttribute("style", "display: none;"); |
| 204 } |
| 205 } |
| 206 } |
166 } | 207 } |
167 | 208 |
OLD | NEW |