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

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

Issue 2667343006: Componentize safe_browsing [X+1] : move the renderer part to component.
Patch Set: Created 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // This class is used by the RenderView to interact with a PhishingClassifier.
6
7 #ifndef CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_
8 #define CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_
9
10 #include <memory>
11
12 #include "base/macros.h"
13 #include "base/strings/string16.h"
14 #include "content/public/renderer/render_frame_observer.h"
15 #include "content/public/renderer/render_thread_observer.h"
16 #include "ui/base/page_transition_types.h"
17 #include "url/gurl.h"
18
19 namespace safe_browsing {
20 class ClientPhishingRequest;
21 class PhishingClassifier;
22 class Scorer;
23
24 class PhishingClassifierFilter : public content::RenderThreadObserver {
25 public:
26 static PhishingClassifierFilter* Create();
27 ~PhishingClassifierFilter() override;
28
29 bool OnControlMessageReceived(const IPC::Message& message) override;
30
31 private:
32 PhishingClassifierFilter();
33 void OnSetPhishingModel(const std::string& model);
34
35 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierFilter);
36 };
37
38 class PhishingClassifierDelegate : public content::RenderFrameObserver {
39 public:
40 // The RenderFrame owns us. This object takes ownership of the classifier.
41 // Note that if classifier is null, a default instance of PhishingClassifier
42 // will be used.
43 static PhishingClassifierDelegate* Create(content::RenderFrame* render_frame,
44 PhishingClassifier* classifier);
45 ~PhishingClassifierDelegate() override;
46
47 // Called by the RenderFrame once there is a phishing scorer available.
48 // The scorer is passed on to the classifier.
49 void SetPhishingScorer(const safe_browsing::Scorer* scorer);
50
51 // Called by the RenderFrame once a page has finished loading. Updates the
52 // last-loaded URL and page text, then starts classification if all other
53 // conditions are met (see MaybeStartClassification for details).
54 // We ignore preliminary captures, since these happen before the page has
55 // finished loading.
56 void PageCaptured(base::string16* page_text, bool preliminary_capture);
57
58 // RenderFrameObserver implementation, public for testing.
59
60 // Called by the RenderFrame when a page has started loading in the given
61 // WebFrame. Typically, this will cause any pending classification to be
62 // cancelled. However, if the navigation is within the same page, we
63 // continue running the current classification.
64 void DidCommitProvisionalLoad(bool is_new_navigation,
65 bool is_same_page_navigation) override;
66
67 private:
68 friend class PhishingClassifierDelegateTest;
69
70 PhishingClassifierDelegate(content::RenderFrame* render_frame,
71 PhishingClassifier* classifier);
72
73 enum CancelClassificationReason {
74 NAVIGATE_AWAY,
75 NAVIGATE_WITHIN_PAGE,
76 PAGE_RECAPTURED,
77 SHUTDOWN,
78 NEW_PHISHING_SCORER,
79 CANCEL_CLASSIFICATION_MAX // Always add new values before this one.
80 };
81
82 // Cancels any pending classification and frees the page text.
83 void CancelPendingClassification(CancelClassificationReason reason);
84
85 // RenderFrameObserver implementation.
86 bool OnMessageReceived(const IPC::Message& message) override;
87 void OnDestruct() override;
88
89 // Called by the RenderFrame when it receives a StartPhishingDetection IPC
90 // from the browser. This signals that it is ok to begin classification
91 // for the given toplevel URL. If the URL has been fully loaded into the
92 // RenderFrame and a Scorer has been set, this will begin classification,
93 // otherwise classification will be deferred until these conditions are met.
94 void OnStartPhishingDetection(const GURL& url);
95
96 // Called when classification for the current page finishes.
97 void ClassificationDone(const ClientPhishingRequest& verdict);
98
99 // Shared code to begin classification if all conditions are met.
100 void MaybeStartClassification();
101
102 // The PhishingClassifier to use for the RenderFrame. This is created once
103 // a scorer is made available via SetPhishingScorer().
104 std::unique_ptr<PhishingClassifier> classifier_;
105
106 // The last URL that the browser instructed us to classify,
107 // with the ref stripped.
108 GURL last_url_received_from_browser_;
109
110 // The last top-level URL that has finished loading in the RenderFrame.
111 // This corresponds to the text in classifier_page_text_.
112 GURL last_finished_load_url_;
113
114 // The transition type for the last load in the main frame. We use this
115 // to exclude back/forward loads from classification. Note that this is
116 // set in DidCommitProvisionalLoad(); the transition is reset after this
117 // call in the RenderFrame, so we need to save off the value.
118 ui::PageTransition last_main_frame_transition_;
119
120 // The URL of the last load that we actually started classification on.
121 // This is used to suppress phishing classification on subframe navigation
122 // and back and forward navigations in history.
123 GURL last_url_sent_to_classifier_;
124
125 // The page text that will be analyzed by the phishing classifier. This is
126 // set by OnNavigate and cleared when the classifier finishes. Note that if
127 // there is no Scorer yet when OnNavigate is called, or the browser has not
128 // instructed us to classify the page, the page text will be cached until
129 // these conditions are met.
130 base::string16 classifier_page_text_;
131
132 // Tracks whether we have stored anything in classifier_page_text_ for the
133 // most recent load. We use this to distinguish empty text from cases where
134 // PageCaptured has not been called.
135 bool have_page_text_;
136
137 // Set to true if the classifier is currently running.
138 bool is_classifying_;
139
140 DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate);
141 };
142
143 } // namespace safe_browsing
144
145 #endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_CLASSIFIER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698