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 "chrome/renderer/safe_browsing/threat_dom_details.h" | 5 #include "chrome/renderer/safe_browsing/threat_dom_details.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <unordered_set> | 9 #include <unordered_set> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace safe_browsing { | 26 namespace safe_browsing { |
27 | 27 |
28 // A map for keeping track of the identity of DOM Elements, used to generate | 28 // A map for keeping track of the identity of DOM Elements, used to generate |
29 // unique IDs for each element and lookup elements IDs by parent Element, to | 29 // unique IDs for each element and lookup elements IDs by parent Element, to |
30 // maintain proper parent/child relationships. | 30 // maintain proper parent/child relationships. |
31 // They key is a WebNode from the DOM, which is basically a pointer so can be | 31 // They key is a WebNode from the DOM, which is basically a pointer so can be |
32 // copied into the map when inserting new elements. | 32 // copied into the map when inserting new elements. |
33 // The values are indices into the resource vector, and are used to retrieve IPC | 33 // The values are indices into the resource vector, and are used to retrieve IPC |
34 // messages generated by ThreatDOMDetails. | 34 // messages generated by ThreatDOMDetails. |
35 using ElementToNodeMap = std::map<blink::WebNode, int>; | 35 using ElementToNodeMap = std::map<blink::WebNode, size_t>; |
36 | 36 |
37 // This Feature specifies which non-resource HTML Elements to collect based on | 37 // This Feature specifies which non-resource HTML Elements to collect based on |
38 // their tag and attributes. It's a single param containing a comma-separated | 38 // their tag and attributes. It's a single param containing a comma-separated |
39 // list of pairs. For example: "tag1,id,tag1,height,tag2,foo" - this will | 39 // list of pairs. For example: "tag1,id,tag1,height,tag2,foo" - this will |
40 // collect elements with tag "tag1" that have attribute "id" or "height" set, | 40 // collect elements with tag "tag1" that have attribute "id" or "height" set, |
41 // and elements of tag "tag2" if they have attribute "foo" set. All tag names | 41 // and elements of tag "tag2" if they have attribute "foo" set. All tag names |
42 // and attributes should be lower case. | 42 // and attributes should be lower case. |
43 const base::Feature kThreatDomDetailsTagAndAttributeFeature{ | 43 const base::Feature kThreatDomDetailsTagAndAttributeFeature{ |
44 "ThreatDomDetailsTagAttributes", base::FEATURE_DISABLED_BY_DEFAULT}; | 44 "ThreatDomDetailsTagAttributes", base::FEATURE_DISABLED_BY_DEFAULT}; |
45 | 45 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 element.getAttribute(attr_webstring).ascii()))); | 164 element.getAttribute(attr_webstring).ascii()))); |
165 if (child_node.attributes.size() == ThreatDOMDetails::kMaxAttributes) { | 165 if (child_node.attributes.size() == ThreatDOMDetails::kMaxAttributes) { |
166 break; | 166 break; |
167 } | 167 } |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 // Update the ID mapping. First generate the ID for the current node. | 171 // Update the ID mapping. First generate the ID for the current node. |
172 // Then, if its parent is available, set the current node's parent ID, and | 172 // Then, if its parent is available, set the current node's parent ID, and |
173 // also update the parent's children with the current node's ID. | 173 // also update the parent's children with the current node's ID. |
174 const int child_id = element_to_node_map->size() + 1; | 174 const size_t child_id = element_to_node_map->size() + 1; |
175 child_node.node_id = child_id; | 175 child_node.node_id = child_id; |
176 blink::WebNode cur_parent_element = element.parentNode(); | 176 blink::WebNode cur_parent_element = element.parentNode(); |
177 while (!cur_parent_element.isNull()) { | 177 while (!cur_parent_element.isNull()) { |
178 if (element_to_node_map->count(cur_parent_element) > 0) { | 178 if (element_to_node_map->count(cur_parent_element) > 0) { |
179 SafeBrowsingHostMsg_ThreatDOMDetails_Node* parent_node = | 179 SafeBrowsingHostMsg_ThreatDOMDetails_Node* parent_node = |
180 GetNodeForElement(cur_parent_element, *element_to_node_map, | 180 GetNodeForElement(cur_parent_element, *element_to_node_map, |
181 resources); | 181 resources); |
182 child_node.parent_node_id = parent_node->node_id; | 182 child_node.parent_node_id = parent_node->node_id; |
183 parent_node->child_node_ids.push_back(child_id); | 183 parent_node->child_node_ids.push_back(child_id); |
184 | 184 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 } | 299 } |
300 resources->push_back(details_node); | 300 resources->push_back(details_node); |
301 } | 301 } |
302 | 302 |
303 void ThreatDOMDetails::OnDestruct() { | 303 void ThreatDOMDetails::OnDestruct() { |
304 delete this; | 304 delete this; |
305 } | 305 } |
306 | 306 |
307 } // namespace safe_browsing | 307 } // namespace safe_browsing |
OLD | NEW |