| 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 content::BrowserContext* browser_context, | 43 const net::HttpNetworkSession* network_session, |
| 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(browser_context, cert_request_info, callback), | 47 : SSLClientAuthObserver(network_session, 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, |
| 75 net::SSLCertRequestInfo* cert_request_info, | 76 net::SSLCertRequestInfo* cert_request_info, |
| 76 const SelectCertificateCallback& callback) { | 77 const SelectCertificateCallback& callback) { |
| 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 78 // The dialog manages its own lifetime. | 79 // The dialog manages its own lifetime. |
| 79 SSLClientCertificateSelectorCocoa* selector = | 80 SSLClientCertificateSelectorCocoa* selector = |
| 80 [[SSLClientCertificateSelectorCocoa alloc] | 81 [[SSLClientCertificateSelectorCocoa alloc] |
| 81 initWithBrowserContext:contents->GetBrowserContext() | 82 initWithNetworkSession:network_session |
| 82 certRequestInfo:cert_request_info | 83 certRequestInfo:cert_request_info |
| 83 callback:callback]; | 84 callback:callback]; |
| 84 [selector displayForWebContents:contents]; | 85 [selector displayForWebContents:contents]; |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace chrome | 88 } // namespace chrome |
| 88 | 89 |
| 89 @implementation SSLClientCertificateSelectorCocoa | 90 @implementation SSLClientCertificateSelectorCocoa |
| 90 | 91 |
| 91 - (id)initWithBrowserContext:(const content::BrowserContext*)browserContext | 92 - (id)initWithNetworkSession:(const net::HttpNetworkSession*)networkSession |
| 92 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo | 93 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo |
| 93 callback:(const chrome::SelectCertificateCallback&)callback { | 94 callback:(const chrome::SelectCertificateCallback&)callback { |
| 94 DCHECK(browserContext); | 95 DCHECK(networkSession); |
| 95 DCHECK(certRequestInfo); | 96 DCHECK(certRequestInfo); |
| 96 if ((self = [super init])) { | 97 if ((self = [super init])) { |
| 97 observer_.reset(new SSLClientAuthObserverCocoaBridge( | 98 observer_.reset(new SSLClientAuthObserverCocoaBridge( |
| 98 browserContext, certRequestInfo, callback, self)); | 99 networkSession, certRequestInfo, callback, self)); |
| 99 } | 100 } |
| 100 return self; | 101 return self; |
| 101 } | 102 } |
| 102 | 103 |
| 103 - (void)sheetDidEnd:(NSWindow*)parent | 104 - (void)sheetDidEnd:(NSWindow*)parent |
| 104 returnCode:(NSInteger)returnCode | 105 returnCode:(NSInteger)returnCode |
| 105 context:(void*)context { | 106 context:(void*)context { |
| 106 net::X509Certificate* cert = NULL; | 107 net::X509Certificate* cert = NULL; |
| 107 if (returnCode == NSFileHandlingPanelOKButton) { | 108 if (returnCode == NSFileHandlingPanelOKButton) { |
| 108 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); | 109 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 230 } |
| 230 | 231 |
| 231 - (void)onConstrainedWindowClosed { | 232 - (void)onConstrainedWindowClosed { |
| 232 observer_->StopObserving(); | 233 observer_->StopObserving(); |
| 233 panel_.reset(); | 234 panel_.reset(); |
| 234 constrainedWindow_.reset(); | 235 constrainedWindow_.reset(); |
| 235 [self release]; | 236 [self release]; |
| 236 } | 237 } |
| 237 | 238 |
| 238 @end | 239 @end |
| OLD | NEW |