Do the callback & release dance

This commit is contained in:
joshaber 2017-04-03 13:21:44 -04:00
parent ee7389bb6d
commit 1ed443ea29

View file

@ -17,6 +17,26 @@
#include "net/cert/x509_certificate.h" #include "net/cert/x509_certificate.h"
#include "net/cert/cert_database.h" #include "net/cert/cert_database.h"
@interface Trampoline : NSObject
- (void)createPanelDidEnd:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
@end
@implementation Trampoline
- (void)createPanelDidEnd:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
void (^block)(int) = (void (^)(int))contextInfo;
block(returnCode);
[(id)block autorelease];
}
@end
namespace atom { namespace atom {
namespace api { namespace api {
@ -26,28 +46,33 @@ void ShowCertificateTrustUI(atom::NativeWindow* parent_window,
std::string message, std::string message,
const ShowTrustCallback& callback) { const ShowTrustCallback& callback) {
auto sec_policy = SecPolicyCreateBasicX509(); auto sec_policy = SecPolicyCreateBasicX509();
auto cert_chain = cert->CreateOSCertChainForCert();
SecTrustRef trust = nullptr; SecTrustRef trust = nullptr;
SecTrustCreateWithCertificates(cert->CreateOSCertChainForCert(), sec_policy, &trust); SecTrustCreateWithCertificates(cert_chain, sec_policy, &trust);
// CFRelease(sec_policy);
// NSWindow* window = parent_window ?
// parent_window->GetNativeWindow() :
// NULL;
auto msg = base::SysUTF8ToNSString(message);
SFCertificateTrustPanel *panel = [[SFCertificateTrustPanel alloc] init]; SFCertificateTrustPanel *panel = [[SFCertificateTrustPanel alloc] init];
[panel runModalForTrust:trust message:msg];
// [panel beginSheetForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:NULL trust:trust message:msg];
void (^callbackBlock)(int) = [^(int returnCode) {
// if (returnCode == NSFileHandlingPanelOKButton) {
auto cert_db = net::CertDatabase::GetInstance(); auto cert_db = net::CertDatabase::GetInstance();
// This forces Chromium to reload the certificate since it might be trusted // This forces Chromium to reload the certificate since it might be trusted
// now. // now.
cert_db->NotifyObserversCertDBChanged(cert.get()); cert_db->NotifyObserversCertDBChanged(cert.get());
// }
callback.Run(true); callback.Run(returnCode);
// CFRelease(trust);
// [panel release]; [panel autorelease];
CFRelease(trust);
CFRelease(cert_chain);
CFRelease(sec_policy);
} copy];
NSWindow* window = parent_window ?
parent_window->GetNativeWindow() :
NULL;
auto msg = base::SysUTF8ToNSString(message);
[panel beginSheetForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:callbackBlock trust:trust message:msg];
} }
} // namespace api } // namespace api