Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: chrome/browser/safe_browsing/malware_details.cc

Issue 6713084: Move the rest of the renderer->browser messages that belong in content. Also do a bunch of cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Implementation of the MalwareDetails class. 5 // Implementation of the MalwareDetails class.
6 6
7 #include "chrome/browser/safe_browsing/malware_details.h" 7 #include "chrome/browser/safe_browsing/malware_details.h"
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 10 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
11 #include "chrome/browser/safe_browsing/report.pb.h" 11 #include "chrome/browser/safe_browsing/report.pb.h"
12 #include "chrome/common/render_messages.h" 12 #include "chrome/common/safebrowsing_messages.h"
13 #include "chrome/common/render_messages_params.h"
14 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
15 #include "content/browser/renderer_host/render_view_host.h" 14 #include "content/browser/renderer_host/render_view_host.h"
16 #include "content/browser/tab_contents/navigation_entry.h" 15 #include "content/browser/tab_contents/navigation_entry.h"
17 #include "content/browser/tab_contents/tab_contents.h" 16 #include "content/browser/tab_contents/tab_contents.h"
18 17
19 using safe_browsing::ClientMalwareReportRequest; 18 using safe_browsing::ClientMalwareReportRequest;
20 19
21 // Keep in sync with KMaxNodes in renderer/safe_browsing/malware_dom_details 20 // Keep in sync with KMaxNodes in renderer/safe_browsing/malware_dom_details
22 static const uint32 kMaxDomNodes = 500; 21 static const uint32 kMaxDomNodes = 500;
23 22
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 : TabContentsObserver(tab_contents), 65 : TabContentsObserver(tab_contents),
67 resource_(resource) { 66 resource_(resource) {
68 StartCollection(); 67 StartCollection();
69 } 68 }
70 69
71 MalwareDetails::~MalwareDetails() {} 70 MalwareDetails::~MalwareDetails() {}
72 71
73 bool MalwareDetails::OnMessageReceived(const IPC::Message& message) { 72 bool MalwareDetails::OnMessageReceived(const IPC::Message& message) {
74 bool handled = true; 73 bool handled = true;
75 IPC_BEGIN_MESSAGE_MAP(MalwareDetails, message) 74 IPC_BEGIN_MESSAGE_MAP(MalwareDetails, message)
76 IPC_MESSAGE_HANDLER(ViewHostMsg_MalwareDOMDetails, 75 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_MalwareDOMDetails,
77 OnReceivedMalwareDOMDetails) 76 OnReceivedMalwareDOMDetails)
78 IPC_MESSAGE_UNHANDLED(handled = false) 77 IPC_MESSAGE_UNHANDLED(handled = false)
79 IPC_END_MESSAGE_MAP() 78 IPC_END_MESSAGE_MAP()
80 return handled; 79 return handled;
81 } 80 }
82 81
83 bool MalwareDetails::IsPublicUrl(const GURL& url) const { 82 bool MalwareDetails::IsPublicUrl(const GURL& url) const {
84 return url.SchemeIs("http"); // TODO(panayiotis): also skip internal urls. 83 return url.SchemeIs("http"); // TODO(panayiotis): also skip internal urls.
85 } 84 }
86 85
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 AddUrl(referrer_url, GURL(), "", NULL); 188 AddUrl(referrer_url, GURL(), "", NULL);
190 } 189 }
191 190
192 // Get URLs of frames, scripts etc from the DOM. 191 // Get URLs of frames, scripts etc from the DOM.
193 // OnReceivedMalwareDOMDetails will be called when the renderer replies. 192 // OnReceivedMalwareDOMDetails will be called when the renderer replies.
194 tab_contents()->render_view_host()->GetMalwareDOMDetails(); 193 tab_contents()->render_view_host()->GetMalwareDOMDetails();
195 } 194 }
196 195
197 // When the renderer is done, this is called. 196 // When the renderer is done, this is called.
198 void MalwareDetails::OnReceivedMalwareDOMDetails( 197 void MalwareDetails::OnReceivedMalwareDOMDetails(
199 const ViewHostMsg_MalwareDOMDetails_Params& params) { 198 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) {
200 // Schedule this in IO thread, so it doesn't conflict with future users 199 // Schedule this in IO thread, so it doesn't conflict with future users
201 // of our data structures (eg GetSerializedReport). 200 // of our data structures (eg GetSerializedReport).
202 BrowserThread::PostTask( 201 BrowserThread::PostTask(
203 BrowserThread::IO, FROM_HERE, 202 BrowserThread::IO, FROM_HERE,
204 NewRunnableMethod( 203 NewRunnableMethod(
205 this, &MalwareDetails::AddDOMDetails, params)); 204 this, &MalwareDetails::AddDOMDetails, params));
206 } 205 }
207 206
208 void MalwareDetails::AddDOMDetails( 207 void MalwareDetails::AddDOMDetails(
209 const ViewHostMsg_MalwareDOMDetails_Params& params) { 208 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) {
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
211 // Add the urls from the DOM to |resources_|. The renderer could be 210 // Add the urls from the DOM to |resources_|. The renderer could be
212 // sending bogus messages, so limit the number of nodes we accept. 211 // sending bogus messages, so limit the number of nodes we accept.
213 DVLOG(1) << "Nodes from the DOM: " << params.nodes.size(); 212 DVLOG(1) << "Nodes from the DOM: " << params.size();
214 for (uint32 i = 0; i < params.nodes.size() && i < kMaxDomNodes; ++i) { 213 for (uint32 i = 0; i < params.size() && i < kMaxDomNodes; ++i) {
215 ViewHostMsg_MalwareDOMDetails_Node node = params.nodes[i]; 214 SafeBrowsingHostMsg_MalwareDOMDetails_Node node = params[i];
216 DVLOG(1) << node.url << ", " << node.tag_name << ", " << node.parent; 215 DVLOG(1) << node.url << ", " << node.tag_name << ", " << node.parent;
217 AddUrl(node.url, node.parent, node.tag_name, &(node.children)); 216 AddUrl(node.url, node.parent, node.tag_name, &(node.children));
218 } 217 }
219 } 218 }
220 219
221 // Called from the SB Service on the IO thread, after the user has 220 // Called from the SB Service on the IO thread, after the user has
222 // closed the tab, or clicked proceed or goback. Since the user needs 221 // closed the tab, or clicked proceed or goback. Since the user needs
223 // to take an action, we expect this to be called after 222 // to take an action, we expect this to be called after
224 // OnReceivedMalwareDOMDetails in most cases. If not, we don't include 223 // OnReceivedMalwareDOMDetails in most cases. If not, we don't include
225 // the DOM data in our report. 224 // the DOM data in our report.
226 const std::string* MalwareDetails::GetSerializedReport() { 225 const std::string* MalwareDetails::GetSerializedReport() {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
228 // The |report_| protocol buffer is now generated: We add all the 227 // The |report_| protocol buffer is now generated: We add all the
229 // urls in our |resources_| maps. 228 // urls in our |resources_| maps.
230 for (ResourceMap::const_iterator it = resources_.begin(); 229 for (ResourceMap::const_iterator it = resources_.begin();
231 it != resources_.end(); it++) { 230 it != resources_.end(); it++) {
232 ClientMalwareReportRequest::Resource* pb_resource = 231 ClientMalwareReportRequest::Resource* pb_resource =
233 report_->add_resources(); 232 report_->add_resources();
234 pb_resource->CopyFrom(*(it->second)); 233 pb_resource->CopyFrom(*(it->second));
235 } 234 }
236 235
237 scoped_ptr<std::string> request_data(new std::string()); 236 scoped_ptr<std::string> request_data(new std::string());
238 if (!report_->SerializeToString(request_data.get())) { 237 if (!report_->SerializeToString(request_data.get())) {
239 DLOG(ERROR) << "Unable to serialize the malware report."; 238 DLOG(ERROR) << "Unable to serialize the malware report.";
240 } 239 }
241 240
242 return request_data.release(); 241 return request_data.release();
243 } 242 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details.h ('k') | chrome/browser/safe_browsing/malware_details_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698