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 <unordered_set> | 10 #include <unordered_set> |
10 | 11 |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/metrics/field_trial_params.h" | 13 #include "base/metrics/field_trial_params.h" |
13 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "components/safe_browsing/common/safebrowsing_messages.h" | 17 #include "components/safe_browsing/common/safebrowsing_messages.h" |
17 #include "components/safe_browsing/common/safebrowsing_types.h" | 18 #include "components/safe_browsing/common/safebrowsing_types.h" |
18 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 std::sort(tag_and_attributes_list->begin(), tag_and_attributes_list->end(), | 102 std::sort(tag_and_attributes_list->begin(), tag_and_attributes_list->end(), |
102 [](const TagAndAttributesItem& a, const TagAndAttributesItem& b) { | 103 [](const TagAndAttributesItem& a, const TagAndAttributesItem& b) { |
103 return a.tag_name < b.tag_name; | 104 return a.tag_name < b.tag_name; |
104 }); | 105 }); |
105 } | 106 } |
106 | 107 |
107 SafeBrowsingHostMsg_ThreatDOMDetails_Node* GetNodeForElement( | 108 SafeBrowsingHostMsg_ThreatDOMDetails_Node* GetNodeForElement( |
108 const blink::WebNode& element, | 109 const blink::WebNode& element, |
109 const safe_browsing::ElementToNodeMap& element_to_node_map, | 110 const safe_browsing::ElementToNodeMap& element_to_node_map, |
110 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources) { | 111 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources) { |
111 DCHECK(element_to_node_map.count(element) > 0); | 112 DCHECK_GT(element_to_node_map.count(element), 0u); |
112 size_t resource_index = element_to_node_map.at(element); | 113 size_t resource_index = element_to_node_map.at(element); |
113 return &(resources->at(resource_index)); | 114 return &(resources->at(resource_index)); |
114 } | 115 } |
115 | 116 |
116 std::string TruncateAttributeString(const std::string& input) { | 117 std::string TruncateAttributeString(const std::string& input) { |
117 if (input.length() <= ThreatDOMDetails::kMaxAttributeStringLength) { | 118 if (input.length() <= ThreatDOMDetails::kMaxAttributeStringLength) { |
118 return input; | 119 return input; |
119 } | 120 } |
120 | 121 |
121 std::string truncated; | 122 std::string truncated; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 274 |
274 void ThreatDOMDetails::OnGetThreatDOMDetails() { | 275 void ThreatDOMDetails::OnGetThreatDOMDetails() { |
275 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> resources; | 276 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> resources; |
276 ExtractResources(&resources); | 277 ExtractResources(&resources); |
277 // Notify the browser. | 278 // Notify the browser. |
278 Send(new SafeBrowsingHostMsg_ThreatDOMDetails(routing_id(), resources)); | 279 Send(new SafeBrowsingHostMsg_ThreatDOMDetails(routing_id(), resources)); |
279 } | 280 } |
280 | 281 |
281 void ThreatDOMDetails::ExtractResources( | 282 void ThreatDOMDetails::ExtractResources( |
282 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources) { | 283 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources) { |
283 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 284 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
284 if (!frame) | 285 if (!frame) |
285 return; | 286 return; |
286 SafeBrowsingHostMsg_ThreatDOMDetails_Node details_node; | 287 SafeBrowsingHostMsg_ThreatDOMDetails_Node details_node; |
287 blink::WebDocument document = frame->GetDocument(); | 288 blink::WebDocument document = frame->GetDocument(); |
288 details_node.url = GURL(document.Url()); | 289 details_node.url = GURL(document.Url()); |
289 if (document.IsNull()) { | 290 if (document.IsNull()) { |
290 // Nothing in this frame. Just report its URL. | 291 // Nothing in this frame. Just report its URL. |
291 resources->push_back(details_node); | 292 resources->push_back(details_node); |
292 return; | 293 return; |
293 } | 294 } |
(...skipping 13 matching lines...) Expand all Loading... |
307 } | 308 } |
308 } | 309 } |
309 resources->push_back(details_node); | 310 resources->push_back(details_node); |
310 } | 311 } |
311 | 312 |
312 void ThreatDOMDetails::OnDestruct() { | 313 void ThreatDOMDetails::OnDestruct() { |
313 delete this; | 314 delete this; |
314 } | 315 } |
315 | 316 |
316 } // namespace safe_browsing | 317 } // namespace safe_browsing |
OLD | NEW |