Chromium Code Reviews| Index: ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_state.mm |
| diff --git a/ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_state.mm b/ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_state.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a6532db9c9c1c4db011c2f725018f86f22d1200b |
| --- /dev/null |
| +++ b/ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_state.mm |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_state.h" |
| + |
| +#include "base/logging.h" |
| +#include "components/strings/grit/components_strings.h" |
| +#include "ios/chrome/grit/ios_strings.h" |
| +#import "ios/shared/chrome/browser/ui/dialogs/nsurl_protection_space_util.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +@interface HTTPAuthDialogState () |
| + |
| +// The authentication callback provided by WebKit. |
| +@property(nonatomic, copy) HTTPAuthDialogCallback callback; |
| + |
| +// Whether |callback| has been executed. |
| +@property(nonatomic, assign) BOOL callbackHasBeenExecuted; |
| + |
| +// Private initializer used by factory method. |
| +- (instancetype)initWithWebState:(web::WebState*)webState |
| + protectionSpace:(NSURLProtectionSpace*)protectionSpace |
| + credential:(NSURLCredential*)credential |
| + callback:(HTTPAuthDialogCallback)callback; |
| + |
| +@end |
| + |
| +@implementation HTTPAuthDialogState |
| +@synthesize webState = _webState; |
| +@synthesize title = _title; |
| +@synthesize message = _message; |
| +@synthesize defaultUserNameText = _defaultUserNameText; |
| +@synthesize callback = _callback; |
| +@synthesize callbackHasBeenExecuted = _callbackHasBeenExecuted; |
| + |
| +- (instancetype)initWithWebState:(web::WebState*)webState |
| + protectionSpace:(NSURLProtectionSpace*)protectionSpace |
| + credential:(NSURLCredential*)credential |
| + callback:(HTTPAuthDialogCallback)callback { |
| + DCHECK(webState); |
|
marq (ping after 24h)
2017/06/14 11:19:16
Document these assertions in the header.
kkhorimoto
2017/06/23 06:25:41
Done. Should we start adding nullablity annotatio
|
| + DCHECK(protectionSpace); |
| + DCHECK(credential); |
| + DCHECK(callback); |
| + if ((self = [super init])) { |
| + _webState = webState; |
| + _title = l10n_util::GetNSStringWithFixup(IDS_LOGIN_DIALOG_TITLE); |
| + _message = ios_internal::nsurlprotectionspace_util::MessageForHTTPAuth( |
| + protectionSpace); |
| + _defaultUserNameText = credential.user ? credential.user : @""; |
| + _callback = [callback copy]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)dealloc { |
| + DCHECK(_callbackHasBeenExecuted); |
|
marq (ping after 24h)
2017/06/14 11:19:16
Would it be correct to run the callback (nil, nil)
kkhorimoto
2017/06/23 06:25:41
We shouldn't be using both DCHECKs and defensive p
|
| +} |
| + |
| +#pragma mark - Public |
| + |
| ++ (instancetype)stateWithWebState:(web::WebState*)webState |
|
marq (ping after 24h)
2017/06/14 11:19:17
Ordering nit: all initializers before dealloc.
kkhorimoto
2017/06/23 06:25:41
The initializer is before |-dealloc|. This is the
|
| + protectionSpace:(NSURLProtectionSpace*)protectionSpace |
| + credential:(NSURLCredential*)credential |
| + callback:(HTTPAuthDialogCallback)callback { |
| + return [[self alloc] initWithWebState:webState |
| + protectionSpace:protectionSpace |
| + credential:credential |
| + callback:callback]; |
| +} |
| + |
| +- (void)runCallbackWithUserName:(NSString*)username |
| + password:(NSString*)password { |
| + if (self.callbackHasBeenExecuted) |
| + return; |
| + self.callback(username, password); |
| + self.callbackHasBeenExecuted = YES; |
| +} |
| + |
| +@end |