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/renderer/safe_browsing/phishing_classifier_delegate.h" | 5 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 OnStartPhishingDetection) | 201 OnStartPhishingDetection) |
202 IPC_MESSAGE_UNHANDLED(handled = false) | 202 IPC_MESSAGE_UNHANDLED(handled = false) |
203 IPC_END_MESSAGE_MAP() | 203 IPC_END_MESSAGE_MAP() |
204 return handled; | 204 return handled; |
205 } | 205 } |
206 | 206 |
207 void PhishingClassifierDelegate::ClassificationDone( | 207 void PhishingClassifierDelegate::ClassificationDone( |
208 const ClientPhishingRequest& verdict) { | 208 const ClientPhishingRequest& verdict) { |
209 // We no longer need the page text. | 209 // We no longer need the page text. |
210 classifier_page_text_.clear(); | 210 classifier_page_text_.clear(); |
211 VLOG(2) << "Phishy verdict = " << verdict.is_phishing() | 211 DVLOG(2) << "Phishy verdict = " << verdict.is_phishing() |
212 << " score = " << verdict.client_score(); | 212 << " score = " << verdict.client_score(); |
213 if (verdict.client_score() != PhishingClassifier::kInvalidScore) { | 213 if (verdict.client_score() != PhishingClassifier::kInvalidScore) { |
214 DCHECK_EQ(last_url_sent_to_classifier_.spec(), verdict.url()); | 214 DCHECK_EQ(last_url_sent_to_classifier_.spec(), verdict.url()); |
215 RenderThread::Get()->Send(new SafeBrowsingHostMsg_PhishingDetectionDone( | 215 RenderThread::Get()->Send(new SafeBrowsingHostMsg_PhishingDetectionDone( |
216 routing_id(), verdict.SerializeAsString())); | 216 routing_id(), verdict.SerializeAsString())); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 GURL PhishingClassifierDelegate::GetToplevelUrl() { | 220 GURL PhishingClassifierDelegate::GetToplevelUrl() { |
221 return render_view()->GetWebView()->mainFrame()->document().url(); | 221 return render_view()->GetWebView()->mainFrame()->document().url(); |
222 } | 222 } |
223 | 223 |
224 void PhishingClassifierDelegate::MaybeStartClassification() { | 224 void PhishingClassifierDelegate::MaybeStartClassification() { |
225 // We can begin phishing classification when the following conditions are | 225 // We can begin phishing classification when the following conditions are |
226 // met: | 226 // met: |
227 // 1. A Scorer has been created | 227 // 1. A Scorer has been created |
228 // 2. The browser has sent a StartPhishingDetection message for the current | 228 // 2. The browser has sent a StartPhishingDetection message for the current |
229 // toplevel URL. | 229 // toplevel URL. |
230 // 3. The page has finished loading and the page text has been extracted. | 230 // 3. The page has finished loading and the page text has been extracted. |
231 // 4. The load is a new navigation (not a session history navigation). | 231 // 4. The load is a new navigation (not a session history navigation). |
232 // 5. The toplevel URL has not already been classified. | 232 // 5. The toplevel URL has not already been classified. |
233 // | 233 // |
234 // Note that if we determine that this particular navigation should not be | 234 // Note that if we determine that this particular navigation should not be |
235 // classified at all (as opposed to deferring it until we get an IPC or the | 235 // classified at all (as opposed to deferring it until we get an IPC or the |
236 // load completes), we discard the page text since it won't be needed. | 236 // load completes), we discard the page text since it won't be needed. |
237 if (!classifier_->is_ready()) { | 237 if (!classifier_->is_ready()) { |
238 VLOG(2) << "Not starting classification, no Scorer created."; | 238 DVLOG(2) << "Not starting classification, no Scorer created."; |
239 // Keep classifier_page_text_, in case a Scorer is set later. | 239 // Keep classifier_page_text_, in case a Scorer is set later. |
240 return; | 240 return; |
241 } | 241 } |
242 | 242 |
243 if (last_main_frame_transition_ & ui::PAGE_TRANSITION_FORWARD_BACK) { | 243 if (last_main_frame_transition_ & ui::PAGE_TRANSITION_FORWARD_BACK) { |
244 // Skip loads from session history navigation. However, update the | 244 // Skip loads from session history navigation. However, update the |
245 // last URL sent to the classifier, so that we'll properly detect | 245 // last URL sent to the classifier, so that we'll properly detect |
246 // in-page navigations. | 246 // in-page navigations. |
247 VLOG(2) << "Not starting classification for back/forward navigation"; | 247 DVLOG(2) << "Not starting classification for back/forward navigation"; |
248 last_url_sent_to_classifier_ = last_finished_load_url_; | 248 last_url_sent_to_classifier_ = last_finished_load_url_; |
249 classifier_page_text_.clear(); // we won't need this. | 249 classifier_page_text_.clear(); // we won't need this. |
250 have_page_text_ = false; | 250 have_page_text_ = false; |
251 return; | 251 return; |
252 } | 252 } |
253 | 253 |
254 GURL stripped_last_load_url(StripRef(last_finished_load_url_)); | 254 GURL stripped_last_load_url(StripRef(last_finished_load_url_)); |
255 if (stripped_last_load_url == StripRef(last_url_sent_to_classifier_)) { | 255 if (stripped_last_load_url == StripRef(last_url_sent_to_classifier_)) { |
256 // We've already classified this toplevel URL, so this was likely an | 256 // We've already classified this toplevel URL, so this was likely an |
257 // in-page navigation or a subframe navigation. The browser should not | 257 // in-page navigation or a subframe navigation. The browser should not |
258 // send a StartPhishingDetection IPC in this case. | 258 // send a StartPhishingDetection IPC in this case. |
259 VLOG(2) << "Toplevel URL is unchanged, not starting classification."; | 259 DVLOG(2) << "Toplevel URL is unchanged, not starting classification."; |
260 classifier_page_text_.clear(); // we won't need this. | 260 classifier_page_text_.clear(); // we won't need this. |
261 have_page_text_ = false; | 261 have_page_text_ = false; |
262 return; | 262 return; |
263 } | 263 } |
264 | 264 |
265 if (!have_page_text_) { | 265 if (!have_page_text_) { |
266 VLOG(2) << "Not starting classification, there is no page text ready."; | 266 DVLOG(2) << "Not starting classification, there is no page text ready."; |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 if (last_url_received_from_browser_ != stripped_last_load_url) { | 270 if (last_url_received_from_browser_ != stripped_last_load_url) { |
271 // The browser has not yet confirmed that this URL should be classified, | 271 // The browser has not yet confirmed that this URL should be classified, |
272 // so defer classification for now. Note: the ref does not affect | 272 // so defer classification for now. Note: the ref does not affect |
273 // any of the browser's preclassification checks, so we don't require it | 273 // any of the browser's preclassification checks, so we don't require it |
274 // to match. | 274 // to match. |
275 VLOG(2) << "Not starting classification, last url from browser is " | 275 DVLOG(2) << "Not starting classification, last url from browser is " |
276 << last_url_received_from_browser_ << ", last finished load is " | 276 << last_url_received_from_browser_ << ", last finished load is " |
277 << last_finished_load_url_; | 277 << last_finished_load_url_; |
278 // Keep classifier_page_text_, in case the browser notifies us later that | 278 // Keep classifier_page_text_, in case the browser notifies us later that |
279 // we should classify the URL. | 279 // we should classify the URL. |
280 return; | 280 return; |
281 } | 281 } |
282 | 282 |
283 VLOG(2) << "Starting classification for " << last_finished_load_url_; | 283 DVLOG(2) << "Starting classification for " << last_finished_load_url_; |
284 last_url_sent_to_classifier_ = last_finished_load_url_; | 284 last_url_sent_to_classifier_ = last_finished_load_url_; |
285 is_classifying_ = true; | 285 is_classifying_ = true; |
286 classifier_->BeginClassification( | 286 classifier_->BeginClassification( |
287 &classifier_page_text_, | 287 &classifier_page_text_, |
288 base::Bind(&PhishingClassifierDelegate::ClassificationDone, | 288 base::Bind(&PhishingClassifierDelegate::ClassificationDone, |
289 base::Unretained(this))); | 289 base::Unretained(this))); |
290 } | 290 } |
291 | 291 |
292 } // namespace safe_browsing | 292 } // namespace safe_browsing |
OLD | NEW |