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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
23 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " | 23 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " |
24 #include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h" | 24 #include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h" |
25 #include "chrome/common/channel_info.h" | 25 #include "chrome/common/channel_info.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/features.h" | 27 #include "chrome/common/features.h" |
28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
29 #include "components/autofill/content/browser/content_autofill_driver.h" | 29 #include "components/autofill/content/browser/content_autofill_driver.h" |
30 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 30 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
31 #include "components/autofill/content/common/autofill_messages.h" | |
32 #include "components/autofill/core/browser/password_generator.h" | 31 #include "components/autofill/core/browser/password_generator.h" |
33 #include "components/autofill/core/common/password_form.h" | 32 #include "components/autofill/core/common/password_form.h" |
34 #include "components/browser_sync/profile_sync_service.h" | 33 #include "components/browser_sync/profile_sync_service.h" |
35 #include "components/password_manager/content/browser/content_password_manager_d river.h" | 34 #include "components/password_manager/content/browser/content_password_manager_d river.h" |
36 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 35 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
37 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" | 36 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" |
38 #include "components/password_manager/core/browser/log_manager.h" | 37 #include "components/password_manager/core/browser/log_manager.h" |
39 #include "components/password_manager/core/browser/log_receiver.h" | 38 #include "components/password_manager/core/browser/log_receiver.h" |
40 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 39 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
41 #include "components/password_manager/core/browser/password_form_manager.h" | 40 #include "components/password_manager/core/browser/password_form_manager.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 } | 134 } |
136 | 135 |
137 ChromePasswordManagerClient::ChromePasswordManagerClient( | 136 ChromePasswordManagerClient::ChromePasswordManagerClient( |
138 content::WebContents* web_contents, | 137 content::WebContents* web_contents, |
139 autofill::AutofillClient* autofill_client) | 138 autofill::AutofillClient* autofill_client) |
140 : content::WebContentsObserver(web_contents), | 139 : content::WebContentsObserver(web_contents), |
141 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 140 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
142 password_manager_(this), | 141 password_manager_(this), |
143 driver_factory_(nullptr), | 142 driver_factory_(nullptr), |
144 credential_manager_impl_(web_contents, this), | 143 credential_manager_impl_(web_contents, this), |
144 password_manager_client_bindings_(web_contents, this), | |
Ken Rockot(use gerrit already)
2016/09/20 18:26:19
Looks like you're hitting DCHECKs on construction
leonhsl(Using Gerrit)
2016/09/21 11:46:57
Yeah this is because another mock ChromePasswordMa
| |
145 observer_(nullptr), | 145 observer_(nullptr), |
146 credentials_filter_(this, | 146 credentials_filter_(this, |
147 base::Bind(&GetSyncService, profile_), | 147 base::Bind(&GetSyncService, profile_), |
148 base::Bind(&GetSigninManager, profile_)) { | 148 base::Bind(&GetSigninManager, profile_)) { |
149 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, | 149 ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this, |
150 autofill_client); | 150 autofill_client); |
151 driver_factory_ = | 151 driver_factory_ = |
152 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); | 152 ContentPasswordManagerDriverFactory::FromWebContents(web_contents); |
153 log_manager_ = password_manager::LogManager::Create( | 153 log_manager_ = password_manager::LogManager::Create( |
154 password_manager::PasswordManagerInternalsServiceFactory:: | 154 password_manager::PasswordManagerInternalsServiceFactory:: |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 ? factory->DriverForFrame(web_contents()->GetMainFrame()) | 453 ? factory->DriverForFrame(web_contents()->GetMainFrame()) |
454 ->autofill_manager() | 454 ->autofill_manager() |
455 : nullptr; | 455 : nullptr; |
456 } | 456 } |
457 | 457 |
458 void ChromePasswordManagerClient::SetTestObserver( | 458 void ChromePasswordManagerClient::SetTestObserver( |
459 autofill::PasswordGenerationPopupObserver* observer) { | 459 autofill::PasswordGenerationPopupObserver* observer) { |
460 observer_ = observer; | 460 observer_ = observer; |
461 } | 461 } |
462 | 462 |
463 bool ChromePasswordManagerClient::OnMessageReceived( | |
464 const IPC::Message& message, | |
465 content::RenderFrameHost* render_frame_host) { | |
466 bool handled = true; | |
467 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ChromePasswordManagerClient, message, | |
468 render_frame_host) | |
469 // Autofill messages: | |
470 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | |
471 ShowPasswordGenerationPopup) | |
472 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | |
473 ShowPasswordEditingPopup) | |
474 IPC_END_MESSAGE_MAP() | |
475 | |
476 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | |
477 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | |
478 HidePasswordGenerationPopup) | |
479 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, | |
480 GenerationAvailableForForm) | |
481 // Default: | |
482 IPC_MESSAGE_UNHANDLED(handled = false) | |
483 IPC_END_MESSAGE_MAP() | |
484 | |
485 return handled; | |
486 } | |
487 | |
488 void ChromePasswordManagerClient::DidStartNavigation( | 463 void ChromePasswordManagerClient::DidStartNavigation( |
489 content::NavigationHandle* navigation_handle) { | 464 content::NavigationHandle* navigation_handle) { |
490 // Logging has no sense on WebUI sites. | 465 // Logging has no sense on WebUI sites. |
491 log_manager_->SetSuspended(web_contents()->GetWebUI() != nullptr); | 466 log_manager_->SetSuspended(web_contents()->GetWebUI() != nullptr); |
492 } | 467 } |
493 | 468 |
494 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 469 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
495 const gfx::RectF& bounds) { | 470 const gfx::RectF& bounds) { |
496 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 471 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
497 return bounds + client_area.OffsetFromOrigin(); | 472 return bounds + client_area.OffsetFromOrigin(); |
498 } | 473 } |
499 | 474 |
500 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 475 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
501 content::RenderFrameHost* render_frame_host, | |
502 const gfx::RectF& bounds, | 476 const gfx::RectF& bounds, |
503 int max_length, | 477 int max_length, |
504 const base::string16& generation_element, | 478 const base::string16& generation_element, |
505 bool is_manually_triggered, | 479 bool is_manually_triggered, |
506 const autofill::PasswordForm& form) { | 480 const autofill::PasswordForm& form) { |
507 // TODO(gcasto): Validate data in PasswordForm. | 481 // TODO(gcasto): Validate data in PasswordForm. |
508 | 482 |
509 auto* driver = driver_factory_->GetDriverForFrame(render_frame_host); | 483 auto* driver = driver_factory_->GetDriverForFrame( |
484 password_manager_client_bindings_.GetCurrentTargetFrame()); | |
510 password_manager_.SetGenerationElementAndReasonForForm( | 485 password_manager_.SetGenerationElementAndReasonForForm( |
511 driver, form, generation_element, is_manually_triggered); | 486 driver, form, generation_element, is_manually_triggered); |
512 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 487 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
513 | 488 |
514 popup_controller_ = | 489 popup_controller_ = |
515 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 490 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
516 popup_controller_, element_bounds_in_screen_space, form, max_length, | 491 popup_controller_, element_bounds_in_screen_space, form, max_length, |
517 &password_manager_, driver, observer_, web_contents(), | 492 &password_manager_, driver, observer_, web_contents(), |
518 web_contents()->GetNativeView()); | 493 web_contents()->GetNativeView()); |
519 popup_controller_->Show(true /* display_password */); | 494 popup_controller_->Show(true /* display_password */); |
520 } | 495 } |
521 | 496 |
522 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 497 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
523 content::RenderFrameHost* render_frame_host, | |
524 const gfx::RectF& bounds, | 498 const gfx::RectF& bounds, |
525 const autofill::PasswordForm& form) { | 499 const autofill::PasswordForm& form) { |
526 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 500 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
527 popup_controller_ = | 501 popup_controller_ = |
528 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 502 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
529 popup_controller_, element_bounds_in_screen_space, form, | 503 popup_controller_, element_bounds_in_screen_space, form, |
530 0, // Unspecified max length. | 504 0, // Unspecified max length. |
531 &password_manager_, | 505 &password_manager_, |
532 driver_factory_->GetDriverForFrame(render_frame_host), observer_, | 506 driver_factory_->GetDriverForFrame( |
533 web_contents(), web_contents()->GetNativeView()); | 507 password_manager_client_bindings_.GetCurrentTargetFrame()), |
508 observer_, web_contents(), web_contents()->GetNativeView()); | |
534 popup_controller_->Show(false /* display_password */); | 509 popup_controller_->Show(false /* display_password */); |
535 } | 510 } |
536 | 511 |
537 void ChromePasswordManagerClient::PromptUserToEnableAutosigninIfNecessary() { | 512 void ChromePasswordManagerClient::PromptUserToEnableAutosigninIfNecessary() { |
538 if (!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 513 if (!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
539 GetPrefs()) || | 514 GetPrefs()) || |
540 !GetPrefs()->GetBoolean( | 515 !GetPrefs()->GetBoolean( |
541 password_manager::prefs::kCredentialsEnableAutosignin) || | 516 password_manager::prefs::kCredentialsEnableAutosignin) || |
542 IsOffTheRecord()) | 517 IsOffTheRecord()) |
543 return; | 518 return; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 password_manager::mojom::CredentialManagerRequest request) { | 607 password_manager::mojom::CredentialManagerRequest request) { |
633 content::WebContents* web_contents = | 608 content::WebContents* web_contents = |
634 content::WebContents::FromRenderFrameHost(render_frame_host); | 609 content::WebContents::FromRenderFrameHost(render_frame_host); |
635 DCHECK(web_contents); | 610 DCHECK(web_contents); |
636 | 611 |
637 ChromePasswordManagerClient* instance = | 612 ChromePasswordManagerClient* instance = |
638 ChromePasswordManagerClient::FromWebContents(web_contents); | 613 ChromePasswordManagerClient::FromWebContents(web_contents); |
639 DCHECK(instance); | 614 DCHECK(instance); |
640 instance->credential_manager_impl_.BindRequest(std::move(request)); | 615 instance->credential_manager_impl_.BindRequest(std::move(request)); |
641 } | 616 } |
OLD | NEW |