Index: chrome/browser/ui/cocoa/certificate_viewer_mac.mm |
diff --git a/chrome/browser/ui/cocoa/certificate_viewer_mac.mm b/chrome/browser/ui/cocoa/certificate_viewer_mac.mm |
index 1adb0f166bd8687c67f8d0aa8155bed3b1d21f63..31c00e61d9e50ce8e2acd9091713dfc6e93d7c6d 100644 |
--- a/chrome/browser/ui/cocoa/certificate_viewer_mac.mm |
+++ b/chrome/browser/ui/cocoa/certificate_viewer_mac.mm |
@@ -4,78 +4,19 @@ |
#import "chrome/browser/ui/cocoa/certificate_viewer_mac.h" |
-#include <Security/Security.h> |
-#include <SecurityInterface/SFCertificatePanel.h> |
-#include <vector> |
- |
-#include "base/mac/foundation_util.h" |
-#include "base/mac/scoped_cftyperef.h" |
-#include "base/macros.h" |
-#include "chrome/browser/certificate_viewer.h" |
-#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
-#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
-#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h" |
+#import "base/mac/foundation_util.h" |
+#import "base/mac/scoped_cftyperef.h" |
tapted
2016/05/31 07:44:47
nit: include (cf is CoreFoundation, which is pure
Patti Lor
2016/06/06 06:52:45
Done.
|
+#import "base/mac/scoped_nsobject.h" |
+#include "content/public/browser/web_contents.h" |
#include "net/cert/x509_certificate.h" |
-#include "net/cert/x509_util_mac.h" |
-#import "ui/base/cocoa/window_size_constants.h" |
- |
-class SSLCertificateViewerCocoaBridge; |
- |
-@interface SFCertificatePanel (SystemPrivate) |
-// A system-private interface that dismisses a panel whose sheet was started by |
-// -beginSheetForWindow: |
-// modalDelegate: |
-// didEndSelector: |
-// contextInfo: |
-// certificates: |
-// showGroup: |
-// as though the user clicked the button identified by returnCode. Verified |
-// present in 10.8. |
-- (void)_dismissWithCode:(NSInteger)code; |
-@end |
- |
-@interface SSLCertificateViewerCocoa () |
-- (void)onConstrainedWindowClosed; |
-@end |
- |
-class SSLCertificateViewerCocoaBridge : public ConstrainedWindowMacDelegate { |
- public: |
- explicit SSLCertificateViewerCocoaBridge(SSLCertificateViewerCocoa * |
- controller) |
- : controller_(controller) { |
- } |
- |
- virtual ~SSLCertificateViewerCocoaBridge() {} |
+#import "net/cert/x509_util_mac.h" |
- // ConstrainedWindowMacDelegate implementation: |
- void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { |
- // |onConstrainedWindowClosed| will delete the sheet which might be still |
- // in use higher up the call stack. Wait for the next cycle of the event |
- // loop to call this function. |
- [controller_ performSelector:@selector(onConstrainedWindowClosed) |
- withObject:nil |
- afterDelay:0]; |
- } |
- |
- private: |
- SSLCertificateViewerCocoa* controller_; // weak |
- |
- DISALLOW_COPY_AND_ASSIGN(SSLCertificateViewerCocoaBridge); |
-}; |
- |
-void ShowCertificateViewer(content::WebContents* web_contents, |
- gfx::NativeWindow parent, |
- net::X509Certificate* cert) { |
- // SSLCertificateViewerCocoa will manage its own lifetime and will release |
- // itself when the dialog is closed. |
- // See -[SSLCertificateViewerCocoa onConstrainedWindowClosed]. |
- SSLCertificateViewerCocoa* viewer = |
- [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert]; |
- [viewer displayForWebContents:web_contents]; |
+@implementation SSLCertificateViewerMac { |
+ // The corresponding list of certificates. |
+ base::scoped_nsobject<NSArray> certificates_; |
+ base::scoped_nsobject<SFCertificatePanel> panel_; |
} |
-@implementation SSLCertificateViewerCocoa |
- |
- (id)initWithCertificate:(net::X509Certificate*)certificate { |
if ((self = [super init])) { |
base::ScopedCFTypeRef<CFArrayRef> cert_chain( |
@@ -89,8 +30,7 @@ void ShowCertificateViewer(content::WebContents* web_contents, |
- (void)sheetDidEnd:(NSWindow*)parent |
returnCode:(NSInteger)returnCode |
context:(void*)context { |
- if (!closePending_) |
- constrainedWindow_->CloseWebContentsModalDialog(); |
+ NOTREACHED(); // Subclasses must implement this. |
} |
- (void)displayForWebContents:(content::WebContents*)webContents { |
@@ -133,17 +73,17 @@ void ShowCertificateViewer(content::WebContents* web_contents, |
panel_.reset([[SFCertificatePanel alloc] init]); |
[panel_ setPolicies:(id) policies.get()]; |
+} |
- constrainedWindow_ = |
- CreateAndShowWebModalDialogMac(observer_.get(), webContents, self); |
+- (void)releaseSheetWindow { |
+ panel_.reset(); |
} |
-- (NSWindow*)overlayWindow { |
- return overlayWindow_; |
+- (NSWindow*)certificatePanel { |
+ return panel_; |
} |
-- (void)showSheetForWindow:(NSWindow*)window { |
- overlayWindow_.reset([window retain]); |
+- (void)showCertificateSheet:(NSWindow*)window { |
[panel_ beginSheetForWindow:window |
modalDelegate:self |
didEndSelector:@selector(sheetDidEnd: |
@@ -154,53 +94,16 @@ void ShowCertificateViewer(content::WebContents* web_contents, |
showGroup:YES]; |
} |
-- (void)closeSheetWithAnimation:(BOOL)withAnimation { |
- closePending_ = YES; |
- overlayWindow_.reset(); |
+- (void)closeCertificateSheet:(BOOL)withAnimation { |
tapted
2016/05/31 07:44:47
|withAnimation| isn't used, so can be removed from
Patti Lor
2016/06/06 06:52:45
Done.
|
// Closing the sheet using -[NSApp endSheet:] doesn't work so use the private |
// method. |
[panel_ _dismissWithCode:NSFileHandlingPanelCancelButton]; |
-} |
+ certificates_.reset(); |
-- (void)hideSheet { |
- NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; |
- [sheetWindow setAlphaValue:0.0]; |
- |
- oldResizesSubviews_ = [[sheetWindow contentView] autoresizesSubviews]; |
- [[sheetWindow contentView] setAutoresizesSubviews:NO]; |
-} |
- |
-- (void)unhideSheet { |
- NSWindow* sheetWindow = [overlayWindow_ attachedSheet]; |
- |
- [[sheetWindow contentView] setAutoresizesSubviews:oldResizesSubviews_]; |
- [[overlayWindow_ attachedSheet] setAlphaValue:1.0]; |
-} |
- |
-- (void)pulseSheet { |
- // NOOP |
-} |
- |
-- (void)makeSheetKeyAndOrderFront { |
- [[overlayWindow_ attachedSheet] makeKeyAndOrderFront:nil]; |
-} |
- |
-- (void)updateSheetPosition { |
- // NOOP |
-} |
- |
-- (void)resizeWithNewSize:(NSSize)preferredSize { |
- // NOOP |
-} |
- |
-- (NSWindow*)sheetWindow { |
- return panel_; |
-} |
- |
-- (void)onConstrainedWindowClosed { |
- panel_.reset(); |
- constrainedWindow_.reset(); |
- [self release]; |
+ // NOTE: Subclasses must release the panel themselves. This allows the Cocoa |
+ // build to use |SSLCertificateViewerCocoaBridge::OnConstrainedWindowClosed|, |
+ // which ensures the sheet is no longer used by waiting for the next event |
+ // loop cycle to release it. |
} |
@end |