| 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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/memory/scoped_callback_factory.h" | 13 #include "base/memory/scoped_callback_factory.h" |
| 14 #include "chrome/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
| 15 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 15 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 16 #include "chrome/renderer/safe_browsing/feature_extractor_clock.h" | 16 #include "chrome/renderer/safe_browsing/feature_extractor_clock.h" |
| 17 #include "chrome/renderer/safe_browsing/phishing_classifier.h" | 17 #include "chrome/renderer/safe_browsing/phishing_classifier.h" |
| 18 #include "chrome/renderer/safe_browsing/scorer.h" | 18 #include "chrome/renderer/safe_browsing/scorer.h" |
| 19 #include "content/public/renderer/document_state.h" |
| 19 #include "content/public/renderer/navigation_state.h" | 20 #include "content/public/renderer/navigation_state.h" |
| 20 #include "content/public/renderer/render_thread.h" | 21 #include "content/public/renderer/render_thread.h" |
| 21 #include "content/public/renderer/render_view.h" | 22 #include "content/public/renderer/render_view.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 26 | 27 |
| 28 using content::DocumentState; |
| 27 using content::NavigationState; | 29 using content::NavigationState; |
| 28 using content::RenderThread; | 30 using content::RenderThread; |
| 29 | 31 |
| 30 namespace safe_browsing { | 32 namespace safe_browsing { |
| 31 | 33 |
| 32 static GURL StripRef(const GURL& url) { | 34 static GURL StripRef(const GURL& url) { |
| 33 GURL::Replacements replacements; | 35 GURL::Replacements replacements; |
| 34 replacements.ClearRef(); | 36 replacements.ClearRef(); |
| 35 return url.ReplaceComponents(replacements); | 37 return url.ReplaceComponents(replacements); |
| 36 } | 38 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 144 |
| 143 void PhishingClassifierDelegate::DidCommitProvisionalLoad( | 145 void PhishingClassifierDelegate::DidCommitProvisionalLoad( |
| 144 WebKit::WebFrame* frame, bool is_new_navigation) { | 146 WebKit::WebFrame* frame, bool is_new_navigation) { |
| 145 // A new page is starting to load, so cancel classificaiton. | 147 // A new page is starting to load, so cancel classificaiton. |
| 146 // | 148 // |
| 147 // TODO(bryner): We shouldn't need to cancel classification if the navigation | 149 // TODO(bryner): We shouldn't need to cancel classification if the navigation |
| 148 // is within the same page. However, if we let classification continue in | 150 // is within the same page. However, if we let classification continue in |
| 149 // this case, we need to properly deal with the fact that PageCaptured will | 151 // this case, we need to properly deal with the fact that PageCaptured will |
| 150 // be called again for the in-page navigation. We need to be sure not to | 152 // be called again for the in-page navigation. We need to be sure not to |
| 151 // swap out the page text while the term feature extractor is still running. | 153 // swap out the page text while the term feature extractor is still running. |
| 152 NavigationState* state = NavigationState::FromDataSource( | 154 DocumentState* document_state = DocumentState::FromDataSource( |
| 153 frame->dataSource()); | 155 frame->dataSource()); |
| 154 CancelPendingClassification(state->was_within_same_page() ? | 156 NavigationState* navigation_state = document_state->navigation_state(); |
| 157 CancelPendingClassification(navigation_state->was_within_same_page() ? |
| 155 NAVIGATE_WITHIN_PAGE : NAVIGATE_AWAY); | 158 NAVIGATE_WITHIN_PAGE : NAVIGATE_AWAY); |
| 156 if (frame == render_view()->GetWebView()->mainFrame()) { | 159 if (frame == render_view()->GetWebView()->mainFrame()) { |
| 157 last_main_frame_transition_ = state->transition_type(); | 160 last_main_frame_transition_ = navigation_state->transition_type(); |
| 158 } | 161 } |
| 159 } | 162 } |
| 160 | 163 |
| 161 void PhishingClassifierDelegate::PageCaptured(string16* page_text, | 164 void PhishingClassifierDelegate::PageCaptured(string16* page_text, |
| 162 bool preliminary_capture) { | 165 bool preliminary_capture) { |
| 163 if (preliminary_capture) { | 166 if (preliminary_capture) { |
| 164 return; | 167 return; |
| 165 } | 168 } |
| 166 // Make sure there's no classification in progress. We don't want to swap | 169 // Make sure there's no classification in progress. We don't want to swap |
| 167 // out the page text string from underneath the term feature extractor. | 170 // out the page text string from underneath the term feature extractor. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 282 |
| 280 VLOG(2) << "Starting classification for " << last_finished_load_url_; | 283 VLOG(2) << "Starting classification for " << last_finished_load_url_; |
| 281 last_url_sent_to_classifier_ = last_finished_load_url_; | 284 last_url_sent_to_classifier_ = last_finished_load_url_; |
| 282 is_classifying_ = true; | 285 is_classifying_ = true; |
| 283 classifier_->BeginClassification( | 286 classifier_->BeginClassification( |
| 284 &classifier_page_text_, | 287 &classifier_page_text_, |
| 285 NewCallback(this, &PhishingClassifierDelegate::ClassificationDone)); | 288 NewCallback(this, &PhishingClassifierDelegate::ClassificationDone)); |
| 286 } | 289 } |
| 287 | 290 |
| 288 } // namespace safe_browsing | 291 } // namespace safe_browsing |
| OLD | NEW |