ios_password_manager_driver.mm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #import "components/password_manager/ios/ios_password_manager_driver.h"
  5. #include <string>
  6. #include "components/autofill/core/common/password_form_fill_data.h"
  7. #include "components/password_manager/core/browser/password_generation_frame_helper.h"
  8. #include "components/password_manager/core/browser/password_manager.h"
  9. #if !defined(__has_feature) || !__has_feature(objc_arc)
  10. #error "This file requires ARC support."
  11. #endif
  12. using password_manager::PasswordAutofillManager;
  13. using password_manager::PasswordManager;
  14. IOSPasswordManagerDriver::IOSPasswordManagerDriver(
  15. id<PasswordManagerDriverBridge> bridge,
  16. password_manager::PasswordManager* password_manager)
  17. : bridge_(bridge), password_manager_(password_manager) {
  18. password_generation_helper_ =
  19. std::make_unique<password_manager::PasswordGenerationFrameHelper>(
  20. password_manager_->client(), this);
  21. }
  22. IOSPasswordManagerDriver::~IOSPasswordManagerDriver() = default;
  23. int IOSPasswordManagerDriver::GetId() const {
  24. // There is only one driver per tab on iOS so returning 0 is fine.
  25. return 0;
  26. }
  27. void IOSPasswordManagerDriver::FillPasswordForm(
  28. const autofill::PasswordFormFillData& form_data) {
  29. [bridge_ fillPasswordForm:form_data completionHandler:nil];
  30. }
  31. void IOSPasswordManagerDriver::InformNoSavedCredentials(
  32. bool should_show_popup_without_passwords) {
  33. [bridge_ onNoSavedCredentials];
  34. }
  35. void IOSPasswordManagerDriver::FormEligibleForGenerationFound(
  36. const autofill::PasswordFormGenerationData& form) {
  37. if (GetPasswordGenerationHelper() &&
  38. GetPasswordGenerationHelper()->IsGenerationEnabled(
  39. /*log_debug_data*/ true)) {
  40. [bridge_ formEligibleForGenerationFound:form];
  41. }
  42. }
  43. void IOSPasswordManagerDriver::GeneratedPasswordAccepted(
  44. const std::u16string& password) {
  45. NOTIMPLEMENTED();
  46. }
  47. void IOSPasswordManagerDriver::FillSuggestion(const std::u16string& username,
  48. const std::u16string& password) {
  49. NOTIMPLEMENTED();
  50. }
  51. void IOSPasswordManagerDriver::PreviewSuggestion(
  52. const std::u16string& username,
  53. const std::u16string& password) {
  54. NOTIMPLEMENTED();
  55. }
  56. void IOSPasswordManagerDriver::ClearPreviewedForm() {
  57. NOTIMPLEMENTED();
  58. }
  59. password_manager::PasswordGenerationFrameHelper*
  60. IOSPasswordManagerDriver::GetPasswordGenerationHelper() {
  61. return password_generation_helper_.get();
  62. }
  63. PasswordManager* IOSPasswordManagerDriver::GetPasswordManager() {
  64. return password_manager_;
  65. }
  66. PasswordAutofillManager*
  67. IOSPasswordManagerDriver::GetPasswordAutofillManager() {
  68. // TODO(crbug.com/341877): Use PasswordAutofillManager to implement password
  69. // autofill on iOS.
  70. return nullptr;
  71. }
  72. bool IOSPasswordManagerDriver::IsInPrimaryMainFrame() const {
  73. // On IOS only processing of password forms in main frame is implemented.
  74. return true;
  75. }
  76. bool IOSPasswordManagerDriver::CanShowAutofillUi() const {
  77. return true;
  78. }
  79. ::ui::AXTreeID IOSPasswordManagerDriver::GetAxTreeId() const {
  80. return {};
  81. }
  82. const GURL& IOSPasswordManagerDriver::GetLastCommittedURL() const {
  83. return bridge_.lastCommittedURL;
  84. }