Commit 69cffb5b authored by macourteau's avatar macourteau Committed by Commit bot

Cancels payment request when Settings is tapped, and opens the Autofill settings page.

Screenshots: http://imgur.com/a/h8xyi

BUG=602666

Review-Url: https://codereview.chromium.org/2804853002
Cr-Commit-Position: refs/heads/master@{#462844}
parent 539e731c
......@@ -1521,6 +1521,9 @@ enum class StackViewDismissalMode { NONE, NORMAL, INCOGNITO };
case IDC_SHOW_ADD_ACCOUNT:
[self showAddAccount];
break;
case IDC_SHOW_AUTOFILL_SETTINGS:
[self showAutofillSettings];
break;
default:
// Unknown commands get dropped with a warning.
NOTREACHED() << "Unknown command id " << command;
......@@ -2013,6 +2016,18 @@ enum class StackViewDismissalMode { NONE, NORMAL, INCOGNITO };
completion:nil];
}
- (void)showAutofillSettings {
if (_settingsNavigationController)
return;
_settingsNavigationController.reset([SettingsNavigationController
newAutofillController:_mainBrowserState
delegate:self]);
[[self topPresentedViewController]
presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
- (void)showReportAnIssue {
if (_settingsNavigationController)
return;
......
......@@ -79,6 +79,7 @@ source_set("payments") {
"//ios/chrome/browser/ui/collection_view",
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/icons",
"//ios/third_party/material_components_ios",
"//ios/third_party/material_roboto_font_loader_ios",
......
......@@ -46,6 +46,11 @@ class PaymentResponse;
- (void)paymentRequestCoordinatorDidCancel:
(PaymentRequestCoordinator*)coordinator;
// Notifies the delegate that the user has selected to go to the card and
// address options page in Settings.
- (void)paymentRequestCoordinatorDidSelectSettings:
(PaymentRequestCoordinator*)coordinator;
// Notifies the delegate that the user has confirmed the payment request.
- (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator
didConfirmWithPaymentResponse:(web::PaymentResponse)paymentResponse;
......
......@@ -343,6 +343,11 @@ class FullCardRequester
[self sendPaymentResponse];
}
- (void)paymentRequestViewControllerDidSelectSettings:
(PaymentRequestViewController*)controller {
[_delegate paymentRequestCoordinatorDidSelectSettings:self];
}
- (void)paymentRequestViewControllerDidSelectPaymentSummaryItem:
(PaymentRequestViewController*)controller {
_itemsDisplayCoordinator = [[PaymentItemsDisplayCoordinator alloc]
......
......@@ -21,6 +21,9 @@
#include "ios/chrome/browser/payments/payment_request.h"
#import "ios/chrome/browser/payments/payment_request_coordinator.h"
#include "ios/chrome/browser/procedural_block_types.h"
#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
#import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
#import "ios/chrome/browser/ui/commands/ios_command_ids.h"
#include "ios/web/public/favicon_status.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/navigation_manager.h"
......@@ -48,6 +51,9 @@ const NSTimeInterval kNoopInterval = 0.1;
// PaymentResponse.complete().
const NSTimeInterval kTimeoutInterval = 60.0;
NSString* kAbortMessage = @"The payment request was aborted.";
NSString* kCancelMessage = @"The payment request was canceled.";
} // namespace
@interface PaymentRequestManager ()<CRWWebStateObserver,
......@@ -225,8 +231,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
}
- (void)cancelRequest {
[self terminateRequestWithErrorMessage:@"The payment request was canceled."
callback:nil];
[self terminateRequestWithErrorMessage:kCancelMessage callback:nil];
}
- (void)terminateRequestWithErrorMessage:(NSString*)errorMessage
......@@ -374,22 +379,13 @@ const NSTimeInterval kTimeoutInterval = 60.0;
__weak PaymentRequestManager* weakSelf = self;
ProceduralBlockWithBool cancellationCallback = ^(BOOL) {
PaymentRequestManager* strongSelf = weakSelf;
// Early return if the manager has been deallocated.
if (!strongSelf)
return;
[[strongSelf paymentRequestJsManager]
[[weakSelf paymentRequestJsManager]
resolveAbortPromiseWithCompletionHandler:nil];
};
ProceduralBlock callback = ^{
PaymentRequestManager* strongSelf = weakSelf;
// Early return if the manager has been deallocated.
if (!strongSelf)
return;
[strongSelf
terminateRequestWithErrorMessage:@"The payment request was aborted."
callback:cancellationCallback];
[weakSelf terminateRequestWithErrorMessage:kAbortMessage
callback:cancellationCallback];
};
[_paymentRequestCoordinator displayErrorWithCallback:callback];
......@@ -406,13 +402,7 @@ const NSTimeInterval kTimeoutInterval = 60.0;
__weak PaymentRequestManager* weakSelf = self;
ProceduralBlock callback = ^{
PaymentRequestManager* strongSelf = weakSelf;
// Early return if the manager has been deallocated.
if (!strongSelf)
return;
[strongSelf
terminateRequestWithErrorMessage:@"The payment request was canceled."
callback:nil];
[weakSelf terminateRequestWithErrorMessage:kCancelMessage callback:nil];
};
[_paymentRequestCoordinator displayErrorWithCallback:callback];
......@@ -441,12 +431,8 @@ const NSTimeInterval kTimeoutInterval = 60.0;
__weak PaymentRequestManager* weakSelf = self;
ProceduralBlock callback = ^{
PaymentRequestManager* strongSelf = weakSelf;
// Early return if the manager has been deallocated.
if (!strongSelf)
return;
[strongSelf dismissUI];
[strongSelf.paymentRequestJsManager
[weakSelf dismissUI];
[weakSelf.paymentRequestJsManager
resolveResponsePromiseWithCompletionHandler:nil];
};
......@@ -535,8 +521,20 @@ const NSTimeInterval kTimeoutInterval = 60.0;
- (void)paymentRequestCoordinatorDidCancel:
(PaymentRequestCoordinator*)coordinator {
[self terminateRequestWithErrorMessage:@"The payment request was canceled."
callback:nil];
[self terminateRequestWithErrorMessage:kCancelMessage callback:nil];
}
- (void)paymentRequestCoordinatorDidSelectSettings:
(PaymentRequestCoordinator*)coordinator {
ProceduralBlockWithBool callback = ^(BOOL) {
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
DCHECK(mainWindow);
GenericChromeCommand* command =
[[GenericChromeCommand alloc] initWithTag:IDC_SHOW_AUTOFILL_SETTINGS];
[mainWindow chromeExecuteCommand:command];
};
[self terminateRequestWithErrorMessage:kCancelMessage callback:callback];
}
- (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator
......
......@@ -28,6 +28,11 @@ class PaymentRequest;
- (void)paymentRequestViewControllerDidConfirm:
(PaymentRequestViewController*)controller;
// Notifies the delegate that the user has selected to go to the card and
// address options page in Settings.
- (void)paymentRequestViewControllerDidSelectSettings:
(PaymentRequestViewController*)controller;
// Notifies the delegate that the user has selected the payment summary item.
- (void)paymentRequestViewControllerDidSelectPaymentSummaryItem:
(PaymentRequestViewController*)controller;
......
......@@ -501,7 +501,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)url {
DCHECK_EQ(url, GURL(kSettingsURL)) << "Unknown URL tapped";
NOTIMPLEMENTED(); // TODO(macourteau): take the user to the right place.
[_delegate paymentRequestViewControllerDidSelectSettings:self];
}
#pragma mark UICollectionViewDataSource
......
......@@ -77,6 +77,7 @@
#define IDC_SHOW_SYNC_PASSPHRASE_SETTINGS 40952
#define IDC_SHOW_QR_SCANNER 40953
#define IDC_SHOW_SUGGESTIONS 40955
#define IDC_SHOW_AUTOFILL_SETTINGS 40956
// clang-format on
#endif // IOS_CHROME_BROWSER_UI_COMMANDS_IOS_COMMAND_IDS_H_
......@@ -127,6 +127,13 @@ newImportDataController:(ios::ChromeBrowserState*)browserState
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn;
// Creates a new AutofillCollectionViewController and the chrome around it.
// |browserState| is used to personalize some settings aspects and should not be
// nil. |delegate| may be nil.
+ (SettingsNavigationController*)
newAutofillController:(ios::ChromeBrowserState*)browserState
delegate:(id<SettingsNavigationControllerDelegate>)delegate;
// Returns a new Done button for a UINavigationItem which will call
// closeSettings when it is pressed. Should only be called by view controllers
// owned by SettingsNavigationController.
......
......@@ -21,6 +21,7 @@
#import "ios/chrome/browser/ui/material_components/app_bar_presenting.h"
#import "ios/chrome/browser/ui/material_components/utils.h"
#import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/contextual_search_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h"
......@@ -282,6 +283,25 @@ newImportDataController:(ios::ChromeBrowserState*)browserState
return nc;
}
+ (SettingsNavigationController*)
newAutofillController:(ios::ChromeBrowserState*)browserState
delegate:(id<SettingsNavigationControllerDelegate>)delegate {
base::scoped_nsobject<UIViewController> controller(
[[AutofillCollectionViewController alloc]
initWithBrowserState:browserState]);
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
browserState:browserState
delegate:delegate];
[controller navigationItem].rightBarButtonItem = [nc doneButton];
// Make sure the close button is always present, as the Autofill screen
// isn't just shown from Settings.
[controller navigationItem].leftBarButtonItem = [nc closeButton];
return nc;
}
#pragma mark - Lifecycle
- (instancetype)
......
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