OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/utf_string_conversions.h" | |
11 #include "chrome/browser/password_manager/password_manager_util.h" | 12 #include "chrome/browser/password_manager/password_manager_util.h" |
12 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
13 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 14 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
14 #include "chrome/browser/password_manager/sync_metrics.h" | 15 #include "chrome/browser/password_manager/sync_metrics.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
18 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " | 19 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " |
19 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 20 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "components/autofill/content/common/autofill_messages.h" | 24 #include "components/autofill/content/common/autofill_messages.h" |
24 #include "components/autofill/core/browser/password_generator.h" | 25 #include "components/autofill/core/browser/password_generator.h" |
25 #include "components/autofill/core/common/password_form.h" | 26 #include "components/autofill/core/common/password_form.h" |
26 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 27 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
27 #include "components/password_manager/core/browser/log_receiver.h" | 28 #include "components/password_manager/core/browser/log_receiver.h" |
28 #include "components/password_manager/core/browser/password_form_manager.h" | 29 #include "components/password_manager/core/browser/password_form_manager.h" |
29 #include "components/password_manager/core/browser/password_manager.h" | 30 #include "components/password_manager/core/browser/password_manager.h" |
30 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" | 31 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" |
31 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 32 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
32 #include "components/password_manager/core/common/password_manager_switches.h" | 33 #include "components/password_manager/core/common/password_manager_switches.h" |
33 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "google_apis/gaia/gaia_urls.h" | |
38 #include "net/base/url_util.h" | |
36 | 39 |
37 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
38 #include "chrome/browser/android/password_authentication_manager.h" | 41 #include "chrome/browser/android/password_authentication_manager.h" |
39 #endif // OS_ANDROID | 42 #endif // OS_ANDROID |
40 | 43 |
41 using password_manager::PasswordManagerInternalsService; | 44 using password_manager::PasswordManagerInternalsService; |
42 using password_manager::PasswordManagerInternalsServiceFactory; | 45 using password_manager::PasswordManagerInternalsServiceFactory; |
43 | 46 |
47 namespace pm_switches = password_manager::switches; | |
Ilya Sherman
2014/08/13 20:48:14
nit: Please don't use acronyms or abbreviations wh
Garrett Casto
2014/08/13 23:12:54
Changed to switches. I don't normally do this, but
| |
48 | |
44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 49 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
45 | 50 |
46 // static | 51 // static |
47 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | 52 void ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
48 content::WebContents* contents, | 53 content::WebContents* contents, |
49 autofill::AutofillClient* autofill_client) { | 54 autofill::AutofillClient* autofill_client) { |
50 if (FromWebContents(contents)) | 55 if (FromWebContents(contents)) |
51 return; | 56 return; |
52 | 57 |
53 contents->SetUserData( | 58 contents->SetUserData( |
54 UserDataKey(), | 59 UserDataKey(), |
55 new ChromePasswordManagerClient(contents, autofill_client)); | 60 new ChromePasswordManagerClient(contents, autofill_client)); |
56 } | 61 } |
57 | 62 |
58 ChromePasswordManagerClient::ChromePasswordManagerClient( | 63 ChromePasswordManagerClient::ChromePasswordManagerClient( |
59 content::WebContents* web_contents, | 64 content::WebContents* web_contents, |
60 autofill::AutofillClient* autofill_client) | 65 autofill::AutofillClient* autofill_client) |
61 : content::WebContentsObserver(web_contents), | 66 : content::WebContentsObserver(web_contents), |
62 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 67 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
63 driver_(web_contents, this, autofill_client), | 68 driver_(web_contents, this, autofill_client), |
64 observer_(NULL), | 69 observer_(NULL), |
65 weak_factory_(this), | 70 weak_factory_(this), |
66 can_use_log_router_(false) { | 71 can_use_log_router_(false), |
72 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS) { | |
67 PasswordManagerInternalsService* service = | 73 PasswordManagerInternalsService* service = |
68 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 74 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
69 if (service) | 75 if (service) |
70 can_use_log_router_ = service->RegisterClient(this); | 76 can_use_log_router_ = service->RegisterClient(this); |
77 SetUpAutofillSyncState(); | |
71 } | 78 } |
72 | 79 |
73 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 80 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
74 PasswordManagerInternalsService* service = | 81 PasswordManagerInternalsService* service = |
75 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 82 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
76 if (service) | 83 if (service) |
77 service->UnregisterClient(this); | 84 service->UnregisterClient(this); |
78 } | 85 } |
79 | 86 |
80 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 87 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
81 return CommandLine::ForCurrentProcess()->HasSwitch( | 88 return CommandLine::ForCurrentProcess()->HasSwitch( |
82 password_manager::switches::kEnableAutomaticPasswordSaving) && | 89 pm_switches::kEnableAutomaticPasswordSaving) && |
83 chrome::VersionInfo::GetChannel() == | 90 chrome::VersionInfo::GetChannel() == |
84 chrome::VersionInfo::CHANNEL_UNKNOWN; | 91 chrome::VersionInfo::CHANNEL_UNKNOWN; |
85 } | 92 } |
86 | 93 |
87 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() | 94 bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() |
88 const { | 95 const { |
89 if (EnabledForSyncSignin()) | 96 if (EnabledForSyncSignin()) |
90 return true; | 97 return true; |
91 | 98 |
92 DCHECK(web_contents()); | 99 DCHECK(web_contents()); |
93 content::NavigationEntry* entry = | 100 content::NavigationEntry* entry = |
94 web_contents()->GetController().GetLastCommittedEntry(); | 101 web_contents()->GetController().GetLastCommittedEntry(); |
95 if (!entry) { | 102 if (!entry) { |
96 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 103 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
97 return true; | 104 return true; |
98 } | 105 } |
99 // Do not fill nor save password when a user is signing in for sync. This | 106 // Do not fill nor save password when a user is signing in for sync. This |
100 // is because users need to remember their password if they are syncing as | 107 // is because users need to remember their password if they are syncing as |
101 // this is effectively their master password. | 108 // this is effectively their master password. |
102 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | 109 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
103 } | 110 } |
104 | 111 |
112 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( | |
113 const autofill::PasswordForm& form) const { | |
114 if (!IsSyncAccountCredential(base::UTF16ToUTF8(form.username_value), | |
115 form.signon_realm)) | |
116 return false; | |
117 | |
118 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS) | |
119 return true; | |
120 | |
121 if (autofill_sync_state_ == DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH && | |
122 LastLoadWasTransactionalReauthPage()) | |
123 return true; | |
124 | |
125 return false; | |
126 } | |
127 | |
105 bool ChromePasswordManagerClient::IsSyncAccountCredential( | 128 bool ChromePasswordManagerClient::IsSyncAccountCredential( |
106 const std::string& username, const std::string& origin) const { | 129 const std::string& username, const std::string& origin) const { |
107 return password_manager_sync_metrics::IsSyncAccountCredential( | 130 return password_manager_sync_metrics::IsSyncAccountCredential( |
108 profile_, username, origin); | 131 profile_, username, origin); |
109 } | 132 } |
110 | 133 |
111 void ChromePasswordManagerClient::PromptUserToSavePassword( | 134 void ChromePasswordManagerClient::PromptUserToSavePassword( |
112 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { | 135 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { |
113 if (IsTheHotNewBubbleUIEnabled()) { | 136 if (IsTheHotNewBubbleUIEnabled()) { |
114 ManagePasswordsUIController* manage_passwords_ui_controller = | 137 ManagePasswordsUIController* manage_passwords_ui_controller = |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 369 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
347 web_contents()->GetRenderViewHost()->GetRoutingID(), | 370 web_contents()->GetRenderViewHost()->GetRoutingID(), |
348 can_use_log_router_)); | 371 can_use_log_router_)); |
349 } | 372 } |
350 | 373 |
351 void ChromePasswordManagerClient::CommitFillPasswordForm( | 374 void ChromePasswordManagerClient::CommitFillPasswordForm( |
352 autofill::PasswordFormFillData* data) { | 375 autofill::PasswordFormFillData* data) { |
353 driver_.FillPasswordForm(*data); | 376 driver_.FillPasswordForm(*data); |
354 } | 377 } |
355 | 378 |
379 bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const { | |
380 DCHECK(web_contents()); | |
381 content::NavigationEntry* entry = | |
382 web_contents()->GetController().GetLastCommittedEntry(); | |
383 if (!entry) | |
384 return false; | |
385 | |
386 if (entry->GetURL().GetOrigin() != | |
387 GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | |
388 return false; | |
389 | |
390 // "rart" is the transactional reauth paramter. | |
391 std::string ignored_value; | |
392 return net::GetValueForKeyInQuery(entry->GetURL(), | |
393 "rart", | |
394 &ignored_value); | |
395 } | |
396 | |
356 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { | 397 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
357 #if !defined(USE_AURA) | 398 #if !defined(USE_AURA) |
358 return false; | 399 return false; |
359 #endif | 400 #endif |
360 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 401 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
361 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 402 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
362 return false; | 403 return false; |
363 | 404 |
364 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) | 405 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) |
365 return true; | 406 return true; |
366 | 407 |
367 std::string group_name = | 408 std::string group_name = |
368 base::FieldTrialList::FindFullName("PasswordManagerUI"); | 409 base::FieldTrialList::FindFullName("PasswordManagerUI"); |
369 | 410 |
370 // The bubble should be the default case that runs on the bots. | 411 // The bubble should be the default case that runs on the bots. |
371 return group_name != "Infobar"; | 412 return group_name != "Infobar"; |
372 } | 413 } |
373 | 414 |
374 bool ChromePasswordManagerClient::EnabledForSyncSignin() { | 415 bool ChromePasswordManagerClient::EnabledForSyncSignin() { |
375 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 416 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
376 if (command_line->HasSwitch( | 417 if (command_line->HasSwitch( |
377 password_manager::switches::kDisableManagerForSyncSignin)) | 418 pm_switches::kDisableManagerForSyncSignin)) |
378 return false; | 419 return false; |
379 | 420 |
380 if (command_line->HasSwitch( | 421 if (command_line->HasSwitch( |
381 password_manager::switches::kEnableManagerForSyncSignin)) | 422 pm_switches::kEnableManagerForSyncSignin)) |
382 return true; | 423 return true; |
383 | 424 |
384 // Default is enabled. | 425 // Default is enabled. |
385 std::string group_name = | 426 std::string group_name = |
386 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); | 427 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); |
387 return group_name != "Disabled"; | 428 return group_name != "Disabled"; |
388 } | 429 } |
430 | |
431 void ChromePasswordManagerClient::SetUpAutofillSyncState() { | |
432 std::string group_name = | |
433 base::FieldTrialList::FindFullName("AutofillSyncCredential"); | |
434 | |
435 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
436 if (command_line->HasSwitch( | |
437 pm_switches::kAllowAutofillSyncCredential)) { | |
438 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
439 return; | |
440 } | |
441 if (command_line->HasSwitch( | |
442 pm_switches::kDisallowAutofillSyncCredentialForReauth)) { | |
443 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
444 return; | |
445 } | |
446 if (command_line->HasSwitch( | |
447 pm_switches::kDisallowAutofillSyncCredential)) { | |
448 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
449 return; | |
450 } | |
451 | |
452 if (group_name == "DisallowSyncCredentialsForReauth") { | |
453 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
454 } else if (group_name == "DisallowSyncCredentials") { | |
455 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | |
456 } else { | |
457 // Allow by default. | |
458 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | |
459 } | |
460 } | |
OLD | NEW |