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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
(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_ request.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/shared/chrome/browser/ui/dialogs/nsurl_protection_space_util.h"
11 #include "ui/base/l10n/l10n_util.h"
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 @interface HTTPAuthDialogRequest ()
18
19 // The authentication callback provided by WebKit.
20 @property(nonatomic, copy) HTTPAuthDialogCallback callback;
21
22 // Whether |callback| has been executed.
23 @property(nonatomic, assign) BOOL callbackHasBeenExecuted;
24
25 // Private initializer used by factory method.
26 - (instancetype)initWithWebState:(web::WebState*)webState
27 protectionSpace:(NSURLProtectionSpace*)protectionSpace
28 credential:(NSURLCredential*)credential
29 callback:(HTTPAuthDialogCallback)callback;
30
31 @end
32
33 @implementation HTTPAuthDialogRequest
34 @synthesize webState = _webState;
35 @synthesize title = _title;
36 @synthesize message = _message;
37 @synthesize defaultUserNameText = _defaultUserNameText;
38 @synthesize callback = _callback;
39 @synthesize callbackHasBeenExecuted = _callbackHasBeenExecuted;
40
41 - (instancetype)initWithWebState:(web::WebState*)webState
42 protectionSpace:(NSURLProtectionSpace*)protectionSpace
43 credential:(NSURLCredential*)credential
44 callback:(HTTPAuthDialogCallback)callback {
45 DCHECK(webState);
46 DCHECK(protectionSpace);
47 DCHECK(credential);
48 DCHECK(callback);
49 if ((self = [super init])) {
50 _webState = webState;
51 _title = l10n_util::GetNSStringWithFixup(IDS_LOGIN_DIALOG_TITLE);
52 _message = ios_internal::nsurlprotectionspace_util::MessageForHTTPAuth(
53 protectionSpace);
54 _defaultUserNameText = credential.user ? credential.user : @"";
55 _callback = [callback copy];
56 }
57 return self;
58 }
59
60 - (void)dealloc {
61 DCHECK(_callbackHasBeenExecuted);
62 }
63
64 #pragma mark - Public
65
66 + (instancetype)stateWithWebState:(web::WebState*)webState
67 protectionSpace:(NSURLProtectionSpace*)protectionSpace
68 credential:(NSURLCredential*)credential
69 callback:(HTTPAuthDialogCallback)callback {
70 return [[self alloc] initWithWebState:webState
71 protectionSpace:protectionSpace
72 credential:credential
73 callback:callback];
74 }
75
76 - (void)completeAuthenticationWithUsername:(NSString*)username
77 password:(NSString*)password {
78 if (self.callbackHasBeenExecuted)
79 return;
80 self.callback(username, password);
81 self.callbackHasBeenExecuted = YES;
82 }
83
84 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698