| 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 "chrome/browser/password_manager/password_manager_util.h" | 11 #include "chrome/browser/password_manager/password_manager_util.h" |
| 12 #include "chrome/browser/password_manager/password_store_factory.h" | 12 #include "chrome/browser/password_manager/password_store_factory.h" |
| 13 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 13 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
| 16 #include "chrome/browser/sync/profile_sync_service_factory.h" | 16 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 17 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" | 17 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" |
| 18 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 18 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
| 21 #include "components/autofill/content/common/autofill_messages.h" | 21 #include "components/autofill/content/common/autofill_messages.h" |
| 22 #include "components/autofill/core/browser/password_generator.h" | 22 #include "components/autofill/core/browser/password_generator.h" |
| 23 #include "components/autofill/core/common/password_form.h" | 23 #include "components/autofill/core/common/password_form.h" |
| 24 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
| 24 #include "components/password_manager/core/browser/password_form_manager.h" | 25 #include "components/password_manager/core/browser/password_form_manager.h" |
| 25 #include "components/password_manager/core/browser/password_manager.h" | 26 #include "components/password_manager/core/browser/password_manager.h" |
| 27 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
| 26 #include "components/password_manager/core/browser/password_manager_logger.h" | 28 #include "components/password_manager/core/browser/password_manager_logger.h" |
| 27 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 29 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| 28 #include "components/password_manager/core/common/password_manager_switches.h" | 30 #include "components/password_manager/core/common/password_manager_switches.h" |
| 29 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 31 | 33 |
| 32 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
| 33 #include "chrome/browser/android/password_authentication_manager.h" | 35 #include "chrome/browser/android/password_authentication_manager.h" |
| 34 #endif // OS_ANDROID | 36 #endif // OS_ANDROID |
| 35 | 37 |
| 38 using password_manager::PasswordManagerInternalsService; |
| 39 using password_manager::PasswordManagerInternalsServiceFactory; |
| 40 |
| 36 namespace { | 41 namespace { |
| 37 | 42 |
| 38 bool IsTheHotNewBubbleUIEnabled() { | 43 bool IsTheHotNewBubbleUIEnabled() { |
| 39 #if !defined(USE_AURA) | 44 #if !defined(USE_AURA) |
| 40 return false; | 45 return false; |
| 41 #endif | 46 #endif |
| 42 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 47 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 43 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 48 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
| 44 return false; | 49 return false; |
| 45 | 50 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 return; | 69 return; |
| 65 | 70 |
| 66 contents->SetUserData(UserDataKey(), | 71 contents->SetUserData(UserDataKey(), |
| 67 new ChromePasswordManagerClient(contents, delegate)); | 72 new ChromePasswordManagerClient(contents, delegate)); |
| 68 } | 73 } |
| 69 | 74 |
| 70 ChromePasswordManagerClient::ChromePasswordManagerClient( | 75 ChromePasswordManagerClient::ChromePasswordManagerClient( |
| 71 content::WebContents* web_contents, | 76 content::WebContents* web_contents, |
| 72 autofill::AutofillManagerDelegate* autofill_manager_delegate) | 77 autofill::AutofillManagerDelegate* autofill_manager_delegate) |
| 73 : content::WebContentsObserver(web_contents), | 78 : content::WebContentsObserver(web_contents), |
| 79 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 74 driver_(web_contents, this, autofill_manager_delegate), | 80 driver_(web_contents, this, autofill_manager_delegate), |
| 75 observer_(NULL), | 81 observer_(NULL), |
| 76 weak_factory_(this), | 82 weak_factory_(this), |
| 77 logger_(NULL) {} | 83 can_use_log_router_(false) { |
| 84 PasswordManagerInternalsService* service = |
| 85 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 86 if (service) |
| 87 can_use_log_router_ = service->RegisterClient(this); |
| 88 } |
| 78 | 89 |
| 79 ChromePasswordManagerClient::~ChromePasswordManagerClient() {} | 90 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
| 91 PasswordManagerInternalsService* service = |
| 92 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 93 if (service) |
| 94 service->UnregisterClient(this); |
| 95 } |
| 80 | 96 |
| 81 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 97 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
| 82 return CommandLine::ForCurrentProcess()->HasSwitch( | 98 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 83 password_manager::switches::kEnableAutomaticPasswordSaving) && | 99 password_manager::switches::kEnableAutomaticPasswordSaving) && |
| 84 chrome::VersionInfo::GetChannel() == | 100 chrome::VersionInfo::GetChannel() == |
| 85 chrome::VersionInfo::CHANNEL_UNKNOWN; | 101 chrome::VersionInfo::CHANNEL_UNKNOWN; |
| 86 } | 102 } |
| 87 | 103 |
| 88 void ChromePasswordManagerClient::PromptUserToSavePassword( | 104 void ChromePasswordManagerClient::PromptUserToSavePassword( |
| 89 password_manager::PasswordFormManager* form_to_save) { | 105 password_manager::PasswordFormManager* form_to_save) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 base::Bind(&ChromePasswordManagerClient::CommitFillPasswordForm, | 145 base::Bind(&ChromePasswordManagerClient::CommitFillPasswordForm, |
| 130 weak_factory_.GetWeakPtr(), | 146 weak_factory_.GetWeakPtr(), |
| 131 base::Owned(fill_data.release()))); | 147 base::Owned(fill_data.release()))); |
| 132 #else | 148 #else |
| 133 // Additional authentication is currently only available for Android, so all | 149 // Additional authentication is currently only available for Android, so all |
| 134 // other plaftorms should just fill the password form directly. | 150 // other plaftorms should just fill the password form directly. |
| 135 CommitFillPasswordForm(fill_data.get()); | 151 CommitFillPasswordForm(fill_data.get()); |
| 136 #endif // OS_ANDROID | 152 #endif // OS_ANDROID |
| 137 } | 153 } |
| 138 | 154 |
| 139 Profile* ChromePasswordManagerClient::GetProfile() { | |
| 140 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 141 } | |
| 142 | |
| 143 void ChromePasswordManagerClient::HidePasswordGenerationPopup() { | 155 void ChromePasswordManagerClient::HidePasswordGenerationPopup() { |
| 144 if (popup_controller_) | 156 if (popup_controller_) |
| 145 popup_controller_->HideAndDestroy(); | 157 popup_controller_->HideAndDestroy(); |
| 146 } | 158 } |
| 147 | 159 |
| 148 PrefService* ChromePasswordManagerClient::GetPrefs() { | 160 PrefService* ChromePasswordManagerClient::GetPrefs() { |
| 149 return GetProfile()->GetPrefs(); | 161 return profile_->GetPrefs(); |
| 150 } | 162 } |
| 151 | 163 |
| 152 password_manager::PasswordStore* | 164 password_manager::PasswordStore* |
| 153 ChromePasswordManagerClient::GetPasswordStore() { | 165 ChromePasswordManagerClient::GetPasswordStore() { |
| 154 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord | 166 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord |
| 155 // itself when it shouldn't access the PasswordStore. | 167 // itself when it shouldn't access the PasswordStore. |
| 156 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? | 168 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? |
| 157 return PasswordStoreFactory::GetForProfile(GetProfile(), | 169 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) |
| 158 Profile::EXPLICIT_ACCESS).get(); | 170 .get(); |
| 159 } | 171 } |
| 160 | 172 |
| 161 password_manager::PasswordManagerDriver* | 173 password_manager::PasswordManagerDriver* |
| 162 ChromePasswordManagerClient::GetDriver() { | 174 ChromePasswordManagerClient::GetDriver() { |
| 163 return &driver_; | 175 return &driver_; |
| 164 } | 176 } |
| 165 | 177 |
| 166 base::FieldTrial::Probability | 178 base::FieldTrial::Probability |
| 167 ChromePasswordManagerClient::GetProbabilityForExperiment( | 179 ChromePasswordManagerClient::GetProbabilityForExperiment( |
| 168 const std::string& experiment_name) { | 180 const std::string& experiment_name) { |
| 169 base::FieldTrial::Probability enabled_probability = 0; | 181 base::FieldTrial::Probability enabled_probability = 0; |
| 170 if (experiment_name == | 182 if (experiment_name == |
| 171 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 183 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
| 172 switch (chrome::VersionInfo::GetChannel()) { | 184 switch (chrome::VersionInfo::GetChannel()) { |
| 173 case chrome::VersionInfo::CHANNEL_DEV: | 185 case chrome::VersionInfo::CHANNEL_DEV: |
| 174 case chrome::VersionInfo::CHANNEL_BETA: | 186 case chrome::VersionInfo::CHANNEL_BETA: |
| 175 enabled_probability = 50; | 187 enabled_probability = 50; |
| 176 break; | 188 break; |
| 177 default: | 189 default: |
| 178 break; | 190 break; |
| 179 } | 191 } |
| 180 } | 192 } |
| 181 return enabled_probability; | 193 return enabled_probability; |
| 182 } | 194 } |
| 183 | 195 |
| 184 bool ChromePasswordManagerClient::IsPasswordSyncEnabled() { | 196 bool ChromePasswordManagerClient::IsPasswordSyncEnabled() { |
| 185 ProfileSyncService* sync_service = | 197 ProfileSyncService* sync_service = |
| 186 ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 198 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 187 // Don't consider sync enabled if the user has a custom passphrase. See | 199 // Don't consider sync enabled if the user has a custom passphrase. See |
| 188 // crbug.com/358998 for more details. | 200 // crbug.com/358998 for more details. |
| 189 if (sync_service && | 201 if (sync_service && |
| 190 sync_service->HasSyncSetupCompleted() && | 202 sync_service->HasSyncSetupCompleted() && |
| 191 sync_service->sync_initialized() && | 203 sync_service->sync_initialized() && |
| 192 !sync_service->IsUsingSecondaryPassphrase()) { | 204 !sync_service->IsUsingSecondaryPassphrase()) { |
| 193 return sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS); | 205 return sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS); |
| 194 } | 206 } |
| 195 return false; | 207 return false; |
| 196 } | 208 } |
| 197 | 209 |
| 198 void ChromePasswordManagerClient::SetLogger( | 210 void ChromePasswordManagerClient::OnLogRouterAvailabilityChanged( |
| 199 password_manager::PasswordManagerLogger* logger) { | 211 bool router_can_be_used) { |
| 200 // We should never be replacing one logger with a different one, because that | 212 if (can_use_log_router_ == router_can_be_used) |
| 201 // will leave the first without further updates, and the user likely confused. | 213 return; |
| 202 // TODO(vabr): For the reason above, before moving the internals page from | 214 can_use_log_router_ = router_can_be_used; |
| 203 // behind the flag, make sure to restrict the number of internals page | 215 |
| 204 // instances to 1 in normal profiles, and 0 in incognito. | 216 if (!web_contents()) |
| 205 DCHECK(!logger || !logger_); | 217 return; |
| 206 logger_ = logger; | |
| 207 | 218 |
| 208 // Also inform the renderer process to start or stop logging. | 219 // Also inform the renderer process to start or stop logging. |
| 209 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_ChangeLoggingState( | 220 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_ChangeLoggingState( |
| 210 web_contents()->GetRenderViewHost()->GetRoutingID(), logger != NULL)); | 221 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 222 can_use_log_router_)); |
| 211 } | 223 } |
| 212 | 224 |
| 213 void ChromePasswordManagerClient::LogSavePasswordProgress( | 225 void ChromePasswordManagerClient::LogSavePasswordProgress( |
| 214 const std::string& text) { | 226 const std::string& text) { |
| 215 if (IsLoggingActive()) | 227 if (!IsLoggingActive()) |
| 216 logger_->LogSavePasswordProgress(text); | 228 return; |
| 229 PasswordManagerInternalsService* service = |
| 230 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
| 231 if (service) |
| 232 service->ProcessLog(text); |
| 217 } | 233 } |
| 218 | 234 |
| 219 bool ChromePasswordManagerClient::IsLoggingActive() const { | 235 bool ChromePasswordManagerClient::IsLoggingActive() const { |
| 220 return logger_ != NULL; | 236 // WebUI tabs do not need to log password saving progress. In particular, the |
| 237 // internals page itself should not send any logs. |
| 238 return can_use_log_router_ && !web_contents()->GetWebUI(); |
| 221 } | 239 } |
| 222 | 240 |
| 223 // static | 241 // static |
| 224 password_manager::PasswordGenerationManager* | 242 password_manager::PasswordGenerationManager* |
| 225 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | 243 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( |
| 226 content::WebContents* contents) { | 244 content::WebContents* contents) { |
| 227 ChromePasswordManagerClient* client = | 245 ChromePasswordManagerClient* client = |
| 228 ChromePasswordManagerClient::FromWebContents(contents); | 246 ChromePasswordManagerClient::FromWebContents(contents); |
| 229 if (!client) | 247 if (!client) |
| 230 return NULL; | 248 return NULL; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 web_contents(), | 328 web_contents(), |
| 311 web_contents()->GetNativeView()); | 329 web_contents()->GetNativeView()); |
| 312 popup_controller_->Show(false /* display_password */); | 330 popup_controller_->Show(false /* display_password */); |
| 313 #endif // #if defined(USE_AURA) | 331 #endif // #if defined(USE_AURA) |
| 314 } | 332 } |
| 315 | 333 |
| 316 void ChromePasswordManagerClient::CommitFillPasswordForm( | 334 void ChromePasswordManagerClient::CommitFillPasswordForm( |
| 317 autofill::PasswordFormFillData* data) { | 335 autofill::PasswordFormFillData* data) { |
| 318 driver_.FillPasswordForm(*data); | 336 driver_.FillPasswordForm(*data); |
| 319 } | 337 } |
| OLD | NEW |