Commit c3707047 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Update the shell app.

1. Use new sync and autofill APIs.
2. Introduce a sync menu.
3. Autofill data menu.
4. Consent/Unlock menu.

Change-Id: I283b6087c09a2688ed7ea3fdf53d44fe72b63e83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1823724
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700078}
parent 110515d4
...@@ -108,20 +108,40 @@ ...@@ -108,20 +108,40 @@
// Not implemented. // Not implemented.
} }
- (void)autofillController:(CWVAutofillController*)autofillController
decideSavePolicyForAutofillProfile:(CWVAutofillProfile*)autofillProfile
decisionHandler:
(void (^)(BOOL decision))decisionHandler {
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Save profile?"
message:autofillProfile.debugDescription
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* allowAction =
[UIAlertAction actionWithTitle:@"Allow"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* _Nonnull action) {
decisionHandler(YES);
}];
UIAlertAction* cancelAction =
[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction* _Nonnull action) {
decisionHandler(NO);
}];
[alertController addAction:allowAction];
[alertController addAction:cancelAction];
[UIApplication.sharedApplication.keyWindow.rootViewController
presentViewController:alertController
animated:YES
completion:nil];
}
- (void)autofillController:(CWVAutofillController*)autofillController - (void)autofillController:(CWVAutofillController*)autofillController
saveCreditCardWithSaver:(CWVCreditCardSaver*)saver { saveCreditCardWithSaver:(CWVCreditCardSaver*)saver {
CWVCreditCard* creditCard = saver.creditCard; CWVCreditCard* creditCard = saver.creditCard;
NSString* cardSummary = [NSString
stringWithFormat:@"%@ %@ %@/%@", creditCard.cardHolderFullName,
creditCard.cardNumber, creditCard.expirationMonth,
creditCard.expirationYear];
NSArray<NSString*>* legalMessages =
[saver.legalMessages valueForKey:@"string"];
NSString* message = [[legalMessages arrayByAddingObject:cardSummary]
componentsJoinedByString:@"\n"];
UIAlertController* alertController = [UIAlertController UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Save card?" alertControllerWithTitle:@"Save card?"
message:message message:creditCard.debugDescription
preferredStyle:UIAlertControllerStyleActionSheet]; preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* allowAction = [UIAlertAction UIAlertAction* allowAction = [UIAlertAction
actionWithTitle:@"Allow" actionWithTitle:@"Allow"
...@@ -150,13 +170,12 @@ ...@@ -150,13 +170,12 @@
} }
- (void)autofillController:(CWVAutofillController*)autofillController - (void)autofillController:(CWVAutofillController*)autofillController
decidePasswordSavingPolicyForUsername:(NSString*)userName decideSavePolicyForPassword:(CWVPassword*)password
decisionHandler:(void (^)(CWVPasswordUserDecision)) decisionHandler:(void (^)(CWVPasswordUserDecision decision))
decisionHandler { decisionHandler {
UIAlertController* alertController = [UIAlertController UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Save Password" alertControllerWithTitle:@"Save password?"
message:@"Do you want to save your password on " message:password.debugDescription
@"this site?"
preferredStyle:UIAlertControllerStyleActionSheet]; preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* noAction = [UIAlertAction UIAlertAction* noAction = [UIAlertAction
...@@ -190,16 +209,12 @@ ...@@ -190,16 +209,12 @@
} }
- (void)autofillController:(CWVAutofillController*)autofillController - (void)autofillController:(CWVAutofillController*)autofillController
decidePasswordUpdatingPolicyForUsername:(NSString*)userName decideUpdatePolicyForPassword:(CWVPassword*)password
decisionHandler:(void (^)(CWVPasswordUserDecision)) decisionHandler:(void (^)(CWVPasswordUserDecision decision))
decisionHandler { decisionHandler {
NSString* message =
[NSString stringWithFormat:@"Do you want to update your password "
@"for %@ on this site?",
userName];
UIAlertController* alertController = [UIAlertController UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Update Password" alertControllerWithTitle:@"Update password?"
message:message message:password.debugDescription
preferredStyle:UIAlertControllerStyleActionSheet]; preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* noAction = [UIAlertAction UIAlertAction* noAction = [UIAlertAction
......
...@@ -138,7 +138,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -138,7 +138,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[_menuButton setImage:[UIImage imageNamed:@"ic_menu"] [_menuButton setImage:[UIImage imageNamed:@"ic_menu"]
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[_menuButton addTarget:self [_menuButton addTarget:self
action:@selector(showMenu) action:@selector(showMainMenu)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
_field.placeholder = @"Search or type URL"; _field.placeholder = @"Search or type URL";
...@@ -246,12 +246,13 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -246,12 +246,13 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[CWVWebView setUserAgentProduct:@"Dummy/1.0"]; [CWVWebView setUserAgentProduct:@"Dummy/1.0"];
_authService = [[ShellAuthService alloc] init];
CWVSyncController.dataSource = _authService;
CWVWebViewConfiguration* configuration = CWVWebViewConfiguration* configuration =
[CWVWebViewConfiguration defaultConfiguration]; [CWVWebViewConfiguration defaultConfiguration];
configuration.syncController.delegate = self; configuration.syncController.delegate = self;
[self createWebViewWithConfiguration:configuration]; [self createWebViewWithConfiguration:configuration];
_authService = [[ShellAuthService alloc] init];
} }
- (UIStatusBarStyle)preferredStatusBarStyle { - (UIStatusBarStyle)preferredStatusBarStyle {
...@@ -293,9 +294,229 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -293,9 +294,229 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
} }
} }
- (void)showMenu { - (void)showAddressData {
CWVAutofillDataManager* dataManager =
_webView.configuration.autofillDataManager;
[dataManager fetchProfilesWithCompletionHandler:^(
NSArray<CWVAutofillProfile*>* _Nonnull profiles) {
NSMutableArray<NSString*>* descriptions = [profiles
valueForKey:NSStringFromSelector(@selector(debugDescription))];
NSString* message = [descriptions componentsJoinedByString:@"\n\n"];
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Addresses"
message:message
preferredStyle:UIAlertControllerStyleActionSheet];
for (CWVAutofillProfile* profile in profiles) {
NSString* title = [NSString
stringWithFormat:@"Delete %@", @([profiles indexOfObject:profile])];
UIAlertAction* action =
[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[dataManager deleteProfile:profile];
}];
[alertController addAction:action];
}
[alertController
addAction:[UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}];
}
- (void)showCreditCardData {
CWVAutofillDataManager* dataManager =
_webView.configuration.autofillDataManager;
[dataManager fetchCreditCardsWithCompletionHandler:^(
NSArray<CWVCreditCard*>* _Nonnull creditCards) {
NSMutableArray<NSString*>* descriptions = [creditCards
valueForKey:NSStringFromSelector(@selector(debugDescription))];
NSString* message = [descriptions componentsJoinedByString:@"\n\n"];
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Credit cards"
message:message
preferredStyle:UIAlertControllerStyleActionSheet];
for (CWVCreditCard* creditCard in creditCards) {
NSString* title =
[NSString stringWithFormat:@"Delete %@",
@([creditCards indexOfObject:creditCard])];
UIAlertAction* action =
[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[dataManager deleteCreditCard:creditCard];
}];
[alertController addAction:action];
}
[alertController
addAction:[UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}];
}
- (void)showPasswordData {
CWVAutofillDataManager* dataManager =
_webView.configuration.autofillDataManager;
[dataManager fetchPasswordsWithCompletionHandler:^(
NSArray<CWVPassword*>* _Nonnull passwords) {
NSMutableArray<NSString*>* descriptions = [passwords
valueForKey:NSStringFromSelector(@selector(debugDescription))];
NSString* message = [descriptions componentsJoinedByString:@"\n\n"];
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Passwords"
message:message
preferredStyle:UIAlertControllerStyleActionSheet];
for (CWVPassword* password in passwords) {
NSString* title = [NSString
stringWithFormat:@"Delete %@", @([passwords indexOfObject:password])];
UIAlertAction* action =
[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[dataManager deletePassword:password];
}];
[alertController addAction:action];
}
[alertController
addAction:[UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}];
}
- (void)showSyncMenu {
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"Sync menu"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
CWVSyncController* syncController = _webView.configuration.syncController;
CWVIdentity* currentIdentity = syncController.currentIdentity;
if (currentIdentity) {
NSString* title = [NSString
stringWithFormat:@"Stop syncing for %@", currentIdentity.email];
[alertController
addAction:[UIAlertAction
actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[syncController stopSyncAndClearIdentity];
}]];
__weak ShellViewController* weakSelf = self;
if (syncController.consentNeeded) {
[alertController
addAction:[UIAlertAction actionWithTitle:@"Opt into sync"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[syncController consent];
}]];
} else if (syncController.passphraseNeeded) {
[alertController
addAction:[UIAlertAction
actionWithTitle:@"Unlock using passphrase"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[weakSelf showPassphraseUnlockAlert];
}]];
} else {
[alertController
addAction:[UIAlertAction actionWithTitle:@"Show autofill data"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[weakSelf showAddressData];
}]];
[alertController
addAction:[UIAlertAction actionWithTitle:@"Show credit card data"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[weakSelf showCreditCardData];
}]];
[alertController
addAction:[UIAlertAction actionWithTitle:@"Show password data"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[weakSelf showPasswordData];
}]];
}
} else {
for (CWVIdentity* identity in [_authService identities]) {
NSString* title =
[NSString stringWithFormat:@"Start sync with %@", identity.email];
[alertController
addAction:[UIAlertAction
actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[syncController
startSyncWithIdentity:identity];
}]];
}
NSString* sandboxTitle = [CWVFlags sharedInstance].usesSyncAndWalletSandbox
? @"Use production sync/wallet"
: @"Use sandbox sync/wallet";
[alertController
addAction:[UIAlertAction actionWithTitle:sandboxTitle
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[CWVFlags sharedInstance]
.usesSyncAndWalletSandbox ^= YES;
}]];
}
[alertController
addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)showPassphraseUnlockAlert {
UIAlertController* alertController =
[UIAlertController alertControllerWithTitle:@"Unlock sync"
message:@"Enter passphrase"
preferredStyle:UIAlertControllerStyleAlert];
__weak UIAlertController* weakAlertController = alertController;
CWVSyncController* syncController = _webView.configuration.syncController;
UIAlertAction* submit = [UIAlertAction
actionWithTitle:@"Unlock"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
UITextField* textField =
weakAlertController.textFields.firstObject;
NSString* passphrase = textField.text;
BOOL result = [syncController unlockWithPassphrase:passphrase];
NSLog(@"Sync passphrase unlock result: %d", result);
}];
[alertController addAction:submit];
UIAlertAction* cancel =
[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil];
[alertController addAction:cancel];
[alertController
addTextFieldWithConfigurationHandler:^(UITextField* textField) {
textField.placeholder = @"passphrase";
textField.keyboardType = UIKeyboardTypeDefault;
}];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)showMainMenu {
UIAlertController* alertController = [UIAlertController UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:nil alertControllerWithTitle:@"Main menu"
message:nil message:nil
preferredStyle:UIAlertControllerStyleActionSheet]; preferredStyle:UIAlertControllerStyleActionSheet];
[alertController [alertController
...@@ -339,47 +560,22 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -339,47 +560,22 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[weakSelf resetTranslateSettings]; [weakSelf resetTranslateSettings];
}]]; }]];
for (CWVIdentity* identity in [_authService identities]) { // Shows sync menu.
NSString* title =
[NSString stringWithFormat:@"Start sync with %@", identity.email];
[alertController
addAction:[UIAlertAction
actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
CWVSyncController* syncController =
weakSelf.webView.configuration
.syncController;
[syncController startSyncWithIdentity:identity];
}]];
}
[alertController [alertController
addAction:[UIAlertAction addAction:[UIAlertAction actionWithTitle:@"Sync menu"
actionWithTitle:@"Stop sync"
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) { handler:^(UIAlertAction* action) {
[weakSelf.webView.configuration [weakSelf showSyncMenu];
.syncController stopSyncAndClearIdentity];
}]];
NSString* sandboxTitle = [CWVFlags sharedInstance].usesSyncAndWalletSandbox
? @"Use production sync/wallet"
: @"Use sandbox sync/wallet";
[alertController
addAction:[UIAlertAction actionWithTitle:sandboxTitle
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[CWVFlags sharedInstance]
.usesSyncAndWalletSandbox ^= YES;
}]]; }]];
if (self.downloadTask) {
[alertController [alertController
addAction:[UIAlertAction actionWithTitle:@"Cancel download" addAction:[UIAlertAction actionWithTitle:@"Cancel download"
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) { handler:^(UIAlertAction* action) {
[weakSelf.downloadTask cancel]; [weakSelf.downloadTask cancel];
}]]; }]];
}
[self presentViewController:alertController animated:YES completion:nil]; [self presentViewController:alertController animated:YES completion:nil];
} }
......
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