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/certificate_viewer_mac.h" |
| 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/certificate_viewer.h" |
| 9 #include "components/constrained_window/constrained_window_views.h" |
| 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 11 #include "ui/views/widget/widget.h" |
| 12 #include "ui/views/widget/widget_delegate.h" |
| 13 |
| 14 // Certificate viewer class for MacViews which handles displaying and closing |
| 15 // the Cocoa certificate viewer. |
| 16 @interface SSLCertificateViewerMacViews : SSLCertificateViewerMac { |
| 17 // Invisible overlay window used to block interaction with the tab underneath. |
| 18 views::Widget* overlayWindow_; |
| 19 } |
| 20 |
| 21 - (void)setOverlayWindow:(views::Widget*)overlayWindow; |
| 22 @end |
| 23 |
| 24 // A fully transparent, borderless web-modal dialog used to display the |
| 25 // OS-provided window-modal sheet that displays certificate information. |
| 26 class CertificateAnchorWidgetDelegate : public views::WidgetDelegateView { |
| 27 public: |
| 28 CertificateAnchorWidgetDelegate(content::WebContents* web_contents, |
| 29 net::X509Certificate* cert) |
| 30 : certificate_viewer_([[SSLCertificateViewerMacViews alloc] |
| 31 initWithCertificate:cert forWebContents:web_contents]) { |
| 32 views::Widget* overlayWindow = |
| 33 constrained_window::ShowWebModalDialogWithOverlayViews(this, |
| 34 web_contents); |
| 35 [certificate_viewer_ showCertificateSheet:overlayWindow->GetNativeWindow()]; |
| 36 [certificate_viewer_ setOverlayWindow:overlayWindow]; |
| 37 } |
| 38 |
| 39 // WidgetDelegate: |
| 40 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; } |
| 41 |
| 42 private: |
| 43 base::scoped_nsobject<SSLCertificateViewerMacViews> certificate_viewer_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(CertificateAnchorWidgetDelegate); |
| 46 }; |
| 47 |
| 48 @implementation SSLCertificateViewerMacViews |
| 49 |
| 50 - (void)sheetDidEnd:(NSWindow*)parent |
| 51 returnCode:(NSInteger)returnCode |
| 52 context:(void*)context { |
| 53 [self closeCertificateSheet]; |
| 54 overlayWindow_->Close(); // Asynchronously releases |self|. |
| 55 [self releaseSheetWindow]; |
| 56 } |
| 57 |
| 58 - (void)setOverlayWindow:(views::Widget*)overlayWindow { |
| 59 overlayWindow_ = overlayWindow; |
| 60 } |
| 61 |
| 62 @end |
| 63 |
| 64 void ShowCertificateViewer(content::WebContents* web_contents, |
| 65 gfx::NativeWindow parent, |
| 66 net::X509Certificate* cert) { |
| 67 // Shows a new widget, which owns the delegate. |
| 68 new CertificateAnchorWidgetDelegate(web_contents, cert); |
| 69 } |
OLD | NEW |