OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h" |
6 | 6 |
7 #import <SecurityInterface/SFChooseIdentityPanel.h> | 7 #import <SecurityInterface/SFChooseIdentityPanel.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 @end | 33 @end |
34 | 34 |
35 @interface SSLClientCertificateSelectorCocoa () | 35 @interface SSLClientCertificateSelectorCocoa () |
36 - (void)onConstrainedWindowClosed; | 36 - (void)onConstrainedWindowClosed; |
37 @end | 37 @end |
38 | 38 |
39 class SSLClientAuthObserverCocoaBridge : public SSLClientAuthObserver, | 39 class SSLClientAuthObserverCocoaBridge : public SSLClientAuthObserver, |
40 public ConstrainedWindowMacDelegate { | 40 public ConstrainedWindowMacDelegate { |
41 public: | 41 public: |
42 SSLClientAuthObserverCocoaBridge( | 42 SSLClientAuthObserverCocoaBridge( |
43 const net::HttpNetworkSession* network_session, | 43 const content::BrowserContext* browser_context, |
44 net::SSLCertRequestInfo* cert_request_info, | 44 net::SSLCertRequestInfo* cert_request_info, |
45 const chrome::SelectCertificateCallback& callback, | 45 const chrome::SelectCertificateCallback& callback, |
46 SSLClientCertificateSelectorCocoa* controller) | 46 SSLClientCertificateSelectorCocoa* controller) |
47 : SSLClientAuthObserver(network_session, cert_request_info, callback), | 47 : SSLClientAuthObserver(browser_context, cert_request_info, callback), |
48 controller_(controller) { | 48 controller_(controller) { |
49 } | 49 } |
50 | 50 |
51 // SSLClientAuthObserver implementation: | 51 // SSLClientAuthObserver implementation: |
52 void OnCertSelectedByNotification() override { | 52 void OnCertSelectedByNotification() override { |
53 [controller_ closeWebContentsModalDialog]; | 53 [controller_ closeWebContentsModalDialog]; |
54 } | 54 } |
55 | 55 |
56 // ConstrainedWindowMacDelegate implementation: | 56 // ConstrainedWindowMacDelegate implementation: |
57 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { | 57 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { |
58 // |onConstrainedWindowClosed| will delete the sheet which might be still | 58 // |onConstrainedWindowClosed| will delete the sheet which might be still |
59 // in use higher up the call stack. Wait for the next cycle of the event | 59 // in use higher up the call stack. Wait for the next cycle of the event |
60 // loop to call this function. | 60 // loop to call this function. |
61 [controller_ performSelector:@selector(onConstrainedWindowClosed) | 61 [controller_ performSelector:@selector(onConstrainedWindowClosed) |
62 withObject:nil | 62 withObject:nil |
63 afterDelay:0]; | 63 afterDelay:0]; |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 SSLClientCertificateSelectorCocoa* controller_; // weak | 67 SSLClientCertificateSelectorCocoa* controller_; // weak |
68 }; | 68 }; |
69 | 69 |
70 namespace chrome { | 70 namespace chrome { |
71 | 71 |
72 void ShowSSLClientCertificateSelector( | 72 void ShowSSLClientCertificateSelector( |
73 content::WebContents* contents, | 73 content::WebContents* contents, |
74 const net::HttpNetworkSession* network_session, | |
75 net::SSLCertRequestInfo* cert_request_info, | 74 net::SSLCertRequestInfo* cert_request_info, |
76 const SelectCertificateCallback& callback) { | 75 const SelectCertificateCallback& callback) { |
77 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
78 // The dialog manages its own lifetime. | 77 // The dialog manages its own lifetime. |
79 SSLClientCertificateSelectorCocoa* selector = | 78 SSLClientCertificateSelectorCocoa* selector = |
80 [[SSLClientCertificateSelectorCocoa alloc] | 79 [[SSLClientCertificateSelectorCocoa alloc] |
81 initWithNetworkSession:network_session | 80 initWithBrowserContext:contents->GetBrowserContext() |
82 certRequestInfo:cert_request_info | 81 certRequestInfo:cert_request_info |
83 callback:callback]; | 82 callback:callback]; |
84 [selector displayForWebContents:contents]; | 83 [selector displayForWebContents:contents]; |
85 } | 84 } |
86 | 85 |
87 } // namespace chrome | 86 } // namespace chrome |
88 | 87 |
89 @implementation SSLClientCertificateSelectorCocoa | 88 @implementation SSLClientCertificateSelectorCocoa |
90 | 89 |
91 - (id)initWithNetworkSession:(const net::HttpNetworkSession*)networkSession | 90 - (id)initWithBrowserContext:(const content::BrowserContext*)browserContext |
92 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo | 91 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo |
93 callback:(const chrome::SelectCertificateCallback&)callback { | 92 callback:(const chrome::SelectCertificateCallback&)callback { |
94 DCHECK(networkSession); | 93 DCHECK(browserContext); |
95 DCHECK(certRequestInfo); | 94 DCHECK(certRequestInfo); |
96 if ((self = [super init])) { | 95 if ((self = [super init])) { |
97 observer_.reset(new SSLClientAuthObserverCocoaBridge( | 96 observer_.reset(new SSLClientAuthObserverCocoaBridge( |
98 networkSession, certRequestInfo, callback, self)); | 97 browserContext, certRequestInfo, callback, self)); |
99 } | 98 } |
100 return self; | 99 return self; |
101 } | 100 } |
102 | 101 |
103 - (void)sheetDidEnd:(NSWindow*)parent | 102 - (void)sheetDidEnd:(NSWindow*)parent |
104 returnCode:(NSInteger)returnCode | 103 returnCode:(NSInteger)returnCode |
105 context:(void*)context { | 104 context:(void*)context { |
106 net::X509Certificate* cert = NULL; | 105 net::X509Certificate* cert = NULL; |
107 if (returnCode == NSFileHandlingPanelOKButton) { | 106 if (returnCode == NSFileHandlingPanelOKButton) { |
108 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); | 107 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 228 } |
230 | 229 |
231 - (void)onConstrainedWindowClosed { | 230 - (void)onConstrainedWindowClosed { |
232 observer_->StopObserving(); | 231 observer_->StopObserving(); |
233 panel_.reset(); | 232 panel_.reset(); |
234 constrainedWindow_.reset(); | 233 constrainedWindow_.reset(); |
235 [self release]; | 234 [self release]; |
236 } | 235 } |
237 | 236 |
238 @end | 237 @end |
OLD | NEW |