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

Side by Side Diff: chrome/browser/safe_browsing/ui_manager.cc

Issue 2623733002: Componentize SafeBrowsingBlockingPage for WebView use (Closed)
Patch Set: rebase again + nits 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/safe_browsing/ui_manager.h" 5 #include "chrome/browser/safe_browsing/ui_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/history/history_service_factory.h"
13 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/safe_browsing/ping_manager.h" 17 #include "chrome/browser/safe_browsing/ping_manager.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
18 #include "chrome/browser/safe_browsing/threat_details.h" 20 #include "chrome/browser/safe_browsing/threat_details.h"
19 #include "chrome/browser/tab_contents/tab_util.h" 21 #include "chrome/browser/tab_contents/tab_util.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h"
21 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
22 #include "components/safe_browsing_db/metadata.pb.h"
23 #include "components/safe_browsing_db/safe_browsing_prefs.h" 25 #include "components/safe_browsing_db/safe_browsing_prefs.h"
24 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/navigation_entry.h" 27 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
28 #include "ipc/ipc_message.h" 30 #include "ipc/ipc_message.h"
29 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 31 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
30 #include "net/ssl/ssl_info.h" 32 #include "net/ssl/ssl_info.h"
31 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
33 #include "url/gurl.h" 35 #include "url/gurl.h"
34 36
35 using content::BrowserThread; 37 using content::BrowserThread;
36 using content::NavigationEntry; 38 using content::NavigationEntry;
37 using content::WebContents; 39 using content::WebContents;
38 using safe_browsing::HitReport; 40 using safe_browsing::HitReport;
39 using safe_browsing::SBThreatType; 41 using safe_browsing::SBThreatType;
40 42
41 namespace {
42
43 // Returns the URL that should be used in a WhitelistUrlSet for the given
44 // |resource|.
45 GURL GetMainFrameWhitelistUrlForResource(
46 const security_interstitials::UnsafeResource& resource) {
47 if (resource.is_subresource) {
48 NavigationEntry* entry = resource.GetNavigationEntryForResource();
49 if (!entry)
50 return GURL();
51 return entry->GetURL().GetWithEmptyPath();
52 }
53 return resource.url.GetWithEmptyPath();
54 }
55
56 } // namespace
57
58 namespace safe_browsing { 43 namespace safe_browsing {
59 44
60 SafeBrowsingUIManager::SafeBrowsingUIManager( 45 SafeBrowsingUIManager::SafeBrowsingUIManager(
61 const scoped_refptr<SafeBrowsingService>& service) 46 const scoped_refptr<SafeBrowsingService>& service)
62 : sb_service_(service) {} 47 : sb_service_(service) {}
63 48
64 SafeBrowsingUIManager::~SafeBrowsingUIManager() {} 49 SafeBrowsingUIManager::~SafeBrowsingUIManager() {}
65 50
66 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) { 51 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) {
67 DCHECK_CURRENTLY_ON(BrowserThread::IO); 52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
68 53
69 if (shutdown) 54 if (shutdown)
70 sb_service_ = NULL; 55 sb_service_ = NULL;
71 } 56 }
72 57
73 void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) {
74 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time);
75 }
76
77 void SafeBrowsingUIManager::DisplayBlockingPage( 58 void SafeBrowsingUIManager::DisplayBlockingPage(
78 const UnsafeResource& resource) { 59 const UnsafeResource& resource) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); 60 DCHECK_CURRENTLY_ON(BrowserThread::UI);
80 if (resource.is_subresource && !resource.is_subframe) { 61 if (resource.is_subresource && !resource.is_subframe) {
81 // Sites tagged as serving Unwanted Software should only show a warning for 62 // Sites tagged as serving Unwanted Software should only show a warning for
82 // main-frame or sub-frame resource. Similar warning restrictions should be 63 // main-frame or sub-frame resource. Similar warning restrictions should be
83 // applied to malware sites tagged as "landing sites" (see "Types of 64 // applied to malware sites tagged as "landing sites" (see "Types of
84 // Malware sites" under 65 // Malware sites" under
85 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs). 66 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs).
86 MalwarePatternType proto;
87 if (resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED || 67 if (resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED ||
88 (resource.threat_type == SB_THREAT_TYPE_URL_MALWARE && 68 (resource.threat_type == SB_THREAT_TYPE_URL_MALWARE &&
89 resource.threat_metadata.threat_pattern_type == 69 resource.threat_metadata.threat_pattern_type ==
90 ThreatPatternType::MALWARE_LANDING)) { 70 ThreatPatternType::MALWARE_LANDING)) {
91 if (!resource.callback.is_null()) { 71 if (!resource.callback.is_null()) {
92 DCHECK(resource.callback_thread); 72 DCHECK(resource.callback_thread);
93 resource.callback_thread->PostTask(FROM_HERE, 73 resource.callback_thread->PostTask(FROM_HERE,
94 base::Bind(resource.callback, true)); 74 base::Bind(resource.callback, true));
95 } 75 }
96 76
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 base::Bind(&SafeBrowsingUIManager::ReportPermissionActionOnIOThread, this, 188 base::Bind(&SafeBrowsingUIManager::ReportPermissionActionOnIOThread, this,
209 report_info)); 189 report_info));
210 } 190 }
211 191
212 // Static. 192 // Static.
213 void SafeBrowsingUIManager::CreateWhitelistForTesting( 193 void SafeBrowsingUIManager::CreateWhitelistForTesting(
214 content::WebContents* web_contents) { 194 content::WebContents* web_contents) {
215 EnsureWhitelistCreated(web_contents); 195 EnsureWhitelistCreated(web_contents);
216 } 196 }
217 197
198 void SafeBrowsingUIManager::AddObserver(Observer* observer) {
199 DCHECK_CURRENTLY_ON(BrowserThread::UI);
200 observer_list_.AddObserver(observer);
201 }
202
203 void SafeBrowsingUIManager::RemoveObserver(Observer* observer) {
204 DCHECK_CURRENTLY_ON(BrowserThread::UI);
205 observer_list_.RemoveObserver(observer);
206 }
207
208 const std::string SafeBrowsingUIManager::app_locale() const {
meacer 2017/01/11 01:33:30 nit: Add DCHECK_CURRENTLY_ON(...) calls for this,
Jialiu Lin 2017/01/11 02:53:15 Done.
209 return g_browser_process->GetApplicationLocale();
210 }
211
212 history::HistoryService* SafeBrowsingUIManager::history_service(
213 content::WebContents* web_contents) {
214 return HistoryServiceFactory::GetForProfile(
215 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
216 ServiceAccessType::EXPLICIT_ACCESS);
217 }
218
219 const GURL SafeBrowsingUIManager::default_safe_page() const {
220 return GURL(chrome::kChromeUINewTabURL);
221 }
222
218 void SafeBrowsingUIManager::ReportPermissionActionOnIOThread( 223 void SafeBrowsingUIManager::ReportPermissionActionOnIOThread(
219 const PermissionReportInfo& report_info) { 224 const PermissionReportInfo& report_info) {
220 DCHECK_CURRENTLY_ON(BrowserThread::IO); 225 DCHECK_CURRENTLY_ON(BrowserThread::IO);
221 226
222 // The service may delete the ping manager (i.e. when user disabling service, 227 // The service may delete the ping manager (i.e. when user disabling service,
223 // etc). This happens on the IO thread. 228 // etc). This happens on the IO thread.
224 if (!sb_service_ || !sb_service_->ping_manager()) 229 if (!sb_service_ || !sb_service_->ping_manager())
225 return; 230 return;
226 231
227 sb_service_->ping_manager()->ReportPermissionAction(report_info); 232 sb_service_->ping_manager()->ReportPermissionAction(report_info);
(...skipping 16 matching lines...) Expand all
244 } 249 }
245 } 250 }
246 251
247 // Static. 252 // Static.
248 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( 253 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting(
249 const security_interstitials::UnsafeResource& resource) { 254 const security_interstitials::UnsafeResource& resource) {
250 return GetMainFrameWhitelistUrlForResource(resource); 255 return GetMainFrameWhitelistUrlForResource(resource);
251 } 256 }
252 257
253 } // namespace safe_browsing 258 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698