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

Unified Diff: chrome/browser/autofill/risk_util.cc

Issue 896583003: Add risk data to getrealpan request. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/risk_util.cc
diff --git a/chrome/browser/autofill/risk_util.cc b/chrome/browser/autofill/risk_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..59cf1333c94c70f0fffcb48bed585db946b08097
--- /dev/null
+++ b/chrome/browser/autofill/risk_util.cc
@@ -0,0 +1,79 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autofill/risk_util.h"
+
+#include "base/base64.h"
+#include "base/callback.h"
+#include "base/prefs/pref_service.h"
+#include "base/time/time.h"
+#include "chrome/browser/apps/app_window_registry_util.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/common/chrome_content_client.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/pref_names.h"
+#include "components/autofill/content/browser/risk/fingerprint.h"
+#include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
+#include "components/metrics/metrics_service.h"
+#include "content/public/browser/web_contents.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/native_app_window.h"
+#include "ui/base/base_window.h"
+
+namespace autofill {
+
+namespace {
+
+void PassRiskData(const base::Callback<void(const std::string&)>& callback,
+ scoped_ptr<risk::Fingerprint> fingerprint) {
+ std::string proto_data, risk_data;
+ fingerprint->SerializeToString(&proto_data);
+ base::Base64Encode(proto_data, &risk_data);
+ callback.Run(risk_data);
+}
+
+// Returns the containing window for the given |web_contents|. The containing
+// window might be a browser window for a Chrome tab, or it might be an app
+// window for a platform app.
+ui::BaseWindow* GetBaseWindowForWebContents(
+ const content::WebContents* web_contents) {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
brettw 2015/02/02 23:44:10 This function is really unfortunate. Is there any
Evan Stade 2015/02/02 23:47:52 This code is moved from AutofillDialogControllerIm
+ if (browser)
+ return browser->window();
+
+ gfx::NativeWindow native_window = web_contents->GetTopLevelNativeWindow();
+ extensions::AppWindow* app_window =
+ AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
+ native_window);
+ return app_window->GetBaseWindow();
+}
+
+} // namespace
+
+void LoadRiskData(uint64 obfuscated_gaia_id,
+ const content::WebContents* web_contents,
+ const base::Callback<void(const std::string&)>& callback) {
+ gfx::Rect window_bounds =
+ GetBaseWindowForWebContents(web_contents)->GetBounds();
+ const PrefService* user_prefs =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext())
+ ->GetPrefs();
+ std::string charset = user_prefs->GetString(::prefs::kDefaultCharset);
+ std::string accept_languages =
+ user_prefs->GetString(::prefs::kAcceptLanguages);
+ base::Time install_time = base::Time::FromTimeT(
+ g_browser_process->metrics_service()->GetInstallDate());
+
+ risk::GetFingerprint(obfuscated_gaia_id, window_bounds, web_contents,
+ chrome::VersionInfo().Version(), charset,
+ accept_languages, install_time,
+ g_browser_process->GetApplicationLocale(),
+ GetUserAgent(), base::Bind(PassRiskData, callback));
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698