Add certificate-error event
This commit is contained in:
parent
341341bf28
commit
e432abfb42
7 changed files with 87 additions and 39 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/net_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
#include "chrome/common/chrome_paths.h"
|
#include "chrome/common/chrome_paths.h"
|
||||||
#include "content/public/browser/client_certificate_delegate.h"
|
#include "content/public/browser/client_certificate_delegate.h"
|
||||||
#include "content/public/browser/gpu_data_manager.h"
|
#include "content/public/browser/gpu_data_manager.h"
|
||||||
|
#include "content/public/browser/render_frame_host.h"
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
@ -216,30 +218,49 @@ void App::OnFinishLaunching() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::OnLogin(LoginHandler* login_handler) {
|
void App::OnLogin(LoginHandler* login_handler) {
|
||||||
// Convert the args explicitly since they will be passed for twice.
|
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
auto web_contents =
|
bool prevent_default = Emit(
|
||||||
WebContents::CreateFrom(isolate(), login_handler->GetWebContents());
|
"login",
|
||||||
auto request = mate::ConvertToV8(isolate(), login_handler->request());
|
WebContents::CreateFrom(isolate(), login_handler->GetWebContents()),
|
||||||
auto auth_info = mate::ConvertToV8(isolate(), login_handler->auth_info());
|
login_handler->request(),
|
||||||
auto callback = mate::ConvertToV8(
|
login_handler->auth_info(),
|
||||||
isolate(),
|
|
||||||
base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler)));
|
base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler)));
|
||||||
|
|
||||||
bool prevent_default =
|
|
||||||
Emit("login", web_contents, request, auth_info, callback);
|
|
||||||
|
|
||||||
// Also pass it to WebContents.
|
|
||||||
if (!prevent_default)
|
|
||||||
prevent_default =
|
|
||||||
web_contents->Emit("login", request, auth_info, callback);
|
|
||||||
|
|
||||||
// Default behavior is to always cancel the auth.
|
// Default behavior is to always cancel the auth.
|
||||||
if (!prevent_default)
|
if (!prevent_default)
|
||||||
login_handler->CancelAuth();
|
login_handler->CancelAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::AllowCertificateError(
|
||||||
|
int pid,
|
||||||
|
int fid,
|
||||||
|
int cert_error,
|
||||||
|
const net::SSLInfo& ssl_info,
|
||||||
|
const GURL& request_url,
|
||||||
|
content::ResourceType resource_type,
|
||||||
|
bool overridable,
|
||||||
|
bool strict_enforcement,
|
||||||
|
bool expired_previous_decision,
|
||||||
|
const base::Callback<void(bool)>& callback,
|
||||||
|
content::CertificateRequestResultType* request) {
|
||||||
|
auto rfh = content::RenderFrameHost::FromID(pid, fid);
|
||||||
|
auto web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
||||||
|
|
||||||
|
v8::Locker locker(isolate());
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
bool prevent_default = Emit("certificate-error",
|
||||||
|
WebContents::CreateFrom(isolate(), web_contents),
|
||||||
|
request_url,
|
||||||
|
cert_error,
|
||||||
|
ssl_info.cert,
|
||||||
|
callback);
|
||||||
|
|
||||||
|
// Deny the certificate by default.
|
||||||
|
if (!prevent_default)
|
||||||
|
*request = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
|
||||||
|
}
|
||||||
|
|
||||||
void App::SelectClientCertificate(
|
void App::SelectClientCertificate(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
|
@ -248,7 +269,7 @@ void App::SelectClientCertificate(
|
||||||
shared_delegate(delegate.release());
|
shared_delegate(delegate.release());
|
||||||
bool prevent_default =
|
bool prevent_default =
|
||||||
Emit("select-client-certificate",
|
Emit("select-client-certificate",
|
||||||
api::WebContents::CreateFrom(isolate(), web_contents),
|
WebContents::CreateFrom(isolate(), web_contents),
|
||||||
cert_request_info->host_and_port.ToString(),
|
cert_request_info->host_and_port.ToString(),
|
||||||
cert_request_info->client_certs,
|
cert_request_info->client_certs,
|
||||||
base::Bind(&OnClientCertificateSelected,
|
base::Bind(&OnClientCertificateSelected,
|
||||||
|
|
|
@ -51,6 +51,18 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
void OnLogin(LoginHandler* login_handler) override;
|
void OnLogin(LoginHandler* login_handler) override;
|
||||||
|
|
||||||
// content::ContentBrowserClient:
|
// content::ContentBrowserClient:
|
||||||
|
void AllowCertificateError(
|
||||||
|
int render_process_id,
|
||||||
|
int render_frame_id,
|
||||||
|
int cert_error,
|
||||||
|
const net::SSLInfo& ssl_info,
|
||||||
|
const GURL& request_url,
|
||||||
|
content::ResourceType resource_type,
|
||||||
|
bool overridable,
|
||||||
|
bool strict_enforcement,
|
||||||
|
bool expired_previous_decision,
|
||||||
|
const base::Callback<void(bool)>& callback,
|
||||||
|
content::CertificateRequestResultType* request) override;
|
||||||
void SelectClientCertificate(
|
void SelectClientCertificate(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
|
|
|
@ -238,12 +238,6 @@ void SetProxyInIO(net::URLRequestContextGetter* getter,
|
||||||
RunCallbackInUI(callback);
|
RunCallbackInUI(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassVerificationResult(
|
|
||||||
scoped_refptr<AtomCertVerifier::CertVerifyRequest> request,
|
|
||||||
bool success) {
|
|
||||||
request->ContinueWithResult(success ? net::OK : net::ERR_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Session::Session(AtomBrowserContext* browser_context)
|
Session::Session(AtomBrowserContext* browser_context)
|
||||||
|
@ -262,19 +256,6 @@ Session::~Session() {
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::RequestCertVerification(
|
|
||||||
const scoped_refptr<AtomCertVerifier::CertVerifyRequest>& request) {
|
|
||||||
bool prevent_default = Emit(
|
|
||||||
"untrusted-certificate",
|
|
||||||
request->args().hostname,
|
|
||||||
request->args().cert,
|
|
||||||
base::Bind(&PassVerificationResult, request));
|
|
||||||
|
|
||||||
if (!prevent_default)
|
|
||||||
// Tell the request to use the result of default verifier.
|
|
||||||
request->ContinueWithResult(net::ERR_IO_PENDING);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||||
content::DownloadItem* item) {
|
content::DownloadItem* item) {
|
||||||
auto web_contents = item->GetWebContents();
|
auto web_contents = item->GetWebContents();
|
||||||
|
|
|
@ -54,10 +54,6 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
explicit Session(AtomBrowserContext* browser_context);
|
explicit Session(AtomBrowserContext* browser_context);
|
||||||
~Session();
|
~Session();
|
||||||
|
|
||||||
// AtomCertVerifier::Delegate:
|
|
||||||
void RequestCertVerification(
|
|
||||||
const scoped_refptr<AtomCertVerifier::CertVerifyRequest>&) override;
|
|
||||||
|
|
||||||
// content::DownloadManager::Observer:
|
// content::DownloadManager::Observer:
|
||||||
void OnDownloadCreated(content::DownloadManager* manager,
|
void OnDownloadCreated(content::DownloadManager* manager,
|
||||||
content::DownloadItem* item) override;
|
content::DownloadItem* item) override;
|
||||||
|
|
|
@ -38,6 +38,12 @@ app.getAppPath = ->
|
||||||
# Helpers.
|
# Helpers.
|
||||||
app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback
|
app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback
|
||||||
|
|
||||||
|
# Routes the events to webContents.
|
||||||
|
for name in ['login', 'certificate-error', 'select-client-certificate']
|
||||||
|
do (name) ->
|
||||||
|
app.on name, (event, webContents, args...) ->
|
||||||
|
webContents.emit name, event, args...
|
||||||
|
|
||||||
# Deprecated.
|
# Deprecated.
|
||||||
{deprecate} = electron
|
{deprecate} = electron
|
||||||
app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
|
app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
|
||||||
|
|
|
@ -207,6 +207,26 @@ content::QuotaPermissionContext*
|
||||||
return new AtomQuotaPermissionContext;
|
return new AtomQuotaPermissionContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AtomBrowserClient::AllowCertificateError(
|
||||||
|
int render_process_id,
|
||||||
|
int render_frame_id,
|
||||||
|
int cert_error,
|
||||||
|
const net::SSLInfo& ssl_info,
|
||||||
|
const GURL& request_url,
|
||||||
|
content::ResourceType resource_type,
|
||||||
|
bool overridable,
|
||||||
|
bool strict_enforcement,
|
||||||
|
bool expired_previous_decision,
|
||||||
|
const base::Callback<void(bool)>& callback,
|
||||||
|
content::CertificateRequestResultType* request) {
|
||||||
|
if (delegate_) {
|
||||||
|
delegate_->AllowCertificateError(
|
||||||
|
render_process_id, render_frame_id, cert_error, ssl_info, request_url,
|
||||||
|
resource_type, overridable, strict_enforcement,
|
||||||
|
expired_previous_decision, callback, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AtomBrowserClient::SelectClientCertificate(
|
void AtomBrowserClient::SelectClientCertificate(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
|
|
|
@ -57,6 +57,18 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||||
int child_process_id) override;
|
int child_process_id) override;
|
||||||
void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
|
void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
|
||||||
content::QuotaPermissionContext* CreateQuotaPermissionContext() override;
|
content::QuotaPermissionContext* CreateQuotaPermissionContext() override;
|
||||||
|
void AllowCertificateError(
|
||||||
|
int render_process_id,
|
||||||
|
int render_frame_id,
|
||||||
|
int cert_error,
|
||||||
|
const net::SSLInfo& ssl_info,
|
||||||
|
const GURL& request_url,
|
||||||
|
content::ResourceType resource_type,
|
||||||
|
bool overridable,
|
||||||
|
bool strict_enforcement,
|
||||||
|
bool expired_previous_decision,
|
||||||
|
const base::Callback<void(bool)>& callback,
|
||||||
|
content::CertificateRequestResultType* request) override;
|
||||||
void SelectClientCertificate(
|
void SelectClientCertificate(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue