OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "android_webview/browser/aw_safe_browsing_ui_manager.h" | 5 #include "android_webview/browser/aw_safe_browsing_ui_manager.h" |
6 | 6 |
7 #include "android_webview/browser/aw_safe_browsing_blocking_page.h" | 7 #include "android_webview/browser/aw_safe_browsing_blocking_page.h" |
| 8 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
| 9 #include "android_webview/common/aw_paths.h" |
| 10 #include "base/command_line.h" |
| 11 #include "base/path_service.h" |
| 12 #include "components/safe_browsing/base_ping_manager.h" |
| 13 #include "components/safe_browsing/base_ui_manager.h" |
| 14 #include "components/safe_browsing/browser/safe_browsing_url_request_context_get
ter.h" |
| 15 #include "components/safe_browsing/common/safebrowsing_constants.h" |
| 16 #include "components/safe_browsing/common/safebrowsing_switches.h" |
8 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
9 | 18 |
10 using content::BrowserThread; | 19 using content::BrowserThread; |
11 using content::WebContents; | 20 using content::WebContents; |
12 | 21 |
| 22 namespace { |
| 23 |
| 24 // TODO(timvolodine): consider unifying with SafeBrowsingService |
| 25 std::string GetProtocolConfigClientName() { |
| 26 std::string client_name; |
| 27 #if defined(GOOGLE_CHROME_BUILD) |
| 28 client_name = "googlechrome"; |
| 29 #else |
| 30 client_name = "chromium"; |
| 31 #endif |
| 32 |
| 33 // Mark client string to allow server to differentiate mobile. |
| 34 #if defined(OS_ANDROID) |
| 35 client_name.append("-a"); |
| 36 #endif |
| 37 |
| 38 return client_name; |
| 39 } |
| 40 |
| 41 } // namespace |
| 42 |
13 namespace android_webview { | 43 namespace android_webview { |
14 | 44 |
15 AwSafeBrowsingUIManager::AwSafeBrowsingUIManager() { | 45 AwSafeBrowsingUIManager::AwSafeBrowsingUIManager( |
| 46 AwURLRequestContextGetter* browser_url_request_context_getter) { |
16 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 |
| 49 // TODO(timvolodine): verify this is what we want regarding the directory. |
| 50 base::FilePath user_data_dir; |
| 51 bool result = |
| 52 PathService::Get(android_webview::DIR_SAFE_BROWSING, &user_data_dir); |
| 53 DCHECK(result); |
| 54 |
| 55 url_request_context_getter_ = |
| 56 new safe_browsing::SafeBrowsingURLRequestContextGetter( |
| 57 browser_url_request_context_getter, user_data_dir); |
17 } | 58 } |
18 | 59 |
19 AwSafeBrowsingUIManager::~AwSafeBrowsingUIManager() {} | 60 AwSafeBrowsingUIManager::~AwSafeBrowsingUIManager() {} |
20 | 61 |
21 void AwSafeBrowsingUIManager::DisplayBlockingPage( | 62 void AwSafeBrowsingUIManager::DisplayBlockingPage( |
22 const UnsafeResource& resource) { | 63 const UnsafeResource& resource) { |
23 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
24 | 65 |
25 WebContents* web_contents = resource.web_contents_getter.Run(); | 66 WebContents* web_contents = resource.web_contents_getter.Run(); |
26 // Check the size of the view | 67 // Check the size of the view |
(...skipping 13 matching lines...) Expand all Loading... |
40 } | 81 } |
41 | 82 |
42 int AwSafeBrowsingUIManager::GetErrorUiType( | 83 int AwSafeBrowsingUIManager::GetErrorUiType( |
43 const UnsafeResource& resource) const { | 84 const UnsafeResource& resource) const { |
44 WebContents* web_contents = resource.web_contents_getter.Run(); | 85 WebContents* web_contents = resource.web_contents_getter.Run(); |
45 UIManagerClient* client = UIManagerClient::FromWebContents(web_contents); | 86 UIManagerClient* client = UIManagerClient::FromWebContents(web_contents); |
46 DCHECK(client); | 87 DCHECK(client); |
47 return client->GetErrorUiType(); | 88 return client->GetErrorUiType(); |
48 } | 89 } |
49 | 90 |
| 91 void AwSafeBrowsingUIManager::SendSerializedThreatDetails( |
| 92 const std::string& serialized) { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 94 |
| 95 if (!ping_manager_) { |
| 96 // Lazy creation of ping manager, needs to happen on IO thread. |
| 97 safe_browsing::SafeBrowsingProtocolConfig config; |
| 98 config.client_name = GetProtocolConfigClientName(); |
| 99 base::CommandLine* cmdline = ::base::CommandLine::ForCurrentProcess(); |
| 100 config.disable_auto_update = |
| 101 cmdline->HasSwitch(::safe_browsing::switches::kSbDisableAutoUpdate); |
| 102 config.url_prefix = ::safe_browsing::kSbDefaultURLPrefix; |
| 103 config.backup_connect_error_url_prefix = |
| 104 ::safe_browsing::kSbBackupConnectErrorURLPrefix; |
| 105 config.backup_http_error_url_prefix = |
| 106 ::safe_browsing::kSbBackupHttpErrorURLPrefix; |
| 107 config.backup_network_error_url_prefix = |
| 108 ::safe_browsing::kSbBackupNetworkErrorURLPrefix; |
| 109 ping_manager_ = ::safe_browsing::BasePingManager::Create( |
| 110 url_request_context_getter_.get(), config); |
| 111 } |
| 112 |
| 113 if (!serialized.empty()) { |
| 114 DVLOG(1) << "Sending serialized threat details"; |
| 115 ping_manager_->ReportThreatDetails(serialized); |
| 116 } |
| 117 } |
| 118 |
50 } // namespace android_webview | 119 } // namespace android_webview |
OLD | NEW |