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

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

Issue 2623733002: Componentize SafeBrowsingBlockingPage for WebView use (Closed)
Patch Set: 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" 25 #include "components/safe_browsing_db/metadata.pb.h"
23 #include "components/safe_browsing_db/safe_browsing_prefs.h" 26 #include "components/safe_browsing_db/safe_browsing_prefs.h"
24 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/navigation_entry.h" 28 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
28 #include "ipc/ipc_message.h" 31 #include "ipc/ipc_message.h"
29 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
30 #include "net/ssl/ssl_info.h" 33 #include "net/ssl/ssl_info.h"
31 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
33 #include "url/gurl.h" 36 #include "url/gurl.h"
34 37
35 using content::BrowserThread; 38 using content::BrowserThread;
36 using content::NavigationEntry; 39 using content::NavigationEntry;
37 using content::WebContents; 40 using content::WebContents;
38 using safe_browsing::HitReport; 41 using safe_browsing::HitReport;
39 using safe_browsing::SBThreatType; 42 using safe_browsing::SBThreatType;
40 43
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 { 44 namespace safe_browsing {
59 45
60 SafeBrowsingUIManager::SafeBrowsingUIManager( 46 SafeBrowsingUIManager::SafeBrowsingUIManager(
61 const scoped_refptr<SafeBrowsingService>& service) 47 const scoped_refptr<SafeBrowsingService>& service)
62 : sb_service_(service) {} 48 : sb_service_(service) {}
63 49
64 SafeBrowsingUIManager::~SafeBrowsingUIManager() {} 50 SafeBrowsingUIManager::~SafeBrowsingUIManager() {}
65 51
66 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) { 52 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) {
67 DCHECK_CURRENTLY_ON(BrowserThread::IO); 53 DCHECK_CURRENTLY_ON(BrowserThread::IO);
68 54
69 if (shutdown) 55 if (shutdown)
70 sb_service_ = NULL; 56 sb_service_ = NULL;
71 } 57 }
72 58
73 void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) { 59 /*void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) {
74 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); 60 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time);
75 } 61 }*/
76 62
77 void SafeBrowsingUIManager::DisplayBlockingPage( 63 void SafeBrowsingUIManager::DisplayBlockingPage(
78 const UnsafeResource& resource) { 64 const UnsafeResource& resource) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); 65 DCHECK_CURRENTLY_ON(BrowserThread::UI);
80 if (resource.is_subresource && !resource.is_subframe) { 66 if (resource.is_subresource && !resource.is_subframe) {
81 // Sites tagged as serving Unwanted Software should only show a warning for 67 // Sites tagged as serving Unwanted Software should only show a warning for
82 // main-frame or sub-frame resource. Similar warning restrictions should be 68 // main-frame or sub-frame resource. Similar warning restrictions should be
83 // applied to malware sites tagged as "landing sites" (see "Types of 69 // applied to malware sites tagged as "landing sites" (see "Types of
84 // Malware sites" under 70 // Malware sites" under
85 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs). 71 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs).
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 base::Bind(&SafeBrowsingUIManager::ReportPermissionActionOnIOThread, this, 194 base::Bind(&SafeBrowsingUIManager::ReportPermissionActionOnIOThread, this,
209 report_info)); 195 report_info));
210 } 196 }
211 197
212 // Static. 198 // Static.
213 void SafeBrowsingUIManager::CreateWhitelistForTesting( 199 void SafeBrowsingUIManager::CreateWhitelistForTesting(
214 content::WebContents* web_contents) { 200 content::WebContents* web_contents) {
215 EnsureWhitelistCreated(web_contents); 201 EnsureWhitelistCreated(web_contents);
216 } 202 }
217 203
204 void SafeBrowsingUIManager::AddObserver(Observer* observer) {
205 DCHECK_CURRENTLY_ON(BrowserThread::UI);
206 observer_list_.AddObserver(observer);
207 }
208
209 void SafeBrowsingUIManager::RemoveObserver(Observer* observer) {
210 DCHECK_CURRENTLY_ON(BrowserThread::UI);
211 observer_list_.RemoveObserver(observer);
212 }
213
214 const std::string SafeBrowsingUIManager::app_locale() {
215 return g_browser_process->GetApplicationLocale();
216 }
217
218 history::HistoryService* SafeBrowsingUIManager::history_service(
219 content::WebContents* web_contents) {
220 return HistoryServiceFactory::GetForProfile(
221 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
222 ServiceAccessType::EXPLICIT_ACCESS);
223 }
224
225 const GURL SafeBrowsingUIManager::default_safe_page() {
226 return GURL(chrome::kChromeUINewTabURL);
227 }
228
218 void SafeBrowsingUIManager::ReportPermissionActionOnIOThread( 229 void SafeBrowsingUIManager::ReportPermissionActionOnIOThread(
219 const PermissionReportInfo& report_info) { 230 const PermissionReportInfo& report_info) {
220 DCHECK_CURRENTLY_ON(BrowserThread::IO); 231 DCHECK_CURRENTLY_ON(BrowserThread::IO);
221 232
222 // The service may delete the ping manager (i.e. when user disabling service, 233 // The service may delete the ping manager (i.e. when user disabling service,
223 // etc). This happens on the IO thread. 234 // etc). This happens on the IO thread.
224 if (!sb_service_ || !sb_service_->ping_manager()) 235 if (!sb_service_ || !sb_service_->ping_manager())
225 return; 236 return;
226 237
227 sb_service_->ping_manager()->ReportPermissionAction(report_info); 238 sb_service_->ping_manager()->ReportPermissionAction(report_info);
(...skipping 16 matching lines...) Expand all
244 } 255 }
245 } 256 }
246 257
247 // Static. 258 // Static.
248 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( 259 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting(
249 const security_interstitials::UnsafeResource& resource) { 260 const security_interstitials::UnsafeResource& resource) {
250 return GetMainFrameWhitelistUrlForResource(resource); 261 return GetMainFrameWhitelistUrlForResource(resource);
251 } 262 }
252 263
253 } // namespace safe_browsing 264 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698