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

Side by Side Diff: android_webview/browser/aw_safe_browsing_ui_manager.cc

Issue 2932703003: Plumbing for safe browsing reporting for Android WebView. (Closed)
Patch Set: modify client name to android_webview Created 3 years, 6 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 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 std::string GetProtocolConfigClientName() {
25 // Return a webview specific client name, see crbug.com/732373 for details.
26 return "android_webview";
27 }
28
29 } // namespace
30
13 namespace android_webview { 31 namespace android_webview {
14 32
15 AwSafeBrowsingUIManager::AwSafeBrowsingUIManager() { 33 AwSafeBrowsingUIManager::AwSafeBrowsingUIManager(
34 AwURLRequestContextGetter* browser_url_request_context_getter) {
16 DCHECK_CURRENTLY_ON(BrowserThread::UI); 35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36
37 // TODO(timvolodine): verify this is what we want regarding the directory.
38 base::FilePath user_data_dir;
39 bool result =
40 PathService::Get(android_webview::DIR_SAFE_BROWSING, &user_data_dir);
41 DCHECK(result);
42
43 url_request_context_getter_ =
44 new safe_browsing::SafeBrowsingURLRequestContextGetter(
45 browser_url_request_context_getter, user_data_dir);
17 } 46 }
18 47
19 AwSafeBrowsingUIManager::~AwSafeBrowsingUIManager() {} 48 AwSafeBrowsingUIManager::~AwSafeBrowsingUIManager() {}
20 49
21 void AwSafeBrowsingUIManager::DisplayBlockingPage( 50 void AwSafeBrowsingUIManager::DisplayBlockingPage(
22 const UnsafeResource& resource) { 51 const UnsafeResource& resource) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI); 52 DCHECK_CURRENTLY_ON(BrowserThread::UI);
24 53
25 WebContents* web_contents = resource.web_contents_getter.Run(); 54 WebContents* web_contents = resource.web_contents_getter.Run();
26 // Check the size of the view 55 // Check the size of the view
(...skipping 13 matching lines...) Expand all
40 } 69 }
41 70
42 int AwSafeBrowsingUIManager::GetErrorUiType( 71 int AwSafeBrowsingUIManager::GetErrorUiType(
43 const UnsafeResource& resource) const { 72 const UnsafeResource& resource) const {
44 WebContents* web_contents = resource.web_contents_getter.Run(); 73 WebContents* web_contents = resource.web_contents_getter.Run();
45 UIManagerClient* client = UIManagerClient::FromWebContents(web_contents); 74 UIManagerClient* client = UIManagerClient::FromWebContents(web_contents);
46 DCHECK(client); 75 DCHECK(client);
47 return client->GetErrorUiType(); 76 return client->GetErrorUiType();
48 } 77 }
49 78
79 void AwSafeBrowsingUIManager::SendSerializedThreatDetails(
80 const std::string& serialized) {
81 DCHECK_CURRENTLY_ON(BrowserThread::IO);
82
83 if (!ping_manager_) {
84 // Lazy creation of ping manager, needs to happen on IO thread.
85 safe_browsing::SafeBrowsingProtocolConfig config;
86 config.client_name = GetProtocolConfigClientName();
87 base::CommandLine* cmdline = ::base::CommandLine::ForCurrentProcess();
88 config.disable_auto_update =
89 cmdline->HasSwitch(::safe_browsing::switches::kSbDisableAutoUpdate);
90 config.url_prefix = ::safe_browsing::kSbDefaultURLPrefix;
91 config.backup_connect_error_url_prefix =
92 ::safe_browsing::kSbBackupConnectErrorURLPrefix;
93 config.backup_http_error_url_prefix =
94 ::safe_browsing::kSbBackupHttpErrorURLPrefix;
95 config.backup_network_error_url_prefix =
96 ::safe_browsing::kSbBackupNetworkErrorURLPrefix;
97 ping_manager_ = ::safe_browsing::BasePingManager::Create(
98 url_request_context_getter_.get(), config);
99 }
100
101 if (!serialized.empty()) {
102 DVLOG(1) << "Sending serialized threat details";
103 ping_manager_->ReportThreatDetails(serialized);
104 }
105 }
106
50 } // namespace android_webview 107 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/aw_safe_browsing_ui_manager.h ('k') | android_webview/common/aw_paths.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698