Commit 1089d064 authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Add context menu items to password details settings view

This adds the Copy context menu item to the cells with site, username and
password, and also the Show/Hide item for password (whether it's Show or Hide
depends on whether the password is masked or unmasked, respectively).

Screenshots are at https://crbug.com/717968#c3.

BUG=717968

Change-Id: Iaeec460deea8c117179a8469eb771e9802765012
Reviewed-on: https://chromium-review.googlesource.com/563695
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarLouis Romero <lpromero@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485252}
parent 4a9ba5fb
...@@ -1122,12 +1122,21 @@ Handoff must also be enabled in the General section of Settings, and your device ...@@ -1122,12 +1122,21 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_SETTINGS_SITE_COPY_BUTTON" desc="Button that the user can press to copy the site to clipboard. [Length: 12em]"> <message name="IDS_IOS_SETTINGS_SITE_COPY_BUTTON" desc="Button that the user can press to copy the site to clipboard. [Length: 12em]">
Copy Copy
</message> </message>
<message name="IDS_IOS_SETTINGS_SITE_COPY_MENU_ITEM" desc="Context menu item available on the cell showing the site/URL with a passwords origin, in the detailed view of a stored credential. The user can select it to copy the site to clipboard. [Length: should be one short word, is under 5em in English]">
Copy
</message>
<message name="IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON" desc="Button that the user can press to copy the username to clipboard. [Length: 12em]"> <message name="IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON" desc="Button that the user can press to copy the username to clipboard. [Length: 12em]">
Copy Copy
</message> </message>
<message name="IDS_IOS_SETTINGS_USERNAME_COPY_MENU_ITEM" desc="Context menu item available on the username cell in the detailed view of a stored credential. The user can select it to copy the username to clipboard. [Length: should be one short word, is under 5em in English]">
Copy
</message>
<message name="IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON" desc="Button that the user can press to copy the password to clipboard. [Length: 12em]"> <message name="IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON" desc="Button that the user can press to copy the password to clipboard. [Length: 12em]">
Copy Copy
</message> </message>
<message name="IDS_IOS_SETTINGS_PASSWORD_COPY_MENU_ITEM" desc="Context menu item available on the password cell in detailed view of a stored credential. The user can select it to copy the password to clipboard. [Length: should be one short word, is under 5em in English]">
Copy
</message>
<message name="IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON" desc="Button that the user can press to delete the saved password. [Length: 31em]"> <message name="IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON" desc="Button that the user can press to delete the saved password. [Length: 31em]">
Delete Saved Password Delete Saved Password
</message> </message>
...@@ -1137,6 +1146,9 @@ Handoff must also be enabled in the General section of Settings, and your device ...@@ -1137,6 +1146,9 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON" desc="Button that the user can press to change the way the password is displayed from plain text to obscured form (i.e. from plain text to dots). [Length: 12em]"> <message name="IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON" desc="Button that the user can press to change the way the password is displayed from plain text to obscured form (i.e. from plain text to dots). [Length: 12em]">
Hide Hide
</message> </message>
<message name="IDS_IOS_SETTINGS_PASSWORD_HIDE_MENU_ITEM" desc="Context menu item available on the password cell in detailed view of a stored password. The user can select it to hide the password to clipboard. [Length: should be one short word, is under 5em in English]">
Hide
</message>
<message name="IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY" desc="Message explaining that the reason why we are requiring the user to re-authenticate is to be able to copy the password. This is shown by iOS in the Touch ID reauthentication system dialogue, right under the OS string 'Touch ID for $BROWSER_NAME'. [Length: 22em]"> <message name="IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY" desc="Message explaining that the reason why we are requiring the user to re-authenticate is to be able to copy the password. This is shown by iOS in the Touch ID reauthentication system dialogue, right under the OS string 'Touch ID for $BROWSER_NAME'. [Length: 22em]">
Copy password Copy password
</message> </message>
...@@ -1146,6 +1158,9 @@ Handoff must also be enabled in the General section of Settings, and your device ...@@ -1146,6 +1158,9 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_SETTINGS_PASSWORD_SHOW_BUTTON" desc="Button that the user can press in order to have the password displayed in plain text. [Length: 12em]"> <message name="IDS_IOS_SETTINGS_PASSWORD_SHOW_BUTTON" desc="Button that the user can press in order to have the password displayed in plain text. [Length: 12em]">
Show Show
</message> </message>
<message name="IDS_IOS_SETTINGS_PASSWORD_SHOW_MENU_ITEM" desc="Context menu item available on the password cell in detailed view of a stored password. The user can select it to show the password to clipboard. [Length: should be one short word, is under 5em in English]">
Show
</message>
<message name="IDS_IOS_SETTINGS_SITE_WAS_COPIED_MESSAGE" desc="Confirmation that the site URL of a saved credential was copied. This is shown alone in an infobar at the bottom of the screen. [Length: 40em]"> <message name="IDS_IOS_SETTINGS_SITE_WAS_COPIED_MESSAGE" desc="Confirmation that the site URL of a saved credential was copied. This is shown alone in an infobar at the bottom of the screen. [Length: 40em]">
The site URL was copied. The site URL was copied.
</message> </message>
......
...@@ -56,7 +56,18 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -56,7 +56,18 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace } // namespace
@interface PasswordDetailsCollectionViewController () { // This protocol declares the methods used by the context menus, so that
// selectors can be created from those methods and passed to UIMenuItem.
@protocol PasswordDetailsViewerProtocol<NSObject>
- (void)copySite;
- (void)copyUsername;
- (void)copyPassword;
- (void)showPassword;
- (void)hidePassword;
@end
@interface PasswordDetailsCollectionViewController ()<
PasswordDetailsViewerProtocol> {
// The username to which the saved password belongs. // The username to which the saved password belongs.
NSString* _username; NSString* _username;
// The saved password. // The saved password.
...@@ -446,6 +457,74 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule { ...@@ -446,6 +457,74 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule {
[self presentViewController:_deleteConfirmation animated:YES completion:nil]; [self presentViewController:_deleteConfirmation animated:YES completion:nil];
} }
// Returns an array of UIMenuItems to display in a context menu on the site
// cell.
- (NSArray*)getSiteMenuItems {
UIMenuItem* copyOption = [[UIMenuItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_IOS_SETTINGS_SITE_COPY_MENU_ITEM)
action:@selector(copySite)];
return @[ copyOption ];
}
// Returns an array of UIMenuItems to display in a context menu on the username
// cell.
- (NSArray*)getUsernameMenuItems {
UIMenuItem* copyOption = [[UIMenuItem alloc]
initWithTitle:l10n_util::GetNSString(
IDS_IOS_SETTINGS_USERNAME_COPY_MENU_ITEM)
action:@selector(copyUsername)];
return @[ copyOption ];
}
// Returns an array of UIMenuItems to display in a context menu on the password
// cell.
- (NSArray*)getPasswordMenuItems {
UIMenuItem* copyOption = [[UIMenuItem alloc]
initWithTitle:l10n_util::GetNSString(
IDS_IOS_SETTINGS_PASSWORD_COPY_MENU_ITEM)
action:@selector(copyPassword)];
UIMenuItem* showOption = [[UIMenuItem alloc]
initWithTitle:l10n_util::GetNSString(
IDS_IOS_SETTINGS_PASSWORD_SHOW_MENU_ITEM)
action:@selector(showPassword)];
UIMenuItem* hideOption = [[UIMenuItem alloc]
initWithTitle:l10n_util::GetNSString(
IDS_IOS_SETTINGS_PASSWORD_HIDE_MENU_ITEM)
action:@selector(hidePassword)];
return @[ copyOption, showOption, hideOption ];
}
// If the context menu is not shown for a given item type, constructs that
// menu and shows it. This method should only be called for item types
// representing the cells with the site, username and password.
- (void)ensureContextMenuShownForItemType:(NSInteger)itemType
collectionView:(UICollectionView*)collectionView
atIndexPath:(NSIndexPath*)indexPath {
UIMenuController* menu = [UIMenuController sharedMenuController];
if (![menu isMenuVisible]) {
NSArray* options = nil;
switch (itemType) {
case ItemTypeSite:
options = [self getSiteMenuItems];
break;
case ItemTypeUsername:
options = [self getUsernameMenuItems];
break;
case ItemTypePassword:
options = [self getPasswordMenuItems];
break;
default:
NOTREACHED();
}
[menu setMenuItems:options];
UICollectionViewLayoutAttributes* attributes =
[collectionView.collectionViewLayout
layoutAttributesForItemAtIndexPath:indexPath];
[menu setTargetRect:attributes.frame inView:collectionView];
[menu setMenuVisible:YES animated:YES];
}
}
#pragma mark - UICollectionViewDelegate #pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView*)collectionView - (void)collectionView:(UICollectionView*)collectionView
...@@ -454,6 +533,13 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule { ...@@ -454,6 +533,13 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule {
NSInteger itemType = NSInteger itemType =
[self.collectionViewModel itemTypeForIndexPath:indexPath]; [self.collectionViewModel itemTypeForIndexPath:indexPath];
switch (itemType) { switch (itemType) {
case ItemTypeSite:
case ItemTypeUsername:
case ItemTypePassword:
[self ensureContextMenuShownForItemType:itemType
collectionView:collectionView
atIndexPath:indexPath];
break;
case ItemTypeCopySite: case ItemTypeCopySite:
[self copySite]; [self copySite];
break; break;
...@@ -502,4 +588,20 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule { ...@@ -502,4 +588,20 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule {
_weakReauthenticationModule = reauthenticationModule; _weakReauthenticationModule = reauthenticationModule;
} }
#pragma mark - UIResponder
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(copySite) || action == @selector(copyUsername) ||
action == @selector(copyPassword) ||
(_plainTextPasswordShown && action == @selector(hidePassword)) ||
(!_plainTextPasswordShown && action == @selector(showPassword))) {
return YES;
}
return NO;
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment