Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/ssl/ssl_add_cert_handler_mac.mm

Issue 652137: Mac: implement <keygen> support, including adding generated cert to the Keychain. (Closed)
Patch Set: Responding to review feedback. Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "app/l10n_util_mac.h"
11 #include "base/scoped_nsobject.h"
12 #include "chrome/common/logging_chrome.h"
13 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/browser.h"
15 #include "chrome/browser/browser_window.h"
16 #include "grit/generated_resources.h"
17 #include "net/base/x509_certificate.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 = BrowserList::GetLastActive();
59 // TODO(snej): Can I get the Browser that issued the request?
60 if (browser) {
61 parentWindow = browser->window()->GetNativeHandle();
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698