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 |
44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 47 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
45 | 48 |
(...skipping 10 matching lines...) Expand all Loading... | |
56 } | 59 } |
57 | 60 |
58 ChromePasswordManagerClient::ChromePasswordManagerClient( | 61 ChromePasswordManagerClient::ChromePasswordManagerClient( |
59 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
60 autofill::AutofillClient* autofill_client) | 63 autofill::AutofillClient* autofill_client) |
61 : content::WebContentsObserver(web_contents), | 64 : content::WebContentsObserver(web_contents), |
62 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 65 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
63 driver_(web_contents, this, autofill_client), | 66 driver_(web_contents, this, autofill_client), |
64 observer_(NULL), | 67 observer_(NULL), |
65 weak_factory_(this), | 68 weak_factory_(this), |
66 can_use_log_router_(false) { | 69 can_use_log_router_(false), |
70 autofill_state_(ALLOW_SYNC_CREDENTIALS){ | |
67 PasswordManagerInternalsService* service = | 71 PasswordManagerInternalsService* service = |
68 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 72 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
69 if (service) | 73 if (service) |
70 can_use_log_router_ = service->RegisterClient(this); | 74 can_use_log_router_ = service->RegisterClient(this); |
75 SetupAutofillSyncState(); | |
71 } | 76 } |
72 | 77 |
73 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 78 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
74 PasswordManagerInternalsService* service = | 79 PasswordManagerInternalsService* service = |
75 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 80 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
76 if (service) | 81 if (service) |
77 service->UnregisterClient(this); | 82 service->UnregisterClient(this); |
78 } | 83 } |
79 | 84 |
80 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 85 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
(...skipping 14 matching lines...) Expand all Loading... | |
95 if (!entry) { | 100 if (!entry) { |
96 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 101 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
97 return true; | 102 return true; |
98 } | 103 } |
99 // Do not fill nor save password when a user is signing in for sync. This | 104 // 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 | 105 // is because users need to remember their password if they are syncing as |
101 // this is effectively their master password. | 106 // this is effectively their master password. |
102 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | 107 return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
103 } | 108 } |
104 | 109 |
110 bool ChromePasswordManagerClient::ShouldFilterAutofillResult( | |
111 const autofill::PasswordForm& form) const { | |
112 if (!password_manager_sync_metrics::IsSyncAccountCredential( | |
113 profile_, base::UTF16ToUTF8(form.username_value), form.signon_realm)) | |
114 return false; | |
115 | |
116 if (autofill_state_ == DISALLOW_SYNC_CREDENTIALS) | |
117 return true; | |
118 | |
119 if (autofill_state_ == DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH && | |
120 LastLoadWasTransactionalReauthPage()) | |
121 return true; | |
122 | |
123 return false; | |
124 } | |
125 | |
105 bool ChromePasswordManagerClient::IsSyncAccountCredential( | 126 bool ChromePasswordManagerClient::IsSyncAccountCredential( |
106 const std::string& username, const std::string& origin) const { | 127 const std::string& username, const std::string& origin) const { |
107 return password_manager_sync_metrics::IsSyncAccountCredential( | 128 return password_manager_sync_metrics::IsSyncAccountCredential( |
108 profile_, username, origin); | 129 profile_, username, origin); |
109 } | 130 } |
110 | 131 |
111 void ChromePasswordManagerClient::PromptUserToSavePassword( | 132 void ChromePasswordManagerClient::PromptUserToSavePassword( |
112 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { | 133 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { |
113 if (IsTheHotNewBubbleUIEnabled()) { | 134 if (IsTheHotNewBubbleUIEnabled()) { |
114 ManagePasswordsUIController* manage_passwords_ui_controller = | 135 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( | 367 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
347 web_contents()->GetRenderViewHost()->GetRoutingID(), | 368 web_contents()->GetRenderViewHost()->GetRoutingID(), |
348 can_use_log_router_)); | 369 can_use_log_router_)); |
349 } | 370 } |
350 | 371 |
351 void ChromePasswordManagerClient::CommitFillPasswordForm( | 372 void ChromePasswordManagerClient::CommitFillPasswordForm( |
352 autofill::PasswordFormFillData* data) { | 373 autofill::PasswordFormFillData* data) { |
353 driver_.FillPasswordForm(*data); | 374 driver_.FillPasswordForm(*data); |
354 } | 375 } |
355 | 376 |
377 bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const { | |
378 DCHECK(web_contents()); | |
379 content::NavigationEntry* entry = | |
380 web_contents()->GetController().GetLastCommittedEntry(); | |
381 if (!entry) | |
382 return false; | |
383 | |
384 if (entry->GetURL().GetOrigin() != | |
385 GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | |
386 return false; | |
387 | |
388 std::string ignored_value; | |
389 return net::GetValueForKeyInQuery(entry->GetURL(), | |
390 "rart", | |
Ilya Sherman
2014/08/12 02:17:32
What is "rart"? Probably worth a comment, IMO.
Garrett Casto
2014/08/13 20:34:40
Done.
| |
391 &ignored_value); | |
392 } | |
393 | |
356 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { | 394 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
357 #if !defined(USE_AURA) | 395 #if !defined(USE_AURA) |
358 return false; | 396 return false; |
359 #endif | 397 #endif |
360 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 398 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
361 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 399 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
362 return false; | 400 return false; |
363 | 401 |
364 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) | 402 if (command_line->HasSwitch(switches::kEnableSavePasswordBubble)) |
365 return true; | 403 return true; |
(...skipping 13 matching lines...) Expand all Loading... | |
379 | 417 |
380 if (command_line->HasSwitch( | 418 if (command_line->HasSwitch( |
381 password_manager::switches::kEnableManagerForSyncSignin)) | 419 password_manager::switches::kEnableManagerForSyncSignin)) |
382 return true; | 420 return true; |
383 | 421 |
384 // Default is enabled. | 422 // Default is enabled. |
385 std::string group_name = | 423 std::string group_name = |
386 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); | 424 base::FieldTrialList::FindFullName("PasswordManagerStateForSyncSignin"); |
387 return group_name != "Disabled"; | 425 return group_name != "Disabled"; |
388 } | 426 } |
427 | |
428 void ChromePasswordManagerClient::SetupAutofillSyncState() { | |
429 std::string group_name = | |
430 base::FieldTrialList::FindFullName("AutofillSyncCredential"); | |
431 | |
432 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
433 if (command_line->HasSwitch( | |
434 password_manager::switches::kAllowAutofillSyncCredential)) { | |
435 autofill_state_ = ALLOW_SYNC_CREDENTIALS; | |
436 return; | |
437 } | |
Ilya Sherman
2014/08/12 02:17:32
Hmm, what about the other switch values?
Garrett Casto
2014/08/13 20:34:40
Fixed, with tests to verify.
| |
438 | |
439 if (group_name == "DisallowSyncCredentialsForReauth") { | |
440 autofill_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | |
441 } else if (group_name == "DisallowSyncCredentials") { | |
442 autofill_state_ = DISALLOW_SYNC_CREDENTIALS; | |
443 } else { | |
444 // Allow by default. | |
445 autofill_state_ = ALLOW_SYNC_CREDENTIALS; | |
446 } | |
Ilya Sherman
2014/08/12 02:17:32
I recall seeing a message on the finch-team mailin
Garrett Casto
2014/08/13 20:34:40
Sent an e-mail out asking. It doesn't seem like it
jww
2014/08/14 01:16:25
The explanation I've gotten in the past is that if
| |
447 } | |
OLD | NEW |