OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/passwords/password_controller.h" | 5 #import "ios/chrome/browser/passwords/password_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
28 #include "components/password_manager/core/browser/password_generation_manager.h
" | 28 #include "components/password_manager/core/browser/password_generation_manager.h
" |
29 #include "components/password_manager/core/browser/password_manager.h" | 29 #include "components/password_manager/core/browser/password_manager.h" |
30 #include "components/password_manager/core/browser/password_manager_client.h" | 30 #include "components/password_manager/core/browser/password_manager_client.h" |
31 #include "components/password_manager/core/browser/password_manager_driver.h" | 31 #include "components/password_manager/core/browser/password_manager_driver.h" |
32 #include "components/sync_driver/sync_service.h" | 32 #include "components/sync_driver/sync_service.h" |
33 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 33 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
34 #include "ios/chrome/browser/experimental_flags.h" | 34 #include "ios/chrome/browser/experimental_flags.h" |
35 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" | 35 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
36 #import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.
h" | 36 #import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.
h" |
| 37 #import "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegat
e.h" |
37 #import "ios/chrome/browser/passwords/js_password_manager.h" | 38 #import "ios/chrome/browser/passwords/js_password_manager.h" |
38 #import "ios/chrome/browser/passwords/password_generation_agent.h" | 39 #import "ios/chrome/browser/passwords/password_generation_agent.h" |
39 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 40 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
40 #include "ios/web/public/url_scheme_util.h" | 41 #include "ios/web/public/url_scheme_util.h" |
41 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 42 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
42 #import "ios/web/public/web_state/web_state.h" | 43 #import "ios/web/public/web_state/web_state.h" |
43 #include "url/gurl.h" | 44 #include "url/gurl.h" |
44 | 45 |
45 using password_manager::PasswordFormManager; | 46 using password_manager::PasswordFormManager; |
46 using password_manager::PasswordGenerationManager; | 47 using password_manager::PasswordGenerationManager; |
47 using password_manager::PasswordManager; | 48 using password_manager::PasswordManager; |
48 using password_manager::PasswordManagerClient; | 49 using password_manager::PasswordManagerClient; |
49 using password_manager::PasswordManagerDriver; | 50 using password_manager::PasswordManagerDriver; |
50 | 51 |
| 52 namespace { |
| 53 // Types of password infobars to display. |
| 54 enum class PasswordInfoBarType { SAVE, UPDATE }; |
| 55 } |
| 56 |
51 @interface PasswordController () | 57 @interface PasswordController () |
52 | 58 |
53 // This is set to YES as soon as the associated WebState is destroyed. | 59 // This is set to YES as soon as the associated WebState is destroyed. |
54 @property(readonly) BOOL isWebStateDestroyed; | 60 @property(readonly) BOOL isWebStateDestroyed; |
55 | 61 |
56 @end | 62 @end |
57 | 63 |
58 @interface PasswordController ()<FormSuggestionProvider> | 64 @interface PasswordController ()<FormSuggestionProvider> |
59 | 65 |
60 // Parses the |jsonString| which contatins the password forms found on a web | 66 // Parses the |jsonString| which contatins the password forms found on a web |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 const autofill::PasswordForm& form)) | 105 const autofill::PasswordForm& form)) |
100 completionHandler; | 106 completionHandler; |
101 | 107 |
102 // Takes values from a JSON |dictionary| and populates the |form|. | 108 // Takes values from a JSON |dictionary| and populates the |form|. |
103 // The |pageLocation| is the URL of the current page. | 109 // The |pageLocation| is the URL of the current page. |
104 // Returns YES if the form was correctly populated, NO otherwise. | 110 // Returns YES if the form was correctly populated, NO otherwise. |
105 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form | 111 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form |
106 fromDictionary:(const base::DictionaryValue*)dictionary | 112 fromDictionary:(const base::DictionaryValue*)dictionary |
107 pageURL:(const GURL&)pageLocation; | 113 pageURL:(const GURL&)pageLocation; |
108 | 114 |
| 115 // Displays infobar for |form| with |type|. If |type| is UPDATE, the user |
| 116 // is prompted to update the password. If |type| is SAVE, the user is prompted |
| 117 // to save the password. |
| 118 - (void)showInfoBarForForm:(std::unique_ptr<PasswordFormManager>)form |
| 119 infoBarType:(PasswordInfoBarType)type; |
| 120 |
109 @end | 121 @end |
110 | 122 |
111 namespace { | 123 namespace { |
112 | 124 |
113 // Constructs an array of FormSuggestions, each corresponding to a username/ | 125 // Constructs an array of FormSuggestions, each corresponding to a username/ |
114 // password pair in |formFillData|, such that |prefix| is a prefix of the | 126 // password pair in |formFillData|, such that |prefix| is a prefix of the |
115 // username of each suggestion. | 127 // username of each suggestion. |
116 NSArray* BuildSuggestions(const autofill::PasswordFormFillData& formFillData, | 128 NSArray* BuildSuggestions(const autofill::PasswordFormFillData& formFillData, |
117 NSString* prefix) { | 129 NSString* prefix) { |
118 NSMutableArray* suggestions = [NSMutableArray array]; | 130 NSMutableArray* suggestions = [NSMutableArray array]; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 withUsername:username | 621 withUsername:username |
610 password:password | 622 password:password |
611 completionHandler:^(BOOL success) { | 623 completionHandler:^(BOOL success) { |
612 completion(); | 624 completion(); |
613 }]; | 625 }]; |
614 } else { | 626 } else { |
615 completion(); | 627 completion(); |
616 } | 628 } |
617 } | 629 } |
618 | 630 |
| 631 #pragma mark - PasswordManagerClientDelegate |
| 632 |
| 633 - (void)showSavePasswordInfoBar: |
| 634 (std::unique_ptr<PasswordFormManager>)formToSave { |
| 635 [self showInfoBarForForm:std::move(formToSave) |
| 636 infoBarType:PasswordInfoBarType::SAVE]; |
| 637 } |
| 638 |
| 639 - (void)showUpdatePasswordInfoBar: |
| 640 (std::unique_ptr<PasswordFormManager>)formToUpdate { |
| 641 [self showInfoBarForForm:std::move(formToUpdate) |
| 642 infoBarType:PasswordInfoBarType::UPDATE]; |
| 643 } |
| 644 |
619 #pragma mark - | 645 #pragma mark - |
620 #pragma mark WebPasswordFormData Adaptation | 646 #pragma mark WebPasswordFormData Adaptation |
621 | 647 |
622 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form | 648 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form |
623 fromDictionary:(const base::DictionaryValue*)dictionary | 649 fromDictionary:(const base::DictionaryValue*)dictionary |
624 pageURL:(const GURL&)pageLocation { | 650 pageURL:(const GURL&)pageLocation { |
625 DCHECK(form); | 651 DCHECK(form); |
626 DCHECK(dictionary); | 652 DCHECK(dictionary); |
627 DCHECK(pageLocation.is_valid()); | 653 DCHECK(pageLocation.is_valid()); |
628 | 654 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 773 } |
748 autofill::FormFieldData field; | 774 autofill::FormFieldData field; |
749 field.name = std::move(element); | 775 field.name = std::move(element); |
750 field.form_control_type = base::UTF16ToUTF8(type); | 776 field.form_control_type = base::UTF16ToUTF8(type); |
751 form->form_data.fields.push_back(field); | 777 form->form_data.fields.push_back(field); |
752 } | 778 } |
753 | 779 |
754 return YES; | 780 return YES; |
755 } | 781 } |
756 | 782 |
757 - (void)showSavePasswordInfoBar: | |
758 (std::unique_ptr<PasswordFormManager>)formToSave { | |
759 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) | |
760 return; | |
761 | |
762 bool isSmartLockBrandingEnabled = false; | |
763 if (self.browserState) { | |
764 sync_driver::SyncService* sync_service = | |
765 IOSChromeProfileSyncServiceFactory::GetForBrowserState( | |
766 self.browserState); | |
767 isSmartLockBrandingEnabled = | |
768 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( | |
769 sync_service); | |
770 } | |
771 infobars::InfoBarManager* infoBarManager = | |
772 InfoBarManagerImpl::FromWebState(webStateObserverBridge_->web_state()); | |
773 IOSChromeSavePasswordInfoBarDelegate::Create( | |
774 isSmartLockBrandingEnabled, infoBarManager, std::move(formToSave)); | |
775 } | |
776 | |
777 - (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData | 783 - (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData |
778 withUsername:(const base::string16&)username | 784 withUsername:(const base::string16&)username |
779 password:(const base::string16&)password | 785 password:(const base::string16&)password |
780 completionHandler:(void (^)(BOOL))completionHandler { | 786 completionHandler:(void (^)(BOOL))completionHandler { |
781 // Send JSON over to the web view. | 787 // Send JSON over to the web view. |
782 [passwordJsManager_ fillPasswordForm:SerializePasswordFormFillData(formData) | 788 [passwordJsManager_ fillPasswordForm:SerializePasswordFormFillData(formData) |
783 withUsername:base::SysUTF16ToNSString(username) | 789 withUsername:base::SysUTF16ToNSString(username) |
784 password:base::SysUTF16ToNSString(password) | 790 password:base::SysUTF16ToNSString(password) |
785 completionHandler:^(BOOL result) { | 791 completionHandler:^(BOOL result) { |
786 if (completionHandler) | 792 if (completionHandler) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 } | 828 } |
823 | 829 |
824 - (PasswordManager*)passwordManager { | 830 - (PasswordManager*)passwordManager { |
825 return passwordManager_.get(); | 831 return passwordManager_.get(); |
826 } | 832 } |
827 | 833 |
828 - (JsPasswordManager*)passwordJsManager { | 834 - (JsPasswordManager*)passwordJsManager { |
829 return passwordJsManager_; | 835 return passwordJsManager_; |
830 } | 836 } |
831 | 837 |
| 838 #pragma mark - Private methods |
| 839 |
| 840 - (void)showInfoBarForForm:(std::unique_ptr<PasswordFormManager>)form |
| 841 infoBarType:(PasswordInfoBarType)type { |
| 842 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) |
| 843 return; |
| 844 |
| 845 bool isSmartLockBrandingEnabled = false; |
| 846 if (self.browserState) { |
| 847 sync_driver::SyncService* sync_service = |
| 848 IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
| 849 self.browserState); |
| 850 isSmartLockBrandingEnabled = |
| 851 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( |
| 852 sync_service); |
| 853 } |
| 854 infobars::InfoBarManager* infoBarManager = |
| 855 InfoBarManagerImpl::FromWebState(webStateObserverBridge_->web_state()); |
| 856 |
| 857 switch (type) { |
| 858 case PasswordInfoBarType::SAVE: |
| 859 IOSChromeSavePasswordInfoBarDelegate::Create( |
| 860 isSmartLockBrandingEnabled, infoBarManager, std::move(form)); |
| 861 break; |
| 862 |
| 863 case PasswordInfoBarType::UPDATE: |
| 864 IOSChromeUpdatePasswordInfoBarDelegate::Create( |
| 865 isSmartLockBrandingEnabled, infoBarManager, std::move(form)); |
| 866 break; |
| 867 } |
| 868 } |
| 869 |
832 @end | 870 @end |
OLD | NEW |