Chromium Code Reviews| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 |
| 138 void PhishingClassifierDelegate::OnStartPhishingDetection(const GURL& url) { | 138 void PhishingClassifierDelegate::OnStartPhishingDetection(const GURL& url) { |
| 139 last_url_received_from_browser_ = StripRef(url); | 139 last_url_received_from_browser_ = StripRef(url); |
| 140 // Start classifying the current page if all conditions are met. | 140 // Start classifying the current page if all conditions are met. |
| 141 // See MaybeStartClassification() for details. | 141 // See MaybeStartClassification() for details. |
| 142 MaybeStartClassification(); | 142 MaybeStartClassification(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void PhishingClassifierDelegate::DidCommitProvisionalLoad( | 145 void PhishingClassifierDelegate::DidCommitProvisionalLoad( |
| 146 blink::WebLocalFrame* frame, bool is_new_navigation) { | 146 blink::WebLocalFrame* frame, bool is_new_navigation) { |
| 147 // A new page is starting to load, so cancel classificaiton. | |
| 148 // | |
| 149 // TODO(bryner): We shouldn't need to cancel classification if the navigation | |
| 150 // is within the same page. However, if we let classification continue in | |
| 151 // this case, we need to properly deal with the fact that PageCaptured will | |
| 152 // be called again for the in-page navigation. We need to be sure not to | |
| 153 // swap out the page text while the term feature extractor is still running. | |
| 154 DocumentState* document_state = DocumentState::FromDataSource( | |
| 155 frame->dataSource()); | |
| 156 NavigationState* navigation_state = document_state->navigation_state(); | |
| 157 CancelPendingClassification(navigation_state->was_within_same_page() ? | |
| 158 NAVIGATE_WITHIN_PAGE : NAVIGATE_AWAY); | |
| 159 if (frame == render_view()->GetWebView()->mainFrame()) { | 147 if (frame == render_view()->GetWebView()->mainFrame()) { |
| 148 DocumentState* document_state = DocumentState::FromDataSource( | |
| 149 frame->dataSource()); | |
| 150 NavigationState* navigation_state = document_state->navigation_state(); | |
| 160 last_main_frame_transition_ = navigation_state->transition_type(); | 151 last_main_frame_transition_ = navigation_state->transition_type(); |
| 161 } | 152 } |
| 162 } | 153 } |
| 163 | 154 |
| 164 void PhishingClassifierDelegate::PageCaptured(base::string16* page_text, | 155 void PhishingClassifierDelegate::PageCaptured(base::string16* page_text, |
| 165 bool preliminary_capture) { | 156 bool preliminary_capture) { |
| 166 if (preliminary_capture) { | 157 if (preliminary_capture || *page_text != classifier_page_text_) |
|
mattm
2014/07/08 23:35:50
should that be "==" ?
Avi (use Gerrit)
2014/07/08 23:43:18
D'oh. Yes.
| |
| 167 return; | 158 return; |
| 168 } | 159 |
| 169 // Make sure there's no classification in progress. We don't want to swap | 160 // Make sure there's no classification in progress. We don't want to swap |
| 170 // out the page text string from underneath the term feature extractor. | 161 // out the page text string from underneath the term feature extractor. |
| 171 // | 162 // |
| 172 // Note: Currently, if the url hasn't changed, we won't restart | 163 // Note: Currently, if the url hasn't changed, we won't restart |
| 173 // classification in this case. We may want to adjust this. | 164 // classification in this case. We may want to adjust this. |
| 174 CancelPendingClassification(PAGE_RECAPTURED); | 165 CancelPendingClassification(PAGE_RECAPTURED); |
| 175 last_finished_load_url_ = GetToplevelUrl(); | 166 last_finished_load_url_ = GetToplevelUrl(); |
| 176 classifier_page_text_.swap(*page_text); | 167 classifier_page_text_.swap(*page_text); |
| 177 have_page_text_ = true; | 168 have_page_text_ = true; |
| 178 MaybeStartClassification(); | 169 MaybeStartClassification(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 VLOG(2) << "Starting classification for " << last_finished_load_url_; | 274 VLOG(2) << "Starting classification for " << last_finished_load_url_; |
| 284 last_url_sent_to_classifier_ = last_finished_load_url_; | 275 last_url_sent_to_classifier_ = last_finished_load_url_; |
| 285 is_classifying_ = true; | 276 is_classifying_ = true; |
| 286 classifier_->BeginClassification( | 277 classifier_->BeginClassification( |
| 287 &classifier_page_text_, | 278 &classifier_page_text_, |
| 288 base::Bind(&PhishingClassifierDelegate::ClassificationDone, | 279 base::Bind(&PhishingClassifierDelegate::ClassificationDone, |
| 289 base::Unretained(this))); | 280 base::Unretained(this))); |
| 290 } | 281 } |
| 291 | 282 |
| 292 } // namespace safe_browsing | 283 } // namespace safe_browsing |
| OLD | NEW |