Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_ mediator.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "components/strings/grit/components_strings.h" | |
| 9 #include "ios/chrome/grit/ios_strings.h" | |
| 10 #import "ios/clean/chrome/browser/ui/commands/dialog_commands.h" | |
| 11 #import "ios/clean/chrome/browser/ui/commands/http_auth_dialog_commands.h" | |
| 12 #import "ios/clean/chrome/browser/ui/dialogs/dialog_button_item.h" | |
| 13 #import "ios/clean/chrome/browser/ui/dialogs/dialog_consumer.h" | |
| 14 #import "ios/clean/chrome/browser/ui/dialogs/dialog_mediator+internal.h" | |
| 15 #import "ios/clean/chrome/browser/ui/dialogs/dialog_text_field_item.h" | |
| 16 #import "ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_ state.h" | |
| 17 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" | |
| 18 #include "ui/base/l10n/l10n_util.h" | |
| 19 | |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 21 #error "This file requires ARC support." | |
| 22 #endif | |
| 23 | |
| 24 namespace { | |
| 25 // Button tags. | |
| 26 NSString* const kOKButtonTag = @"OK"; | |
| 27 NSString* const kCancelButtonTag = @"Cancel"; | |
| 28 // An enum representing the indices of the username and password fields in the | |
| 29 // DialogTextFieldItem array passed to the consumer. | |
| 30 typedef NS_ENUM(NSInteger, TextFieldIndex) { | |
| 31 USER_NAME_IDX = 0, | |
| 32 PASSWORD_IDX, | |
| 33 TEXT_FIELD_COUNT, | |
| 34 }; | |
| 35 } | |
| 36 | |
| 37 @interface HTTPAuthDialogMediator ()<DialogDismissalCommands> | |
| 38 | |
| 39 // The dispatcher to use for HTTPAuthDialogDismissalCommands. | |
| 40 @property(nonatomic, readonly) id<HTTPAuthDialogDismissalCommands> | |
| 41 dismissalDispatcher; | |
| 42 // The state passed on initialization. | |
| 43 @property(nonatomic, readonly, strong) HTTPAuthDialogState* state; | |
| 44 | |
| 45 @end | |
| 46 | |
| 47 @implementation HTTPAuthDialogMediator | |
| 48 | |
| 49 @synthesize state = _state; | |
| 50 | |
| 51 - (instancetype)initWithDispatcher:(CommandDispatcher*)dispatcher | |
| 52 state:(HTTPAuthDialogState*)state { | |
| 53 DCHECK(state); | |
| 54 if ((self = [super initWithDispatcher:dispatcher])) { | |
| 55 _state = state; | |
| 56 } | |
| 57 return self; | |
| 58 } | |
| 59 | |
| 60 #pragma mark - Accessors | |
| 61 | |
| 62 - (id<HTTPAuthDialogDismissalCommands>)dismissalDispatcher { | |
| 63 return static_cast<id<HTTPAuthDialogDismissalCommands>>(self.dispatcher); | |
| 64 } | |
| 65 | |
| 66 @end | |
| 67 | |
| 68 @implementation HTTPAuthDialogMediator (Internal) | |
| 69 | |
| 70 - (NSString*)dialogTitle { | |
| 71 return self.state.title; | |
| 72 } | |
| 73 | |
| 74 - (NSString*)dialogMessage { | |
| 75 return self.state.message; | |
| 76 } | |
| 77 | |
| 78 - (NSArray<DialogButtonItem*>*)buttonItems { | |
| 79 NSMutableArray<DialogButtonItem*>* items = [[NSMutableArray alloc] init]; | |
|
marq (ping after 24h)
2017/06/14 11:19:15
I'd prefer just a static array return here:
re
kkhorimoto
2017/06/23 06:25:41
Done.
| |
| 80 [items addObject:[DialogButtonItem itemWithText:l10n_util::GetNSString(IDS_OK) | |
| 81 style:DialogButtonStyle::DEFAULT | |
| 82 tag:kOKButtonTag]]; | |
| 83 NSString* cancelText = l10n_util::GetNSString(IDS_CANCEL); | |
| 84 [items addObject:[DialogButtonItem itemWithText:cancelText | |
| 85 style:DialogButtonStyle::CANCEL | |
| 86 tag:kCancelButtonTag]]; | |
| 87 return items; | |
| 88 } | |
| 89 | |
| 90 - (NSArray<DialogTextFieldItem*>*)textFieldItems { | |
| 91 NSMutableArray<DialogTextFieldItem*>* items = [[NSMutableArray alloc] init]; | |
|
marq (ping after 24h)
2017/06/14 11:19:15
Static array return here too.
kkhorimoto
2017/06/23 06:25:41
Done.
| |
| 92 NSString* defaultUsername = self.state.defaultUserNameText; | |
| 93 NSString* usernamePlaceholder = | |
| 94 l10n_util::GetNSString(IDS_IOS_HTTP_LOGIN_DIALOG_USERNAME_PLACEHOLDER); | |
| 95 [items addObject:[DialogTextFieldItem itemWithDefaultText:defaultUsername | |
| 96 placeholderText:usernamePlaceholder | |
| 97 secure:NO]]; | |
| 98 NSString* passwordPlaceholder = | |
| 99 l10n_util::GetNSString(IDS_IOS_HTTP_LOGIN_DIALOG_PASSWORD_PLACEHOLDER); | |
| 100 [items addObject:[DialogTextFieldItem itemWithDefaultText:nil | |
| 101 placeholderText:passwordPlaceholder | |
| 102 secure:YES]]; | |
| 103 return items; | |
| 104 } | |
| 105 | |
| 106 #pragma mark - DialogDismissalCommands | |
| 107 | |
| 108 - (void)dismissDialogWithButtonTag:(id)buttonTag | |
| 109 userInputStrings:(NSArray<NSString*>*)inputStrings { | |
| 110 DCHECK_EQ(inputStrings.count, TEXT_FIELD_COUNT); | |
| 111 if (buttonTag == kOKButtonTag) { | |
| 112 NSString* username = inputStrings[USER_NAME_IDX]; | |
|
marq (ping after 24h)
2017/06/14 11:19:15
Hmm.
Should the text field items be mutable objec
kkhorimoto
2017/06/23 06:25:41
As we discussed in the weekly meeting, I just impl
| |
| 113 NSString* password = inputStrings[PASSWORD_IDX]; | |
| 114 [self.dismissalDispatcher dismissHTTPAuthDialogWithUsername:username | |
| 115 password:password]; | |
| 116 } else if (buttonTag == kCancelButtonTag) { | |
| 117 [self.dismissalDispatcher dismissHTTPAuthDialogWithUsername:nil | |
| 118 password:nil]; | |
| 119 } else { | |
| 120 NOTREACHED() << "Received dialog dismissal for unknown button tag."; | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 @end | |
| OLD | NEW |