| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 #include "ssl_add_cert_handler.h" | |
| 6 | |
| 7 #include <SecurityInterface/SFCertificatePanel.h> | |
| 8 #include <SecurityInterface/SFCertificateView.h> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_window.h" | |
| 13 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | |
| 14 #include "chrome/common/logging_chrome.h" | |
| 15 #include "grit/generated_resources.h" | |
| 16 #include "net/cert/x509_certificate.h" | |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | |
| 18 | |
| 19 @interface SSLAddCertHandlerCocoa : NSObject | |
| 20 { | |
| 21 scoped_refptr<SSLAddCertHandler> handler_; | |
| 22 } | |
| 23 | |
| 24 - (id)initWithHandler:(SSLAddCertHandler*)handler; | |
| 25 - (void)askToAddCert; | |
| 26 @end | |
| 27 | |
| 28 | |
| 29 void SSLAddCertHandler::AskToAddCert() { | |
| 30 [[[SSLAddCertHandlerCocoa alloc] initWithHandler: this] askToAddCert]; | |
| 31 // The new object will release itself when the sheet ends. | |
| 32 } | |
| 33 | |
| 34 | |
| 35 // The actual implementation of the add-client-cert handler is an Obj-C class. | |
| 36 @implementation SSLAddCertHandlerCocoa | |
| 37 | |
| 38 - (id)initWithHandler:(SSLAddCertHandler*)handler { | |
| 39 DCHECK(handler && handler->cert()); | |
| 40 self = [super init]; | |
| 41 if (self) { | |
| 42 handler_ = handler; | |
| 43 } | |
| 44 return self; | |
| 45 } | |
| 46 | |
| 47 - (void)sheetDidEnd:(SFCertificatePanel*)panel | |
| 48 returnCode:(NSInteger)returnCode | |
| 49 context:(void*)context { | |
| 50 [panel orderOut:self]; | |
| 51 [panel autorelease]; | |
| 52 handler_->Finished(returnCode == NSOKButton); | |
| 53 [self release]; | |
| 54 } | |
| 55 | |
| 56 - (void)askToAddCert { | |
| 57 NSWindow* parentWindow = NULL; | |
| 58 Browser* browser = chrome::GetLastActiveBrowser(); | |
| 59 // TODO(snej): Can I get the Browser that issued the request? | |
| 60 if (browser) { | |
| 61 parentWindow = browser->window()->GetNativeWindow(); | |
| 62 if ([parentWindow attachedSheet]) | |
| 63 parentWindow = nil; | |
| 64 } | |
| 65 | |
| 66 // Create the cert panel, which will be released in my -sheetDidEnd: method. | |
| 67 SFCertificatePanel* panel = [[SFCertificatePanel alloc] init]; | |
| 68 [panel setDefaultButtonTitle:l10n_util::GetNSString(IDS_ADD_CERT_DIALOG_ADD)]; | |
| 69 [panel setAlternateButtonTitle:l10n_util::GetNSString(IDS_CANCEL)]; | |
| 70 SecCertificateRef cert = handler_->cert()->os_cert_handle(); | |
| 71 NSArray* certs = [NSArray arrayWithObject: (id)cert]; | |
| 72 | |
| 73 if (parentWindow) { | |
| 74 // Open the cert panel as a sheet on the browser window. | |
| 75 [panel beginSheetForWindow:parentWindow | |
| 76 modalDelegate:self | |
| 77 didEndSelector:@selector(sheetDidEnd:returnCode:context:) | |
| 78 contextInfo:NULL | |
| 79 certificates:certs | |
| 80 showGroup:NO]; | |
| 81 } else { | |
| 82 // No available browser window, so run independently as a (blocking) dialog. | |
| 83 int returnCode = [panel runModalForCertificates:certs showGroup:NO]; | |
| 84 [self sheetDidEnd:panel returnCode:returnCode context:NULL]; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 @end | |
| OLD | NEW |