ChromiumBrowser: new callback executed when server has invalid certificate

git-svn-id: svn://ultimatepp.org/upp/trunk@9519 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
zbych 2016-02-23 20:42:16 +00:00
parent 24c4432906
commit 8c10ee12da
7 changed files with 94 additions and 13 deletions

View file

@ -148,7 +148,7 @@ void ChromiumBrowser::AfterInit()
WhenGotFocus = LAMBDA(){ SetFocus(); };
handler = new ClientHandler(WhenUrlChange, WhenStatus, WhenMessage, WhenTakeFocus,
WhenGotFocus, WhenKeyboard, WhenConsoleMessage);
WhenGotFocus, WhenKeyboard, WhenConsoleMessage, WhenCertificateError);
CefBrowserSettings br_settings;
br_settings.file_access_from_file_urls = STATE_DISABLED;

View file

@ -30,12 +30,13 @@ public:
~ChromiumBrowser();
static const char * const JSFunctions[];
Callback1<String> WhenUrlChange;
Callback3<bool, bool, bool> WhenStatus;
Callback2<String, const Vector<Value>&> WhenMessage;
Callback WhenTakeFocus;
Callback1<bool> WhenKeyboard;
Callback3<Upp::String, int, Upp::String> WhenConsoleMessage;
Callback1<String> WhenUrlChange;
Callback3<bool, bool, bool> WhenStatus;
Callback2<String, const Vector<Value>&> WhenMessage;
Callback WhenTakeFocus;
Callback1<bool> WhenKeyboard;
Callback3<String, int, String> WhenConsoleMessage;
Gate1<String> WhenCertificateError;
static void ChildProcess();
static bool IsChildProcess();

View file

@ -34,7 +34,7 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
WindowOpenDisposition target_disposition,
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
bool user_gesture,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
@ -54,7 +54,7 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
const CefString& errorText,
const CefString& failedUrl)
{
frame->LoadString("<html><head></head><body><center><h1>Page not found</h1></center></body><html>", failedUrl);
frame->LoadString("<html><head></head><body><center><h1>Page not found</h1></center></body></html>", failedUrl);
}
@ -144,3 +144,57 @@ bool ClientHandler::OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& o
RLOG(message_text.ToString().c_str());
return false;
}
static Upp::String GetCefTimeString(const CefTime& v) {
if (v.GetTimeT() == 0) return "Unspecified";
Upp::Time t;
t.year = v.year;
t.month = v.month;
t.day = v.day_of_month;
t.hour = v.hour;
t.minute= v.minute;
t.second= v.second;
return Upp::FormatTime(t, "YYYY-MM-DD hh:mm:ss");
}
bool ClientHandler::OnCertificateError(CefRefPtr<CefBrowser> browser, ErrorCode cert_error,
const CefString& request_url, CefRefPtr<CefSSLInfo> ssl_info,
CefRefPtr<CefRequestCallback> callback)
{
ASSERT(CefCurrentlyOn(TID_UI));
bool cont = WhenCertificateError(request_url.ToString());
if (!cont){
CefRefPtr<CefSSLCertPrincipal> subject = ssl_info->GetSubject();
CefRefPtr<CefSSLCertPrincipal> issuer = ssl_info->GetIssuer();
// Build a table showing certificate information.
Upp::String ss;
ss << "<html><head></head><body>"
"<center><h1>Page certificate is not trusted</h1></center>"
"<br/>Certificate Information:"
"<table border=1><tr><th>Field</th><th>Value</th></tr>"
"<tr><td>Subject</td><td>" <<
(subject.get() ? subject->GetDisplayName().ToString().c_str() : "&nbsp;") <<
"</td></tr>"
"<tr><td>Issuer</td><td>" <<
(issuer.get() ? issuer->GetDisplayName().ToString().c_str() : "&nbsp;") <<
"</td></tr>"
"<tr><td>Valid Start</td><td>" <<
GetCefTimeString(ssl_info->GetValidStart()) << "</td></tr>"
"<tr><td>Valid Expiry</td><td>" <<
GetCefTimeString(ssl_info->GetValidExpiry()) << "</td></tr>"
"</table>"
"</body></html>";
browser->GetMainFrame()->LoadString(~ss, request_url);
}
callback->Continue(cont);
return cont;
}

