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

Unified Diff: android_webview/browser/aw_safe_browsing_ui_manager.cc

Issue 2932703003: Plumbing for safe browsing reporting for Android WebView. (Closed)
Patch Set: address comment 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 side-by-side diff with in-line comments
Download patch
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";
+#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

Powered by Google App Engine
This is Rietveld 408576698