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

Side by Side Diff: components/safe_browsing/base_ui_manager.h

Issue 2623733002: Componentize SafeBrowsingBlockingPage for WebView use (Closed)
Patch Set: address final comments Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef COMPONENTS_SAFE_BROWSING_BASE_UI_MANAGER_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_BASE_UI_MANAGER_H_
6 #define COMPONENTS_SAFE_BROWSING_BASE_UI_MANAGER_H_ 6 #define COMPONENTS_SAFE_BROWSING_BASE_UI_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
15 #include "base/observer_list.h"
16 #include "base/supports_user_data.h"
17 #include "base/time/time.h" 14 #include "base/time/time.h"
18 #include "components/security_interstitials/content/unsafe_resource.h" 15 #include "components/security_interstitials/content/unsafe_resource.h"
19 16
20 class GURL; 17 class GURL;
21 18
22 namespace content { 19 namespace content {
23 class NavigationEntry; 20 class NavigationEntry;
24 class WebContents; 21 class WebContents;
25 } // namespace content 22 } // namespace content
26 23
24 namespace history {
25 class HistoryService;
26 } // namespace history
27
27 namespace safe_browsing { 28 namespace safe_browsing {
28 29
29 // Construction needs to happen on the main thread. 30 // Construction needs to happen on the main thread.
30 class BaseSafeBrowsingUIManager 31 class BaseUIManager
31 : public base::RefCountedThreadSafe<BaseSafeBrowsingUIManager> { 32 : public base::RefCountedThreadSafe<BaseUIManager> {
32 public: 33 public:
33 typedef security_interstitials::UnsafeResource UnsafeResource; 34 typedef security_interstitials::UnsafeResource UnsafeResource;
34 35
35 // Observer class can be used to get notified when a SafeBrowsing hit 36 BaseUIManager();
36 // was found.
37 class Observer {
38 public:
39 // The |resource| was classified as unsafe by SafeBrowsing, and is
40 // not whitelisted.
41 // The |resource| must not be accessed after OnSafeBrowsingHit returns.
42 // This method will be called on the UI thread.
43 virtual void OnSafeBrowsingHit(const UnsafeResource& resource) = 0;
44
45 protected:
46 Observer() {}
47 virtual ~Observer() {}
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(Observer);
51 };
52
53 BaseSafeBrowsingUIManager();
54 37
55 // Called to stop or shutdown operations on the io_thread. This may be called 38 // Called to stop or shutdown operations on the io_thread. This may be called
56 // multiple times during the life of the UIManager. Should be called 39 // multiple times during the life of the UIManager. Should be called
57 // on IO thread. If shutdown is true, the manager is disabled permanently. 40 // on IO thread. If shutdown is true, the manager is disabled permanently.
58 virtual void StopOnIOThread(bool shutdown); 41 virtual void StopOnIOThread(bool shutdown);
59 42
60 // Called on the UI thread to display an interstitial page. 43 // Called on the UI thread to display an interstitial page.
61 // |url| is the url of the resource that matches a safe browsing list. 44 // |url| is the url of the resource that matches a safe browsing list.
62 // If the request contained a chain of redirects, |url| is the last url 45 // If the request contained a chain of redirects, |url| is the last url
63 // in the chain, and |original_url| is the first one (the root of the 46 // in the chain, and |original_url| is the first one (the root of the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // otherwise. |web_contents| is the WebContents that was displaying 92 // otherwise. |web_contents| is the WebContents that was displaying
110 // the blocking page. |main_frame_url| is the top-level URL on which 93 // the blocking page. |main_frame_url| is the top-level URL on which
111 // the blocking page was displayed. If |proceed| is true, 94 // the blocking page was displayed. If |proceed| is true,
112 // |main_frame_url| is whitelisted so that the user will not see 95 // |main_frame_url| is whitelisted so that the user will not see
113 // another warning for that URL in this WebContents. 96 // another warning for that URL in this WebContents.
114 virtual void OnBlockingPageDone(const std::vector<UnsafeResource>& resources, 97 virtual void OnBlockingPageDone(const std::vector<UnsafeResource>& resources,
115 bool proceed, 98 bool proceed,
116 content::WebContents* web_contents, 99 content::WebContents* web_contents,
117 const GURL& main_frame_url); 100 const GURL& main_frame_url);
118 101
119 // Add and remove observers. These methods must be invoked on the UI thread. 102 virtual const std::string app_locale() const;
120 virtual void AddObserver(Observer* observer); 103
121 virtual void RemoveObserver(Observer* remove); 104 virtual history::HistoryService* history_service(
105 content::WebContents* web_contents);
106
107 // The default safe page when there is no entry in the history to go back to.
108 // e.g. about::blank page, or chrome's new tab page.
109 virtual const GURL default_safe_page() const;
122 110
123 protected: 111 protected:
124 virtual ~BaseSafeBrowsingUIManager(); 112 virtual ~BaseUIManager();
125 113
126 // Updates the whitelist URL set for |web_contents|. Called on the UI thread. 114 // Updates the whitelist URL set for |web_contents|. Called on the UI thread.
127 void AddToWhitelistUrlSet(const GURL& whitelist_url, 115 void AddToWhitelistUrlSet(const GURL& whitelist_url,
128 content::WebContents* web_contents, 116 content::WebContents* web_contents,
129 bool is_pending, 117 bool is_pending,
130 SBThreatType threat_type); 118 SBThreatType threat_type);
131 119
132 // Call protocol manager on IO thread to report hits of unsafe contents. 120 // Call protocol manager on IO thread to report hits of unsafe contents.
133 virtual void ReportSafeBrowsingHitOnIOThread( 121 virtual void ReportSafeBrowsingHitOnIOThread(
134 const safe_browsing::HitReport& hit_report); 122 const safe_browsing::HitReport& hit_report);
135 123
136 // Removes |whitelist_url| from the pending whitelist for 124 // Removes |whitelist_url| from the pending whitelist for
137 // |web_contents|. Called on the UI thread. 125 // |web_contents|. Called on the UI thread.
138 void RemoveFromPendingWhitelistUrlSet(const GURL& whitelist_url, 126 void RemoveFromPendingWhitelistUrlSet(const GURL& whitelist_url,
139 content::WebContents* web_contents); 127 content::WebContents* web_contents);
140 128
141 // Ensures that |web_contents| has its whitelist set in its userdata 129 // Ensures that |web_contents| has its whitelist set in its userdata
142 static void EnsureWhitelistCreated(content::WebContents* web_contents); 130 static void EnsureWhitelistCreated(content::WebContents* web_contents);
143 131
144 base::ObserverList<Observer> observer_list_; 132 // Returns the URL that should be used in a WhitelistUrlSet for the given
133 // |resource|.
134 static GURL GetMainFrameWhitelistUrlForResource(
135 const security_interstitials::UnsafeResource& resource);
145 136
146 private: 137 private:
147 friend class base::RefCountedThreadSafe<BaseSafeBrowsingUIManager>; 138 friend class base::RefCountedThreadSafe<BaseUIManager>;
148 139
149 DISALLOW_COPY_AND_ASSIGN(BaseSafeBrowsingUIManager); 140 DISALLOW_COPY_AND_ASSIGN(BaseUIManager);
150 }; 141 };
151 142
152 } // namespace safe_browsing 143 } // namespace safe_browsing
153 144
154 #endif // COMPONENTS_SAFE_BROWSING_BASE_UI_MANAGER_H_ 145 #endif // COMPONENTS_SAFE_BROWSING_BASE_UI_MANAGER_H_
OLDNEW
« no previous file with comments | « components/safe_browsing/base_safe_browsing_resource_throttle.cc ('k') | components/safe_browsing/base_ui_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698