View file

@ -18,7 +18,7 @@
class ClientHandler : public CefClient, public CefLifeSpanHandler, public CefDisplayHandler,
public CefLoadHandler, public CefFocusHandler, public CefContextMenuHandler,
public CefJSDialogHandler
public CefJSDialogHandler, public CefRequestHandler
{
public:
@ -30,9 +30,11 @@ public:
Upp::Callback & tf,
Upp::Callback & gf,
Upp::Callback1<bool> & wk,
Upp::Callback3<Upp::String, int, Upp::String> & wcm):
Upp::Callback3<Upp::String, int, Upp::String> & wcm,
Upp::Gate1<Upp::String> & wce):
browser(nullptr), WhenUrlChange(wuc), WhenStateChange(wsc), WhenMessage(wm),
WhenTakeFocus(tf), WhenGotFocus(gf), WhenKeyboard(wk), WhenConsoleMessage(wcm) { }
WhenTakeFocus(tf), WhenGotFocus(gf), WhenKeyboard(wk), WhenConsoleMessage(wcm),
WhenCertificateError(wce) { }
~ClientHandler() { }
@ -43,6 +45,7 @@ public:
const Upp::Callback & WhenGotFocus;
const Upp::Callback1<bool> & WhenKeyboard;
const Upp::Callback3<Upp::String, int, Upp::String> & WhenConsoleMessage;
const Upp::Gate1<Upp::String> & WhenCertificateError;
void WhenMessageWrapper(Upp::String name, Upp::Vector<Upp::Value> * par);
@ -52,12 +55,13 @@ public:
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE { return this; }
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
WindowOpenDisposition target_disposition,
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
bool user_gesture,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
@ -106,6 +110,13 @@ public:
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) OVERRIDE;
virtual bool OnCertificateError(CefRefPtr<CefBrowser> browser,
ErrorCode cert_error,
const CefString& request_url,
CefRefPtr<CefSSLInfo> ssl_info,
CefRefPtr<CefRequestCallback> callback) OVERRIDE;
CefRefPtr<CefBrowser> GetBrowser() { return browser; }
protected:

View file

@ -341,6 +341,12 @@ third `- message itself&]
[s2; &]
[s3;%- &]
[s4;%- &]
[s5;:Upp`:`:ChromiumBrowser`:`:WhenCertificateError:%- [_^Upp`:`:Gate1^ Gate1]<[_^Upp`:`:String^ S
tring]>_[* WhenCertificateError]&]
[s2; Called when server certificate is not trusted. Gate should return
true if you want to ignore the warning and load the page&]
[s3;%- &]
[s4;%- &]
[s5;:ChromiumBrowser`:`:IsChildProcess`(`):%- [@(0.0.255) static] [@(0.0.255) bool]_[* IsCh
ildProcess]()&]
[s2; This function should be called from the application GUI`_APP`_MAIN

View file

@ -18,6 +18,7 @@ private:
void OnMessage(String name, const Vector<Value>& par);
void OnStatus(bool loading, bool back, bool forward);
void OnConsoleMessage(String url, int line, String msg);
bool OnCertificateError(String url);
public:
typedef ChromiumBrowserExample CLASSNAME;

View file

@ -44,6 +44,7 @@ ChromiumBrowserExample::ChromiumBrowserExample()
Browser.WhenKeyboard = STDBACK(::ShowKeyboard);
Browser.WhenConsoleMessage = THISBACK(OnConsoleMessage);
Browser.WhenMessage = THISBACK(OnMessage);
Browser.WhenCertificateError = THISBACK(OnCertificateError);
Back.WhenAction = callback(&Browser, &ChromiumBrowser::GoBack);
Forward.WhenAction = callback(&Browser, &ChromiumBrowser::GoForward);
@ -90,6 +91,13 @@ void ChromiumBrowserExample::OnMessage(String name, const Vector<Value>& par)
}
bool ChromiumBrowserExample::OnCertificateError(String url)
{
//return true to load page with invalid certificate
return PromptOKCancel(Format(t_("Connection to '%s' is untrusted&Load page anyway?"), DeQtfLf(url)));
}
GUI_APP_MAIN
{
StdLogSetup(LOG_FILE | LOG_CERR | LOG_TIMESTAMP | LOG_APPEND);