#include "ClientHandler.h" #include "include/cef_task.h" void ClientHandler::OnAfterCreated(CefRefPtr new_browser) { if (!browser.get()) { // We need to keep the main child window, but not popup windows browser = new_browser; } } void ClientHandler::OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) { PostCallback(callback1(WhenUrlChange, url.ToString())); } void ClientHandler::OnLoadingStateChange(CefRefPtr browser, bool isLoading, bool canGoBack, bool canGoForward) { PostCallback(callback3(WhenStateChange, isLoading, canGoBack, canGoForward)); } bool ClientHandler::OnConsoleMessage(CefRefPtr browser, const CefString& message, const CefString& source, int line) { ASSERT(CefCurrentlyOn(TID_UI)); PostCallback(callback3(WhenConsoleMessage, source.ToString(), line, message.ToString())); return true; } bool ClientHandler::OnBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString& target_url, const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, bool* no_javascript_access) { RLOG(Upp::Format("Popup canceled, frame name: '%s', url '%s'", target_frame_name.ToString().c_str(), target_url.ToString().c_str())); // Cancel popups return true; } void ClientHandler::OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) { if (errorCode == ERR_ABORTED) return; Upp::String err = Upp::String("

") + Upp::t_("Page not found") + "
" + failedUrl.ToString().c_str() + "

"; frame->LoadString(~err, failedUrl); } bool ClientHandler::OnProcessMessageReceived(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { if (message->GetName().ToString() == "show_keyboard"){ PostCallback(callback1(WhenKeyboard, true)); }else if (message->GetName().ToString() == "hide_keyboard"){ PostCallback(callback1(WhenKeyboard, false)); }else{ CefRefPtr args = message->GetArgumentList(); Upp::Vector * par = new Upp::Vector; for (unsigned i = 0; i < args->GetSize(); i++){ CefValueType type = args->GetType(i); switch(type){ case VTYPE_BOOL: par->Add(args->GetBool(i)); break; case VTYPE_DOUBLE: par->Add(args->GetDouble(i)); break; case VTYPE_INT: par->Add(args->GetInt(i)); break; case VTYPE_STRING: par->Add(args->GetString(i).ToString().c_str()); break; default: par->Add("OnProcessMessageReceived: unsupported parameter type"); break; } } PostCallback(THISBACK2(WhenMessageWrapper, message->GetName().ToString(), par)); } return true; } void ClientHandler::WhenMessageWrapper(Upp::String name, Upp::Vector * par) { WhenMessage(name, *par); delete par; } void ClientHandler::OnTakeFocus(CefRefPtr browser, bool next ) { PostCallback(WhenTakeFocus); } void ClientHandler::OnGotFocus(CefRefPtr browser) { PostCallback(WhenGotFocus); } void ClientHandler::OnBeforeContextMenu(CefRefPtr browser, CefRefPtr frame, CefRefPtr params, CefRefPtr model) { #ifndef _DEBUG //Empty context menu model->Clear(); #endif } bool ClientHandler::OnJSDialog(CefRefPtr browser, const CefString& origin_url, JSDialogType dialog_type, const CefString& message_text, const CefString& default_prompt_text, CefRefPtr callback, bool& suppress_message) { RLOG(message_text.ToString().c_str()); return false; } bool ClientHandler::OnCertificateError(CefRefPtr browser, ErrorCode cert_error, const CefString& request_url, CefRefPtr ssl_info, CefRefPtr callback) { ASSERT(CefCurrentlyOn(TID_UI)); bool cont = WhenCertificateError(request_url.ToString()); if (!cont){ Upp::String valid_start; Upp::String valid_expiry; Upp::String subject_str = " "; Upp::String issuer_str = " "; if (ssl_info){ CefRefPtr cert = ssl_info->GetX509Certificate(); if (cert.get()){ valid_start = Upp::Format(Upp::TimeFromUTC(cert->GetValidStart().GetTimeT())); valid_expiry = Upp::Format(Upp::TimeFromUTC(cert->GetValidExpiry().GetTimeT())); CefRefPtr subject = cert->GetSubject(); subject_str = subject.get() ? subject->GetDisplayName().ToString().c_str() : " "; CefRefPtr issuer = cert->GetIssuer(); issuer_str = issuer.get() ? issuer->GetDisplayName().ToString().c_str() : " "; } } // certificate information Upp::String ss; ss << "

Page certificate is not trusted



X.509 Certificate Information:" "" << "" "" "" "" "
FieldValue
Subject" << subject_str << "
Issuer" << issuer_str << "
Valid Start" << valid_start << "
Valid Expiry" << valid_expiry << "
"; browser->GetMainFrame()->LoadString(~ss, request_url); } callback->Continue(cont); return cont; } bool ClientHandler::OnFileDialog(CefRefPtr browser, FileDialogMode mode, const CefString& title, const CefString& default_file_path, const std::vector& accept_filters, int selected_accept_filter, CefRefPtr callback) { RLOG("File dialog blocked"); return true; }