Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: ios/chrome/browser/ui/settings/password_details_collection_view_controller.mm

Issue 2722853003: List site in password settings (Closed)
Patch Set: Just rebased Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ui/settings/password_details_collection_view_control ler.h" 5 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control ler.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "components/autofill/core/common/password_form.h" 9 #include "components/autofill/core/common/password_form.h"
10 #include "components/password_manager/core/browser/affiliation_utils.h" 10 #include "components/password_manager/core/browser/affiliation_utils.h"
(...skipping 14 matching lines...) Expand all
25 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" 25 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h"
26 #include "ui/base/l10n/l10n_util_mac.h" 26 #include "ui/base/l10n/l10n_util_mac.h"
27 27
28 #if !defined(__has_feature) || !__has_feature(objc_arc) 28 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support." 29 #error "This file requires ARC support."
30 #endif 30 #endif
31 31
32 namespace { 32 namespace {
33 33
34 typedef NS_ENUM(NSInteger, SectionIdentifier) { 34 typedef NS_ENUM(NSInteger, SectionIdentifier) {
35 SectionIdentifierUsername = kSectionIdentifierEnumZero, 35 SectionIdentifierSite = kSectionIdentifierEnumZero,
36 SectionIdentifierUsername,
36 SectionIdentifierPassword, 37 SectionIdentifierPassword,
37 }; 38 };
38 39
39 typedef NS_ENUM(NSInteger, ItemType) { 40 typedef NS_ENUM(NSInteger, ItemType) {
40 ItemTypeHeader = kItemTypeEnumZero, 41 ItemTypeHeader = kItemTypeEnumZero,
42 ItemTypeSite,
43 ItemTypeCopySite,
41 ItemTypeUsername, 44 ItemTypeUsername,
42 ItemTypeCopyUsername, 45 ItemTypeCopyUsername,
43 ItemTypePassword, 46 ItemTypePassword,
44 ItemTypeShowHide, 47 ItemTypeShowHide,
45 ItemTypeCopyPassword, 48 ItemTypeCopyPassword,
46 ItemTypeDelete, 49 ItemTypeDelete,
47 }; 50 };
48 51
49 } // namespace 52 } // namespace
50 53
51 @interface PasswordDetailsCollectionViewController () { 54 @interface PasswordDetailsCollectionViewController () {
52 // The username to which the saved password belongs. 55 // The username to which the saved password belongs.
53 NSString* _username; 56 NSString* _username;
54 // The saved password. 57 // The saved password.
55 NSString* _password; 58 NSString* _password;
59 // The origin site of the saved credential.
60 NSString* _site;
56 // Whether the password is shown in plain text form or in obscured form. 61 // Whether the password is shown in plain text form or in obscured form.
57 BOOL _plainTextPasswordShown; 62 BOOL _plainTextPasswordShown;
58 // The password form. 63 // The password form.
59 autofill::PasswordForm _passwordForm; 64 autofill::PasswordForm _passwordForm;
60 // Instance of the parent view controller needed in order to update the 65 // Instance of the parent view controller needed in order to update the
61 // password list when a password is deleted. 66 // password list when a password is deleted.
62 __weak id<PasswordDetailsCollectionViewControllerDelegate> _weakDelegate; 67 __weak id<PasswordDetailsCollectionViewControllerDelegate> _weakDelegate;
63 // Module containing the reauthentication mechanism for viewing and copying 68 // Module containing the reauthentication mechanism for viewing and copying
64 // passwords. 69 // passwords.
65 __weak id<ReauthenticationProtocol> _weakReauthenticationModule; 70 __weak id<ReauthenticationProtocol> _weakReauthenticationModule;
(...skipping 15 matching lines...) Expand all
81 origin:(NSString*)origin { 86 origin:(NSString*)origin {
82 DCHECK(delegate); 87 DCHECK(delegate);
83 DCHECK(reauthenticationModule); 88 DCHECK(reauthenticationModule);
84 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; 89 self = [super initWithStyle:CollectionViewControllerStyleAppBar];
85 if (self) { 90 if (self) {
86 _weakDelegate = delegate; 91 _weakDelegate = delegate;
87 _weakReauthenticationModule = reauthenticationModule; 92 _weakReauthenticationModule = reauthenticationModule;
88 _passwordForm = passwordForm; 93 _passwordForm = passwordForm;
89 _username = [username copy]; 94 _username = [username copy];
90 _password = [password copy]; 95 _password = [password copy];
96 _site = base::SysUTF8ToNSString(_passwordForm.origin.spec());
91 self.title = 97 self.title =
92 [PasswordDetailsCollectionViewController simplifyOrigin:origin]; 98 [PasswordDetailsCollectionViewController simplifyOrigin:origin];
93 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 99 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
94 [defaultCenter addObserver:self 100 [defaultCenter addObserver:self
95 selector:@selector(hidePassword) 101 selector:@selector(hidePassword)
96 name:UIApplicationDidEnterBackgroundNotification 102 name:UIApplicationDidEnterBackgroundNotification
97 object:nil]; 103 object:nil];
98 104
99 [self loadModel]; 105 [self loadModel];
100 } 106 }
(...skipping 11 matching lines...) Expand all
112 return 118 return
113 [[originWithoutScheme componentsSeparatedByString:@"/"] objectAtIndex:0]; 119 [[originWithoutScheme componentsSeparatedByString:@"/"] objectAtIndex:0];
114 } 120 }
115 121
116 #pragma mark - SettingsRootCollectionViewController 122 #pragma mark - SettingsRootCollectionViewController
117 123
118 - (void)loadModel { 124 - (void)loadModel {
119 [super loadModel]; 125 [super loadModel];
120 CollectionViewModel* model = self.collectionViewModel; 126 CollectionViewModel* model = self.collectionViewModel;
121 127
128 [model addSectionWithIdentifier:SectionIdentifierSite];
129 CollectionViewTextItem* siteHeader =
130 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
131 siteHeader.text = l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_SITE);
132 [model setHeader:siteHeader forSectionWithIdentifier:SectionIdentifierSite];
133 PasswordDetailsItem* siteItem =
134 [[PasswordDetailsItem alloc] initWithType:ItemTypeSite];
135 siteItem.text = _site;
136 siteItem.showingText = YES;
137 [model addItem:siteItem toSectionWithIdentifier:SectionIdentifierSite];
138 [model addItem:[self siteCopyButtonItem]
139 toSectionWithIdentifier:SectionIdentifierSite];
140
122 [model addSectionWithIdentifier:SectionIdentifierUsername]; 141 [model addSectionWithIdentifier:SectionIdentifierUsername];
123 CollectionViewTextItem* usernameHeader = 142 CollectionViewTextItem* usernameHeader =
124 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; 143 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
125 usernameHeader.text = 144 usernameHeader.text =
126 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); 145 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME);
127 usernameHeader.textColor = [[MDCPalette greyPalette] tint500]; 146 usernameHeader.textColor = [[MDCPalette greyPalette] tint500];
128 [model setHeader:usernameHeader 147 [model setHeader:usernameHeader
129 forSectionWithIdentifier:SectionIdentifierUsername]; 148 forSectionWithIdentifier:SectionIdentifierUsername];
130 PasswordDetailsItem* usernameItem = 149 PasswordDetailsItem* usernameItem =
131 [[PasswordDetailsItem alloc] initWithType:ItemTypeUsername]; 150 [[PasswordDetailsItem alloc] initWithType:ItemTypeUsername];
(...skipping 27 matching lines...) Expand all
159 [model addItem:[self deletePasswordButtonItem] 178 [model addItem:[self deletePasswordButtonItem]
160 toSectionWithIdentifier:SectionIdentifierPassword]; 179 toSectionWithIdentifier:SectionIdentifierPassword];
161 } 180 }
162 181
163 - (void)dealloc { 182 - (void)dealloc {
164 [[NSNotificationCenter defaultCenter] removeObserver:self]; 183 [[NSNotificationCenter defaultCenter] removeObserver:self];
165 } 184 }
166 185
167 #pragma mark - Items 186 #pragma mark - Items
168 187
188 - (CollectionViewItem*)siteCopyButtonItem {
189 CollectionViewTextItem* item =
190 [[CollectionViewTextItem alloc] initWithType:ItemTypeCopySite];
191 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_SITE_COPY_BUTTON);
192 item.textColor = [[MDCPalette cr_bluePalette] tint500];
193 // Accessibility label adds the header to the text, so that accessibility
194 // users do not have to rely on the visual grouping to understand which part
195 // of the credential is being copied.
196 item.accessibilityLabel = [NSString
197 stringWithFormat:@"%@: %@",
198 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_SITE),
199 l10n_util::GetNSString(
200 IDS_IOS_SETTINGS_SITE_COPY_BUTTON)];
201 item.accessibilityTraits |= UIAccessibilityTraitButton;
202 return item;
203 }
204
169 - (CollectionViewItem*)usernameCopyButtonItem { 205 - (CollectionViewItem*)usernameCopyButtonItem {
170 CollectionViewTextItem* item = 206 CollectionViewTextItem* item =
171 [[CollectionViewTextItem alloc] initWithType:ItemTypeCopyUsername]; 207 [[CollectionViewTextItem alloc] initWithType:ItemTypeCopyUsername];
172 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON); 208 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON);
173 item.textColor = [[MDCPalette cr_bluePalette] tint500]; 209 item.textColor = [[MDCPalette cr_bluePalette] tint500];
174 // Accessibility label adds the header to the text, so that accessibility 210 // Accessibility label adds the header to the text, so that accessibility
175 // users do not have to rely on the visual grouping to understand which part 211 // users do not have to rely on the visual grouping to understand which part
176 // of the credential is being copied. 212 // of the credential is being copied.
177 item.accessibilityLabel = 213 item.accessibilityLabel =
178 [NSString stringWithFormat:@"%@: %@", 214 [NSString stringWithFormat:@"%@: %@",
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 CollectionViewTextItem* item = 251 CollectionViewTextItem* item =
216 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete]; 252 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete];
217 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); 253 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON);
218 item.textColor = [[MDCPalette cr_redPalette] tint500]; 254 item.textColor = [[MDCPalette cr_redPalette] tint500];
219 item.accessibilityTraits |= UIAccessibilityTraitButton; 255 item.accessibilityTraits |= UIAccessibilityTraitButton;
220 return item; 256 return item;
221 } 257 }
222 258
223 #pragma mark - Actions 259 #pragma mark - Actions
224 260
261 - (void)copySite {
262 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard];
263 generalPasteboard.string = _site;
264 [self showCopyResultToast:l10n_util::GetNSString(
265 IDS_IOS_SETTINGS_SITE_WAS_COPIED_MESSAGE)];
266 }
267
225 - (void)copyUsername { 268 - (void)copyUsername {
226 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; 269 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard];
227 generalPasteboard.string = _username; 270 generalPasteboard.string = _username;
228 [self showCopyResultToast:l10n_util::GetNSString( 271 [self showCopyResultToast:l10n_util::GetNSString(
229 IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE)]; 272 IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE)];
230 } 273 }
231 274
232 - (NSString*)showHideButtonText { 275 - (NSString*)showHideButtonText {
233 if (_plainTextPasswordShown) { 276 if (_plainTextPasswordShown) {
234 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); 277 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 385 }
343 386
344 #pragma mark - UICollectionViewDelegate 387 #pragma mark - UICollectionViewDelegate
345 388
346 - (void)collectionView:(UICollectionView*)collectionView 389 - (void)collectionView:(UICollectionView*)collectionView
347 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 390 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
348 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 391 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
349 NSInteger itemType = 392 NSInteger itemType =
350 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 393 [self.collectionViewModel itemTypeForIndexPath:indexPath];
351 switch (itemType) { 394 switch (itemType) {
395 case ItemTypeCopySite:
396 [self copySite];
397 break;
352 case ItemTypeCopyUsername: 398 case ItemTypeCopyUsername:
353 [self copyUsername]; 399 [self copyUsername];
354 break; 400 break;
355 case ItemTypeShowHide: 401 case ItemTypeShowHide:
356 if (_plainTextPasswordShown) { 402 if (_plainTextPasswordShown) {
357 [self hidePassword]; 403 [self hidePassword];
358 } else { 404 } else {
359 [self showPassword]; 405 [self showPassword];
360 } 406 }
361 break; 407 break;
(...skipping 26 matching lines...) Expand all
388 } 434 }
389 435
390 #pragma mark - ForTesting 436 #pragma mark - ForTesting
391 437
392 - (void)setReauthenticationModule: 438 - (void)setReauthenticationModule:
393 (id<ReauthenticationProtocol>)reauthenticationModule { 439 (id<ReauthenticationProtocol>)reauthenticationModule {
394 _weakReauthenticationModule = reauthenticationModule; 440 _weakReauthenticationModule = reauthenticationModule;
395 } 441 }
396 442
397 @end 443 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698