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 // 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 GURL referrer_url; | 171 GURL referrer_url; |
172 NavigationEntry* nav_entry = web_contents()->GetController().GetActiveEntry(); | 172 NavigationEntry* nav_entry = web_contents()->GetController().GetActiveEntry(); |
173 if (nav_entry) { | 173 if (nav_entry) { |
174 referrer_url = nav_entry->GetReferrer().url; | 174 referrer_url = nav_entry->GetReferrer().url; |
175 if (IsPublicUrl(referrer_url)) { | 175 if (IsPublicUrl(referrer_url)) { |
176 report_->set_referrer_url(referrer_url.spec()); | 176 report_->set_referrer_url(referrer_url.spec()); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 // Add the nodes, starting from the page url. | 180 // Add the nodes, starting from the page url. |
181 AddUrl(page_url, GURL(), "", NULL); | 181 AddUrl(page_url, GURL(), std::string(), NULL); |
182 | 182 |
183 // Add the resource_url and its original url, if non-empty and different. | 183 // Add the resource_url and its original url, if non-empty and different. |
184 if (!resource_.original_url.is_empty() && | 184 if (!resource_.original_url.is_empty() && |
185 resource_.url != resource_.original_url) { | 185 resource_.url != resource_.original_url) { |
186 // Add original_url, as the parent of resource_url. | 186 // Add original_url, as the parent of resource_url. |
187 AddUrl(resource_.original_url, GURL(), "", NULL); | 187 AddUrl(resource_.original_url, GURL(), std::string(), NULL); |
188 AddUrl(resource_.url, resource_.original_url, "", NULL); | 188 AddUrl(resource_.url, resource_.original_url, std::string(), NULL); |
189 } else { | 189 } else { |
190 AddUrl(resource_.url, GURL(), "", NULL); | 190 AddUrl(resource_.url, GURL(), std::string(), NULL); |
191 } | 191 } |
192 | 192 |
193 // Add the redirect urls, if non-empty. The redirect urls do not include the | 193 // Add the redirect urls, if non-empty. The redirect urls do not include the |
194 // original url, but include the unsafe url which is the last one of the | 194 // original url, but include the unsafe url which is the last one of the |
195 // redirect urls chain | 195 // redirect urls chain |
196 GURL parent_url; | 196 GURL parent_url; |
197 // Set the original url as the parent of the first redirect url if it's not | 197 // Set the original url as the parent of the first redirect url if it's not |
198 // empty. | 198 // empty. |
199 if (!resource_.original_url.is_empty()) { | 199 if (!resource_.original_url.is_empty()) { |
200 parent_url = resource_.original_url; | 200 parent_url = resource_.original_url; |
201 } | 201 } |
202 // Set the previous redirect url as the parent of the next one | 202 // Set the previous redirect url as the parent of the next one |
203 for (unsigned int i = 0; i < resource_.redirect_urls.size(); ++i) { | 203 for (unsigned int i = 0; i < resource_.redirect_urls.size(); ++i) { |
204 AddUrl(resource_.redirect_urls[i], parent_url, "", NULL); | 204 AddUrl(resource_.redirect_urls[i], parent_url, std::string(), NULL); |
205 parent_url = resource_.redirect_urls[i]; | 205 parent_url = resource_.redirect_urls[i]; |
206 } | 206 } |
207 | 207 |
208 // Add the referrer url. | 208 // Add the referrer url. |
209 if (nav_entry && !referrer_url.is_empty()) { | 209 if (nav_entry && !referrer_url.is_empty()) { |
210 AddUrl(referrer_url, GURL(), "", NULL); | 210 AddUrl(referrer_url, GURL(), std::string(), NULL); |
211 } | 211 } |
212 | 212 |
213 // Get URLs of frames, scripts etc from the DOM. | 213 // Get URLs of frames, scripts etc from the DOM. |
214 // OnReceivedMalwareDOMDetails will be called when the renderer replies. | 214 // OnReceivedMalwareDOMDetails will be called when the renderer replies. |
215 content::RenderViewHost* view = web_contents()->GetRenderViewHost(); | 215 content::RenderViewHost* view = web_contents()->GetRenderViewHost(); |
216 view->Send(new SafeBrowsingMsg_GetMalwareDOMDetails(view->GetRoutingID())); | 216 view->Send(new SafeBrowsingMsg_GetMalwareDOMDetails(view->GetRoutingID())); |
217 } | 217 } |
218 | 218 |
219 // When the renderer is done, this is called. | 219 // When the renderer is done, this is called. |
220 void MalwareDetails::OnReceivedMalwareDOMDetails( | 220 void MalwareDetails::OnReceivedMalwareDOMDetails( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 cache_collector_->StartCacheCollection( | 280 cache_collector_->StartCacheCollection( |
281 request_context_getter_, | 281 request_context_getter_, |
282 &resources_, | 282 &resources_, |
283 &cache_result_, | 283 &cache_result_, |
284 base::Bind(&MalwareDetails::OnCacheCollectionReady, this)); | 284 base::Bind(&MalwareDetails::OnCacheCollectionReady, this)); |
285 } | 285 } |
286 | 286 |
287 void MalwareDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { | 287 void MalwareDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { |
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
289 for (size_t i = 0; i < urls.size()-1; ++i) { | 289 for (size_t i = 0; i < urls.size()-1; ++i) { |
290 AddUrl(urls[i], urls[i+1], "", NULL); | 290 AddUrl(urls[i], urls[i + 1], std::string(), NULL); |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 void MalwareDetails::OnCacheCollectionReady() { | 294 void MalwareDetails::OnCacheCollectionReady() { |
295 DVLOG(1) << "OnCacheCollectionReady."; | 295 DVLOG(1) << "OnCacheCollectionReady."; |
296 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. | 296 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. |
297 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); | 297 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); |
298 it != resources_.end(); it++) { | 298 it != resources_.end(); it++) { |
299 ClientMalwareReportRequest::Resource* pb_resource = | 299 ClientMalwareReportRequest::Resource* pb_resource = |
300 report_->add_resources(); | 300 report_->add_resources(); |
301 pb_resource->CopyFrom(*(it->second)); | 301 pb_resource->CopyFrom(*(it->second)); |
302 } | 302 } |
303 | 303 |
304 report_->set_complete(cache_result_); | 304 report_->set_complete(cache_result_); |
305 | 305 |
306 // Send the report, using the SafeBrowsingService. | 306 // Send the report, using the SafeBrowsingService. |
307 std::string serialized; | 307 std::string serialized; |
308 if (!report_->SerializeToString(&serialized)) { | 308 if (!report_->SerializeToString(&serialized)) { |
309 DLOG(ERROR) << "Unable to serialize the malware report."; | 309 DLOG(ERROR) << "Unable to serialize the malware report."; |
310 return; | 310 return; |
311 } | 311 } |
312 | 312 |
313 ui_manager_->SendSerializedMalwareDetails(serialized); | 313 ui_manager_->SendSerializedMalwareDetails(serialized); |
314 } | 314 } |
OLD | NEW |