Chromium Code Reviews| Index: android_webview/browser/aw_safe_browsing_ui_manager.cc |
| diff --git a/android_webview/browser/aw_safe_browsing_ui_manager.cc b/android_webview/browser/aw_safe_browsing_ui_manager.cc |
| index cf33463c1e22080ced25dee1270c52f7de603574..4a25d09e57271fc5450b05cf2fb9da15e4ed2067 100644 |
| --- a/android_webview/browser/aw_safe_browsing_ui_manager.cc |
| +++ b/android_webview/browser/aw_safe_browsing_ui_manager.cc |
| @@ -5,15 +5,56 @@ |
| #include "android_webview/browser/aw_safe_browsing_ui_manager.h" |
| #include "android_webview/browser/aw_safe_browsing_blocking_page.h" |
| +#include "android_webview/browser/net/aw_url_request_context_getter.h" |
| +#include "android_webview/common/aw_paths.h" |
| +#include "base/command_line.h" |
| +#include "base/path_service.h" |
| +#include "components/safe_browsing/base_ping_manager.h" |
| +#include "components/safe_browsing/base_ui_manager.h" |
| +#include "components/safe_browsing/browser/safe_browsing_url_request_context_getter.h" |
| +#include "components/safe_browsing/common/safebrowsing_constants.h" |
| +#include "components/safe_browsing/common/safebrowsing_switches.h" |
| #include "content/public/browser/browser_thread.h" |
| using content::BrowserThread; |
| using content::WebContents; |
| +namespace { |
| + |
| +// TODO(timvolodine): consider unifying with SafeBrowsingService |
| +std::string GetProtocolConfigClientName() { |
| + std::string client_name; |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + client_name = "googlechrome"; |
| +#else |
| + client_name = "chromium"; |
|
Nate Fischer
2017/06/08 22:21:47
Do these names still make sense for webview? Not s
timvolodine
2017/06/09 11:53:21
good point, will try to discuss this during the me
|
| +#endif |
| + |
| +// Mark client string to allow server to differentiate mobile. |
| +#if defined(OS_ANDROID) |
| + client_name.append("-a"); |
| +#endif |
| + |
| + return client_name; |
| +} |
| + |
| +} // namespace |
| + |
| namespace android_webview { |
| -AwSafeBrowsingUIManager::AwSafeBrowsingUIManager() { |
| +AwSafeBrowsingUIManager::AwSafeBrowsingUIManager( |
| + AwURLRequestContextGetter* browser_url_request_context_getter) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + // TODO(timvolodine): verify this is what we want regarding the directory. |
| + base::FilePath user_data_dir; |
| + bool result = |
| + PathService::Get(android_webview::DIR_SAFE_BROWSING, &user_data_dir); |
| + DCHECK(result); |
| + |
| + url_request_context_getter_ = |
| + new safe_browsing::SafeBrowsingURLRequestContextGetter( |
| + browser_url_request_context_getter, user_data_dir); |
| } |
| AwSafeBrowsingUIManager::~AwSafeBrowsingUIManager() {} |
| @@ -47,4 +88,32 @@ int AwSafeBrowsingUIManager::GetErrorUiType( |
| return client->GetErrorUiType(); |
| } |
| +void AwSafeBrowsingUIManager::SendSerializedThreatDetails( |
| + const std::string& serialized) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + if (!ping_manager_) { |
| + // Lazy creation of ping manager, needs to happen on IO thread. |
| + safe_browsing::SafeBrowsingProtocolConfig config; |
| + config.client_name = GetProtocolConfigClientName(); |
| + base::CommandLine* cmdline = ::base::CommandLine::ForCurrentProcess(); |
| + config.disable_auto_update = |
| + cmdline->HasSwitch(::safe_browsing::switches::kSbDisableAutoUpdate); |
| + config.url_prefix = ::safe_browsing::kSbDefaultURLPrefix; |
| + config.backup_connect_error_url_prefix = |
| + ::safe_browsing::kSbBackupConnectErrorURLPrefix; |
| + config.backup_http_error_url_prefix = |
| + ::safe_browsing::kSbBackupHttpErrorURLPrefix; |
| + config.backup_network_error_url_prefix = |
| + ::safe_browsing::kSbBackupNetworkErrorURLPrefix; |
| + ping_manager_ = ::safe_browsing::BasePingManager::Create( |
| + url_request_context_getter_.get(), config); |
| + } |
| + |
| + if (!serialized.empty()) { |
| + DVLOG(1) << "Sending serialized threat details"; |
| + ping_manager_->ReportThreatDetails(serialized); |
| + } |
| +} |
| + |
| } // namespace android_webview |