Chromium Code Reviews| Index: chrome/browser/ui/cocoa/certificate_viewer_mac_views.mm |
| diff --git a/chrome/browser/ui/cocoa/certificate_viewer_mac_views.mm b/chrome/browser/ui/cocoa/certificate_viewer_mac_views.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..33ab5a4d655c63dcb133f2abae313a6a30d5907a |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/certificate_viewer_mac_views.mm |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/browser/ui/cocoa/certificate_viewer_mac.h" |
| + |
| +#import "base/mac/scoped_nsobject.h" |
| +#include "chrome/browser/certificate_viewer.h" |
| +#include "components/constrained_window/constrained_window_views.h" |
| +#include "components/web_modal/web_contents_modal_dialog_manager.h" |
| +#include "ui/views/widget/widget.h" |
| +#include "ui/views/widget/widget_delegate.h" |
| + |
| +// Certificate viewer class for MacViews which handles displaying and closing |
| +// the Cocoa certificate viewer. |
| +@interface SSLCertificateViewerMacViews : SSLCertificateViewerMac { |
| + @private |
| + // Invisible overlay window used to block interaction with the tab underneath. |
| + views::Widget* overlayWindow_; |
| +} |
| + |
| +- (void)setOverlayWindow:(views::Widget*)overlayWindow; |
| +@end |
| + |
| +// A fully transparent, borderless web-modal dialog used to display the |
| +// OS-provided window-modal sheet that displays certificate information. |
| +class CertificateAnchorWidgetDelegate : public views::WidgetDelegateView { |
| + public: |
| + CertificateAnchorWidgetDelegate(content::WebContents* web_contents, |
| + net::X509Certificate* cert) |
| + : certificate_viewer_( |
| + [[SSLCertificateViewerMacViews alloc] initWithCertificate:cert]) { |
| + [certificate_viewer_ displayForWebContents:web_contents]; |
| + views::Widget* overlayWindow = |
| + constrained_window::ShowWebModalDialogWithOverlayViews(this, |
| + web_contents); |
| + [certificate_viewer_ showCertificateSheet:overlayWindow->GetNativeWindow()]; |
| + [certificate_viewer_ setOverlayWindow:overlayWindow]; |
| + } |
| + |
| + // WidgetDelegate: |
| + ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; } |
| + |
| + private: |
| + base::scoped_nsobject<SSLCertificateViewerMacViews> certificate_viewer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CertificateAnchorWidgetDelegate); |
| +}; |
| + |
| +@implementation SSLCertificateViewerMacViews |
| + |
| +- (void)sheetDidEnd:(NSWindow*)parent |
|
tapted
2016/06/07 06:10:02
nit: // SSLCertificateViewerMac overrides:
|
| + returnCode:(NSInteger)returnCode |
| + context:(void*)context { |
| + [self closeCertificateSheet]; |
| + overlayWindow_->Close(); // Asynchronously releases |self|. |
| + [self releaseSheetWindow]; |
| +} |
| + |
| +- (void)setOverlayWindow:(views::Widget*)overlayWindow { |
| + overlayWindow_ = overlayWindow; |
| +} |
| + |
| +@end |
| + |
| +void ShowCertificateViewer(content::WebContents* web_contents, |
| + gfx::NativeWindow parent, |
| + net::X509Certificate* cert) { |
| + // Shows a new widget, which owns the delegate. |
|
tapted
2016/06/07 06:10:02
nit: widget -> Widget
|
| + new CertificateAnchorWidgetDelegate(web_contents, cert); |
| +} |