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

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

Issue 1779383002: MacViews: Remove constrained window dependencies for certificate viewer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep a reference to the sheet window in single_web_contents_dialog_manager_cocoa.mm. Created 4 years, 6 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/certificate_viewer_mac_cocoa.h"
6
7 #include "base/logging.h"
8 #import "base/mac/foundation_util.h"
9 #include "chrome/browser/certificate_viewer.h"
10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h"
12
13 @interface SSLCertificateViewerCocoa ()
14 - (void)displayForWebContents:(content::WebContents*)webContents;
15 - (void)onConstrainedWindowClosed;
16 @end
17
18 namespace {
19
20 class SSLCertificateViewerCocoaBridge : public ConstrainedWindowMacDelegate {
21 public:
22 explicit SSLCertificateViewerCocoaBridge(
23 SSLCertificateViewerCocoa* controller)
24 : controller_(controller) {}
25
26 // ConstrainedWindowMacDelegate:
27 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override {
28 // |onConstrainedWindowClosed| will delete the sheet which might still be
29 // in use higher up the call stack. Wait for the next cycle of the event
30 // loop to call this function.
31 [controller_ performSelector:@selector(onConstrainedWindowClosed)
32 withObject:nil
33 afterDelay:0];
34 }
35
36 private:
37 SSLCertificateViewerCocoa* controller_; // Weak. Owns this.
38
39 DISALLOW_COPY_AND_ASSIGN(SSLCertificateViewerCocoaBridge);
40 };
41
42 } // namespace
43
44 @implementation SSLCertificateViewerCocoa {
45 std::unique_ptr<SSLCertificateViewerCocoaBridge> observer_;
46 std::unique_ptr<ConstrainedWindowMac> constrainedWindow_;
47 base::scoped_nsobject<NSWindow> overlayWindow_;
48 // A copy of the sheet's frame. Used to restore on show.
49 NSRect oldSheetFrame_;
50 BOOL closePending_;
51 // A copy of the sheet's |autoresizesSubviews| flag to restore on show.
52 BOOL oldResizesSubviews_;
53 }
54
55 - (NSWindow*)overlayWindow {
56 return overlayWindow_;
57 }
58
59 - (void)displayForWebContents:(content::WebContents*)webContents {
60 [super displayForWebContents:webContents];
61
62 observer_.reset(new SSLCertificateViewerCocoaBridge(self));
63 constrainedWindow_ =
64 CreateAndShowWebModalDialogMac(observer_.get(), webContents, self);
65 }
66
67 - (void)onConstrainedWindowClosed {
68 constrainedWindow_.reset();
69 [self release];
70 }
71
72 // SSLCertificateViewerMac overrides:
73
74 - (void)sheetDidEnd:(NSWindow*)parent
75 returnCode:(NSInteger)returnCode
76 context:(void*)context {
77 if (!closePending_)
78 constrainedWindow_->CloseWebContentsModalDialog();
79 }
80
81 // ConstrainedWindowSheet protocol implementation.
82
83 - (void)showSheetForWindow:(NSWindow*)window {
84 overlayWindow_.reset([window retain]);
85 [self showCertificateSheet:window];
86 }
87
88 - (void)closeSheetWithAnimation:(BOOL)withAnimation {
89 closePending_ = YES;
90 overlayWindow_.reset();
91 [self closeCertificateSheet];
92 }
93
94 - (void)hideSheet {
95 NSWindow* sheetWindow = [overlayWindow_ attachedSheet];
96 [sheetWindow setAlphaValue:0.0];
97 [sheetWindow setIgnoresMouseEvents:YES];
98
99 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews];
100 [[sheetWindow contentView] setAutoresizesSubviews:NO];
101 }
102
103 - (void)unhideSheet {
104 NSWindow* sheetWindow = [overlayWindow_ attachedSheet];
105 [sheetWindow setIgnoresMouseEvents:NO];
106
107 [[sheetWindow contentView] setAutoresizesSubviews:oldResizesSubviews_];
108 [[overlayWindow_ attachedSheet] setAlphaValue:1.0];
109 }
110
111 - (void)pulseSheet {
112 // NOOP
113 }
114
115 - (void)makeSheetKeyAndOrderFront {
116 [[overlayWindow_ attachedSheet] makeKeyAndOrderFront:nil];
117 }
118
119 - (void)updateSheetPosition {
120 // NOOP
121 }
122
123 - (void)resizeWithNewSize:(NSSize)preferredSize {
124 // NOOP
125 }
126
127 - (NSWindow*)sheetWindow {
128 return [self certificatePanel];
129 }
130
131 @end
132
133 void ShowCertificateViewer(content::WebContents* web_contents,
134 gfx::NativeWindow parent,
135 net::X509Certificate* cert) {
136 // SSLCertificateViewerCocoa will manage its own lifetime and will release
137 // itself when the dialog is closed.
138 // See -[SSLCertificateViewerCocoa onConstrainedWindowClosed].
139 SSLCertificateViewerCocoa* viewer =
140 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert];
141 [viewer displayForWebContents:web_contents];
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698