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

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

Issue 6398001: Run pre-classification checks in the browser before starting client-side phishing detection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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) 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_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/platform_file.h" 12 #include "base/platform_file.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/stl_util-inl.h" 14 #include "base/stl_util-inl.h"
15 #include "base/task.h" 15 #include "base/task.h"
16 #include "chrome/browser/browser_thread.h" 16 #include "chrome/browser/browser_thread.h"
17 #include "chrome/browser/renderer_host/render_view_host.h"
17 #include "chrome/browser/safe_browsing/csd.pb.h" 18 #include "chrome/browser/safe_browsing/csd.pb.h"
19 #include "chrome/browser/tab_contents/provisional_load_details.h"
20 #include "chrome/browser/tab_contents/tab_contents.h"
18 #include "chrome/common/net/http_return.h" 21 #include "chrome/common/net/http_return.h"
19 #include "chrome/common/net/url_fetcher.h" 22 #include "chrome/common/net/url_fetcher.h"
20 #include "chrome/common/net/url_request_context_getter.h" 23 #include "chrome/common/net/url_request_context_getter.h"
24 #include "chrome/common/notification_service.h"
25 #include "chrome/common/notification_type.h"
26 #include "chrome/common/render_messages.h"
21 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
22 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
23 #include "net/url_request/url_request_status.h" 29 #include "net/url_request/url_request_status.h"
24 30
25 namespace safe_browsing { 31 namespace safe_browsing {
26 32
27 const char ClientSideDetectionService::kClientReportPhishingUrl[] = 33 const char ClientSideDetectionService::kClientReportPhishingUrl[] =
28 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing"; 34 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing";
29 const char ClientSideDetectionService::kClientModelUrl[] = 35 const char ClientSideDetectionService::kClientModelUrl[] =
30 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb"; 36 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb";
31 37
32 struct ClientSideDetectionService::ClientReportInfo { 38 struct ClientSideDetectionService::ClientReportInfo {
33 scoped_ptr<ClientReportPhishingRequestCallback> callback; 39 scoped_ptr<ClientReportPhishingRequestCallback> callback;
34 GURL phishing_url; 40 GURL phishing_url;
35 }; 41 };
36 42
43 // ShouldClassifyUrlRequest tracks the pre-classification checks for a
44 // toplevel URL that has started loading into a renderer. When these
45 // checks are complete, the renderer is notified if it should run
46 // client-side phishing classification, then the ShouldClassifyUrlRequest
47 // deletes itself.
48 class ClientSideDetectionService::ShouldClassifyUrlRequest
49 : public NotificationObserver {
50 public:
51 ShouldClassifyUrlRequest(const GURL& url, TabContents* tab_contents)
52 : url_(url),
53 tab_contents_(tab_contents),
54 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 registrar_.Add(this,
57 NotificationType::TAB_CONTENTS_DESTROYED,
58 Source<TabContents>(tab_contents));
59 }
60
61 virtual ~ShouldClassifyUrlRequest() {}
noelutz 2011/01/26 01:31:21 make the destructor private to make sure we delete
Brian Ryner 2011/02/01 21:45:45 Done.
62
63 virtual void Observe(NotificationType type,
64 const NotificationSource& source,
65 const NotificationDetails& details) {
66 switch (type.value) {
67 case NotificationType::TAB_CONTENTS_DESTROYED:
68 Cancel();
69 break;
70 default:
71 NOTREACHED();
72 };
73 }
74
75 void Start() {
76 // TODO(bryner): add pre-classification checks here.
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
noelutz 2011/01/26 01:31:21 Maybe comment why you're not simply calling Finish
Brian Ryner 2011/02/01 21:45:45 Done.
78 BrowserThread::PostTask(BrowserThread::UI,
79 FROM_HERE,
80 method_factory_.NewRunnableMethod(
81 &ShouldClassifyUrlRequest::Finish));
82 }
83
84 private:
85 void Cancel() {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
87 tab_contents_ = NULL;
noelutz 2011/01/26 01:31:21 delete this or call Finish()?
Brian Ryner 2011/02/01 21:45:45 Originally I was thinking we might not be able to
88 }
89
90 void Finish() {
91 if (tab_contents_) {
92 RenderViewHost* rvh = tab_contents_->render_view_host();
93 rvh->Send(new ViewMsg_StartPhishingDetection(rvh->routing_id(), url_));
94 }
95 delete this;
96 }
97
98 GURL url_;
99 TabContents* tab_contents_;
100 NotificationRegistrar registrar_;
101 ScopedRunnableMethodFactory<ShouldClassifyUrlRequest> method_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest);
104 };
105
37 ClientSideDetectionService::ClientSideDetectionService( 106 ClientSideDetectionService::ClientSideDetectionService(
38 const FilePath& model_path, 107 const FilePath& model_path,
39 URLRequestContextGetter* request_context_getter) 108 URLRequestContextGetter* request_context_getter)
40 : model_path_(model_path), 109 : model_path_(model_path),
41 model_status_(UNKNOWN_STATUS), 110 model_status_(UNKNOWN_STATUS),
42 model_file_(base::kInvalidPlatformFileValue), 111 model_file_(base::kInvalidPlatformFileValue),
43 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 112 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
44 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), 113 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
45 request_context_getter_(request_context_getter) { 114 request_context_getter_(request_context_getter) {
115 // Register to find out when pages begin loading into a renderer.
116 // When this happens, we'll do our pre-classificaton checks for
117 // client side phishing detection.
118 registrar_.Add(this,
119 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
120 NotificationService::AllSources());
46 } 121 }
47 122
48 ClientSideDetectionService::~ClientSideDetectionService() { 123 ClientSideDetectionService::~ClientSideDetectionService() {
49 method_factory_.RevokeAll(); 124 method_factory_.RevokeAll();
50 STLDeleteContainerPairPointers(client_phishing_reports_.begin(), 125 STLDeleteContainerPairPointers(client_phishing_reports_.begin(),
51 client_phishing_reports_.end()); 126 client_phishing_reports_.end());
52 client_phishing_reports_.clear(); 127 client_phishing_reports_.clear();
53 STLDeleteElements(&open_callbacks_); 128 STLDeleteElements(&open_callbacks_);
54 CloseModelFile(); 129 CloseModelFile();
55 } 130 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (source == model_fetcher_.get()) { 182 if (source == model_fetcher_.get()) {
108 HandleModelResponse(source, url, status, response_code, cookies, data); 183 HandleModelResponse(source, url, status, response_code, cookies, data);
109 } else if (client_phishing_reports_.find(source) != 184 } else if (client_phishing_reports_.find(source) !=
110 client_phishing_reports_.end()) { 185 client_phishing_reports_.end()) {
111 HandlePhishingVerdict(source, url, status, response_code, cookies, data); 186 HandlePhishingVerdict(source, url, status, response_code, cookies, data);
112 } else { 187 } else {
113 NOTREACHED(); 188 NOTREACHED();
114 } 189 }
115 } 190 }
116 191
192 void ClientSideDetectionService::Observe(NotificationType type,
193 const NotificationSource& source,
194 const NotificationDetails& details) {
195 switch (type.value) {
196 case NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED:
197 {
lzheng 2011/01/27 18:31:27 { and the later } should not be needed.
Brian Ryner 2011/02/01 21:45:45 I need an enclosing scope since I'm defining varia
198 // Check whether the load should trigger a phishing classification.
199 ProvisionalLoadDetails* load_details =
200 Details<ProvisionalLoadDetails>(details).ptr();
201
202 if (load_details->main_frame() &&
203 (load_details->transition_type() & PageTransition::FORWARD_BACK) !=
204 PageTransition::FORWARD_BACK &&
205 !load_details->in_page_navigation()) {
206 NavigationController* controller =
207 Source<NavigationController>(source).ptr();
208 ShouldClassifyUrlRequest* request =
209 new ShouldClassifyUrlRequest(load_details->url(),
210 controller->tab_contents());
211 request->Start(); // the request will delete itself on completion
212 }
213 break;
214 }
215 default:
216 NOTREACHED();
217 };
218 }
219
117 void ClientSideDetectionService::SetModelStatus(ModelStatus status) { 220 void ClientSideDetectionService::SetModelStatus(ModelStatus status) {
118 DCHECK_NE(READY_STATUS, model_status_); 221 DCHECK_NE(READY_STATUS, model_status_);
119 model_status_ = status; 222 model_status_ = status;
120 if (READY_STATUS == status || ERROR_STATUS == status) { 223 if (READY_STATUS == status || ERROR_STATUS == status) {
121 for (size_t i = 0; i < open_callbacks_.size(); ++i) { 224 for (size_t i = 0; i < open_callbacks_.size(); ++i) {
122 open_callbacks_[i]->Run(model_file_); 225 open_callbacks_[i]->Run(model_file_);
123 } 226 }
124 STLDeleteElements(&open_callbacks_); 227 STLDeleteElements(&open_callbacks_);
125 } else { 228 } else {
126 NOTREACHED(); 229 NOTREACHED();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } else { 400 } else {
298 DLOG(ERROR) << "Unable to get the server verdict for URL: " 401 DLOG(ERROR) << "Unable to get the server verdict for URL: "
299 << info->phishing_url; 402 << info->phishing_url;
300 info->callback->Run(info->phishing_url, false); 403 info->callback->Run(info->phishing_url, false);
301 } 404 }
302 client_phishing_reports_.erase(source); 405 client_phishing_reports_.erase(source);
303 delete source; 406 delete source;
304 } 407 }
305 408
306 } // namespace safe_browsing 409 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_service.h ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698