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.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "chrome/browser/certificate_viewer.h" | |
| 10 #include "components/constrained_window/constrained_window_views.h" | |
| 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 #include "ui/views/widget/widget_delegate.h" | |
| 14 | |
| 15 // Certificate viewer class for MacViews which handles displaying and closing | |
| 16 // the Cocoa certificate viewer. | |
| 17 @interface SSLCertificateViewerMacViews : SSLCertificateViewerMac { | |
| 18 @private | |
| 19 views::Widget* overlayWindow_; | |
| 20 } | |
| 21 | |
| 22 // Closes the certificate viewer properly. | |
| 23 - (void)sheetDidEnd:(NSWindow*)parent | |
|
tapted
2016/05/25 06:52:24
doesn't need to be redeclared
Patti Lor
2016/05/31 06:00:33
Done.
| |
| 24 returnCode:(NSInteger)returnCode | |
| 25 context:(void*)context; | |
| 26 | |
| 27 @end | |
| 28 | |
| 29 // A fully transparent, borderless web-modal dialog used to display the | |
| 30 // OS-provided window-modal sheet that displays certificate information. | |
| 31 class CertificateAnchorWidgetDelegate : public views::WidgetDelegateView { | |
| 32 public: | |
| 33 CertificateAnchorWidgetDelegate( | |
|
tapted
2016/05/25 06:52:24
nit: explicit.. but! The ownership is still a litt
Patti Lor
2016/05/31 06:00:33
Done.
| |
| 34 SSLCertificateViewerMacViews* certificate_viewer) | |
| 35 : certificate_viewer_(certificate_viewer) {} | |
| 36 | |
| 37 // WidgetDelegate: | |
| 38 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; } | |
| 39 | |
| 40 private: | |
| 41 base::scoped_nsobject<SSLCertificateViewerMacViews> certificate_viewer_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(CertificateAnchorWidgetDelegate); | |
| 44 }; | |
| 45 | |
| 46 @implementation SSLCertificateViewerMacViews | |
| 47 | |
| 48 - (void)sheetDidEnd:(NSWindow*)parent | |
| 49 returnCode:(NSInteger)returnCode | |
| 50 context:(void*)context { | |
| 51 [self closeSheetWithAnimation:YES]; | |
| 52 overlayWindow_->Close(); // Asynchronously releases |self|. | |
| 53 [self releaseSheetWindow]; | |
| 54 } | |
| 55 | |
| 56 - (void)displayForWebContents:(content::WebContents*)webContents { | |
| 57 [super displayForWebContents:webContents]; | |
| 58 | |
| 59 views::WidgetDelegateView* delegate_ = | |
| 60 new CertificateAnchorWidgetDelegate(self); | |
| 61 overlayWindow_ = constrained_window::ShowWebModalDialogWithOverlayViews( | |
| 62 delegate_, webContents); | |
| 63 [self showSheetForWindow:overlayWindow_->GetNativeWindow()]; | |
| 64 } | |
| 65 | |
| 66 @end | |
| 67 | |
| 68 void ShowCertificateViewer(content::WebContents* web_contents, | |
| 69 gfx::NativeWindow parent, | |
| 70 net::X509Certificate* cert) { | |
| 71 SSLCertificateViewerMacViews* viewer = | |
| 72 [[SSLCertificateViewerMacViews alloc] initWithCertificate:cert]; | |
| 73 [viewer displayForWebContents:web_contents]; | |
| 74 } | |
| OLD | NEW |