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 // 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 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "content/public/renderer/render_process_observer.h" | 12 #include "content/public/renderer/render_process_observer.h" |
13 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_view_observer.h" |
14 #include "ui/base/page_transition_types.h" | 14 #include "ui/base/page_transition_types.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 namespace safe_browsing { | 17 namespace safe_browsing { |
18 class ClientPhishingRequest; | 18 class ClientPhishingRequest; |
19 class PhishingClassifier; | 19 class PhishingClassifier; |
20 class Scorer; | 20 class Scorer; |
21 | 21 |
22 class PhishingClassifierFilter : public content::RenderProcessObserver { | 22 class PhishingClassifierFilter : public content::RenderProcessObserver { |
23 public: | 23 public: |
24 static PhishingClassifierFilter* Create(); | 24 static PhishingClassifierFilter* Create(); |
25 virtual ~PhishingClassifierFilter(); | 25 ~PhishingClassifierFilter() override; |
26 | 26 |
27 virtual bool OnControlMessageReceived(const IPC::Message& message) override; | 27 bool OnControlMessageReceived(const IPC::Message& message) override; |
28 | 28 |
29 private: | 29 private: |
30 PhishingClassifierFilter(); | 30 PhishingClassifierFilter(); |
31 void OnSetPhishingModel(const std::string& model); | 31 void OnSetPhishingModel(const std::string& model); |
32 | 32 |
33 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierFilter); | 33 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierFilter); |
34 }; | 34 }; |
35 | 35 |
36 class PhishingClassifierDelegate : public content::RenderViewObserver { | 36 class PhishingClassifierDelegate : public content::RenderViewObserver { |
37 public: | 37 public: |
38 // The RenderView owns us. This object takes ownership of the classifier. | 38 // The RenderView owns us. This object takes ownership of the classifier. |
39 // Note that if classifier is null, a default instance of PhishingClassifier | 39 // Note that if classifier is null, a default instance of PhishingClassifier |
40 // will be used. | 40 // will be used. |
41 static PhishingClassifierDelegate* Create(content::RenderView* render_view, | 41 static PhishingClassifierDelegate* Create(content::RenderView* render_view, |
42 PhishingClassifier* classifier); | 42 PhishingClassifier* classifier); |
43 virtual ~PhishingClassifierDelegate(); | 43 ~PhishingClassifierDelegate() override; |
44 | 44 |
45 // Called by the RenderView once there is a phishing scorer available. | 45 // Called by the RenderView once there is a phishing scorer available. |
46 // The scorer is passed on to the classifier. | 46 // The scorer is passed on to the classifier. |
47 void SetPhishingScorer(const safe_browsing::Scorer* scorer); | 47 void SetPhishingScorer(const safe_browsing::Scorer* scorer); |
48 | 48 |
49 // Called by the RenderView once a page has finished loading. Updates the | 49 // Called by the RenderView once a page has finished loading. Updates the |
50 // last-loaded URL and page text, then starts classification if all other | 50 // last-loaded URL and page text, then starts classification if all other |
51 // conditions are met (see MaybeStartClassification for details). | 51 // conditions are met (see MaybeStartClassification for details). |
52 // We ignore preliminary captures, since these happen before the page has | 52 // We ignore preliminary captures, since these happen before the page has |
53 // finished loading. | 53 // finished loading. |
54 void PageCaptured(base::string16* page_text, bool preliminary_capture); | 54 void PageCaptured(base::string16* page_text, bool preliminary_capture); |
55 | 55 |
56 // RenderViewObserver implementation, public for testing. | 56 // RenderViewObserver implementation, public for testing. |
57 | 57 |
58 // Called by the RenderView when a page has started loading in the given | 58 // Called by the RenderView when a page has started loading in the given |
59 // WebFrame. Typically, this will cause any pending classification to be | 59 // WebFrame. Typically, this will cause any pending classification to be |
60 // cancelled. However, if the navigation is within the same page, we | 60 // cancelled. However, if the navigation is within the same page, we |
61 // continue running the current classification. | 61 // continue running the current classification. |
62 virtual void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, | 62 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, |
63 bool is_new_navigation) override; | 63 bool is_new_navigation) override; |
64 | 64 |
65 private: | 65 private: |
66 friend class PhishingClassifierDelegateTest; | 66 friend class PhishingClassifierDelegateTest; |
67 | 67 |
68 PhishingClassifierDelegate(content::RenderView* render_view, | 68 PhishingClassifierDelegate(content::RenderView* render_view, |
69 PhishingClassifier* classifier); | 69 PhishingClassifier* classifier); |
70 | 70 |
71 enum CancelClassificationReason { | 71 enum CancelClassificationReason { |
72 NAVIGATE_AWAY, | 72 NAVIGATE_AWAY, |
73 NAVIGATE_WITHIN_PAGE, | 73 NAVIGATE_WITHIN_PAGE, |
74 PAGE_RECAPTURED, | 74 PAGE_RECAPTURED, |
75 SHUTDOWN, | 75 SHUTDOWN, |
76 NEW_PHISHING_SCORER, | 76 NEW_PHISHING_SCORER, |
77 CANCEL_CLASSIFICATION_MAX // Always add new values before this one. | 77 CANCEL_CLASSIFICATION_MAX // Always add new values before this one. |
78 }; | 78 }; |
79 | 79 |
80 // Cancels any pending classification and frees the page text. | 80 // Cancels any pending classification and frees the page text. |
81 void CancelPendingClassification(CancelClassificationReason reason); | 81 void CancelPendingClassification(CancelClassificationReason reason); |
82 | 82 |
83 // RenderViewObserver implementation. | 83 // RenderViewObserver implementation. |
84 virtual bool OnMessageReceived(const IPC::Message& message) override; | 84 bool OnMessageReceived(const IPC::Message& message) override; |
85 | 85 |
86 // Called by the RenderView when it receives a StartPhishingDetection IPC | 86 // Called by the RenderView when it receives a StartPhishingDetection IPC |
87 // from the browser. This signals that it is ok to begin classification | 87 // from the browser. This signals that it is ok to begin classification |
88 // for the given toplevel URL. If the URL has been fully loaded into the | 88 // for the given toplevel URL. If the URL has been fully loaded into the |
89 // RenderView and a Scorer has been set, this will begin classification, | 89 // RenderView and a Scorer has been set, this will begin classification, |
90 // otherwise classification will be deferred until these conditions are met. | 90 // otherwise classification will be deferred until these conditions are met. |
91 void OnStartPhishingDetection(const GURL& url); | 91 void OnStartPhishingDetection(const GURL& url); |
92 | 92 |
93 // Called when classification for the current page finishes. | 93 // Called when classification for the current page finishes. |
94 void ClassificationDone(const ClientPhishingRequest& verdict); | 94 void ClassificationDone(const ClientPhishingRequest& verdict); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 // Set to true if the classifier is currently running. | 137 // Set to true if the classifier is currently running. |
138 bool is_classifying_; | 138 bool is_classifying_; |
139 | 139 |
140 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate); | 140 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate); |
141 }; | 141 }; |
142 | 142 |
143 } // namespace safe_browsing | 143 } // namespace safe_browsing |
144 | 144 |
145 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ | 145 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_ |
OLD | NEW |