| 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), |
| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 ? factory->DriverForFrame(web_contents()->GetMainFrame()) | 448 ? factory->DriverForFrame(web_contents()->GetMainFrame()) |
| 449 ->autofill_manager() | 449 ->autofill_manager() |
| 450 : nullptr; | 450 : nullptr; |
| 451 } | 451 } |
| 452 | 452 |
| 453 void ChromePasswordManagerClient::SetTestObserver( | 453 void ChromePasswordManagerClient::SetTestObserver( |
| 454 autofill::PasswordGenerationPopupObserver* observer) { | 454 autofill::PasswordGenerationPopupObserver* observer) { |
| 455 observer_ = observer; | 455 observer_ = observer; |
| 456 } | 456 } |
| 457 | 457 |
| 458 bool ChromePasswordManagerClient::OnMessageReceived( | |
| 459 const IPC::Message& message, | |
| 460 content::RenderFrameHost* render_frame_host) { | |
| 461 bool handled = true; | |
| 462 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ChromePasswordManagerClient, message, | |
| 463 render_frame_host) | |
| 464 // Autofill messages: | |
| 465 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | |
| 466 ShowPasswordGenerationPopup) | |
| 467 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | |
| 468 ShowPasswordEditingPopup) | |
| 469 IPC_END_MESSAGE_MAP() | |
| 470 | |
| 471 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | |
| 472 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | |
| 473 HidePasswordGenerationPopup) | |
| 474 IPC_MESSAGE_HANDLER(AutofillHostMsg_GenerationAvailableForForm, | |
| 475 GenerationAvailableForForm) | |
| 476 // Default: | |
| 477 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 478 IPC_END_MESSAGE_MAP() | |
| 479 | |
| 480 return handled; | |
| 481 } | |
| 482 | |
| 483 void ChromePasswordManagerClient::DidStartNavigation( | 458 void ChromePasswordManagerClient::DidStartNavigation( |
| 484 content::NavigationHandle* navigation_handle) { | 459 content::NavigationHandle* navigation_handle) { |
| 485 // Logging has no sense on WebUI sites. | 460 // Logging has no sense on WebUI sites. |
| 486 log_manager_->SetSuspended(web_contents()->GetWebUI() != nullptr); | 461 log_manager_->SetSuspended(web_contents()->GetWebUI() != nullptr); |
| 487 } | 462 } |
| 488 | 463 |
| 489 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 464 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
| 490 const gfx::RectF& bounds) { | 465 const gfx::RectF& bounds) { |
| 491 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 466 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
| 492 return bounds + client_area.OffsetFromOrigin(); | 467 return bounds + client_area.OffsetFromOrigin(); |
| 493 } | 468 } |
| 494 | 469 |
| 495 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 470 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
| 496 content::RenderFrameHost* render_frame_host, | |
| 497 const gfx::RectF& bounds, | 471 const gfx::RectF& bounds, |
| 498 int max_length, | 472 int max_length, |
| 499 const base::string16& generation_element, | 473 const base::string16& generation_element, |
| 500 bool is_manually_triggered, | 474 bool is_manually_triggered, |
| 501 const autofill::PasswordForm& form) { | 475 const autofill::PasswordForm& form) { |
| 502 // TODO(gcasto): Validate data in PasswordForm. | 476 // TODO(gcasto): Validate data in PasswordForm. |
| 503 | 477 |
| 504 auto* driver = driver_factory_->GetDriverForFrame(render_frame_host); | 478 auto* driver = driver_factory_->GetDriverForFrame( |
| 479 password_manager_client_bindings_.GetCurrentTargetFrame()); |
| 505 password_manager_.SetGenerationElementAndReasonForForm( | 480 password_manager_.SetGenerationElementAndReasonForForm( |
| 506 driver, form, generation_element, is_manually_triggered); | 481 driver, form, generation_element, is_manually_triggered); |
| 507 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 482 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 508 | 483 |
| 509 popup_controller_ = | 484 popup_controller_ = |
| 510 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 485 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 511 popup_controller_, element_bounds_in_screen_space, form, max_length, | 486 popup_controller_, element_bounds_in_screen_space, form, max_length, |
| 512 &password_manager_, driver, observer_, web_contents(), | 487 &password_manager_, driver, observer_, web_contents(), |
| 513 web_contents()->GetNativeView()); | 488 web_contents()->GetNativeView()); |
| 514 popup_controller_->Show(true /* display_password */); | 489 popup_controller_->Show(true /* display_password */); |
| 515 } | 490 } |
| 516 | 491 |
| 517 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 492 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
| 518 content::RenderFrameHost* render_frame_host, | |
| 519 const gfx::RectF& bounds, | 493 const gfx::RectF& bounds, |
| 520 const autofill::PasswordForm& form) { | 494 const autofill::PasswordForm& form) { |
| 521 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 495 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
| 522 popup_controller_ = | 496 popup_controller_ = |
| 523 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 497 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
| 524 popup_controller_, element_bounds_in_screen_space, form, | 498 popup_controller_, element_bounds_in_screen_space, form, |
| 525 0, // Unspecified max length. | 499 0, // Unspecified max length. |
| 526 &password_manager_, | 500 &password_manager_, |
| 527 driver_factory_->GetDriverForFrame(render_frame_host), observer_, | 501 driver_factory_->GetDriverForFrame( |
| 528 web_contents(), web_contents()->GetNativeView()); | 502 password_manager_client_bindings_.GetCurrentTargetFrame()), |
| 503 observer_, web_contents(), web_contents()->GetNativeView()); |
| 529 popup_controller_->Show(false /* display_password */); | 504 popup_controller_->Show(false /* display_password */); |
| 530 } | 505 } |
| 531 | 506 |
| 532 void ChromePasswordManagerClient::PromptUserToEnableAutosigninIfNecessary() { | 507 void ChromePasswordManagerClient::PromptUserToEnableAutosigninIfNecessary() { |
| 533 if (!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 508 if (!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
| 534 GetPrefs()) || | 509 GetPrefs()) || |
| 535 !GetPrefs()->GetBoolean( | 510 !GetPrefs()->GetBoolean( |
| 536 password_manager::prefs::kCredentialsEnableAutosignin) || | 511 password_manager::prefs::kCredentialsEnableAutosignin) || |
| 537 IsOffTheRecord()) | 512 IsOffTheRecord()) |
| 538 return; | 513 return; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 ChromePasswordManagerClient::FromWebContents(web_contents); | 608 ChromePasswordManagerClient::FromWebContents(web_contents); |
| 634 | 609 |
| 635 // Try to bind to the driver, but if driver is not available for this render | 610 // Try to bind to the driver, but if driver is not available for this render |
| 636 // frame host, the request will be just dropped. This will cause the message | 611 // frame host, the request will be just dropped. This will cause the message |
| 637 // pipe to be closed, which will raise a connection error on the peer side. | 612 // pipe to be closed, which will raise a connection error on the peer side. |
| 638 if (!instance) | 613 if (!instance) |
| 639 return; | 614 return; |
| 640 | 615 |
| 641 instance->credential_manager_impl_.BindRequest(std::move(request)); | 616 instance->credential_manager_impl_.BindRequest(std::move(request)); |
| 642 } | 617 } |
| OLD | NEW |