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/malware_dom_details.h" | 5 #include "chrome/renderer/safe_browsing/malware_dom_details.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "chrome/common/chrome_constants.h" | 8 #include "chrome/common/chrome_constants.h" |
9 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 9 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 void MalwareDOMDetails::OnGetMalwareDOMDetails() { | 47 void MalwareDOMDetails::OnGetMalwareDOMDetails() { |
48 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> resources; | 48 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> resources; |
49 ExtractResources(&resources); | 49 ExtractResources(&resources); |
50 // Notify the browser. | 50 // Notify the browser. |
51 render_view()->Send(new SafeBrowsingHostMsg_MalwareDOMDetails( | 51 render_view()->Send(new SafeBrowsingHostMsg_MalwareDOMDetails( |
52 render_view()->GetRoutingID(), resources)); | 52 render_view()->GetRoutingID(), resources)); |
53 } | 53 } |
54 | 54 |
55 void MalwareDOMDetails::ExtractResources( | 55 void MalwareDOMDetails::ExtractResources( |
56 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>* resources) { | 56 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>* resources) { |
57 WebKit::WebView* web_view = render_view()->GetWebView(); | 57 blink::WebView* web_view = render_view()->GetWebView(); |
58 if (!web_view) { | 58 if (!web_view) { |
59 NOTREACHED(); | 59 NOTREACHED(); |
60 return; | 60 return; |
61 } | 61 } |
62 WebKit::WebFrame* frame = web_view->mainFrame(); | 62 blink::WebFrame* frame = web_view->mainFrame(); |
63 for (; frame; frame = frame->traverseNext(false /* don't wrap */)) { | 63 for (; frame; frame = frame->traverseNext(false /* don't wrap */)) { |
64 DCHECK(frame); | 64 DCHECK(frame); |
65 SafeBrowsingHostMsg_MalwareDOMDetails_Node details_node; | 65 SafeBrowsingHostMsg_MalwareDOMDetails_Node details_node; |
66 WebKit::WebDocument document = frame->document(); | 66 blink::WebDocument document = frame->document(); |
67 details_node.url = GURL(document.url()); | 67 details_node.url = GURL(document.url()); |
68 if (document.isNull()) { | 68 if (document.isNull()) { |
69 // Nothing in this frame, move on to the next one. | 69 // Nothing in this frame, move on to the next one. |
70 resources->push_back(details_node); | 70 resources->push_back(details_node); |
71 continue; | 71 continue; |
72 } | 72 } |
73 | 73 |
74 WebKit::WebNodeCollection elements = document.all(); | 74 blink::WebNodeCollection elements = document.all(); |
75 WebKit::WebNode cur_node = elements.firstItem(); | 75 blink::WebNode cur_node = elements.firstItem(); |
76 for (; !cur_node.isNull(); cur_node = elements.nextItem()) { | 76 for (; !cur_node.isNull(); cur_node = elements.nextItem()) { |
77 if (!cur_node.isElementNode()) { | 77 if (!cur_node.isElementNode()) { |
78 continue; | 78 continue; |
79 } | 79 } |
80 WebKit::WebElement element = cur_node.to<WebKit::WebElement>(); | 80 blink::WebElement element = cur_node.to<blink::WebElement>(); |
81 if (element.hasTagName("iframe") || element.hasTagName("frame") || | 81 if (element.hasTagName("iframe") || element.hasTagName("frame") || |
82 element.hasTagName("embed") || element.hasTagName("script")) { | 82 element.hasTagName("embed") || element.hasTagName("script")) { |
83 HandleElement(element, &details_node, resources); | 83 HandleElement(element, &details_node, resources); |
84 if (resources->size() >= kMaxNodes) { | 84 if (resources->size() >= kMaxNodes) { |
85 // We have reached kMaxNodes, exit early. | 85 // We have reached kMaxNodes, exit early. |
86 resources->push_back(details_node); | 86 resources->push_back(details_node); |
87 return; | 87 return; |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 resources->push_back(details_node); | 92 resources->push_back(details_node); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void MalwareDOMDetails::HandleElement( | 96 void MalwareDOMDetails::HandleElement( |
97 const WebKit::WebElement& element, | 97 const blink::WebElement& element, |
98 SafeBrowsingHostMsg_MalwareDOMDetails_Node* parent_node, | 98 SafeBrowsingHostMsg_MalwareDOMDetails_Node* parent_node, |
99 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>* resources) { | 99 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>* resources) { |
100 if (!element.hasAttribute("src")) { | 100 if (!element.hasAttribute("src")) { |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 // Retrieve the link and resolve the link in case it's relative. | 104 // Retrieve the link and resolve the link in case it's relative. |
105 WebKit::WebURL full_url = element.document().completeURL( | 105 blink::WebURL full_url = element.document().completeURL( |
106 element.getAttribute("src")); | 106 element.getAttribute("src")); |
107 | 107 |
108 const GURL& child_url = GURL(full_url); | 108 const GURL& child_url = GURL(full_url); |
109 | 109 |
110 // Add to the parent node. | 110 // Add to the parent node. |
111 parent_node->children.push_back(child_url); | 111 parent_node->children.push_back(child_url); |
112 | 112 |
113 // Create the child node. | 113 // Create the child node. |
114 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node; | 114 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node; |
115 child_node.url = child_url; | 115 child_node.url = child_url; |
116 child_node.tag_name = element.tagName().utf8(); | 116 child_node.tag_name = element.tagName().utf8(); |
117 child_node.parent = parent_node->url; | 117 child_node.parent = parent_node->url; |
118 resources->push_back(child_node); | 118 resources->push_back(child_node); |
119 } | 119 } |
120 | 120 |
121 } // namespace safe_browsing | 121 } // namespace safe_browsing |
OLD | NEW |