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

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

Issue 2623733002: Componentize SafeBrowsingBlockingPage for WebView use (Closed)
Patch Set: address comments from ntfischer 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
meacer 2017/01/10 21:18:21 nit: I wonder if this class could be renamed to Sa
Jialiu Lin 2017/01/11 00:50:06 Since it is already in the safe_browsing namespace
Jialiu Lin 2017/01/11 00:50:06 Renamed to BaseBlockingPage and BaseUIManager acco
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Base class for managing the SafeBrowsing interstitial pages.
6 #ifndef COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_BLOCKING_PAGE_H_
7 #define COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_BLOCKING_PAGE_H_
8
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "components/safe_browsing/base_ui_manager.h"
15 #include "components/security_interstitials/content/security_interstitial_page.h "
16 #include "components/security_interstitials/core/safe_browsing_error_ui.h"
17 #include "content/public/browser/interstitial_page_delegate.h"
18 #include "url/gurl.h"
19
20 namespace history {
21 class HistoryService;
22 }
23
24 namespace safe_browsing {
25
26 class BaseSafeBrowsingBlockingPage
vakh (use Gerrit instead) 2017/01/10 20:44:26 Since this is already in the safe_browsing namespa
meacer 2017/01/10 21:18:21 nit: Documentation
Jialiu Lin 2017/01/11 00:50:06 Done.
27 : public security_interstitials::SecurityInterstitialPage {
28 public:
29 typedef security_interstitials::UnsafeResource UnsafeResource;
30 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI;
31 typedef std::vector<UnsafeResource> UnsafeResourceList;
32 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap;
vakh (use Gerrit instead) 2017/01/10 20:44:26 Do we need the map to be sorted? If not, we can us
Jialiu Lin 2017/01/11 00:50:06 Done.
33
34 ~BaseSafeBrowsingBlockingPage() override;
35
36 // Creates a blocking page. Use ShowBlockingPage if you don't need to access
37 // the blocking page directly.
38 static BaseSafeBrowsingBlockingPage* CreateBlockingPage(
39 BaseSafeBrowsingUIManager* ui_manager,
vakh (use Gerrit instead) 2017/01/10 20:44:26 Ideally this should also have been called BaseUIMa
Jialiu Lin 2017/01/11 00:50:06 Sure, renamed BaseUIManager as well.
40 content::WebContents* web_contents,
41 const GURL& main_frame_url,
42 const UnsafeResource& unsafe_resource);
43
44 // Shows a blocking page warning the user about phishing/malware for a
45 // specific resource.
46 // You can call this method several times, if an interstitial is already
47 // showing, the new one will be queued and displayed if the user decides
48 // to proceed on the currently showing interstitial.
49 static void ShowBlockingPage(BaseSafeBrowsingUIManager* ui_manager,
50 const UnsafeResource& resource);
51
52 // Returns true if the passed |unsafe_resources| is blocking the load of
53 // the main page.
54 static bool IsMainPageLoadBlocked(const UnsafeResourceList& unsafe_resources);
55
56 // InterstitialPageDelegate method:
57 void OnProceed() override;
58 void OnDontProceed() override;
59 void CommandReceived(const std::string& command) override;
60
61 protected:
62 // Don't instantiate this class directly, use ShowBlockingPage instead.
63 BaseSafeBrowsingBlockingPage(
64 BaseSafeBrowsingUIManager* ui_manager,
65 content::WebContents* web_contents,
66 const GURL& main_frame_url,
67 const UnsafeResourceList& unsafe_resources,
68 std::unique_ptr<
69 security_interstitials::SecurityInterstitialControllerClient>
70 controller_client,
71 SafeBrowsingErrorUI::SBErrorDisplayOptions* display_options);
72
73 // SecurityInterstitialPage methods:
74 bool ShouldCreateNewNavigation() const override;
75 void PopulateInterstitialStrings(
76 base::DictionaryValue* load_time_data) override;
77
78 // Called when the interstitial is going away. Intentionally do nothing in
79 // this base class. Overrided by SafeBrowsingBlockingPage class.
80 virtual void FinishThreatDetails(int64_t delay_ms,
81 bool did_proceed,
82 int num_visits);
83
84 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user
85 // should be warned about. They are queued when displaying more than one
86 // interstitial at a time.
87 static UnsafeResourceMap* GetUnsafeResourcesMap();
88
89 static std::string GetMetricPrefix(
90 const UnsafeResourceList& unsafe_resources,
91 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason);
92
93 static std::string GetExtraMetricsSuffix(
94 const UnsafeResourceList& unsafe_resources);
95
96 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason(
97 const UnsafeResourceList& unsafe_resources);
98
99 // For reporting back user actions.
100 BaseSafeBrowsingUIManager* ui_manager_;
101
102 // For displaying safe browsing interstitial.
103 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_;
104
105 // The URL of the main frame that caused the warning.
106 GURL main_frame_url_;
107
108 // The index of a navigation entry that should be removed when DontProceed()
109 // is invoked, -1 if entry should not be removed.
110 int navigation_entry_index_to_remove_;
111
112 // The list of unsafe resources this page is warning about.
113 UnsafeResourceList unsafe_resources_;
114
115 bool proceeded_;
vakh (use Gerrit instead) 2017/01/10 20:44:27 Please add a comment explaining the purpose.
Jialiu Lin 2017/01/11 00:50:06 Done.
116
117 // Which type of Safe Browsing interstitial this is.
118 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason_;
119
120 private:
121 static std::unique_ptr<
122 security_interstitials::SecurityInterstitialControllerClient>
123 CreateControllerClient(content::WebContents* web_contents,
124 const UnsafeResourceList& unsafe_resources,
125 history::HistoryService* history_service,
126 const std::string& app_locale,
127 const GURL& default_safe_page);
128
129 static const SafeBrowsingErrorUI::SBErrorDisplayOptions
130 CreateDefaultDisplayOptions(const UnsafeResourceList& unsafe_resources);
131
132 DISALLOW_COPY_AND_ASSIGN(BaseSafeBrowsingBlockingPage);
133 };
134
135 } // namespace safe_browsing
136
137 #endif // COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_BLOCKING_PAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698