Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_request.mm

Issue 2930763003: [iOS Clean] Added HTTP authentication dialog support.
Patch Set: rebase && Mark's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_request.mm
diff --git a/ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_request.mm b/ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_request.mm
new file mode 100644
index 0000000000000000000000000000000000000000..24b65e632aaf4cb496c6571a427441ee5ea63892
--- /dev/null
+++ b/ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs/http_auth_dialog_request.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_request.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 HTTPAuthDialogRequest ()
+
+// 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 HTTPAuthDialogRequest
+@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);
+ 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);
+}
+
+#pragma mark - Public
+
++ (instancetype)stateWithWebState:(web::WebState*)webState
+ protectionSpace:(NSURLProtectionSpace*)protectionSpace
+ credential:(NSURLCredential*)credential
+ callback:(HTTPAuthDialogCallback)callback {
+ return [[self alloc] initWithWebState:webState
+ protectionSpace:protectionSpace
+ credential:credential
+ callback:callback];
+}
+
+- (void)completeAuthenticationWithUsername:(NSString*)username
+ password:(NSString*)password {
+ if (self.callbackHasBeenExecuted)
+ return;
+ self.callback(username, password);
+ self.callbackHasBeenExecuted = YES;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698