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/browser/ui/browser_finder.h" | |
| 16 #include "chrome/browser/ui/browser_window.h" | |
| 17 #include "chrome/common/chrome_content_client.h" | |
| 18 #include "chrome/common/chrome_version_info.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 #include "components/autofill/content/browser/risk/fingerprint.h" | |
| 21 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | |
| 22 #include "components/metrics/metrics_service.h" | |
| 23 #include "content/public/browser/web_contents.h" | |
| 24 #include "extensions/browser/app_window/app_window.h" | |
| 25 #include "extensions/browser/app_window/native_app_window.h" | |
| 26 #include "ui/base/base_window.h" | |
| 27 | |
| 28 namespace autofill { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 void PassRiskData(const base::Callback<void(const std::string&)>& callback, | |
| 33 scoped_ptr<risk::Fingerprint> fingerprint) { | |
| 34 std::string proto_data, risk_data; | |
| 35 fingerprint->SerializeToString(&proto_data); | |
| 36 base::Base64Encode(proto_data, &risk_data); | |
| 37 callback.Run(risk_data); | |
| 38 } | |
| 39 | |
| 40 // Returns the containing window for the given |web_contents|. The containing | |
| 41 // window might be a browser window for a Chrome tab, or it might be an app | |
| 42 // window for a platform app. | |
| 43 ui::BaseWindow* GetBaseWindowForWebContents( | |
| 44 const content::WebContents* web_contents) { | |
| 45 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
| |
| 46 if (browser) | |
| 47 return browser->window(); | |
| 48 | |
| 49 gfx::NativeWindow native_window = web_contents->GetTopLevelNativeWindow(); | |
| 50 extensions::AppWindow* app_window = | |
| 51 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | |
| 52 native_window); | |
| 53 return app_window->GetBaseWindow(); | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 void LoadRiskData(uint64 obfuscated_gaia_id, | |
| 59 const content::WebContents* web_contents, | |
| 60 const base::Callback<void(const std::string&)>& callback) { | |
| 61 gfx::Rect window_bounds = | |
| 62 GetBaseWindowForWebContents(web_contents)->GetBounds(); | |
| 63 const PrefService* user_prefs = | |
| 64 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | |
| 65 ->GetPrefs(); | |
| 66 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | |
| 67 std::string accept_languages = | |
| 68 user_prefs->GetString(::prefs::kAcceptLanguages); | |
| 69 base::Time install_time = base::Time::FromTimeT( | |
| 70 g_browser_process->metrics_service()->GetInstallDate()); | |
| 71 | |
| 72 risk::GetFingerprint(obfuscated_gaia_id, window_bounds, web_contents, | |
| 73 chrome::VersionInfo().Version(), charset, | |
| 74 accept_languages, install_time, | |
| 75 g_browser_process->GetApplicationLocale(), | |
| 76 GetUserAgent(), base::Bind(PassRiskData, callback)); | |
| 77 } | |
| 78 | |
| 79 } // namespace autofill | |
| OLD | NEW |