OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/safe_browsing/renderer/threat_dom_details.h" | 5 #include "components/safe_browsing/renderer/threat_dom_details.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_set> | 10 #include <unordered_set> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/metrics/field_trial_params.h" | 13 #include "base/metrics/field_trial_params.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "components/safe_browsing/common/safebrowsing_messages.h" | 17 #include "components/safe_browsing/common/safebrowsing_messages.h" |
18 #include "components/safe_browsing/common/safebrowsing_types.h" | 18 #include "components/safe_browsing/common/safebrowsing_types.h" |
19 #include "components/safe_browsing/features.h" | |
20 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
21 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
24 #include "third_party/WebKit/public/web/WebElementCollection.h" | 23 #include "third_party/WebKit/public/web/WebElementCollection.h" |
25 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
27 | 26 |
28 namespace safe_browsing { | 27 namespace safe_browsing { |
29 | 28 |
30 // A map for keeping track of the identity of DOM Elements, used to generate | 29 // A map for keeping track of the identity of DOM Elements, used to generate |
31 // unique IDs for each element and lookup elements IDs by parent Element, to | 30 // unique IDs for each element and lookup elements IDs by parent Element, to |
32 // maintain proper parent/child relationships. | 31 // maintain proper parent/child relationships. |
33 // They key is a WebNode from the DOM, which is basically a pointer so can be | 32 // They key is a WebNode from the DOM, which is basically a pointer so can be |
34 // copied into the map when inserting new elements. | 33 // copied into the map when inserting new elements. |
35 // The values are indices into the resource vector, and are used to retrieve IPC | 34 // The values are indices into the resource vector, and are used to retrieve IPC |
36 // messages generated by ThreatDOMDetails. | 35 // messages generated by ThreatDOMDetails. |
37 using ElementToNodeMap = std::map<blink::WebNode, size_t>; | 36 using ElementToNodeMap = std::map<blink::WebNode, size_t>; |
38 | 37 |
| 38 // This Feature specifies which non-resource HTML Elements to collect based on |
| 39 // their tag and attributes. It's a single param containing a comma-separated |
| 40 // list of pairs. For example: "tag1,id,tag1,height,tag2,foo" - this will |
| 41 // collect elements with tag "tag1" that have attribute "id" or "height" set, |
| 42 // and elements of tag "tag2" if they have attribute "foo" set. All tag names |
| 43 // and attributes should be lower case. |
| 44 const base::Feature kThreatDomDetailsTagAndAttributeFeature{ |
| 45 "ThreatDomDetailsTagAttributes", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 46 |
39 // The name of the param containing the tags and attributes list. | 47 // The name of the param containing the tags and attributes list. |
40 const char kTagAndAttributeParamName[] = "tag_attribute_csv"; | 48 const char kTagAndAttributeParamName[] = "tag_attribute_csv"; |
41 | 49 |
42 namespace { | 50 namespace { |
43 | 51 |
44 // Predicate used to search |tag_and_attributes_list_| by tag_name. | 52 // Predicate used to search |tag_and_attributes_list_| by tag_name. |
45 class TagNameIs { | 53 class TagNameIs { |
46 public: | 54 public: |
47 explicit TagNameIs(const std::string& tag) : tag_(tag) {} | 55 explicit TagNameIs(const std::string& tag) : tag_(tag) {} |
48 bool operator()(const TagAndAttributesItem& tag_and_attribute) { | 56 bool operator()(const TagAndAttributesItem& tag_and_attribute) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 308 } |
301 } | 309 } |
302 resources->push_back(details_node); | 310 resources->push_back(details_node); |
303 } | 311 } |
304 | 312 |
305 void ThreatDOMDetails::OnDestruct() { | 313 void ThreatDOMDetails::OnDestruct() { |
306 delete this; | 314 delete this; |
307 } | 315 } |
308 | 316 |
309 } // namespace safe_browsing | 317 } // namespace safe_browsing |
OLD | NEW |