| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/browser/risk/fingerprint.h" | 5 #include "components/autofill/browser/risk/fingerprint.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" | 16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" |
| 17 #include "content/public/browser/content_browser_client.h" | |
| 18 #include "content/public/browser/font_list_async.h" | 17 #include "content/public/browser/font_list_async.h" |
| 19 #include "content/public/browser/gpu_data_manager.h" | 18 #include "content/public/browser/gpu_data_manager.h" |
| 20 #include "content/public/browser/gpu_data_manager_observer.h" | 19 #include "content/public/browser/gpu_data_manager_observer.h" |
| 21 #include "content/public/browser/plugin_service.h" | 20 #include "content/public/browser/plugin_service.h" |
| 22 #include "content/public/browser/render_widget_host.h" | 21 #include "content/public/browser/render_widget_host.h" |
| 23 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
| 24 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 26 #include "content/public/common/content_client.h" | 25 #include "content/public/common/content_client.h" |
| 27 #include "content/public/common/gpu_info.h" | 26 #include "content/public/common/gpu_info.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 FingerprintDataLoader( | 181 FingerprintDataLoader( |
| 183 int64 gaia_id, | 182 int64 gaia_id, |
| 184 const gfx::Rect& window_bounds, | 183 const gfx::Rect& window_bounds, |
| 185 const gfx::Rect& content_bounds, | 184 const gfx::Rect& content_bounds, |
| 186 const WebScreenInfo& screen_info, | 185 const WebScreenInfo& screen_info, |
| 187 const std::string& version, | 186 const std::string& version, |
| 188 const std::string& charset, | 187 const std::string& charset, |
| 189 const std::string& accept_languages, | 188 const std::string& accept_languages, |
| 190 const base::Time& install_time, | 189 const base::Time& install_time, |
| 191 DialogType dialog_type, | 190 DialogType dialog_type, |
| 191 const std::string& app_locale, |
| 192 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); | 192 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 virtual ~FingerprintDataLoader(); | 195 virtual ~FingerprintDataLoader(); |
| 196 | 196 |
| 197 // content::GpuDataManagerObserver: | 197 // content::GpuDataManagerObserver: |
| 198 virtual void OnGpuInfoUpdate() OVERRIDE; | 198 virtual void OnGpuInfoUpdate() OVERRIDE; |
| 199 | 199 |
| 200 // Callbacks for asynchronously loaded data. | 200 // Callbacks for asynchronously loaded data. |
| 201 void OnGotFonts(scoped_ptr<base::ListValue> fonts); | 201 void OnGotFonts(scoped_ptr<base::ListValue> fonts); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 220 const std::string charset_; | 220 const std::string charset_; |
| 221 const std::string accept_languages_; | 221 const std::string accept_languages_; |
| 222 const base::Time install_time_; | 222 const base::Time install_time_; |
| 223 DialogType dialog_type_; | 223 DialogType dialog_type_; |
| 224 | 224 |
| 225 // Data that will be loaded asynchronously. | 225 // Data that will be loaded asynchronously. |
| 226 scoped_ptr<base::ListValue> fonts_; | 226 scoped_ptr<base::ListValue> fonts_; |
| 227 std::vector<webkit::WebPluginInfo> plugins_; | 227 std::vector<webkit::WebPluginInfo> plugins_; |
| 228 bool has_loaded_plugins_; | 228 bool has_loaded_plugins_; |
| 229 | 229 |
| 230 // The current application locale. |
| 231 std::string app_locale_; |
| 232 |
| 230 // The callback that will be called once all the data is available. | 233 // The callback that will be called once all the data is available. |
| 231 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; | 234 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; |
| 232 | 235 |
| 233 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); | 236 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); |
| 234 }; | 237 }; |
| 235 | 238 |
| 236 FingerprintDataLoader::FingerprintDataLoader( | 239 FingerprintDataLoader::FingerprintDataLoader( |
| 237 int64 gaia_id, | 240 int64 gaia_id, |
| 238 const gfx::Rect& window_bounds, | 241 const gfx::Rect& window_bounds, |
| 239 const gfx::Rect& content_bounds, | 242 const gfx::Rect& content_bounds, |
| 240 const WebScreenInfo& screen_info, | 243 const WebScreenInfo& screen_info, |
| 241 const std::string& version, | 244 const std::string& version, |
| 242 const std::string& charset, | 245 const std::string& charset, |
| 243 const std::string& accept_languages, | 246 const std::string& accept_languages, |
| 244 const base::Time& install_time, | 247 const base::Time& install_time, |
| 245 DialogType dialog_type, | 248 DialogType dialog_type, |
| 249 const std::string& app_locale, |
| 246 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) | 250 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) |
| 247 : gpu_data_manager_(content::GpuDataManager::GetInstance()), | 251 : gpu_data_manager_(content::GpuDataManager::GetInstance()), |
| 248 gaia_id_(gaia_id), | 252 gaia_id_(gaia_id), |
| 249 window_bounds_(window_bounds), | 253 window_bounds_(window_bounds), |
| 250 content_bounds_(content_bounds), | 254 content_bounds_(content_bounds), |
| 251 screen_info_(screen_info), | 255 screen_info_(screen_info), |
| 252 version_(version), | 256 version_(version), |
| 253 charset_(charset), | 257 charset_(charset), |
| 254 accept_languages_(accept_languages), | 258 accept_languages_(accept_languages), |
| 255 install_time_(install_time), | 259 install_time_(install_time), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 void FingerprintDataLoader::FillFingerprint() { | 315 void FingerprintDataLoader::FillFingerprint() { |
| 312 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); | 316 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); |
| 313 Fingerprint_MachineCharacteristics* machine = | 317 Fingerprint_MachineCharacteristics* machine = |
| 314 fingerprint->mutable_machine_characteristics(); | 318 fingerprint->mutable_machine_characteristics(); |
| 315 | 319 |
| 316 machine->set_operating_system_build(GetOperatingSystemVersion()); | 320 machine->set_operating_system_build(GetOperatingSystemVersion()); |
| 317 // We use the delta between the install time and the Unix epoch, in hours. | 321 // We use the delta between the install time and the Unix epoch, in hours. |
| 318 machine->set_browser_install_time_hours( | 322 machine->set_browser_install_time_hours( |
| 319 (install_time_ - base::Time::UnixEpoch()).InHours()); | 323 (install_time_ - base::Time::UnixEpoch()).InHours()); |
| 320 machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); | 324 machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); |
| 321 machine->set_browser_language( | 325 machine->set_browser_language(app_locale_); |
| 322 content::GetContentClient()->browser()->GetApplicationLocale()); | |
| 323 machine->set_charset(charset_); | 326 machine->set_charset(charset_); |
| 324 machine->set_user_agent(content::GetContentClient()->GetUserAgent()); | 327 machine->set_user_agent(content::GetUserAgent(GURL())); |
| 325 machine->set_ram(base::SysInfo::AmountOfPhysicalMemory()); | 328 machine->set_ram(base::SysInfo::AmountOfPhysicalMemory()); |
| 326 machine->set_browser_build(version_); | 329 machine->set_browser_build(version_); |
| 327 machine->set_browser_feature(DialogTypeToBrowserFeature(dialog_type_)); | 330 machine->set_browser_feature(DialogTypeToBrowserFeature(dialog_type_)); |
| 328 AddFontsToFingerprint(*fonts_, machine); | 331 AddFontsToFingerprint(*fonts_, machine); |
| 329 AddPluginsToFingerprint(plugins_, machine); | 332 AddPluginsToFingerprint(plugins_, machine); |
| 330 AddAcceptLanguagesToFingerprint(accept_languages_, machine); | 333 AddAcceptLanguagesToFingerprint(accept_languages_, machine); |
| 331 AddScreenInfoToFingerprint(screen_info_, machine); | 334 AddScreenInfoToFingerprint(screen_info_, machine); |
| 332 AddCpuInfoToFingerprint(machine); | 335 AddCpuInfoToFingerprint(machine); |
| 333 AddGpuInfoToFingerprint(machine); | 336 AddGpuInfoToFingerprint(machine); |
| 334 | 337 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 364 | 367 |
| 365 void GetFingerprint( | 368 void GetFingerprint( |
| 366 int64 gaia_id, | 369 int64 gaia_id, |
| 367 const gfx::Rect& window_bounds, | 370 const gfx::Rect& window_bounds, |
| 368 const content::WebContents& web_contents, | 371 const content::WebContents& web_contents, |
| 369 const std::string& version, | 372 const std::string& version, |
| 370 const std::string& charset, | 373 const std::string& charset, |
| 371 const std::string& accept_languages, | 374 const std::string& accept_languages, |
| 372 const base::Time& install_time, | 375 const base::Time& install_time, |
| 373 DialogType dialog_type, | 376 DialogType dialog_type, |
| 377 const std::string& app_locale, |
| 374 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 378 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
| 375 gfx::Rect content_bounds; | 379 gfx::Rect content_bounds; |
| 376 web_contents.GetView()->GetContainerBounds(&content_bounds); | 380 web_contents.GetView()->GetContainerBounds(&content_bounds); |
| 377 | 381 |
| 378 WebKit::WebScreenInfo screen_info; | 382 WebKit::WebScreenInfo screen_info; |
| 379 content::RenderWidgetHostView* host_view = | 383 content::RenderWidgetHostView* host_view = |
| 380 web_contents.GetRenderWidgetHostView(); | 384 web_contents.GetRenderWidgetHostView(); |
| 381 if (host_view) | 385 if (host_view) |
| 382 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); | 386 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); |
| 383 | 387 |
| 384 internal::GetFingerprintInternal( | 388 internal::GetFingerprintInternal( |
| 385 gaia_id, window_bounds, content_bounds, screen_info, version, charset, | 389 gaia_id, window_bounds, content_bounds, screen_info, version, charset, |
| 386 accept_languages, install_time, dialog_type, callback); | 390 accept_languages, install_time, dialog_type, app_locale, callback); |
| 387 } | 391 } |
| 388 | 392 |
| 389 namespace internal { | 393 namespace internal { |
| 390 | 394 |
| 391 void GetFingerprintInternal( | 395 void GetFingerprintInternal( |
| 392 int64 gaia_id, | 396 int64 gaia_id, |
| 393 const gfx::Rect& window_bounds, | 397 const gfx::Rect& window_bounds, |
| 394 const gfx::Rect& content_bounds, | 398 const gfx::Rect& content_bounds, |
| 395 const WebKit::WebScreenInfo& screen_info, | 399 const WebKit::WebScreenInfo& screen_info, |
| 396 const std::string& version, | 400 const std::string& version, |
| 397 const std::string& charset, | 401 const std::string& charset, |
| 398 const std::string& accept_languages, | 402 const std::string& accept_languages, |
| 399 const base::Time& install_time, | 403 const base::Time& install_time, |
| 400 DialogType dialog_type, | 404 DialogType dialog_type, |
| 405 const std::string& app_locale, |
| 401 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 406 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
| 402 // Begin loading all of the data that we need to load asynchronously. | 407 // Begin loading all of the data that we need to load asynchronously. |
| 403 // This class is responsible for freeing its own memory. | 408 // This class is responsible for freeing its own memory. |
| 404 new FingerprintDataLoader(gaia_id, window_bounds, content_bounds, screen_info, | 409 new FingerprintDataLoader(gaia_id, window_bounds, content_bounds, screen_info, |
| 405 version, charset, accept_languages, install_time, | 410 version, charset, accept_languages, install_time, |
| 406 dialog_type, callback); | 411 dialog_type, app_locale, callback); |
| 407 } | 412 } |
| 408 | 413 |
| 409 } // namespace internal | 414 } // namespace internal |
| 410 | 415 |
| 411 } // namespace risk | 416 } // namespace risk |
| 412 } // namespace autofill | 417 } // namespace autofill |
| OLD | NEW |