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 virtual void OnCertSelectedByNotification() OVERRIDE { | 52 virtual void OnCertSelectedByNotification() OVERRIDE { |
53 [controller_ closeWebContentsModalDialog]; | 53 [controller_ closeWebContentsModalDialog]; |
54 } | 54 } |
55 | 55 |
56 // ConstrainedWindowMacDelegate implementation: | 56 // ConstrainedWindowMacDelegate implementation: |
57 virtual void OnConstrainedWindowClosed( | 57 virtual void OnConstrainedWindowClosed( |
58 ConstrainedWindowMac* window) OVERRIDE { | 58 ConstrainedWindowMac* window) OVERRIDE { |
59 // |onConstrainedWindowClosed| will delete the sheet which might be still | 59 // |onConstrainedWindowClosed| will delete the sheet which might be still |
60 // in use higher up the call stack. Wait for the next cycle of the event | 60 // in use higher up the call stack. Wait for the next cycle of the event |
61 // loop to call this function. | 61 // loop to call this function. |
62 [controller_ performSelector:@selector(onConstrainedWindowClosed) | 62 [controller_ performSelector:@selector(onConstrainedWindowClosed) |
63 withObject:nil | 63 withObject:nil |
64 afterDelay:0]; | 64 afterDelay:0]; |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 SSLClientCertificateSelectorCocoa* controller_; // weak | 68 SSLClientCertificateSelectorCocoa* controller_; // weak |
69 }; | 69 }; |
70 | 70 |
71 namespace chrome { | 71 namespace chrome { |
72 | 72 |
73 void ShowSSLClientCertificateSelector( | 73 void ShowSSLClientCertificateSelector( |
74 content::WebContents* contents, | 74 content::WebContents* contents, |
75 const net::HttpNetworkSession* network_session, | |
76 net::SSLCertRequestInfo* cert_request_info, | 75 net::SSLCertRequestInfo* cert_request_info, |
77 const SelectCertificateCallback& callback) { | 76 const SelectCertificateCallback& callback) { |
78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
79 // The dialog manages its own lifetime. | 78 // The dialog manages its own lifetime. |
80 SSLClientCertificateSelectorCocoa* selector = | 79 SSLClientCertificateSelectorCocoa* selector = |
81 [[SSLClientCertificateSelectorCocoa alloc] | 80 [[SSLClientCertificateSelectorCocoa alloc] |
82 initWithNetworkSession:network_session | 81 initWithBrowserContext:contents->GetBrowserContext() |
83 certRequestInfo:cert_request_info | 82 certRequestInfo:cert_request_info |
84 callback:callback]; | 83 callback:callback]; |
85 [selector displayForWebContents:contents]; | 84 [selector displayForWebContents:contents]; |
86 } | 85 } |
87 | 86 |
88 } // namespace chrome | 87 } // namespace chrome |
89 | 88 |
90 @implementation SSLClientCertificateSelectorCocoa | 89 @implementation SSLClientCertificateSelectorCocoa |
91 | 90 |
92 - (id)initWithNetworkSession:(const net::HttpNetworkSession*)networkSession | 91 - (id)initWithBrowserContext:(const content::BrowserContext*)browserContext |
93 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo | 92 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo |
94 callback:(const chrome::SelectCertificateCallback&)callback { | 93 callback:(const chrome::SelectCertificateCallback&)callback { |
95 DCHECK(networkSession); | 94 DCHECK(browserContext); |
96 DCHECK(certRequestInfo); | 95 DCHECK(certRequestInfo); |
97 if ((self = [super init])) { | 96 if ((self = [super init])) { |
98 observer_.reset(new SSLClientAuthObserverCocoaBridge( | 97 observer_.reset(new SSLClientAuthObserverCocoaBridge( |
99 networkSession, certRequestInfo, callback, self)); | 98 browserContext, certRequestInfo, callback, self)); |
100 } | 99 } |
101 return self; | 100 return self; |
102 } | 101 } |
103 | 102 |
104 - (void)sheetDidEnd:(NSWindow*)parent | 103 - (void)sheetDidEnd:(NSWindow*)parent |
105 returnCode:(NSInteger)returnCode | 104 returnCode:(NSInteger)returnCode |
106 context:(void*)context { | 105 context:(void*)context { |
107 net::X509Certificate* cert = NULL; | 106 net::X509Certificate* cert = NULL; |
108 if (returnCode == NSFileHandlingPanelOKButton) { | 107 if (returnCode == NSFileHandlingPanelOKButton) { |
109 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); | 108 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 229 } |
231 | 230 |
232 - (void)onConstrainedWindowClosed { | 231 - (void)onConstrainedWindowClosed { |
233 observer_->StopObserving(); | 232 observer_->StopObserving(); |
234 panel_.reset(); | 233 panel_.reset(); |
235 constrainedWindow_.reset(); | 234 constrainedWindow_.reset(); |
236 [self release]; | 235 [self release]; |
237 } | 236 } |
238 | 237 |
239 @end | 238 @end |
OLD | NEW |