Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/renderer/safe_browsing/phishing_classifier_delegate.h

Issue 6250176: Make RenderView not have to know about how PhishingClassifierDelegate. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "chrome/renderer/render_view_observer.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 15 #include "ipc/ipc_platform_file.h"
15 class RenderView;
16
17 namespace WebKit {
18 class WebFrame;
19 }
20 16
21 namespace safe_browsing { 17 namespace safe_browsing {
22 class PhishingClassifier; 18 class PhishingClassifier;
23 class Scorer; 19 class Scorer;
24 20
25 class PhishingClassifierDelegate { 21 class PhishingClassifierDelegate : public RenderViewObserver {
26 public: 22 public:
23 static void SetPhishingModel(IPC::PlatformFileForTransit model_file);
24
27 // The RenderView owns us. This object takes ownership of the classifier. 25 // The RenderView owns us. This object takes ownership of the classifier.
28 // Note that if classifier is null, a default instance of PhishingClassifier 26 // Note that if classifier is null, a default instance of PhishingClassifier
29 // will be used. 27 // will be used.
30 PhishingClassifierDelegate(RenderView* render_view, 28 PhishingClassifierDelegate(RenderView* render_view,
31 PhishingClassifier* classifier); 29 PhishingClassifier* classifier);
32 ~PhishingClassifierDelegate(); 30 ~PhishingClassifierDelegate();
33 31
34 // Called by the RenderView once there is a phishing scorer available. 32 // Called by the RenderView once there is a phishing scorer available.
35 // The scorer is passed on to the classifier. 33 // The scorer is passed on to the classifier.
36 void SetPhishingScorer(const safe_browsing::Scorer* scorer); 34 void SetPhishingScorer(const safe_browsing::Scorer* scorer);
37 35
38 // Called by the RenderView when a page has started loading in the given 36 // RenderViewObserver implementation, public for testing.
39 // WebFrame. Typically, this will cause any pending classification to be 37 virtual void PageCaptured(const string16& page_text);
40 // cancelled. However, if the load is for the main frame, and the toplevel 38 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
41 // URL has not changed, we continue running the current classification. 39 bool is_new_navigation);
42 void CommittedLoadInFrame(WebKit::WebFrame* frame);
43
44 // Called by the RenderView once a page has finished loading. Determines
45 // whether a new toplevel load has taken place, and if so, begins
46 // classification. May modify page_text. Note that it is an error to
47 // call OnNavigate if there is a pending classification.
48 void FinishedLoad(string16* page_text);
49 40
50 // Cancels any pending classification and frees the page text. Called by 41 // Cancels any pending classification and frees the page text. Called by
51 // the RenderView when the RenderView is going away. 42 // the RenderView when the RenderView is going away.
52 void CancelPendingClassification(); 43 void CancelPendingClassification();
53 44
54 private: 45 private:
55 friend class PhishingClassifierDelegateTest; 46 friend class PhishingClassifierDelegateTest;
56 47
48 // RenderViewObserver implementation.
49 virtual bool OnMessageReceived(const IPC::Message& message);
50
57 // Called when classification for the current page finishes. 51 // Called when classification for the current page finishes.
58 void ClassificationDone(bool is_phishy, double phishy_score); 52 void ClassificationDone(bool is_phishy, double phishy_score);
59 53
60 // Returns the RenderView's toplevel URL, with the ref stripped. 54 // Returns the RenderView's toplevel URL, with the ref stripped.
61 GURL StripToplevelUrl(); 55 GURL StripToplevelUrl();
62 56
63 // The RenderView that owns this object.
64 RenderView* render_view_;
65
66 // The PhishingClassifier to use for the RenderView. This is created once 57 // The PhishingClassifier to use for the RenderView. This is created once
67 // a scorer is made available via SetPhishingScorer(). 58 // a scorer is made available via SetPhishingScorer().
68 scoped_ptr<PhishingClassifier> classifier_; 59 scoped_ptr<PhishingClassifier> classifier_;
69 60
70 // The last URL that was sent to the phishing classifier. 61 // The last URL that was sent to the phishing classifier.
71 GURL last_url_sent_to_classifier_; 62 GURL last_url_sent_to_classifier_;
72 63
73 // The page id of the last load that was sent to the phishing classifier. 64 // The page id of the last load that was sent to the phishing classifier.
74 // This is used to suppress phishing classification on back and forward 65 // This is used to suppress phishing classification on back and forward
75 // navigations in history. 66 // navigations in history.
76 int32 last_page_id_sent_to_classifier_; 67 int32 last_page_id_sent_to_classifier_;
77 68
78 // The page text that will be analyzed by the phishing classifier. This is 69 // The page text that will be analyzed by the phishing classifier. This is
79 // set by OnNavigate and cleared when the classifier finishes. Note that if 70 // set by OnNavigate and cleared when the classifier finishes. Note that if
80 // there is no classifier yet when OnNavigate is called, the page text will 71 // there is no classifier yet when OnNavigate is called, the page text will
81 // be cached until the scorer is set and a classifier can be created. 72 // be cached until the scorer is set and a classifier can be created.
82 string16 classifier_page_text_; 73 string16 classifier_page_text_;
83 74
84 // Set to true if we should run the phishing classifier on the current page 75 // Set to true if we should run the phishing classifier on the current page
85 // as soon as SetPhishingScorer() is called. 76 // as soon as SetPhishingScorer() is called.
86 bool pending_classification_; 77 bool pending_classification_;
87 78
88 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate); 79 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate);
89 }; 80 };
90 81
91 } // namespace safe_browsing 82 } // namespace safe_browsing
92 83
93 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ 84 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698