OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
tapted
2016/03/21 02:47:12
nit: no (c)
Patti Lor
2016/05/03 00:05:00
Done.
| |
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/certificate_viewer_mac.h" | 5 #include "chrome/browser/mac/certificate_viewer_base.h" |
tapted
2016/03/21 02:47:12
import
Patti Lor
2016/05/03 00:05:00
Done.
| |
6 | |
7 #include <Security/Security.h> | |
8 #include <SecurityInterface/SFCertificatePanel.h> | |
9 #include <vector> | |
10 | 6 |
11 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/macros.h" | |
14 #include "chrome/browser/certificate_viewer.h" | |
15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | |
16 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | |
17 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h" | |
18 #include "net/cert/x509_certificate.h" | 9 #include "net/cert/x509_certificate.h" |
19 #include "net/cert/x509_util_mac.h" | 10 #include "net/cert/x509_util_mac.h" |
20 #import "ui/base/cocoa/window_size_constants.h" | |
21 | 11 |
22 class SSLCertificateViewerCocoaBridge; | |
23 | 12 |
24 @interface SFCertificatePanel (SystemPrivate) | 13 @implementation SSLCertificateViewerMacBase |
25 // A system-private interface that dismisses a panel whose sheet was started by | |
26 // -beginSheetForWindow: | |
27 // modalDelegate: | |
28 // didEndSelector: | |
29 // contextInfo: | |
30 // certificates: | |
31 // showGroup: | |
32 // as though the user clicked the button identified by returnCode. Verified | |
33 // present in 10.8. | |
34 - (void)_dismissWithCode:(NSInteger)code; | |
35 @end | |
36 | |
37 @interface SSLCertificateViewerCocoa () | |
38 - (void)onConstrainedWindowClosed; | |
39 @end | |
40 | |
41 class SSLCertificateViewerCocoaBridge : public ConstrainedWindowMacDelegate { | |
42 public: | |
43 explicit SSLCertificateViewerCocoaBridge(SSLCertificateViewerCocoa * | |
44 controller) | |
45 : controller_(controller) { | |
46 } | |
47 | |
48 virtual ~SSLCertificateViewerCocoaBridge() {} | |
49 | |
50 // ConstrainedWindowMacDelegate implementation: | |
51 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { | |
52 // |onConstrainedWindowClosed| will delete the sheet which might be still | |
53 // in use higher up the call stack. Wait for the next cycle of the event | |
54 // loop to call this function. | |
55 [controller_ performSelector:@selector(onConstrainedWindowClosed) | |
56 withObject:nil | |
57 afterDelay:0]; | |
58 } | |
59 | |
60 private: | |
61 SSLCertificateViewerCocoa* controller_; // weak | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(SSLCertificateViewerCocoaBridge); | |
64 }; | |
65 | |
66 void ShowCertificateViewer(content::WebContents* web_contents, | |
67 gfx::NativeWindow parent, | |
68 net::X509Certificate* cert) { | |
69 // SSLCertificateViewerCocoa will manage its own lifetime and will release | |
70 // itself when the dialog is closed. | |
71 // See -[SSLCertificateViewerCocoa onConstrainedWindowClosed]. | |
72 SSLCertificateViewerCocoa* viewer = | |
73 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert]; | |
74 [viewer displayForWebContents:web_contents]; | |
75 } | |
76 | |
77 @implementation SSLCertificateViewerCocoa | |
78 | 14 |
79 - (id)initWithCertificate:(net::X509Certificate*)certificate { | 15 - (id)initWithCertificate:(net::X509Certificate*)certificate { |
80 if ((self = [super init])) { | 16 if ((self = [super init])) { |
81 base::ScopedCFTypeRef<CFArrayRef> cert_chain( | 17 base::ScopedCFTypeRef<CFArrayRef> cert_chain( |
82 certificate->CreateOSCertChainForCert()); | 18 certificate->CreateOSCertChainForCert()); |
83 NSArray* certificates = base::mac::CFToNSCast(cert_chain.get()); | 19 NSArray* certificates = base::mac::CFToNSCast(cert_chain.get()); |
84 certificates_.reset([certificates retain]); | 20 certificates_.reset([certificates retain]); |
85 } | 21 } |
86 return self; | 22 return self; |
87 } | 23 } |
88 | 24 |
89 - (void)sheetDidEnd:(NSWindow*)parent | |
90 returnCode:(NSInteger)returnCode | |
91 context:(void*)context { | |
92 if (!closePending_) | |
93 constrainedWindow_->CloseWebContentsModalDialog(); | |
94 } | |
95 | |
96 - (void)displayForWebContents:(content::WebContents*)webContents { | 25 - (void)displayForWebContents:(content::WebContents*)webContents { |
97 // Explicitly disable revocation checking, regardless of user preferences | 26 // Explicitly disable revocation checking, regardless of user preferences |
98 // or system settings. The behaviour of SFCertificatePanel is to call | 27 // or system settings. The behaviour of SFCertificatePanel is to call |
99 // SecTrustEvaluate on the certificate(s) supplied, effectively | 28 // SecTrustEvaluate on the certificate(s) supplied, effectively |
100 // duplicating the behaviour of net::X509Certificate::Verify(). However, | 29 // duplicating the behaviour of net::X509Certificate::Verify(). However, |
101 // this call stalls the UI if revocation checking is enabled in the | 30 // this call stalls the UI if revocation checking is enabled in the |
102 // Keychain preferences or if the cert may be an EV cert. By disabling | 31 // Keychain preferences or if the cert may be an EV cert. By disabling |
103 // revocation checking, the stall is limited to the time taken for path | 32 // revocation checking, the stall is limited to the time taken for path |
104 // building and verification, which should be minimized due to the path | 33 // building and verification, which should be minimized due to the path |
105 // being provided in |certificates|. This does not affect normal | 34 // being provided in |certificates|. This does not affect normal |
(...skipping 20 matching lines...) Expand all Loading... | |
126 CFRelease(basic_policy); | 55 CFRelease(basic_policy); |
127 | 56 |
128 status = net::x509_util::CreateRevocationPolicies(false, false, policies); | 57 status = net::x509_util::CreateRevocationPolicies(false, false, policies); |
129 if (status != noErr) { | 58 if (status != noErr) { |
130 NOTREACHED(); | 59 NOTREACHED(); |
131 return; | 60 return; |
132 } | 61 } |
133 | 62 |
134 panel_.reset([[SFCertificatePanel alloc] init]); | 63 panel_.reset([[SFCertificatePanel alloc] init]); |
135 [panel_ setPolicies:(id) policies.get()]; | 64 [panel_ setPolicies:(id) policies.get()]; |
136 | |
137 constrainedWindow_ = | |
138 CreateAndShowWebModalDialogMac(observer_.get(), webContents, self); | |
139 } | 65 } |
140 | 66 |
141 - (NSWindow*)overlayWindow { | 67 - (NSWindow*)overlayWindow { |
142 return overlayWindow_; | 68 return overlayWindow_; |
143 } | 69 } |
144 | 70 |
71 // ConstrainedWindowSheet: | |
tapted
2016/03/21 02:47:12
For objc the current approach is something like
/
Patti Lor
2016/05/03 00:05:00
Done.
| |
72 | |
145 - (void)showSheetForWindow:(NSWindow*)window { | 73 - (void)showSheetForWindow:(NSWindow*)window { |
146 overlayWindow_.reset([window retain]); | 74 overlayWindow_.reset([window retain]); |
147 [panel_ beginSheetForWindow:window | 75 [panel_ beginSheetForWindow:window |
148 modalDelegate:self | 76 modalDelegate:self |
149 didEndSelector:@selector(sheetDidEnd: | 77 didEndSelector:@selector(sheetDidEnd: |
150 returnCode: | 78 returnCode: |
151 context:) | 79 context:) |
152 contextInfo:NULL | 80 contextInfo:NULL |
tapted
2016/03/21 02:47:12
rollback indenting change
Patti Lor
2016/05/03 00:05:00
Done.
| |
153 certificates:certificates_ | 81 certificates:certificates_ |
154 showGroup:YES]; | 82 showGroup:YES]; |
155 } | 83 } |
156 | 84 |
157 - (void)closeSheetWithAnimation:(BOOL)withAnimation { | 85 - (void)closeSheetWithAnimation:(BOOL)withAnimation { |
158 closePending_ = YES; | 86 closePending_ = YES; |
159 overlayWindow_.reset(); | 87 overlayWindow_.reset(); |
160 // Closing the sheet using -[NSApp endSheet:] doesn't work so use the private | 88 // Closing the sheet using -[NSApp endSheet:] doesn't work so use the |
tapted
2016/03/21 02:47:12
re-wrap
Patti Lor
2016/05/03 00:05:00
Done.
| |
161 // method. | 89 // private method. |
162 [panel_ _dismissWithCode:NSFileHandlingPanelCancelButton]; | 90 [panel_ _dismissWithCode:NSFileHandlingPanelCancelButton]; |
163 } | 91 } |
164 | 92 |
165 - (void)hideSheet { | 93 - (void)hideSheet { |
166 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; | 94 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; |
167 [sheetWindow setAlphaValue:0.0]; | 95 [sheetWindow setAlphaValue:0.0]; |
168 | 96 |
169 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews]; | 97 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews]; |
170 [[sheetWindow contentView] setAutoresizesSubviews:NO]; | 98 [[sheetWindow contentView] setAutoresizesSubviews:NO]; |
171 } | 99 } |
(...skipping 18 matching lines...) Expand all Loading... | |
190 } | 118 } |
191 | 119 |
192 - (void)resizeWithNewSize:(NSSize)preferredSize { | 120 - (void)resizeWithNewSize:(NSSize)preferredSize { |
193 // NOOP | 121 // NOOP |
194 } | 122 } |
195 | 123 |
196 - (NSWindow*)sheetWindow { | 124 - (NSWindow*)sheetWindow { |
197 return panel_; | 125 return panel_; |
198 } | 126 } |
199 | 127 |
200 - (void)onConstrainedWindowClosed { | |
201 panel_.reset(); | |
202 constrainedWindow_.reset(); | |
203 [self release]; | |
204 } | |
205 | |
206 @end | 128 @end |
OLD | NEW |