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_)), |
142 log_manager_(password_manager::LogManager::Create( | |
143 GetLogRouter(), | |
144 base::Bind(&ChromePasswordManagerClient:: | |
145 NotifyDriversAboutLoggingAvailability, | |
146 base::Unretained(this)))) { | |
143 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 147 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
144 autofill_client); | 148 autofill_client); |
145 driver_factory_ = | 149 driver_factory_ = |
146 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 150 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
147 | 151 |
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( | 152 saving_and_filling_passwords_enabled_.Init( |
153 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); | 153 password_manager::prefs::kPasswordManagerSavingEnabled, GetPrefs()); |
154 ReportMetrics(*saving_and_filling_passwords_enabled_, this, profile_); | 154 ReportMetrics(*saving_and_filling_passwords_enabled_, this, profile_); |
155 NotifyDriversAboutLoggingAvailability(log_manager_->IsLoggingActive()); | |
155 } | 156 } |
156 | 157 |
157 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 158 ChromePasswordManagerClient::~ChromePasswordManagerClient() {} |
158 PasswordManagerInternalsService* service = | |
159 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | |
160 if (service) | |
161 service->UnregisterClient(this); | |
162 } | |
163 | 159 |
164 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { | 160 bool ChromePasswordManagerClient::IsAutomaticPasswordSavingEnabled() const { |
165 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 161 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
166 password_manager::switches::kEnableAutomaticPasswordSaving) && | 162 password_manager::switches::kEnableAutomaticPasswordSaving) && |
167 chrome::GetChannel() == version_info::Channel::UNKNOWN; | 163 chrome::GetChannel() == version_info::Channel::UNKNOWN; |
168 } | 164 } |
169 | 165 |
170 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() | 166 bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage() |
171 const { | 167 const { |
172 DCHECK(web_contents()); | 168 DCHECK(web_contents()); |
173 content::NavigationEntry* entry = | 169 content::NavigationEntry* entry = |
174 web_contents()->GetController().GetLastCommittedEntry(); | 170 web_contents()->GetController().GetLastCommittedEntry(); |
175 bool is_enabled = false; | 171 bool is_enabled = false; |
176 if (!entry) { | 172 if (!entry) { |
177 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. | 173 // TODO(gcasto): Determine if fix for crbug.com/388246 is relevant here. |
178 is_enabled = true; | 174 is_enabled = true; |
179 } else if (EnabledForSyncSignin()) { | 175 } else if (EnabledForSyncSignin()) { |
180 is_enabled = true; | 176 is_enabled = true; |
181 } else { | 177 } else { |
182 // Do not fill nor save password when a user is signing in for sync. This | 178 // 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 | 179 // is because users need to remember their password if they are syncing as |
184 // this is effectively their master password. | 180 // this is effectively their master password. |
185 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; | 181 is_enabled = entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; |
186 } | 182 } |
187 if (IsLoggingActive()) { | 183 if (log_manager_->IsLoggingActive()) { |
188 password_manager::BrowserSavePasswordProgressLogger logger(this); | 184 password_manager::BrowserSavePasswordProgressLogger logger( |
185 log_manager_.get()); | |
189 logger.LogBoolean( | 186 logger.LogBoolean( |
190 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, | 187 Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE, |
191 is_enabled); | 188 is_enabled); |
192 } | 189 } |
193 return is_enabled; | 190 return is_enabled; |
194 } | 191 } |
195 | 192 |
196 bool ChromePasswordManagerClient::IsSavingAndFillingEnabledForCurrentPage() | 193 bool ChromePasswordManagerClient::IsSavingAndFillingEnabledForCurrentPage() |
197 const { | 194 const { |
198 // TODO(melandory): remove saving_and_filling_passwords_enabled_ check from | 195 // 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(); | 312 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); |
316 } | 313 } |
317 | 314 |
318 password_manager::PasswordSyncState | 315 password_manager::PasswordSyncState |
319 ChromePasswordManagerClient::GetPasswordSyncState() const { | 316 ChromePasswordManagerClient::GetPasswordSyncState() const { |
320 const ProfileSyncService* sync_service = | 317 const ProfileSyncService* sync_service = |
321 ProfileSyncServiceFactory::GetForProfile(profile_); | 318 ProfileSyncServiceFactory::GetForProfile(profile_); |
322 return password_manager_util::GetPasswordSyncState(sync_service); | 319 return password_manager_util::GetPasswordSyncState(sync_service); |
323 } | 320 } |
324 | 321 |
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 { | 322 bool ChromePasswordManagerClient::WasLastNavigationHTTPError() const { |
351 DCHECK(web_contents()); | 323 DCHECK(web_contents()); |
352 | 324 |
353 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; | 325 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; |
354 if (IsLoggingActive()) { | 326 if (log_manager_->IsLoggingActive()) { |
355 logger.reset(new password_manager::BrowserSavePasswordProgressLogger(this)); | 327 logger.reset(new password_manager::BrowserSavePasswordProgressLogger( |
328 log_manager_.get())); | |
356 logger->LogMessage( | 329 logger->LogMessage( |
357 Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD); | 330 Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD); |
358 } | 331 } |
359 | 332 |
360 content::NavigationEntry* entry = | 333 content::NavigationEntry* entry = |
361 web_contents()->GetController().GetVisibleEntry(); | 334 web_contents()->GetController().GetVisibleEntry(); |
362 if (!entry) | 335 if (!entry) |
363 return false; | 336 return false; |
364 int http_status_code = entry->GetHttpStatusCode(); | 337 int http_status_code = entry->GetHttpStatusCode(); |
365 | 338 |
366 if (logger) | 339 if (logger) |
367 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); | 340 logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code); |
368 | 341 |
369 if (http_status_code >= 400 && http_status_code < 600) | 342 if (http_status_code >= 400 && http_status_code < 600) |
370 return true; | 343 return true; |
371 return false; | 344 return false; |
372 } | 345 } |
373 | 346 |
374 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { | 347 bool ChromePasswordManagerClient::DidLastPageLoadEncounterSSLErrors() const { |
375 content::NavigationEntry* entry = | 348 content::NavigationEntry* entry = |
376 web_contents()->GetController().GetLastCommittedEntry(); | 349 web_contents()->GetController().GetLastCommittedEntry(); |
377 bool ssl_errors = true; | 350 bool ssl_errors = true; |
378 if (!entry) { | 351 if (!entry) { |
379 ssl_errors = false; | 352 ssl_errors = false; |
380 } else { | 353 } else { |
381 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); | 354 ssl_errors = net::IsCertStatusError(entry->GetSSL().cert_status); |
382 } | 355 } |
383 if (IsLoggingActive()) { | 356 if (log_manager_->IsLoggingActive()) { |
384 password_manager::BrowserSavePasswordProgressLogger logger(this); | 357 password_manager::BrowserSavePasswordProgressLogger logger( |
358 log_manager_.get()); | |
385 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); | 359 logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors); |
386 } | 360 } |
387 return ssl_errors; | 361 return ssl_errors; |
388 } | 362 } |
389 | 363 |
390 bool ChromePasswordManagerClient::IsOffTheRecord() const { | 364 bool ChromePasswordManagerClient::IsOffTheRecord() const { |
391 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 365 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
392 } | 366 } |
393 | 367 |
394 const password_manager::PasswordManager* | 368 const password_manager::PasswordManager* |
(...skipping 27 matching lines...) Expand all Loading... | |
422 ShowPasswordGenerationPopup) | 396 ShowPasswordGenerationPopup) |
423 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 397 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
424 ShowPasswordEditingPopup) | 398 ShowPasswordEditingPopup) |
425 IPC_END_MESSAGE_MAP() | 399 IPC_END_MESSAGE_MAP() |
426 | 400 |
427 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 401 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
428 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 402 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
429 HidePasswordGenerationPopup) | 403 HidePasswordGenerationPopup) |
430 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, | 404 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, |
431 GenerationAvailableForForm) | 405 GenerationAvailableForForm) |
432 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | |
vasilii
2015/11/13 12:17:31
What happened to this message?
vabr (Chromium)
2015/11/13 20:48:18
It is handled by the driver. This is the very core
| |
433 NotifyRendererOfLoggingAvailability) | |
434 // Default: | 406 // Default: |
435 IPC_MESSAGE_UNHANDLED(handled = false) | 407 IPC_MESSAGE_UNHANDLED(handled = false) |
436 IPC_END_MESSAGE_MAP() | 408 IPC_END_MESSAGE_MAP() |
437 | 409 |
438 return handled; | 410 return handled; |
439 } | 411 } |
440 | 412 |
441 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 413 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
442 const gfx::RectF& bounds) { | 414 const gfx::RectF& bounds) { |
443 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 415 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 driver_factory_->GetDriverForFrame(render_frame_host), observer_, | 447 driver_factory_->GetDriverForFrame(render_frame_host), observer_, |
476 web_contents(), web_contents()->GetNativeView()); | 448 web_contents(), web_contents()->GetNativeView()); |
477 popup_controller_->Show(false /* display_password */); | 449 popup_controller_->Show(false /* display_password */); |
478 } | 450 } |
479 | 451 |
480 void ChromePasswordManagerClient::GenerationAvailableForForm( | 452 void ChromePasswordManagerClient::GenerationAvailableForForm( |
481 const autofill::PasswordForm& form) { | 453 const autofill::PasswordForm& form) { |
482 password_manager_.GenerationAvailableForForm(form); | 454 password_manager_.GenerationAvailableForForm(form); |
483 } | 455 } |
484 | 456 |
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() { | 457 bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() { |
495 #if defined(OS_ANDROID) | 458 #if defined(OS_ANDROID) |
496 return false; | 459 return false; |
497 #elif defined(OS_MACOSX) | 460 #elif defined(OS_MACOSX) |
498 // Query the group first for correct UMA reporting. | 461 // Query the group first for correct UMA reporting. |
499 std::string group_name = | 462 std::string group_name = |
500 base::FieldTrialList::FindFullName("PasswordManagerUI"); | 463 base::FieldTrialList::FindFullName("PasswordManagerUI"); |
501 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 464 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
502 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) | 465 if (command_line->HasSwitch(switches::kDisableSavePasswordBubble)) |
503 return false; | 466 return false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 if (!entry) | 511 if (!entry) |
549 return GURL::EmptyGURL(); | 512 return GURL::EmptyGURL(); |
550 | 513 |
551 return entry->GetURL(); | 514 return entry->GetURL(); |
552 } | 515 } |
553 | 516 |
554 const password_manager::CredentialsFilter* | 517 const password_manager::CredentialsFilter* |
555 ChromePasswordManagerClient::GetStoreResultFilter() const { | 518 ChromePasswordManagerClient::GetStoreResultFilter() const { |
556 return &credentials_filter_; | 519 return &credentials_filter_; |
557 } | 520 } |
521 | |
522 const password_manager::LogManager* ChromePasswordManagerClient::GetLogManager() | |
523 const { | |
524 return log_manager_.get(); | |
525 } | |
526 | |
527 password_manager::LogRouter* ChromePasswordManagerClient::GetLogRouter() const { | |
528 if (web_contents()->GetWebUI()) | |
529 return nullptr; | |
530 return password_manager::PasswordManagerInternalsServiceFactory:: | |
531 GetForBrowserContext(profile_); | |
532 } | |
533 | |
534 void ChromePasswordManagerClient::NotifyDriversAboutLoggingAvailability( | |
535 bool is_available) { | |
536 driver_factory_->NotifyDriversAboutLoggingAvailability(is_available); | |
537 } | |
OLD | NEW |