| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.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/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 16 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/render_messages.h" | |
| 20 #include "chrome/common/safebrowsing_messages.h" | 19 #include "chrome/common/safebrowsing_messages.h" |
| 21 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 22 #include "content/browser/renderer_host/render_process_host.h" | 21 #include "content/browser/renderer_host/render_process_host.h" |
| 23 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| 24 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 23 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 25 #include "content/browser/tab_contents/navigation_controller.h" | 24 #include "content/browser/tab_contents/navigation_controller.h" |
| 26 #include "content/browser/tab_contents/tab_contents.h" | 25 #include "content/browser/tab_contents/tab_contents.h" |
| 27 #include "content/common/notification_service.h" | 26 #include "content/common/notification_service.h" |
| 28 #include "content/common/notification_type.h" | 27 #include "content/common/notification_type.h" |
| 29 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 VLOG(1) << "Too many report phishing requests sent recently, " | 163 VLOG(1) << "Too many report phishing requests sent recently, " |
| 165 << "not running classification for " << params_.url; | 164 << "not running classification for " << params_.url; |
| 166 UMA_HISTOGRAM_COUNTS("SBClientPhishing.NoClassifyTooManyReports", 1); | 165 UMA_HISTOGRAM_COUNTS("SBClientPhishing.NoClassifyTooManyReports", 1); |
| 167 return; | 166 return; |
| 168 } | 167 } |
| 169 | 168 |
| 170 // Everything checks out, so start classification. | 169 // Everything checks out, so start classification. |
| 171 // |tab_contents_| is safe to call as we will be destructed | 170 // |tab_contents_| is safe to call as we will be destructed |
| 172 // before it is. | 171 // before it is. |
| 173 RenderViewHost* rvh = tab_contents_->render_view_host(); | 172 RenderViewHost* rvh = tab_contents_->render_view_host(); |
| 174 rvh->Send(new ViewMsg_StartPhishingDetection( | 173 rvh->Send(new SafeBrowsingMsg_StartPhishingDetection( |
| 175 rvh->routing_id(), params_.url)); | 174 rvh->routing_id(), params_.url)); |
| 176 } | 175 } |
| 177 | 176 |
| 178 // No need to protect |canceled_| with a lock because it is only read and | 177 // No need to protect |canceled_| with a lock because it is only read and |
| 179 // written by the UI thread. | 178 // written by the UI thread. |
| 180 bool canceled_; | 179 bool canceled_; |
| 181 ViewHostMsg_FrameNavigate_Params params_; | 180 ViewHostMsg_FrameNavigate_Params params_; |
| 182 TabContents* tab_contents_; | 181 TabContents* tab_contents_; |
| 183 ClientSideDetectionService* csd_service_; | 182 ClientSideDetectionService* csd_service_; |
| 184 // We keep a ref pointer here just to make sure the service class stays alive | 183 // We keep a ref pointer here just to make sure the service class stays alive |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 ClientSideDetectionHost::~ClientSideDetectionHost() { | 230 ClientSideDetectionHost::~ClientSideDetectionHost() { |
| 232 // Tell any pending classification request that it is being canceled. | 231 // Tell any pending classification request that it is being canceled. |
| 233 if (classification_request_.get()) { | 232 if (classification_request_.get()) { |
| 234 classification_request_->Cancel(); | 233 classification_request_->Cancel(); |
| 235 } | 234 } |
| 236 } | 235 } |
| 237 | 236 |
| 238 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { | 237 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { |
| 239 bool handled = true; | 238 bool handled = true; |
| 240 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | 239 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) |
| 241 IPC_MESSAGE_HANDLER(SafeBrowsingDetectionHostMsg_DetectedPhishingSite, | 240 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_DetectedPhishingSite, |
| 242 OnDetectedPhishingSite) | 241 OnDetectedPhishingSite) |
| 243 IPC_MESSAGE_UNHANDLED(handled = false) | 242 IPC_MESSAGE_UNHANDLED(handled = false) |
| 244 IPC_END_MESSAGE_MAP() | 243 IPC_END_MESSAGE_MAP() |
| 245 return handled; | 244 return handled; |
| 246 } | 245 } |
| 247 | 246 |
| 248 void ClientSideDetectionHost::DidNavigateMainFramePostCommit( | 247 void ClientSideDetectionHost::DidNavigateMainFramePostCommit( |
| 249 const NavigationController::LoadCommittedDetails& details, | 248 const NavigationController::LoadCommittedDetails& details, |
| 250 const ViewHostMsg_FrameNavigate_Params& params) { | 249 const ViewHostMsg_FrameNavigate_Params& params) { |
| 251 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests | 250 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 ClientSideDetectionService* service) { | 339 ClientSideDetectionService* service) { |
| 341 csd_service_ = service; | 340 csd_service_ = service; |
| 342 } | 341 } |
| 343 | 342 |
| 344 void ClientSideDetectionHost::set_safe_browsing_service( | 343 void ClientSideDetectionHost::set_safe_browsing_service( |
| 345 SafeBrowsingService* service) { | 344 SafeBrowsingService* service) { |
| 346 sb_service_ = service; | 345 sb_service_ = service; |
| 347 } | 346 } |
| 348 | 347 |
| 349 } // namespace safe_browsing | 348 } // namespace safe_browsing |
| OLD | NEW |