Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.h" | |
|
tapted
2016/05/31 07:44:47
nit: remove (not needed since the corresponding he
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h" | |
| 13 | |
| 14 class SSLCertificateViewerCocoaBridge : public ConstrainedWindowMacDelegate { | |
|
tapted
2016/05/31 07:44:47
wrap this in an anonymous
namespace {
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 15 public: | |
| 16 explicit SSLCertificateViewerCocoaBridge( | |
| 17 SSLCertificateViewerCocoa* controller) | |
| 18 : controller_(controller) {} | |
| 19 | |
| 20 virtual ~SSLCertificateViewerCocoaBridge() {} | |
|
tapted
2016/05/31 07:44:47
nit: can this be removed? the compiler-provided de
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 21 | |
| 22 // ConstrainedWindowMacDelegate implementation: | |
|
tapted
2016/05/31 07:44:47
nit: // ConstrainedWindowMacDelegate:
(the ... im
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 23 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { | |
| 24 // |onConstrainedWindowClosed| will delete the sheet which might still be | |
| 25 // in use higher up the call stack. Wait for the next cycle of the event | |
| 26 // loop to call this function. | |
| 27 [controller_ performSelector:@selector(onConstrainedWindowClosed) | |
| 28 withObject:nil | |
| 29 afterDelay:0]; | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 SSLCertificateViewerCocoa* controller_; // Weak. Owns this. | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(SSLCertificateViewerCocoaBridge); | |
| 36 }; | |
| 37 | |
|
tapted
2016/05/31 07:44:47
} // namespace
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 38 @implementation SSLCertificateViewerCocoa { | |
| 39 std::unique_ptr<SSLCertificateViewerCocoaBridge> observer_; | |
| 40 std::unique_ptr<ConstrainedWindowMac> constrainedWindow_; | |
| 41 base::scoped_nsobject<NSWindow> overlayWindow_; | |
| 42 // A copy of the sheet's frame. Used to restore on show. | |
| 43 NSRect oldSheetFrame_; | |
| 44 BOOL closePending_; | |
| 45 // A copy of the sheet's |autoresizesSubviews| flag to restore on show. | |
| 46 BOOL oldResizesSubviews_; | |
| 47 } | |
| 48 | |
| 49 - (void)sheetDidEnd:(NSWindow*)parent | |
|
tapted
2016/05/31 07:44:47
nit: this should come before // ConstrainedWindowS
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 50 returnCode:(NSInteger)returnCode | |
| 51 context:(void*)context { | |
| 52 if (!closePending_) | |
| 53 constrainedWindow_->CloseWebContentsModalDialog(); | |
| 54 } | |
| 55 | |
| 56 - (void)displayForWebContents:(content::WebContents*)webContents { | |
|
tapted
2016/05/31 07:44:48
So.. since displayForWebContents and onConstrained
Patti Lor
2016/06/06 06:52:45
Done.
| |
| 57 [super displayForWebContents:webContents]; | |
| 58 | |
| 59 observer_.reset(new SSLCertificateViewerCocoaBridge(self)); | |
| 60 constrainedWindow_ = | |
| 61 CreateAndShowWebModalDialogMac(observer_.get(), webContents, self); | |
| 62 } | |
| 63 | |
| 64 - (NSWindow*)overlayWindow { | |
|
tapted
2016/05/31 07:44:47
nit: this should be defined first, since it's in t
Patti Lor
2016/06/06 06:52:46
Done.
| |
| 65 return overlayWindow_; | |
| 66 } | |
| 67 | |
| 68 - (void)onConstrainedWindowClosed { | |
| 69 constrainedWindow_.reset(); | |
| 70 [self release]; | |
| 71 } | |
| 72 | |
| 73 // ConstrainedWindowSheet protocol implementation. | |
| 74 | |
| 75 - (void)showSheetForWindow:(NSWindow*)window { | |
| 76 overlayWindow_.reset([window retain]); | |
| 77 [self showCertificateSheet:window]; | |
| 78 } | |
| 79 | |
| 80 - (void)closeSheetWithAnimation:(BOOL)withAnimation { | |
| 81 closePending_ = YES; | |
| 82 overlayWindow_.reset(); | |
| 83 [self closeCertificateSheet:withAnimation]; | |
| 84 } | |
| 85 | |
| 86 - (void)hideSheet { | |
| 87 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; | |
| 88 [sheetWindow setAlphaValue:0.0]; | |
| 89 [sheetWindow setIgnoresMouseEvents:YES]; | |
| 90 | |
| 91 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews]; | |
| 92 [[sheetWindow contentView] setAutoresizesSubviews:NO]; | |
| 93 } | |
| 94 | |
| 95 - (void)unhideSheet { | |
| 96 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; | |
| 97 [sheetWindow setIgnoresMouseEvents:NO]; | |
| 98 | |
| 99 [[sheetWindow contentView] setAutoresizesSubviews:oldResizesSubviews_]; | |
| 100 [[overlayWindow_ attachedSheet] setAlphaValue:1.0]; | |
| 101 } | |
| 102 | |
| 103 - (void)pulseSheet { | |
| 104 // NOOP | |
| 105 } | |
| 106 | |
| 107 - (void)makeSheetKeyAndOrderFront { | |
| 108 [[overlayWindow_ attachedSheet] makeKeyAndOrderFront:nil]; | |
| 109 } | |
| 110 | |
| 111 - (void)updateSheetPosition { | |
| 112 // NOOP | |
| 113 } | |
| 114 | |
| 115 - (void)resizeWithNewSize:(NSSize)preferredSize { | |
| 116 // NOOP | |
| 117 } | |
| 118 | |
| 119 - (NSWindow*)sheetWindow { | |
| 120 return [self certificatePanel]; | |
| 121 } | |
| 122 | |
| 123 @end | |
| 124 | |
| 125 void ShowCertificateViewer(content::WebContents* web_contents, | |
| 126 gfx::NativeWindow parent, | |
| 127 net::X509Certificate* cert) { | |
| 128 // SSLCertificateViewerCocoa will manage its own lifetime and will release | |
| 129 // itself when the dialog is closed. | |
| 130 // See -[SSLCertificateViewerCocoa onConstrainedWindowClosed]. | |
| 131 SSLCertificateViewerCocoa* viewer = | |
| 132 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert]; | |
| 133 [viewer displayForWebContents:web_contents]; | |
| 134 } | |
| OLD | NEW |