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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "components/autofill/content/browser/content_autofill_driver.h" | 26 #include "components/autofill/content/browser/content_autofill_driver.h" |
27 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 27 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
28 #include "components/autofill/content/common/autofill_messages.h" | 28 #include "components/autofill/content/common/autofill_messages.h" |
29 #include "components/autofill/core/browser/password_generator.h" | 29 #include "components/autofill/core/browser/password_generator.h" |
30 #include "components/autofill/core/common/password_form.h" | 30 #include "components/autofill/core/common/password_form.h" |
31 #include "components/browser_sync/browser/profile_sync_service.h" | 31 #include "components/browser_sync/browser/profile_sync_service.h" |
32 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 32 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
33 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" | 33 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
34 #include "components/password_manager/content/common/credential_manager_messages
.h" | 34 #include "components/password_manager/content/common/credential_manager_messages
.h" |
35 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 35 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
| 36 #include "components/password_manager/core/browser/log_manager.h" |
36 #include "components/password_manager/core/browser/log_receiver.h" | 37 #include "components/password_manager/core/browser/log_receiver.h" |
37 #include "components/password_manager/core/browser/password_form_manager.h" | 38 #include "components/password_manager/core/browser/password_form_manager.h" |
38 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 39 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
39 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 40 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
40 #include "components/password_manager/core/browser/password_manager_settings_mig
ration_experiment.h" | 41 #include "components/password_manager/core/browser/password_manager_settings_mig
ration_experiment.h" |
41 #include "components/password_manager/core/browser/password_manager_util.h" | 42 #include "components/password_manager/core/browser/password_manager_util.h" |
42 #include "components/password_manager/core/common/credential_manager_types.h" | 43 #include "components/password_manager/core/common/credential_manager_types.h" |
43 #include "components/password_manager/core/common/password_manager_pref_names.h" | 44 #include "components/password_manager/core/common/password_manager_pref_names.h" |
44 #include "components/password_manager/core/common/password_manager_switches.h" | 45 #include "components/password_manager/core/common/password_manager_switches.h" |
45 #include "components/password_manager/sync/browser/password_sync_util.h" | 46 #include "components/password_manager/sync/browser/password_sync_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
57 #endif | 58 #endif |
58 | 59 |
59 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
60 #include "chrome/browser/android/tab_android.h" | 61 #include "chrome/browser/android/tab_android.h" |
61 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" | 62 #include "chrome/browser/password_manager/generated_password_saved_infobar_deleg
ate_android.h" |
62 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" | 63 #include "chrome/browser/ui/android/snackbars/auto_signin_prompt_controller.h" |
63 #endif | 64 #endif |
64 | 65 |
65 using password_manager::ContentPasswordManagerDriverFactory; | 66 using password_manager::ContentPasswordManagerDriverFactory; |
66 using password_manager::PasswordManagerInternalsService; | 67 using password_manager::PasswordManagerInternalsService; |
67 using password_manager::PasswordManagerInternalsServiceFactory; | |
68 | 68 |
69 // Shorten the name to spare line breaks. The code provides enough context | 69 // Shorten the name to spare line breaks. The code provides enough context |
70 // already. | 70 // already. |
71 typedef autofill::SavePasswordProgressLogger Logger; | 71 typedef autofill::SavePasswordProgressLogger Logger; |
72 | 72 |
73 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); | 73 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromePasswordManagerClient); |
74 | 74 |
75 namespace { | 75 namespace { |
76 | 76 |
77 const sync_driver::SyncService* GetSyncService(Profile* profile) { | 77 const sync_driver::SyncService* GetSyncService(Profile* profile) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 ChromePasswordManagerClient::ChromePasswordManagerClient( | 130 ChromePasswordManagerClient::ChromePasswordManagerClient( |
131 content::WebContents* web_contents, | 131 content::WebContents* web_contents, |
132 autofill::AutofillClient* autofill_client) | 132 autofill::AutofillClient* autofill_client) |
133 : content::WebContentsObserver(web_contents), | 133 : content::WebContentsObserver(web_contents), |
134 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 134 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
135 password_manager_(this), | 135 password_manager_(this), |
136 driver_factory_(nullptr), | 136 driver_factory_(nullptr), |
137 credential_manager_dispatcher_(web_contents, this), | 137 credential_manager_dispatcher_(web_contents, this), |
138 observer_(nullptr), | 138 observer_(nullptr), |
139 can_use_log_router_(false), | |
140 credentials_filter_(this, | 139 credentials_filter_(this, |
141 base::Bind(&GetSyncService, profile_), | 140 base::Bind(&GetSyncService, profile_), |
142 base::Bind(&GetSigninManager, profile_)) { | 141 base::Bind(&GetSigninManager, profile_)) { |
143 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 142 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
144 autofill_client); | 143 autofill_client); |
145 driver_factory_ = | 144 driver_factory_ = |
146 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 145 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
| 146 log_manager_ = password_manager::LogManager::Create( |
| 147 password_manager::PasswordManagerInternalsServiceFactory:: |
| 148 GetForBrowserContext(profile_), |
| 149 base::Bind( |
| 150 &ContentPasswordManagerDriverFactory::RequestSendLoggingAvailability, |
| 151 base::Unretained(driver_factory_))); |
147 | 152 |
148 PasswordManagerInternalsService* service = | |
149 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
150 if (service) | |
151 can_use_log_router_ = service->RegisterClient(this); | |
152 saving_and_filling_passwords_enabled_.Init( | 153 saving_and_filling_passwords_enabled_.Init( |
153 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); | 154 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); |
154 ReportMetrics(*saving_and_filling_passwords_enabled_, this, profile_); | 155 ReportMetrics(*saving_and_filling_passwords_enabled_, this, profile_); |
| 156 driver_factory_->RequestSendLoggingAvailability(); |
155 } | 157 } |
156 | 158 |
157 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 159 ChromePasswordManagerClient::~ChromePasswordManagerClient() {} |
158 PasswordManagerInternalsService* service = | |
159 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
160 if (service) | |
161 service->UnregisterClient(this); | |
162 } | |
163 | 160 |
164 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 161 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
165 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 162 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
166 password_manager::switches::kEnableAutomaticPasswordSaving) && | 163 password_manager::switches::kEnableAutomaticPasswordSaving) && |
167 chrome::GetChannel() == version_info::Channel::UNKNOWN; | 164 chrome::GetChannel() == version_info::Channel::UNKNOWN; |
168 } | 165 } |
169 | 166 |
170 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() | 167 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() |
171 const { | 168 const { |
172 DCHECK(web_contents()); | 169 DCHECK(web_contents()); |
173 content::NavigationEntry* entry = | 170 content::NavigationEntry* entry = |
174 web_contents()->GetController().GetLastCommittedEntry(); | 171 web_contents()->GetController().GetLastCommittedEntry(); |
175 bool is_enabled = false; | 172 bool is_enabled = false; |
176 if (!entry) { | 173 if (!entry) { |
177 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 174 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
178 is_enabled = true; | 175 is_enabled = true; |
179 } else if (EnabledForSyncSignin()) { | 176 } else if (EnabledForSyncSignin()) { |
180 is_enabled = true; | 177 is_enabled = true; |
181 } else { | 178 } else { |
182 // Do not fill nor save password when a user is signing in for sync. This | 179 // Do not fill nor save password when a user is signing in for sync. This |
183 // is because users need to remember their password if they are syncing as | 180 // is because users need to remember their password if they are syncing as |
184 // this is effectively their master password. | 181 // this is effectively their master password. |
185 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | 182 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
186 } | 183 } |
187 if (IsLoggingActive()) { | 184 if (log_manager_->IsLoggingActive()) { |
188 password_manager::BrowserSavePasswordProgressLogger logger(this); | 185 password_manager::BrowserSavePasswordProgressLogger logger( |
| 186 log_manager_.get()); |
189 logger.LogBoolean( | 187 logger.LogBoolean( |
190 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, | 188 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, |
191 is_enabled); | 189 is_enabled); |
192 } | 190 } |
193 return is_enabled; | 191 return is_enabled; |
194 } | 192 } |
195 | 193 |
196 bool ChromePasswordManagerClient::IsSavingAndFillingEnabledForCurrentPage() | 194 bool ChromePasswordManagerClient::IsSavingAndFillingEnabledForCurrentPage() |
197 const { | 195 const { |
198 // TODO(melandory): remove saving_and_filling_passwords_enabled_ check from | 196 // TODO(melandory): remove saving_and_filling_passwords_enabled_ check from |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); | 313 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); |
316 } | 314 } |
317 | 315 |
318 password_manager::PasswordSyncState | 316 password_manager::PasswordSyncState |
319 ChromePasswordManagerClient::GetPasswordSyncState() const { | 317 ChromePasswordManagerClient::GetPasswordSyncState() const { |
320 const ProfileSyncService* sync_service = | 318 const ProfileSyncService* sync_service = |
321 ProfileSyncServiceFactory::GetForProfile(profile_); | 319 ProfileSyncServiceFactory::GetForProfile(profile_); |
322 return password_manager_util::GetPasswordSyncState(sync_service); | 320 return password_manager_util::GetPasswordSyncState(sync_service); |
323 } | 321 } |
324 | 322 |
325 void ChromePasswordManagerClient::OnLogRouterAvailabilityChanged( | |
326 bool router_can_be_used) { | |
327 if (can_use_log_router_ == router_can_be_used) | |
328 return; | |
329 can_use_log_router_ = router_can_be_used; | |
330 | |
331 NotifyRendererOfLoggingAvailability(); | |
332 } | |
333 | |
334 void ChromePasswordManagerClient::LogSavePasswordProgress( | |
335 const std::string& text) const { | |
336 if (!IsLoggingActive()) | |
337 return; | |
338 PasswordManagerInternalsService* service = | |
339 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
340 if (service) | |
341 service->ProcessLog(text); | |
342 } | |
343 | |
344 bool ChromePasswordManagerClient::IsLoggingActive() const { | |
345 // WebUI tabs do not need to log password saving progress. In particular, the | |
346 // internals page itself should not send any logs. | |
347 return can_use_log_router_ && !web_contents()->GetWebUI(); | |
348 } | |
349 | |
350 bool ChromePasswordManagerClient::WasLastNavigationHTTPError() const { | 323 bool ChromePasswordManagerClient::WasLastNavigationHTTPError() const { |
351 DCHECK(web_contents()); | 324 DCHECK(web_contents()); |
352 | 325 |
353 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; | 326 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; |
354 if (IsLoggingActive()) { | 327 if (log_manager_->IsLoggingActive()) { |
355 logger.reset(new password_manager::BrowserSavePasswordProgressLogger(this)); | 328 logger.reset(new password_manager::BrowserSavePasswordProgressLogger( |
| 329 log_manager_.get())); |
356 logger->LogMessage( | 330 logger->LogMessage( |
357 Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD); | 331 Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD); |
358 } | 332 } |
359 | 333 |
360 content::NavigationEntry* entry = | 334 content::NavigationEntry* entry = |
361 web_contents()->GetController().GetVisibleEntry(); | 335 web_contents()->GetController().GetVisibleEntry(); |
362 if (!entry) | 336 if (!entry) |
363 return false; | 337 return false; |
364 int http_status_code = entry->GetHttpStatusCode(); | 338 int http_status_code = entry->GetHttpStatusCode(); |
365 | 339 |
366 if (logger) | 340 if (logger) |
367 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 341 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
368 | 342 |
369 if (http_status_code >= 400 && http_status_code < 600) | 343 if (http_status_code >= 400 && http_status_code < 600) |
370 return true; | 344 return true; |
371 return false; | 345 return false; |
372 } | 346 } |
373 | 347 |
374 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { | 348 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { |
375 content::NavigationEntry* entry = | 349 content::NavigationEntry* entry = |
376 web_contents()->GetController().GetLastCommittedEntry(); | 350 web_contents()->GetController().GetLastCommittedEntry(); |
377 bool ssl_errors = true; | 351 bool ssl_errors = true; |
378 if (!entry) { | 352 if (!entry) { |
379 ssl_errors = false; | 353 ssl_errors = false; |
380 } else { | 354 } else { |
381 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); | 355 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); |
382 } | 356 } |
383 if (IsLoggingActive()) { | 357 if (log_manager_->IsLoggingActive()) { |
384 password_manager::BrowserSavePasswordProgressLogger logger(this); | 358 password_manager::BrowserSavePasswordProgressLogger logger( |
| 359 log_manager_.get()); |
385 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); | 360 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); |
386 } | 361 } |
387 return ssl_errors; | 362 return ssl_errors; |
388 } | 363 } |
389 | 364 |
390 bool ChromePasswordManagerClient::IsOffTheRecord() const { | 365 bool ChromePasswordManagerClient::IsOffTheRecord() const { |
391 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 366 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
392 } | 367 } |
393 | 368 |
394 const password_manager::PasswordManager* | 369 const password_manager::PasswordManager* |
(...skipping 27 matching lines...) Expand all Loading... |
422 ShowPasswordGenerationPopup) | 397 ShowPasswordGenerationPopup) |
423 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 398 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
424 ShowPasswordEditingPopup) | 399 ShowPasswordEditingPopup) |
425 IPC_END_MESSAGE_MAP() | 400 IPC_END_MESSAGE_MAP() |
426 | 401 |
427 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 402 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
428 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 403 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
429 HidePasswordGenerationPopup) | 404 HidePasswordGenerationPopup) |
430 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, | 405 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, |
431 GenerationAvailableForForm) | 406 GenerationAvailableForForm) |
432 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | |
433 NotifyRendererOfLoggingAvailability) | |
434 // Default: | 407 // Default: |
435 IPC_MESSAGE_UNHANDLED(handled = false) | 408 IPC_MESSAGE_UNHANDLED(handled = false) |
436 IPC_END_MESSAGE_MAP() | 409 IPC_END_MESSAGE_MAP() |
437 | 410 |
438 return handled; | 411 return handled; |
439 } | 412 } |
440 | 413 |
| 414 void ChromePasswordManagerClient::DidStartNavigation( |
| 415 content::NavigationHandle* navigation_handle) { |
| 416 // Logging has no sense on WebUI sites. |
| 417 log_manager_->SetSuspended(web_contents()->GetWebUI() != nullptr); |
| 418 } |
| 419 |
441 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 420 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
442 const gfx::RectF& bounds) { | 421 const gfx::RectF& bounds) { |
443 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 422 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
444 return bounds + client_area.OffsetFromOrigin(); | 423 return bounds + client_area.OffsetFromOrigin(); |
445 } | 424 } |
446 | 425 |
447 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 426 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
448 content::RenderFrameHost* render_frame_host, | 427 content::RenderFrameHost* render_frame_host, |
449 const gfx::RectF& bounds, | 428 const gfx::RectF& bounds, |
450 int max_length, | 429 int max_length, |
(...skipping 24 matching lines...) Expand all Loading... |
475 driver_factory_->GetDriverForFrame(render_frame_host), observer_, | 454 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
476 web_contents(), web_contents()->GetNativeView()); | 455 web_contents(), web_contents()->GetNativeView()); |
477 popup_controller_->Show(false /* display_password */); | 456 popup_controller_->Show(false /* display_password */); |
478 } | 457 } |
479 | 458 |
480 void ChromePasswordManagerClient::GenerationAvailableForForm( | 459 void ChromePasswordManagerClient::GenerationAvailableForForm( |
481 const autofill::PasswordForm& form) { | 460 const autofill::PasswordForm& form) { |
482 password_manager_.GenerationAvailableForForm(form); | 461 password_manager_.GenerationAvailableForForm(form); |
483 } | 462 } |
484 | 463 |
485 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | |
486 if (!web_contents()) | |
487 return; | |
488 | |
489 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | |
490 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
491 can_use_log_router_)); | |
492 } | |
493 | |
494 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { | 464 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
495 #if defined(OS_ANDROID) | 465 #if defined(OS_ANDROID) |
496 return false; | 466 return false; |
497 #elif defined(OS_MACOSX) | 467 #elif defined(OS_MACOSX) |
498 // Query the group first for correct UMA reporting. | 468 // Query the group first for correct UMA reporting. |
499 std::string group_name = | 469 std::string group_name = |
500 base::FieldTrialList::FindFullName("PasswordManagerUI"); | 470 base::FieldTrialList::FindFullName("PasswordManagerUI"); |
501 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 471 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
502 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 472 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
503 return false; | 473 return false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 if (!entry) | 518 if (!entry) |
549 return GURL::EmptyGURL(); | 519 return GURL::EmptyGURL(); |
550 | 520 |
551 return entry->GetURL(); | 521 return entry->GetURL(); |
552 } | 522 } |
553 | 523 |
554 const password_manager::CredentialsFilter* | 524 const password_manager::CredentialsFilter* |
555 ChromePasswordManagerClient::GetStoreResultFilter() const { | 525 ChromePasswordManagerClient::GetStoreResultFilter() const { |
556 return &credentials_filter_; | 526 return &credentials_filter_; |
557 } | 527 } |
| 528 |
| 529 const password_manager::LogManager* ChromePasswordManagerClient::GetLogManager() |
| 530 const { |
| 531 return log_manager_.get(); |
| 532 } |
OLD | NEW |