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" |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 13 |
| 14 class SSLCertificateViewerCocoaBridge : public ConstrainedWindowMacDelegate { |
| 15 public: |
| 16 explicit SSLCertificateViewerCocoaBridge( |
| 17 SSLCertificateViewerCocoa* controller) |
| 18 : controller_(controller) {} |
| 19 |
| 20 virtual ~SSLCertificateViewerCocoaBridge() {} |
| 21 |
| 22 // ConstrainedWindowMacDelegate implementation: |
| 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 |
| 38 @implementation SSLCertificateViewerCocoa |
| 39 |
| 40 - (void)sheetDidEnd:(NSWindow*)parent |
| 41 returnCode:(NSInteger)returnCode |
| 42 context:(void*)context { |
| 43 if (!closePending_) |
| 44 constrainedWindow_->CloseWebContentsModalDialog(); |
| 45 } |
| 46 |
| 47 - (void)displayForWebContents:(content::WebContents*)webContents { |
| 48 [super displayForWebContents:webContents]; |
| 49 |
| 50 constrainedWindow_ = |
| 51 CreateAndShowWebModalDialogMac(observer_.get(), webContents, self); |
| 52 } |
| 53 |
| 54 - (NSWindow*)overlayWindow { |
| 55 return overlayWindow_; |
| 56 } |
| 57 |
| 58 - (void)showSheetForWindow:(NSWindow*)window { |
| 59 overlayWindow_.reset([window retain]); |
| 60 [super showSheetForWindow:window]; |
| 61 } |
| 62 |
| 63 - (void)closeSheetWithAnimation:(BOOL)withAnimation { |
| 64 overlayWindow_.reset(); |
| 65 [super closeSheetWithAnimation:withAnimation]; |
| 66 } |
| 67 |
| 68 - (void)hideSheet { |
| 69 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; |
| 70 [sheetWindow setAlphaValue:0.0]; |
| 71 [sheetWindow setIgnoresMouseEvents:YES]; |
| 72 |
| 73 oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews]; |
| 74 [[sheetWindow contentView] setAutoresizesSubviews:NO]; |
| 75 } |
| 76 |
| 77 - (void)unhideSheet { |
| 78 NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; |
| 79 [sheetWindow setIgnoresMouseEvents:NO]; |
| 80 |
| 81 [[sheetWindow contentView] setAutoresizesSubviews:oldResizesSubviews_]; |
| 82 [[overlayWindow_ attachedSheet] setAlphaValue:1.0]; |
| 83 } |
| 84 |
| 85 - (void)makeSheetKeyAndOrderFront { |
| 86 [[overlayWindow_ attachedSheet] makeKeyAndOrderFront:nil]; |
| 87 } |
| 88 |
| 89 - (void)onConstrainedWindowClosed { |
| 90 panel_.reset(); |
| 91 constrainedWindow_.reset(); |
| 92 [self release]; |
| 93 } |
| 94 |
| 95 @end |
| 96 |
| 97 void ShowCertificateViewer(content::WebContents* web_contents, |
| 98 gfx::NativeWindow parent, |
| 99 net::X509Certificate* cert) { |
| 100 // SSLCertificateViewerCocoa will manage its own lifetime and will release |
| 101 // itself when the dialog is closed. |
| 102 // See -[SSLCertificateViewerCocoa onConstrainedWindowClosed]. |
| 103 SSLCertificateViewerCocoa* viewer = |
| 104 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert]; |
| 105 [viewer displayForWebContents:web_contents]; |
| 106 } |
OLD | NEW |