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

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: Move certificate_viewer_mac.* to chrome/browser/ui and certificate_viewer_mac_views.mm to chrome/br… Created 4 years, 4 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 - (void)displayForWebContents:(content::WebContents*)webContents {
56 [super displayForWebContents:webContents];
57
58 observer_.reset(new SSLCertificateViewerCocoaBridge(self));
59 constrainedWindow_ =
60 CreateAndShowWebModalDialogMac(observer_.get(), webContents, self);
61 }
62
63 - (void)onConstrainedWindowClosed {
64 [self releaseSheetWindow];
65 constrainedWindow_.reset();
66 [self release];
67 }
68
69 // SSLCertificateViewerMac overrides:
70
71 - (void)sheetDidEnd:(NSWindow*)parent
72 returnCode:(NSInteger)returnCode
73 context:(void*)context {
74 if (!closePending_)
75 constrainedWindow_->CloseWebContentsModalDialog();
76 }
77
78 // ConstrainedWindowSheet protocol implementation.
79
80 - (void)showSheetForWindow:(NSWindow*)window {
81 overlayWindow_.reset([window retain]);
82 [self showCertificateSheet:window];
83 }
84
85 - (void)closeSheetWithAnimation:(BOOL)withAnimation {
86 closePending_ = YES;
87 overlayWindow_.reset();
88 [self closeCertificateSheet];
89 }
90
91 - (void)hideSheet {
92 NSWindow* sheetWindow = [overlayWindow_ attachedSheet];
93 [sheetWindow setAlphaValue:0.0];
94 [sheetWindow setIgnoresMouseEvents:YES];
95
96 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews];
97 [[sheetWindow contentView] setAutoresizesSubviews:NO];
98 }
99
100 - (void)unhideSheet {
101 NSWindow* sheetWindow = [overlayWindow_ attachedSheet];
102 [sheetWindow setIgnoresMouseEvents:NO];
103
104 [[sheetWindow contentView] setAutoresizesSubviews:oldResizesSubviews_];
105 [[overlayWindow_ attachedSheet] setAlphaValue:1.0];
106 }
107
108 - (void)pulseSheet {
109 // NOOP
110 }
111
112 - (void)makeSheetKeyAndOrderFront {
113 [[overlayWindow_ attachedSheet] makeKeyAndOrderFront:nil];
114 }
115
116 - (void)updateSheetPosition {
117 // NOOP
118 }
119
120 - (void)resizeWithNewSize:(NSSize)preferredSize {
121 // NOOP
122 }
123
124 - (NSWindow*)sheetWindow {
125 return [self certificatePanel];
126 }
127
128 @end
129
130 void ShowCertificateViewer(content::WebContents* web_contents,
131 gfx::NativeWindow parent,
132 net::X509Certificate* cert) {
133 // SSLCertificateViewerCocoa will manage its own lifetime and will release
134 // itself when the dialog is closed.
135 // See -[SSLCertificateViewerCocoa onConstrainedWindowClosed].
136 SSLCertificateViewerCocoa* viewer =
137 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert];
138 [viewer displayForWebContents:web_contents];
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698