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/string_util.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/common/jstemplate_builder.h" | 12 #include "chrome/common/jstemplate_builder.h" |
12 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
13 #include "chrome/renderer/render_view.h" | 14 #include "chrome/renderer/render_view.h" |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // as opposed to merely visible. | 182 // as opposed to merely visible. |
182 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for | 183 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for |
183 // now for these reasons: | 184 // now for these reasons: |
184 // 1) Makes the user experience better. | 185 // 1) Makes the user experience better. |
185 // 2) Foulness is encapsulated within this single function. | 186 // 2) Foulness is encapsulated within this single function. |
186 // 3) Confidence in no fasle positives. | 187 // 3) Confidence in no fasle positives. |
187 // 4) Seems to have a good / low false negative rate at this time. | 188 // 4) Seems to have a good / low false negative rate at this time. |
188 if (element.hasAttribute("width") && element.hasAttribute("height")) { | 189 if (element.hasAttribute("width") && element.hasAttribute("height")) { |
189 std::string width_str("width:[\\s]*"); | 190 std::string width_str("width:[\\s]*"); |
190 width_str += element.getAttribute("width").utf8().data(); | 191 width_str += element.getAttribute("width").utf8().data(); |
| 192 if (EndsWith(width_str, "px", false)) { |
| 193 width_str = width_str.substr(0, width_str.length() - 2); |
| 194 } |
| 195 TrimWhitespace(width_str, TRIM_TRAILING, &width_str); |
191 width_str += "[\\s]*px"; | 196 width_str += "[\\s]*px"; |
192 WebRegularExpression width_regex(WebString::fromUTF8(width_str.c_str()), | 197 WebRegularExpression width_regex(WebString::fromUTF8(width_str.c_str()), |
193 WebKit::WebTextCaseSensitive); | 198 WebKit::WebTextCaseSensitive); |
194 std::string height_str("height:[\\s]*"); | 199 std::string height_str("height:[\\s]*"); |
195 height_str += element.getAttribute("height").utf8().data(); | 200 height_str += element.getAttribute("height").utf8().data(); |
| 201 if (EndsWith(height_str, "px", false)) { |
| 202 height_str = height_str.substr(0, height_str.length() - 2); |
| 203 } |
| 204 TrimWhitespace(height_str, TRIM_TRAILING, &height_str); |
196 height_str += "[\\s]*px"; | 205 height_str += "[\\s]*px"; |
197 WebRegularExpression height_regex(WebString::fromUTF8(height_str.c_str()), | 206 WebRegularExpression height_regex(WebString::fromUTF8(height_str.c_str()), |
198 WebKit::WebTextCaseSensitive); | 207 WebKit::WebTextCaseSensitive); |
199 WebNode parent = element; | 208 WebNode parent = element; |
200 while (!parent.parentNode().isNull()) { | 209 while (!parent.parentNode().isNull()) { |
201 parent = parent.parentNode(); | 210 parent = parent.parentNode(); |
202 if (!parent.isElementNode()) | 211 if (!parent.isElementNode()) |
203 continue; | 212 continue; |
204 element = parent.toConst<WebElement>(); | 213 element = parent.toConst<WebElement>(); |
205 if (element.hasAttribute("style")) { | 214 if (element.hasAttribute("style")) { |
206 WebString style_str = element.getAttribute("style"); | 215 WebString style_str = element.getAttribute("style"); |
207 if (width_regex.match(style_str) >= 0 && | 216 if (width_regex.match(style_str) >= 0 && |
208 height_regex.match(style_str) >= 0) | 217 height_regex.match(style_str) >= 0) |
209 element.setAttribute("style", "display: none;"); | 218 element.setAttribute("style", "display: none;"); |
210 } | 219 } |
211 } | 220 } |
212 } | 221 } |
213 } | 222 } |
214 | 223 |
OLD | NEW |