| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This class is used by the RenderView to interact with a PhishingClassifier. | 5 // This class is used by the RenderView to interact with a PhishingClassifier. |
| 6 | 6 |
| 7 #ifndef CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ | 7 #ifndef CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ |
| 8 #define CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ | 8 #define CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // will be used. | 27 // will be used. |
| 28 PhishingClassifierDelegate(RenderView* render_view, | 28 PhishingClassifierDelegate(RenderView* render_view, |
| 29 PhishingClassifier* classifier); | 29 PhishingClassifier* classifier); |
| 30 ~PhishingClassifierDelegate(); | 30 ~PhishingClassifierDelegate(); |
| 31 | 31 |
| 32 // Called by the RenderView once there is a phishing scorer available. | 32 // Called by the RenderView once there is a phishing scorer available. |
| 33 // The scorer is passed on to the classifier. | 33 // The scorer is passed on to the classifier. |
| 34 void SetPhishingScorer(const safe_browsing::Scorer* scorer); | 34 void SetPhishingScorer(const safe_browsing::Scorer* scorer); |
| 35 | 35 |
| 36 // RenderViewObserver implementation, public for testing. | 36 // RenderViewObserver implementation, public for testing. |
| 37 |
| 38 // Called by the RenderView once a page has finished loading. Updates the |
| 39 // last-loaded URL and page id, then starts classification if all other |
| 40 // conditions are met (see MaybeStartClassification for details). |
| 37 virtual void PageCaptured(const string16& page_text); | 41 virtual void PageCaptured(const string16& page_text); |
| 42 |
| 43 // Called by the RenderView when a page has started loading in the given |
| 44 // WebFrame. Typically, this will cause any pending classification to be |
| 45 // cancelled. However, if the navigation is within the same page, we |
| 46 // continue running the current classification. |
| 38 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, | 47 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, |
| 39 bool is_new_navigation); | 48 bool is_new_navigation); |
| 40 | 49 |
| 41 // Cancels any pending classification and frees the page text. Called by | 50 // Cancels any pending classification and frees the page text. Called by |
| 42 // the RenderView when the RenderView is going away. | 51 // the RenderView when the RenderView is going away. |
| 43 void CancelPendingClassification(); | 52 void CancelPendingClassification(); |
| 44 | 53 |
| 45 private: | 54 private: |
| 46 friend class PhishingClassifierDelegateTest; | 55 friend class PhishingClassifierDelegateTest; |
| 47 | 56 |
| 48 // RenderViewObserver implementation. | 57 // RenderViewObserver implementation. |
| 49 virtual bool OnMessageReceived(const IPC::Message& message); | 58 virtual bool OnMessageReceived(const IPC::Message& message); |
| 50 | 59 |
| 60 // Called by the RenderView when it receives a StartPhishingDetection IPC |
| 61 // from the browser. This signals that it is ok to begin classification |
| 62 // for the given toplevel URL. If the URL has been fully loaded into the |
| 63 // RenderView and a Scorer has been set, this will begin classification, |
| 64 // otherwise classification will be deferred until these conditions are met. |
| 65 void OnStartPhishingDetection(const GURL& url); |
| 66 |
| 51 // Called when classification for the current page finishes. | 67 // Called when classification for the current page finishes. |
| 52 void ClassificationDone(bool is_phishy, double phishy_score); | 68 void ClassificationDone(bool is_phishy, double phishy_score); |
| 53 | 69 |
| 54 // Returns the RenderView's toplevel URL, with the ref stripped. | 70 // Returns the RenderView's toplevel URL, with the ref stripped. |
| 55 GURL StripToplevelUrl(); | 71 GURL StripToplevelUrl(); |
| 56 | 72 |
| 73 // Shared code to begin classification if all conditions are met. |
| 74 void MaybeStartClassification(); |
| 75 |
| 57 // The PhishingClassifier to use for the RenderView. This is created once | 76 // The PhishingClassifier to use for the RenderView. This is created once |
| 58 // a scorer is made available via SetPhishingScorer(). | 77 // a scorer is made available via SetPhishingScorer(). |
| 59 scoped_ptr<PhishingClassifier> classifier_; | 78 scoped_ptr<PhishingClassifier> classifier_; |
| 60 | 79 |
| 61 // The last URL that was sent to the phishing classifier. | 80 // The last URL that the browser instructed us to classify. |
| 81 GURL last_url_received_from_browser_; |
| 82 |
| 83 // The last URL and page id that have finished loading in the RenderView. |
| 84 // These correspond to the text in classifier_page_text_. |
| 85 GURL last_finished_load_url_; |
| 86 int32 last_finished_load_id_; |
| 87 |
| 88 // The URL and page id of the last load that we actually started |
| 89 // classification on. This is used to suppress phishing classification on |
| 90 // subframe navigation and back and forward navigations in history. |
| 62 GURL last_url_sent_to_classifier_; | 91 GURL last_url_sent_to_classifier_; |
| 63 | |
| 64 // The page id of the last load that was sent to the phishing classifier. | |
| 65 // This is used to suppress phishing classification on back and forward | |
| 66 // navigations in history. | |
| 67 int32 last_page_id_sent_to_classifier_; | 92 int32 last_page_id_sent_to_classifier_; |
| 68 | 93 |
| 69 // The page text that will be analyzed by the phishing classifier. This is | 94 // The page text that will be analyzed by the phishing classifier. This is |
| 70 // set by OnNavigate and cleared when the classifier finishes. Note that if | 95 // set by OnNavigate and cleared when the classifier finishes. Note that if |
| 71 // there is no classifier yet when OnNavigate is called, the page text will | 96 // there is no Scorer yet when OnNavigate is called, or the browser has not |
| 72 // be cached until the scorer is set and a classifier can be created. | 97 // instructed us to classify the page, the page text will be cached until |
| 98 // these conditions are met. |
| 73 string16 classifier_page_text_; | 99 string16 classifier_page_text_; |
| 74 | 100 |
| 75 // Set to true if we should run the phishing classifier on the current page | |
| 76 // as soon as SetPhishingScorer() is called. | |
| 77 bool pending_classification_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate); |
| 80 }; | 102 }; |
| 81 | 103 |
| 82 } // namespace safe_browsing | 104 } // namespace safe_browsing |
| 83 | 105 |
| 84 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ | 106 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ |
| OLD | NEW |