| 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 <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 MaybeStartClassification(); | 142 MaybeStartClassification(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void PhishingClassifierDelegate::DidCommitProvisionalLoad( | 145 void PhishingClassifierDelegate::DidCommitProvisionalLoad( |
| 146 bool is_new_navigation, | 146 bool is_new_navigation, |
| 147 bool is_same_page_navigation) { | 147 bool is_same_page_navigation) { |
| 148 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); | 148 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 149 // A new page is starting to load, so cancel classificaiton. | 149 // A new page is starting to load, so cancel classificaiton. |
| 150 // | 150 // |
| 151 // TODO(bryner): We shouldn't need to cancel classification if the navigation | 151 // TODO(bryner): We shouldn't need to cancel classification if the navigation |
| 152 // is within the same page. However, if we let classification continue in | 152 // is within the same document. However, if we let classification continue in |
| 153 // this case, we need to properly deal with the fact that PageCaptured will | 153 // this case, we need to properly deal with the fact that PageCaptured will |
| 154 // be called again for the in-page navigation. We need to be sure not to | 154 // be called again for the same-document navigation. We need to be sure not |
| 155 // swap out the page text while the term feature extractor is still running. | 155 // to swap out the page text while the term feature extractor is still |
| 156 // running. |
| 156 DocumentState* document_state = DocumentState::FromDataSource( | 157 DocumentState* document_state = DocumentState::FromDataSource( |
| 157 frame->dataSource()); | 158 frame->dataSource()); |
| 158 NavigationState* navigation_state = document_state->navigation_state(); | 159 NavigationState* navigation_state = document_state->navigation_state(); |
| 159 CancelPendingClassification(navigation_state->WasWithinSamePage() | 160 CancelPendingClassification(navigation_state->WasWithinSameDocument() |
| 160 ? NAVIGATE_WITHIN_PAGE | 161 ? NAVIGATE_WITHIN_PAGE |
| 161 : NAVIGATE_AWAY); | 162 : NAVIGATE_AWAY); |
| 162 if (frame->parent()) | 163 if (frame->parent()) |
| 163 return; | 164 return; |
| 164 | 165 |
| 165 last_main_frame_transition_ = navigation_state->GetTransitionType(); | 166 last_main_frame_transition_ = navigation_state->GetTransitionType(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void PhishingClassifierDelegate::PageCaptured(base::string16* page_text, | 169 void PhishingClassifierDelegate::PageCaptured(base::string16* page_text, |
| 169 bool preliminary_capture) { | 170 bool preliminary_capture) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // load completes), we discard the page text since it won't be needed. | 237 // load completes), we discard the page text since it won't be needed. |
| 237 if (!classifier_->is_ready()) { | 238 if (!classifier_->is_ready()) { |
| 238 DVLOG(2) << "Not starting classification, no Scorer created."; | 239 DVLOG(2) << "Not starting classification, no Scorer created."; |
| 239 // Keep classifier_page_text_, in case a Scorer is set later. | 240 // Keep classifier_page_text_, in case a Scorer is set later. |
| 240 return; | 241 return; |
| 241 } | 242 } |
| 242 | 243 |
| 243 if (last_main_frame_transition_ & ui::PAGE_TRANSITION_FORWARD_BACK) { | 244 if (last_main_frame_transition_ & ui::PAGE_TRANSITION_FORWARD_BACK) { |
| 244 // Skip loads from session history navigation. However, update the | 245 // Skip loads from session history navigation. However, update the |
| 245 // last URL sent to the classifier, so that we'll properly detect | 246 // last URL sent to the classifier, so that we'll properly detect |
| 246 // in-page navigations. | 247 // same-document navigations. |
| 247 DVLOG(2) << "Not starting classification for back/forward navigation"; | 248 DVLOG(2) << "Not starting classification for back/forward navigation"; |
| 248 last_url_sent_to_classifier_ = last_finished_load_url_; | 249 last_url_sent_to_classifier_ = last_finished_load_url_; |
| 249 classifier_page_text_.clear(); // we won't need this. | 250 classifier_page_text_.clear(); // we won't need this. |
| 250 have_page_text_ = false; | 251 have_page_text_ = false; |
| 251 return; | 252 return; |
| 252 } | 253 } |
| 253 | 254 |
| 254 GURL stripped_last_load_url(StripRef(last_finished_load_url_)); | 255 GURL stripped_last_load_url(StripRef(last_finished_load_url_)); |
| 255 if (stripped_last_load_url == StripRef(last_url_sent_to_classifier_)) { | 256 if (stripped_last_load_url == StripRef(last_url_sent_to_classifier_)) { |
| 256 // We've already classified this toplevel URL, so this was likely an | 257 // We've already classified this toplevel URL, so this was likely an |
| 257 // in-page navigation or a subframe navigation. The browser should not | 258 // same-document navigation or a subframe navigation. The browser should |
| 258 // send a StartPhishingDetection IPC in this case. | 259 // not send a StartPhishingDetection IPC in this case. |
| 259 DVLOG(2) << "Toplevel URL is unchanged, not starting classification."; | 260 DVLOG(2) << "Toplevel URL is unchanged, not starting classification."; |
| 260 classifier_page_text_.clear(); // we won't need this. | 261 classifier_page_text_.clear(); // we won't need this. |
| 261 have_page_text_ = false; | 262 have_page_text_ = false; |
| 262 return; | 263 return; |
| 263 } | 264 } |
| 264 | 265 |
| 265 if (!have_page_text_) { | 266 if (!have_page_text_) { |
| 266 DVLOG(2) << "Not starting classification, there is no page text ready."; | 267 DVLOG(2) << "Not starting classification, there is no page text ready."; |
| 267 return; | 268 return; |
| 268 } | 269 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 287 &classifier_page_text_, | 288 &classifier_page_text_, |
| 288 base::Bind(&PhishingClassifierDelegate::ClassificationDone, | 289 base::Bind(&PhishingClassifierDelegate::ClassificationDone, |
| 289 base::Unretained(this))); | 290 base::Unretained(this))); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void PhishingClassifierDelegate::OnDestruct() { | 293 void PhishingClassifierDelegate::OnDestruct() { |
| 293 delete this; | 294 delete this; |
| 294 } | 295 } |
| 295 | 296 |
| 296 } // namespace safe_browsing | 297 } // namespace safe_browsing |
| OLD | NEW |