OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/safe_browsing/client_side_detection_host.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 17 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
23 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 23 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
25 #include "content/browser/renderer_host/render_view_host_delegate.h" | 25 #include "content/browser/renderer_host/render_view_host_delegate.h" |
26 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 26 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
27 #include "content/browser/renderer_host/resource_request_details.h" | 27 #include "content/browser/renderer_host/resource_request_details.h" |
28 #include "content/browser/tab_contents/tab_contents.h" | |
29 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
31 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
32 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
33 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
34 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 34 #include "content/public/browser/web_contents.h" |
35 #include "content/public/common/frame_navigate_params.h" | 35 #include "content/public/common/frame_navigate_params.h" |
36 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
37 | 37 |
38 using content::BrowserThread; | 38 using content::BrowserThread; |
39 using content::WebContents; | 39 using content::WebContents; |
40 | 40 |
41 namespace safe_browsing { | 41 namespace safe_browsing { |
42 | 42 |
43 // This class is instantiated each time a new toplevel URL loads, and | 43 // This class is instantiated each time a new toplevel URL loads, and |
44 // asynchronously checks whether the phishing classifier should run for this | 44 // asynchronously checks whether the phishing classifier should run for this |
45 // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. | 45 // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. |
46 // Objects of this class are ref-counted and will be destroyed once nobody | 46 // Objects of this class are ref-counted and will be destroyed once nobody |
47 // uses it anymore. If |tab_contents|, |csd_service| or |host| go away you need | 47 // uses it anymore. If |tab_contents|, |csd_service| or |host| go away you need |
48 // to call Cancel(). We keep the |sb_service| alive in a ref pointer for as | 48 // to call Cancel(). We keep the |sb_service| alive in a ref pointer for as |
49 // long as it takes. | 49 // long as it takes. |
50 class ClientSideDetectionHost::ShouldClassifyUrlRequest | 50 class ClientSideDetectionHost::ShouldClassifyUrlRequest |
51 : public base::RefCountedThreadSafe< | 51 : public base::RefCountedThreadSafe< |
52 ClientSideDetectionHost::ShouldClassifyUrlRequest> { | 52 ClientSideDetectionHost::ShouldClassifyUrlRequest> { |
53 public: | 53 public: |
54 ShouldClassifyUrlRequest(const content::FrameNavigateParams& params, | 54 ShouldClassifyUrlRequest(const content::FrameNavigateParams& params, |
55 TabContents* tab_contents, | 55 WebContents* web_contents, |
56 ClientSideDetectionService* csd_service, | 56 ClientSideDetectionService* csd_service, |
57 SafeBrowsingService* sb_service, | 57 SafeBrowsingService* sb_service, |
58 ClientSideDetectionHost* host) | 58 ClientSideDetectionHost* host) |
59 : canceled_(false), | 59 : canceled_(false), |
60 params_(params), | 60 params_(params), |
61 tab_contents_(tab_contents), | 61 web_contents_(web_contents), |
62 csd_service_(csd_service), | 62 csd_service_(csd_service), |
63 sb_service_(sb_service), | 63 sb_service_(sb_service), |
64 host_(host) { | 64 host_(host) { |
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
66 DCHECK(tab_contents_); | 66 DCHECK(web_contents_); |
67 DCHECK(csd_service_); | 67 DCHECK(csd_service_); |
68 DCHECK(sb_service_); | 68 DCHECK(sb_service_); |
69 DCHECK(host_); | 69 DCHECK(host_); |
70 } | 70 } |
71 | 71 |
72 void Start() { | 72 void Start() { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
74 | 74 |
75 // We start by doing some simple checks that can run on the UI thread. | 75 // We start by doing some simple checks that can run on the UI thread. |
76 UMA_HISTOGRAM_COUNTS("SBClientPhishing.ClassificationStart", 1); | 76 UMA_HISTOGRAM_COUNTS("SBClientPhishing.ClassificationStart", 1); |
(...skipping 14 matching lines...) Expand all Loading... |
91 VLOG(1) << "Skipping phishing classification for URL: " << params_.url | 91 VLOG(1) << "Skipping phishing classification for URL: " << params_.url |
92 << " because of hosting on private IP: " | 92 << " because of hosting on private IP: " |
93 << params_.socket_address.host(); | 93 << params_.socket_address.host(); |
94 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", | 94 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", |
95 NO_CLASSIFY_PRIVATE_IP, | 95 NO_CLASSIFY_PRIVATE_IP, |
96 NO_CLASSIFY_MAX); | 96 NO_CLASSIFY_MAX); |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 // Don't run the phishing classifier if the tab is incognito. | 100 // Don't run the phishing classifier if the tab is incognito. |
101 if (tab_contents_->GetBrowserContext()->IsOffTheRecord()) { | 101 if (web_contents_->GetBrowserContext()->IsOffTheRecord()) { |
102 VLOG(1) << "Skipping phishing classification for URL: " << params_.url | 102 VLOG(1) << "Skipping phishing classification for URL: " << params_.url |
103 << " because we're browsing incognito."; | 103 << " because we're browsing incognito."; |
104 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", | 104 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", |
105 NO_CLASSIFY_OFF_THE_RECORD, | 105 NO_CLASSIFY_OFF_THE_RECORD, |
106 NO_CLASSIFY_MAX); | 106 NO_CLASSIFY_MAX); |
107 | 107 |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 // We lookup the csd-whitelist before we lookup the cache because | 111 // We lookup the csd-whitelist before we lookup the cache because |
112 // a URL may have recently been whitelisted. If the URL matches | 112 // a URL may have recently been whitelisted. If the URL matches |
113 // the csd-whitelist we won't start classification. The | 113 // the csd-whitelist we won't start classification. The |
114 // csd-whitelist check has to be done on the IO thread because it | 114 // csd-whitelist check has to be done on the IO thread because it |
115 // uses the SafeBrowsing service class. | 115 // uses the SafeBrowsing service class. |
116 BrowserThread::PostTask( | 116 BrowserThread::PostTask( |
117 BrowserThread::IO, | 117 BrowserThread::IO, |
118 FROM_HERE, | 118 FROM_HERE, |
119 base::Bind(&ShouldClassifyUrlRequest::CheckCsdWhitelist, | 119 base::Bind(&ShouldClassifyUrlRequest::CheckCsdWhitelist, |
120 this, params_.url)); | 120 this, params_.url)); |
121 } | 121 } |
122 | 122 |
123 void Cancel() { | 123 void Cancel() { |
124 canceled_ = true; | 124 canceled_ = true; |
125 // Just to make sure we don't do anything stupid we reset all these | 125 // Just to make sure we don't do anything stupid we reset all these |
126 // pointers except for the safebrowsing service class which may be | 126 // pointers except for the safebrowsing service class which may be |
127 // accessed by CheckCsdWhitelist(). | 127 // accessed by CheckCsdWhitelist(). |
128 tab_contents_ = NULL; | 128 web_contents_ = NULL; |
129 csd_service_ = NULL; | 129 csd_service_ = NULL; |
130 host_ = NULL; | 130 host_ = NULL; |
131 } | 131 } |
132 | 132 |
133 private: | 133 private: |
134 friend class base::RefCountedThreadSafe< | 134 friend class base::RefCountedThreadSafe< |
135 ClientSideDetectionHost::ShouldClassifyUrlRequest>; | 135 ClientSideDetectionHost::ShouldClassifyUrlRequest>; |
136 | 136 |
137 // Enum used to keep stats about why the pre-classification check failed. | 137 // Enum used to keep stats about why the pre-classification check failed. |
138 enum PreClassificationCheckFailures { | 138 enum PreClassificationCheckFailures { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } else if (csd_service_->OverReportLimit()) { | 194 } else if (csd_service_->OverReportLimit()) { |
195 VLOG(1) << "Too many report phishing requests sent recently, " | 195 VLOG(1) << "Too many report phishing requests sent recently, " |
196 << "not running classification for " << params_.url; | 196 << "not running classification for " << params_.url; |
197 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", | 197 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", |
198 NO_CLASSIFY_TOO_MANY_REPORTS, | 198 NO_CLASSIFY_TOO_MANY_REPORTS, |
199 NO_CLASSIFY_MAX); | 199 NO_CLASSIFY_MAX); |
200 return; | 200 return; |
201 } | 201 } |
202 | 202 |
203 // Everything checks out, so start classification. | 203 // Everything checks out, so start classification. |
204 // |tab_contents_| is safe to call as we will be destructed | 204 // |web_contents_| is safe to call as we will be destructed |
205 // before it is. | 205 // before it is. |
206 VLOG(1) << "Instruct renderer to start phishing detection for URL: " | 206 VLOG(1) << "Instruct renderer to start phishing detection for URL: " |
207 << params_.url; | 207 << params_.url; |
208 RenderViewHost* rvh = tab_contents_->GetRenderViewHost(); | 208 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
209 rvh->Send(new SafeBrowsingMsg_StartPhishingDetection( | 209 rvh->Send(new SafeBrowsingMsg_StartPhishingDetection( |
210 rvh->routing_id(), params_.url)); | 210 rvh->routing_id(), params_.url)); |
211 } | 211 } |
212 | 212 |
213 // No need to protect |canceled_| with a lock because it is only read and | 213 // No need to protect |canceled_| with a lock because it is only read and |
214 // written by the UI thread. | 214 // written by the UI thread. |
215 bool canceled_; | 215 bool canceled_; |
216 content::FrameNavigateParams params_; | 216 content::FrameNavigateParams params_; |
217 TabContents* tab_contents_; | 217 WebContents* web_contents_; |
218 ClientSideDetectionService* csd_service_; | 218 ClientSideDetectionService* csd_service_; |
219 // We keep a ref pointer here just to make sure the service class stays alive | 219 // We keep a ref pointer here just to make sure the service class stays alive |
220 // long enough. | 220 // long enough. |
221 scoped_refptr<SafeBrowsingService> sb_service_; | 221 scoped_refptr<SafeBrowsingService> sb_service_; |
222 ClientSideDetectionHost* host_; | 222 ClientSideDetectionHost* host_; |
223 | 223 |
224 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest); | 224 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest); |
225 }; | 225 }; |
226 | 226 |
227 // This class is used to display the phishing interstitial. | 227 // This class is used to display the phishing interstitial. |
(...skipping 17 matching lines...) Expand all Loading... |
245 | 245 |
246 // We're taking care of deleting this object. No-one else should delete | 246 // We're taking care of deleting this object. No-one else should delete |
247 // this object. | 247 // this object. |
248 virtual ~CsdClient() {} | 248 virtual ~CsdClient() {} |
249 | 249 |
250 DISALLOW_COPY_AND_ASSIGN(CsdClient); | 250 DISALLOW_COPY_AND_ASSIGN(CsdClient); |
251 }; | 251 }; |
252 | 252 |
253 // static | 253 // static |
254 ClientSideDetectionHost* ClientSideDetectionHost::Create( | 254 ClientSideDetectionHost* ClientSideDetectionHost::Create( |
255 TabContents* tab) { | 255 WebContents* tab) { |
256 return new ClientSideDetectionHost(tab); | 256 return new ClientSideDetectionHost(tab); |
257 } | 257 } |
258 | 258 |
259 ClientSideDetectionHost::ClientSideDetectionHost(TabContents* tab) | 259 ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) |
260 : content::WebContentsObserver(tab), | 260 : content::WebContentsObserver(tab), |
261 csd_service_(NULL), | 261 csd_service_(NULL), |
262 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 262 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
263 unsafe_unique_page_id_(-1) { | 263 unsafe_unique_page_id_(-1) { |
264 DCHECK(tab); | 264 DCHECK(tab); |
265 csd_service_ = g_browser_process->safe_browsing_detection_service(); | 265 csd_service_ = g_browser_process->safe_browsing_detection_service(); |
266 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); | 266 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); |
267 sb_service_ = g_browser_process->safe_browsing_service(); | 267 sb_service_ = g_browser_process->safe_browsing_service(); |
268 // Note: csd_service_ and sb_service_ will be NULL here in testing. | 268 // Note: csd_service_ and sb_service_ will be NULL here in testing. |
269 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, | 269 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
270 content::Source<RenderViewHostDelegate>(tab)); | 270 content::Source<WebContents>(tab)); |
271 if (sb_service_) { | 271 if (sb_service_) { |
272 sb_service_->AddObserver(this); | 272 sb_service_->AddObserver(this); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 ClientSideDetectionHost::~ClientSideDetectionHost() { | 276 ClientSideDetectionHost::~ClientSideDetectionHost() { |
277 if (sb_service_) { | 277 if (sb_service_) { |
278 sb_service_->RemoveObserver(this); | 278 sb_service_->RemoveObserver(this); |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { | 282 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { |
283 bool handled = true; | 283 bool handled = true; |
284 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | 284 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) |
285 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, | 285 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, |
286 OnPhishingDetectionDone) | 286 OnPhishingDetectionDone) |
287 IPC_MESSAGE_UNHANDLED(handled = false) | 287 IPC_MESSAGE_UNHANDLED(handled = false) |
288 IPC_END_MESSAGE_MAP() | 288 IPC_END_MESSAGE_MAP() |
289 return handled; | 289 return handled; |
290 } | 290 } |
291 | 291 |
292 void ClientSideDetectionHost::DidNavigateMainFrame( | 292 void ClientSideDetectionHost::DidNavigateMainFrame( |
293 const content::LoadCommittedDetails& details, | 293 const content::LoadCommittedDetails& details, |
294 const content::FrameNavigateParams& params) { | 294 const content::FrameNavigateParams& params) { |
295 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests | 295 // TODO(noelutz): move this DCHECK to WebContents and fix all the unit tests |
296 // that don't call this method on the UI thread. | 296 // that don't call this method on the UI thread. |
297 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 297 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
298 if (details.is_in_page) { | 298 if (details.is_in_page) { |
299 // If the navigation is within the same page, the user isn't really | 299 // If the navigation is within the same page, the user isn't really |
300 // navigating away. We don't need to cancel a pending callback or | 300 // navigating away. We don't need to cancel a pending callback or |
301 // begin a new classification. | 301 // begin a new classification. |
302 return; | 302 return; |
303 } | 303 } |
304 // If we navigate away and there currently is a pending phishing | 304 // If we navigate away and there currently is a pending phishing |
305 // report request we have to cancel it to make sure we don't display | 305 // report request we have to cancel it to make sure we don't display |
(...skipping 16 matching lines...) Expand all Loading... |
322 if (params.url.host() != cur_host_) { | 322 if (params.url.host() != cur_host_) { |
323 cur_host_ = params.url.host(); | 323 cur_host_ = params.url.host(); |
324 cur_host_redirects_ = params.redirects; | 324 cur_host_redirects_ = params.redirects; |
325 } | 325 } |
326 browse_info_->host_redirects = cur_host_redirects_; | 326 browse_info_->host_redirects = cur_host_redirects_; |
327 browse_info_->url_redirects = params.redirects; | 327 browse_info_->url_redirects = params.redirects; |
328 browse_info_->http_status_code = details.http_status_code; | 328 browse_info_->http_status_code = details.http_status_code; |
329 | 329 |
330 // Notify the renderer if it should classify this URL. | 330 // Notify the renderer if it should classify this URL. |
331 classification_request_ = new ShouldClassifyUrlRequest(params, | 331 classification_request_ = new ShouldClassifyUrlRequest(params, |
332 tab_contents(), | 332 web_contents(), |
333 csd_service_, | 333 csd_service_, |
334 sb_service_, | 334 sb_service_, |
335 this); | 335 this); |
336 classification_request_->Start(); | 336 classification_request_->Start(); |
337 } | 337 } |
338 | 338 |
339 void ClientSideDetectionHost::OnSafeBrowsingHit( | 339 void ClientSideDetectionHost::OnSafeBrowsingHit( |
340 const SafeBrowsingService::UnsafeResource& resource) { | 340 const SafeBrowsingService::UnsafeResource& resource) { |
341 // Check that this notification is really for us and that it corresponds to | 341 // Check that this notification is really for us and that it corresponds to |
342 // either a malware or phishing hit. In this case we store the unique page | 342 // either a malware or phishing hit. In this case we store the unique page |
343 // ID for later. | 343 // ID for later. |
344 if (tab_contents() && | 344 if (web_contents() && |
345 tab_contents()->GetRenderProcessHost()->GetID() == | 345 web_contents()->GetRenderProcessHost()->GetID() == |
346 resource.render_process_host_id && | 346 resource.render_process_host_id && |
347 tab_contents()->GetRenderViewHost()->routing_id() == | 347 web_contents()->GetRenderViewHost()->routing_id() == |
348 resource.render_view_id && | 348 resource.render_view_id && |
349 (resource.threat_type == SafeBrowsingService::URL_PHISHING || | 349 (resource.threat_type == SafeBrowsingService::URL_PHISHING || |
350 resource.threat_type == SafeBrowsingService::URL_MALWARE) && | 350 resource.threat_type == SafeBrowsingService::URL_MALWARE) && |
351 tab_contents()->GetController().GetActiveEntry()) { | 351 web_contents()->GetController().GetActiveEntry()) { |
352 unsafe_unique_page_id_ = | 352 unsafe_unique_page_id_ = |
353 tab_contents()->GetController().GetActiveEntry()->GetUniqueID(); | 353 web_contents()->GetController().GetActiveEntry()->GetUniqueID(); |
354 // We also keep the resource around in order to be able to send the | 354 // We also keep the resource around in order to be able to send the |
355 // malicious URL to the server. | 355 // malicious URL to the server. |
356 unsafe_resource_.reset(new SafeBrowsingService::UnsafeResource(resource)); | 356 unsafe_resource_.reset(new SafeBrowsingService::UnsafeResource(resource)); |
357 unsafe_resource_->client = NULL; // Make sure we don't do anything stupid. | 357 unsafe_resource_->client = NULL; // Make sure we don't do anything stupid. |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) { | 361 void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) { |
362 DCHECK(tab); | 362 DCHECK(tab); |
363 // Tell any pending classification request that it is being canceled. | 363 // Tell any pending classification request that it is being canceled. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 406 } |
407 browse_info_.reset(); | 407 browse_info_.reset(); |
408 } | 408 } |
409 | 409 |
410 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, | 410 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, |
411 bool is_phishing) { | 411 bool is_phishing) { |
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
413 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url | 413 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url |
414 << " is_phishing:" << is_phishing; | 414 << " is_phishing:" << is_phishing; |
415 if (is_phishing) { | 415 if (is_phishing) { |
416 DCHECK(tab_contents()); | 416 DCHECK(web_contents()); |
417 if (sb_service_) { | 417 if (sb_service_) { |
418 SafeBrowsingService::UnsafeResource resource; | 418 SafeBrowsingService::UnsafeResource resource; |
419 resource.url = phishing_url; | 419 resource.url = phishing_url; |
420 resource.original_url = phishing_url; | 420 resource.original_url = phishing_url; |
421 resource.is_subresource = false; | 421 resource.is_subresource = false; |
422 resource.threat_type = SafeBrowsingService::CLIENT_SIDE_PHISHING_URL; | 422 resource.threat_type = SafeBrowsingService::CLIENT_SIDE_PHISHING_URL; |
423 resource.render_process_host_id = | 423 resource.render_process_host_id = |
424 tab_contents()->GetRenderProcessHost()->GetID(); | 424 web_contents()->GetRenderProcessHost()->GetID(); |
425 resource.render_view_id = | 425 resource.render_view_id = |
426 tab_contents()->GetRenderViewHost()->routing_id(); | 426 web_contents()->GetRenderViewHost()->routing_id(); |
427 if (!sb_service_->IsWhitelisted(resource)) { | 427 if (!sb_service_->IsWhitelisted(resource)) { |
428 // We need to stop any pending navigations, otherwise the interstital | 428 // We need to stop any pending navigations, otherwise the interstital |
429 // might not get created properly. | 429 // might not get created properly. |
430 tab_contents()->GetController().DiscardNonCommittedEntries(); | 430 web_contents()->GetController().DiscardNonCommittedEntries(); |
431 resource.client = new CsdClient(); // Will delete itself | 431 resource.client = new CsdClient(); // Will delete itself |
432 sb_service_->DoDisplayBlockingPage(resource); | 432 sb_service_->DoDisplayBlockingPage(resource); |
433 } | 433 } |
434 } | 434 } |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 void ClientSideDetectionHost::FeatureExtractionDone( | 438 void ClientSideDetectionHost::FeatureExtractionDone( |
439 bool success, | 439 bool success, |
440 ClientPhishingRequest* request) { | 440 ClientPhishingRequest* request) { |
(...skipping 23 matching lines...) Expand all Loading... |
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
465 DCHECK_EQ(type, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED); | 465 DCHECK_EQ(type, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED); |
466 const ResourceRequestDetails* req = content::Details<ResourceRequestDetails>( | 466 const ResourceRequestDetails* req = content::Details<ResourceRequestDetails>( |
467 details).ptr(); | 467 details).ptr(); |
468 if (req && browse_info_.get()) { | 468 if (req && browse_info_.get()) { |
469 browse_info_->ips.insert(req->socket_address().host()); | 469 browse_info_->ips.insert(req->socket_address().host()); |
470 } | 470 } |
471 } | 471 } |
472 | 472 |
473 bool ClientSideDetectionHost::DidShowSBInterstitial() { | 473 bool ClientSideDetectionHost::DidShowSBInterstitial() { |
474 if (unsafe_unique_page_id_ <= 0 || !tab_contents()) { | 474 if (unsafe_unique_page_id_ <= 0 || !web_contents()) { |
475 return false; | 475 return false; |
476 } | 476 } |
477 const NavigationEntry* nav_entry = | 477 const NavigationEntry* nav_entry = |
478 tab_contents()->GetController().GetActiveEntry(); | 478 web_contents()->GetController().GetActiveEntry(); |
479 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); | 479 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); |
480 } | 480 } |
481 | 481 |
482 void ClientSideDetectionHost::set_client_side_detection_service( | 482 void ClientSideDetectionHost::set_client_side_detection_service( |
483 ClientSideDetectionService* service) { | 483 ClientSideDetectionService* service) { |
484 csd_service_ = service; | 484 csd_service_ = service; |
485 } | 485 } |
486 | 486 |
487 void ClientSideDetectionHost::set_safe_browsing_service( | 487 void ClientSideDetectionHost::set_safe_browsing_service( |
488 SafeBrowsingService* service) { | 488 SafeBrowsingService* service) { |
489 if (sb_service_) { | 489 if (sb_service_) { |
490 sb_service_->RemoveObserver(this); | 490 sb_service_->RemoveObserver(this); |
491 } | 491 } |
492 sb_service_ = service; | 492 sb_service_ = service; |
493 if (sb_service_) { | 493 if (sb_service_) { |
494 sb_service_->AddObserver(this); | 494 sb_service_->AddObserver(this); |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
498 } // namespace safe_browsing | 498 } // namespace safe_browsing |
OLD | NEW |