Chromium Code Reviews| 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 <unordered_set> | 9 #include <unordered_set> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 [](const TagAndAttributesItem& a, const TagAndAttributesItem& b) { | 102 [](const TagAndAttributesItem& a, const TagAndAttributesItem& b) { |
| 103 return a.tag_name < b.tag_name; | 103 return a.tag_name < b.tag_name; |
| 104 }); | 104 }); |
| 105 } | 105 } |
| 106 | 106 |
| 107 SafeBrowsingHostMsg_ThreatDOMDetails_Node* GetNodeForElement( | 107 SafeBrowsingHostMsg_ThreatDOMDetails_Node* GetNodeForElement( |
| 108 const blink::WebNode& element, | 108 const blink::WebNode& element, |
| 109 const safe_browsing::ElementToNodeMap& element_to_node_map, | 109 const safe_browsing::ElementToNodeMap& element_to_node_map, |
| 110 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources) { | 110 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources) { |
| 111 DCHECK(element_to_node_map.count(element) > 0); | 111 DCHECK(element_to_node_map.count(element) > 0); |
| 112 int resource_index = element_to_node_map.at(element); | 112 size_t resource_index = element_to_node_map.at(element); |
| 113 return &(resources->at(resource_index)); | 113 return &(resources->at(resource_index)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 std::string TruncateAttributeString(const std::string& input) { | 116 std::string TruncateAttributeString(const std::string& input) { |
| 117 if (input.length() <= ThreatDOMDetails::kMaxAttributeStringLength) { | 117 if (input.length() <= ThreatDOMDetails::kMaxAttributeStringLength) { |
| 118 return input; | 118 return input; |
| 119 } | 119 } |
| 120 | 120 |
| 121 std::string truncated; | 121 std::string truncated; |
| 122 base::TruncateUTF8ToByteSize( | 122 base::TruncateUTF8ToByteSize( |
| (...skipping 41 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 size_t child_id = element_to_node_map->size() + 1; | 174 const int child_id = static_cast<int>(element_to_node_map->size()) + 1; |
|
Nathan Parker
2017/03/22 21:12:56
Why cast to int? I'm not confident I know which i
lpz
2017/03/23 15:37:32
The alternative would be to keep size_t here but t
| |
| 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 |