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

Side by Side Diff: chrome/browser/ui/cocoa/certificate_viewer_mac.mm

Issue 1779383002: MacViews: Remove constrained window dependencies for certificate viewer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore overlayWindow method for SSLCertificateViewerCocoa, fix test, other nits. Created 4 years, 7 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
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/certificate_viewer_mac.h" 5 #import "chrome/browser/ui/cocoa/certificate_viewer_mac.h"
6 6
7 #include <Security/Security.h>
8 #include <SecurityInterface/SFCertificatePanel.h>
9 #include <vector>
10
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" 9 #include "content/public/browser/web_contents.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" 10 #include "net/cert/x509_certificate.h"
19 #include "net/cert/x509_util_mac.h" 11 #include "net/cert/x509_util_mac.h"
20 #import "ui/base/cocoa/window_size_constants.h"
21 12
22 class SSLCertificateViewerCocoaBridge; 13 @implementation SSLCertificateViewerMac {
23 14 // The corresponding list of certificates.
24 @interface SFCertificatePanel (SystemPrivate) 15 base::scoped_nsobject<NSArray> certificates_;
25 // A system-private interface that dismisses a panel whose sheet was started by 16 base::scoped_nsobject<SFCertificatePanel> panel_;
26 // -beginSheetForWindow: 17 BOOL closePending_;
27 // modalDelegate: 18 BOOL oldResizesSubviews_;
tapted 2016/05/19 01:53:25 Can this move into certificate_viewer_mac_cocoa.mm
Patti Lor 2016/05/25 05:43:00 Done.
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 } 19 }
76 20
77 @implementation SSLCertificateViewerCocoa 21 @synthesize closePending = closePending_;
22 @synthesize oldResizesSubviews = oldResizesSubviews_;
78 23
79 - (id)initWithCertificate:(net::X509Certificate*)certificate { 24 - (id)initWithCertificate:(net::X509Certificate*)certificate {
80 if ((self = [super init])) { 25 if ((self = [super init])) {
81 base::ScopedCFTypeRef<CFArrayRef> cert_chain( 26 base::ScopedCFTypeRef<CFArrayRef> cert_chain(
82 certificate->CreateOSCertChainForCert()); 27 certificate->CreateOSCertChainForCert());
83 NSArray* certificates = base::mac::CFToNSCast(cert_chain.get()); 28 NSArray* certificates = base::mac::CFToNSCast(cert_chain.get());
84 certificates_.reset([certificates retain]); 29 certificates_.reset([certificates retain]);
85 } 30 }
86 return self; 31 return self;
87 } 32 }
88 33
89 - (void)sheetDidEnd:(NSWindow*)parent 34 - (void)sheetDidEnd:(NSWindow*)parent {
tapted 2016/05/19 01:53:25 this should be the full prototype - (void)sheetDi
Patti Lor 2016/05/25 05:43:00 Done.
90 returnCode:(NSInteger)returnCode 35 NOTREACHED(); // Subclasses must implement this.
91 context:(void*)context {
92 if (!closePending_)
93 constrainedWindow_->CloseWebContentsModalDialog();
94 } 36 }
95 37
96 - (void)displayForWebContents:(content::WebContents*)webContents { 38 - (void)displayForWebContents:(content::WebContents*)webContents {
97 // Explicitly disable revocation checking, regardless of user preferences 39 // Explicitly disable revocation checking, regardless of user preferences
98 // or system settings. The behaviour of SFCertificatePanel is to call 40 // or system settings. The behaviour of SFCertificatePanel is to call
99 // SecTrustEvaluate on the certificate(s) supplied, effectively 41 // SecTrustEvaluate on the certificate(s) supplied, effectively
100 // duplicating the behaviour of net::X509Certificate::Verify(). However, 42 // duplicating the behaviour of net::X509Certificate::Verify(). However,
101 // this call stalls the UI if revocation checking is enabled in the 43 // 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 44 // 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 45 // revocation checking, the stall is limited to the time taken for path
(...skipping 22 matching lines...) Expand all
126 CFRelease(basic_policy); 68 CFRelease(basic_policy);
127 69
128 status = net::x509_util::CreateRevocationPolicies(false, false, policies); 70 status = net::x509_util::CreateRevocationPolicies(false, false, policies);
129 if (status != noErr) { 71 if (status != noErr) {
130 NOTREACHED(); 72 NOTREACHED();
131 return; 73 return;
132 } 74 }
133 75
134 panel_.reset([[SFCertificatePanel alloc] init]); 76 panel_.reset([[SFCertificatePanel alloc] init]);
135 [panel_ setPolicies:(id) policies.get()]; 77 [panel_ setPolicies:(id) policies.get()];
136
137 constrainedWindow_ =
138 CreateAndShowWebModalDialogMac(observer_.get(), webContents, self);
139 } 78 }
140 79
141 - (NSWindow*)overlayWindow { 80 - (void)deleteSheetWindow {
142 return overlayWindow_; 81 panel_.reset();
143 } 82 }
144 83
84 // ConstrainedWindowSheet protocol implementation.
85
145 - (void)showSheetForWindow:(NSWindow*)window { 86 - (void)showSheetForWindow:(NSWindow*)window {
tapted 2016/05/19 01:53:25 Rename this method to showCertificateSheet
Patti Lor 2016/05/25 05:43:00 This is a method declared in the ConstrainedWindow
146 overlayWindow_.reset([window retain]);
147 [panel_ beginSheetForWindow:window 87 [panel_ beginSheetForWindow:window
148 modalDelegate:self 88 modalDelegate:self
149 didEndSelector:@selector(sheetDidEnd: 89 didEndSelector:@selector(sheetDidEnd:
150 returnCode: 90 returnCode:
151 context:) 91 context:)
152 contextInfo:NULL 92 contextInfo:NULL
153 certificates:certificates_ 93 certificates:certificates_
154 showGroup:YES]; 94 showGroup:YES];
155 } 95 }
156 96
157 - (void)closeSheetWithAnimation:(BOOL)withAnimation { 97 - (void)closeSheetWithAnimation:(BOOL)withAnimation {
tapted 2016/05/19 01:53:25 Rename this method to closeCertificateSheet
Patti Lor 2016/05/25 05:43:00 See comment on showSheetForWindow.
158 closePending_ = YES; 98 closePending_ = YES;
159 overlayWindow_.reset();
160 // Closing the sheet using -[NSApp endSheet:] doesn't work so use the private 99 // Closing the sheet using -[NSApp endSheet:] doesn't work so use the private
161 // method. 100 // method.
162 [panel_ _dismissWithCode:NSFileHandlingPanelCancelButton]; 101 [panel_ _dismissWithCode:NSFileHandlingPanelCancelButton];
tapted 2016/05/19 01:53:25 try a panel_.reset() after this?
Patti Lor 2016/05/25 05:43:00 As discussed offline this doesn't work for the Coc
163 } 102 }
164 103
165 - (void)hideSheet { 104 - (void)hideSheet {
166 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; 105 NOTREACHED(); // Subclasses must implement this.
167 [sheetWindow setAlphaValue:0.0];
168
169 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews];
170 [[sheetWindow contentView] setAutoresizesSubviews:NO];
171 } 106 }
172 107
173 - (void)unhideSheet { 108 - (void)unhideSheet {
174 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; 109 NOTREACHED(); // Subclasses must implement this.
175
176 [[sheetWindow contentView] setAutoresizesSubviews:oldResizesSubviews_];
177 [[overlayWindow_ attachedSheet] setAlphaValue:1.0];
178 } 110 }
179 111
180 - (void)pulseSheet { 112 - (void)pulseSheet {
181 // NOOP 113 // NOOP
182 } 114 }
183 115
184 - (void)makeSheetKeyAndOrderFront { 116 - (void)makeSheetKeyAndOrderFront {
185 [[overlayWindow_ attachedSheet] makeKeyAndOrderFront:nil]; 117 NOTREACHED(); // Subclasses must implement this.
186 } 118 }
187 119
188 - (void)updateSheetPosition { 120 - (void)updateSheetPosition {
189 // NOOP 121 // NOOP
190 } 122 }
191 123
192 - (void)resizeWithNewSize:(NSSize)preferredSize { 124 - (void)resizeWithNewSize:(NSSize)preferredSize {
193 // NOOP 125 // NOOP
194 } 126 }
195 127
196 - (NSWindow*)sheetWindow { 128 - (NSWindow*)sheetWindow {
197 return panel_; 129 return panel_;
198 } 130 }
199 131
200 - (void)onConstrainedWindowClosed {
201 panel_.reset();
202 constrainedWindow_.reset();
203 [self release];
204 }
205
206 @end 132 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698