Chromium Code Reviews| 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" | |
|
sdefresne
2016/07/05 13:29:55
I don't see this file in this CL nor in the reposi
Jackie Quinn
2016/07/05 13:52:35
It just landed earlier today: https://codereview.c
| |
| 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 |
| 46 namespace { | |
|
sdefresne
2016/07/05 13:29:55
Please move this after the "using" statements, and
Jackie Quinn
2016/07/05 13:52:35
Done.
| |
| 47 // Types of password infobars to display. | |
| 48 typedef NS_ENUM(BOOL, PasswordInfoBarType) { SAVE, UPDATE }; | |
|
sdefresne
2016/07/05 13:29:55
Since this is internal only and in an anonymous na
Jackie Quinn
2016/07/05 13:52:34
Done.
| |
| 49 } | |
| 45 using password_manager::PasswordFormManager; | 50 using password_manager::PasswordFormManager; |
| 46 using password_manager::PasswordGenerationManager; | 51 using password_manager::PasswordGenerationManager; |
| 47 using password_manager::PasswordManager; | 52 using password_manager::PasswordManager; |
| 48 using password_manager::PasswordManagerClient; | 53 using password_manager::PasswordManagerClient; |
| 49 using password_manager::PasswordManagerDriver; | 54 using password_manager::PasswordManagerDriver; |
| 50 | 55 |
| 51 @interface PasswordController () | 56 @interface PasswordController () |
| 52 | 57 |
| 53 // This is set to YES as soon as the associated WebState is destroyed. | 58 // This is set to YES as soon as the associated WebState is destroyed. |
| 54 @property(readonly) BOOL isWebStateDestroyed; | 59 @property(readonly) BOOL isWebStateDestroyed; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 const autofill::PasswordForm& form)) | 104 const autofill::PasswordForm& form)) |
| 100 completionHandler; | 105 completionHandler; |
| 101 | 106 |
| 102 // Takes values from a JSON |dictionary| and populates the |form|. | 107 // Takes values from a JSON |dictionary| and populates the |form|. |
| 103 // The |pageLocation| is the URL of the current page. | 108 // The |pageLocation| is the URL of the current page. |
| 104 // Returns YES if the form was correctly populated, NO otherwise. | 109 // Returns YES if the form was correctly populated, NO otherwise. |
| 105 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form | 110 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form |
| 106 fromDictionary:(const base::DictionaryValue*)dictionary | 111 fromDictionary:(const base::DictionaryValue*)dictionary |
| 107 pageURL:(const GURL&)pageLocation; | 112 pageURL:(const GURL&)pageLocation; |
| 108 | 113 |
| 114 // Displays infobar for |form| with |type|. If |type| is UPDATE, the user | |
| 115 // is prompted to update the password. If |type| is SAVE, the user is prompted | |
| 116 // to save the password. | |
| 117 - (void)showInfoBarForForm:(std::unique_ptr<PasswordFormManager>)form | |
| 118 infoBarType:(PasswordInfoBarType)type; | |
| 119 | |
| 109 @end | 120 @end |
| 110 | 121 |
| 111 namespace { | 122 namespace { |
| 112 | 123 |
| 113 // Constructs an array of FormSuggestions, each corresponding to a username/ | 124 // Constructs an array of FormSuggestions, each corresponding to a username/ |
| 114 // password pair in |formFillData|, such that |prefix| is a prefix of the | 125 // password pair in |formFillData|, such that |prefix| is a prefix of the |
| 115 // username of each suggestion. | 126 // username of each suggestion. |
| 116 NSArray* BuildSuggestions(const autofill::PasswordFormFillData& formFillData, | 127 NSArray* BuildSuggestions(const autofill::PasswordFormFillData& formFillData, |
| 117 NSString* prefix) { | 128 NSString* prefix) { |
| 118 NSMutableArray* suggestions = [NSMutableArray array]; | 129 NSMutableArray* suggestions = [NSMutableArray array]; |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 withUsername:username | 620 withUsername:username |
| 610 password:password | 621 password:password |
| 611 completionHandler:^(BOOL success) { | 622 completionHandler:^(BOOL success) { |
| 612 completion(); | 623 completion(); |
| 613 }]; | 624 }]; |
| 614 } else { | 625 } else { |
| 615 completion(); | 626 completion(); |
| 616 } | 627 } |
| 617 } | 628 } |
| 618 | 629 |
| 630 #pragma mark - PasswordManagerClientDelegate | |
| 631 | |
| 632 - (void)showSavePasswordInfoBar: | |
| 633 (std::unique_ptr<PasswordFormManager>)formToSave { | |
| 634 [self showInfoBarForForm:std::move(formToSave) infoBarType:SAVE]; | |
| 635 } | |
| 636 | |
| 637 - (void)showUpdatePasswordInfoBar: | |
| 638 (std::unique_ptr<PasswordFormManager>)formToUpdate { | |
| 639 [self showInfoBarForForm:std::move(formToUpdate) infoBarType:UPDATE]; | |
| 640 } | |
| 641 | |
| 619 #pragma mark - | 642 #pragma mark - |
| 620 #pragma mark WebPasswordFormData Adaptation | 643 #pragma mark WebPasswordFormData Adaptation |
| 621 | 644 |
| 622 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form | 645 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form |
| 623 fromDictionary:(const base::DictionaryValue*)dictionary | 646 fromDictionary:(const base::DictionaryValue*)dictionary |
| 624 pageURL:(const GURL&)pageLocation { | 647 pageURL:(const GURL&)pageLocation { |
| 625 DCHECK(form); | 648 DCHECK(form); |
| 626 DCHECK(dictionary); | 649 DCHECK(dictionary); |
| 627 DCHECK(pageLocation.is_valid()); | 650 DCHECK(pageLocation.is_valid()); |
| 628 | 651 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 } | 770 } |
| 748 autofill::FormFieldData field; | 771 autofill::FormFieldData field; |
| 749 field.name = std::move(element); | 772 field.name = std::move(element); |
| 750 field.form_control_type = base::UTF16ToUTF8(type); | 773 field.form_control_type = base::UTF16ToUTF8(type); |
| 751 form->form_data.fields.push_back(field); | 774 form->form_data.fields.push_back(field); |
| 752 } | 775 } |
| 753 | 776 |
| 754 return YES; | 777 return YES; |
| 755 } | 778 } |
| 756 | 779 |
| 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 | 780 - (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData |
| 778 withUsername:(const base::string16&)username | 781 withUsername:(const base::string16&)username |
| 779 password:(const base::string16&)password | 782 password:(const base::string16&)password |
| 780 completionHandler:(void (^)(BOOL))completionHandler { | 783 completionHandler:(void (^)(BOOL))completionHandler { |
| 781 // Send JSON over to the web view. | 784 // Send JSON over to the web view. |
| 782 [passwordJsManager_ fillPasswordForm:SerializePasswordFormFillData(formData) | 785 [passwordJsManager_ fillPasswordForm:SerializePasswordFormFillData(formData) |
| 783 withUsername:base::SysUTF16ToNSString(username) | 786 withUsername:base::SysUTF16ToNSString(username) |
| 784 password:base::SysUTF16ToNSString(password) | 787 password:base::SysUTF16ToNSString(password) |
| 785 completionHandler:^(BOOL result) { | 788 completionHandler:^(BOOL result) { |
| 786 if (completionHandler) | 789 if (completionHandler) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 } | 825 } |
| 823 | 826 |
| 824 - (PasswordManager*)passwordManager { | 827 - (PasswordManager*)passwordManager { |
| 825 return passwordManager_.get(); | 828 return passwordManager_.get(); |
| 826 } | 829 } |
| 827 | 830 |
| 828 - (JsPasswordManager*)passwordJsManager { | 831 - (JsPasswordManager*)passwordJsManager { |
| 829 return passwordJsManager_; | 832 return passwordJsManager_; |
| 830 } | 833 } |
| 831 | 834 |
| 835 #pragma mark - Private methods | |
| 836 | |
| 837 - (void)showInfoBarForForm:(std::unique_ptr<PasswordFormManager>)form | |
| 838 infoBarType:(PasswordInfoBarType)type { | |
| 839 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) | |
| 840 return; | |
| 841 | |
| 842 bool isSmartLockBrandingEnabled = false; | |
| 843 if (self.browserState) { | |
| 844 sync_driver::SyncService* sync_service = | |
| 845 IOSChromeProfileSyncServiceFactory::GetForBrowserState( | |
| 846 self.browserState); | |
| 847 isSmartLockBrandingEnabled = | |
| 848 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( | |
| 849 sync_service); | |
| 850 } | |
| 851 infobars::InfoBarManager* infoBarManager = | |
| 852 InfoBarManagerImpl::FromWebState(webStateObserverBridge_->web_state()); | |
| 853 | |
| 854 switch (type) { | |
| 855 case SAVE: | |
| 856 IOSChromeSavePasswordInfoBarDelegate::Create( | |
| 857 isSmartLockBrandingEnabled, infoBarManager, std::move(form)); | |
| 858 break; | |
| 859 | |
| 860 case UPDATE: | |
| 861 IOSChromeUpdatePasswordInfoBarDelegate::Create( | |
| 862 isSmartLockBrandingEnabled, infoBarManager, std::move(form)); | |
| 863 break; | |
| 864 | |
| 865 default: | |
|
sdefresne
2016/07/05 13:29:55
If you use C++ enum or enum class, then you should
Jackie Quinn
2016/07/05 13:52:34
Done.
| |
| 866 NOTREACHED(); | |
| 867 break; | |
| 868 } | |
| 869 } | |
| 870 | |
| 832 @end | 871 @end |
| OLD | NEW |