Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/autofill/risk_util.h" | |
| 6 | |
| 7 #include "base/base64.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/prefs/pref_service.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "chrome/browser/apps/app_window_registry_util.h" | |
| 12 #include "chrome/browser/browser_process.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/ui/browser.h" | |
| 15 #include "chrome/common/chrome_content_client.h" | |
| 16 #include "chrome/common/chrome_version_info.h" | |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "components/autofill/content/browser/risk/fingerprint.h" | |
| 19 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | |
| 20 #include "components/metrics/metrics_service.h" | |
| 21 #include "content/public/browser/web_contents.h" | |
| 22 | |
| 23 #if !defined(OS_ANDROID) | |
| 24 #include "chrome/browser/ui/browser_finder.h" | |
| 25 #include "chrome/browser/ui/browser_window.h" | |
| 26 #include "extensions/browser/app_window/app_window.h" | |
| 27 #include "extensions/browser/app_window/native_app_window.h" | |
| 28 #include "ui/base/base_window.h" | |
| 29 #endif | |
| 30 | |
| 31 namespace autofill { | |
| 32 | |
| 33 namespace { | |
| 34 | |
| 35 void PassRiskData(const base::Callback<void(const std::string&)>& callback, | |
| 36 scoped_ptr<risk::Fingerprint> fingerprint) { | |
| 37 std::string proto_data, risk_data; | |
| 38 fingerprint->SerializeToString(&proto_data); | |
| 39 base::Base64Encode(proto_data, &risk_data); | |
| 40 callback.Run(risk_data); | |
| 41 } | |
| 42 | |
| 43 #if !defined(OS_ANDROID) | |
| 44 // Returns the containing window for the given |web_contents|. The containing | |
| 45 // window might be a browser window for a Chrome tab, or it might be an app | |
| 46 // window for a platform app. | |
| 47 ui::BaseWindow* GetBaseWindowForWebContents( | |
| 48 content::WebContents* web_contents) { | |
| 49 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 50 if (browser) | |
| 51 return browser->window(); | |
| 52 | |
| 53 gfx::NativeWindow native_window = web_contents->GetTopLevelNativeWindow(); | |
| 54 extensions::AppWindow* app_window = | |
| 55 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | |
| 56 native_window); | |
| 57 return app_window->GetBaseWindow(); | |
| 58 } | |
| 59 #endif | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 void LoadRiskData(uint64 obfuscated_gaia_id, | |
| 64 content::WebContents* web_contents, | |
| 65 const base::Callback<void(const std::string&)>& callback) { | |
| 66 // No easy way to get window bounds on Android, and that signal isn't very | |
|
Evan Stade
2015/02/06 00:15:46
aruslan@, is there an easy way to get the browser
aruslan
2015/02/10 00:18:21
You might use the size of the display with and wit
| |
| 67 // useful anyway (given that we're also including the bounds of the web | |
| 68 // contents). | |
| 69 gfx::Rect window_bounds; | |
| 70 #if !defined(OS_ANDROID) | |
| 71 window_bounds = GetBaseWindowForWebContents(web_contents)->GetBounds(); | |
| 72 #endif | |
| 73 | |
| 74 const PrefService* user_prefs = | |
| 75 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | |
| 76 ->GetPrefs(); | |
| 77 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | |
| 78 std::string accept_languages = | |
| 79 user_prefs->GetString(::prefs::kAcceptLanguages); | |
| 80 base::Time install_time = base::Time::FromTimeT( | |
| 81 g_browser_process->metrics_service()->GetInstallDate()); | |
| 82 | |
| 83 risk::GetFingerprint(obfuscated_gaia_id, window_bounds, web_contents, | |
| 84 chrome::VersionInfo().Version(), charset, | |
| 85 accept_languages, install_time, | |
| 86 g_browser_process->GetApplicationLocale(), | |
| 87 GetUserAgent(), base::Bind(PassRiskData, callback)); | |
| 88 } | |
| 89 | |
| 90 } // namespace autofill | |
| OLD | NEW |