bool FCEFWebBrowserWindow::OnBeforeUnloadDialog(const CefString& MessageText, bool IsReload, CefRefPtr<CefJSDialogCallback> Callback)
{
	bool Retval = false;
	if ( OnShowDialog().IsBound() )
	{
		TSharedPtr<IWebBrowserDialog> Dialog(new FCEFWebBrowserDialog(MessageText, IsReload, Callback));
		EWebBrowserDialogEventResponse EventResponse = OnShowDialog().Execute(TWeakPtr<IWebBrowserDialog>(Dialog));
		switch (EventResponse)
		{
		case EWebBrowserDialogEventResponse::Handled:
			Retval = true;
			break;
		case EWebBrowserDialogEventResponse::Continue:
			Callback->Continue(true, CefString());
			Retval = true;
			break;
		case EWebBrowserDialogEventResponse::Ignore:
			Callback->Continue(false, CefString());
			Retval = true;
			break;
		case EWebBrowserDialogEventResponse::Unhandled:
		default:
			Retval = false;
			break;
		}
	}
	return Retval;
}
Пример #2
0
void ClientHandler::OnBeforeDownload(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDownloadItem> download_item, const CefString& suggested_name, CefRefPtr<CefBeforeDownloadCallback> callback)
{
	REQUIRE_UI_THREAD();

	// Continue the download and show the "Save As" dialog.
	callback->Continue(GetDownloadPath(suggested_name), true);
}
Пример #3
0
bool LocalSchemeHandler::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
    CEF_REQUIRE_IO_THREAD();
        
    String url = request->GetURL();
    Error err;
    m_pData = NULL;
    
    // remove query and hash parts
    String::size_type posQuery = url.find(TEXT("?"));
    String::size_type posHash = url.find(TEXT("#"));
    String::size_type len = String::npos;

    if (posQuery != String::npos && posHash != String::npos)
        len = std::min(posQuery, posHash);
    else if (posQuery != String::npos)
        len = posQuery;
    else if (posHash != String::npos)
        len = posHash;
    
    // the URL is prefixed with "local://"
    FileUtil::ReadFileBinary(DecodeURL(url.substr(8, len - 8)), &m_pData, m_size, err);
    m_mimeType = GetMIMETypeForFilename(url);

    // indicate the headers are available
    callback->Continue();
    return true;
}
Пример #4
0
bool CaffeineClientHandler::OnJSDialog(
    CefRefPtr<CefBrowser> browser,
    const CefString& origin_url,
    const CefString& accept_lang,
    JSDialogType dialog_type,
    const CefString& message_text,
    const CefString& default_prompt_text,
    CefRefPtr<CefJSDialogCallback> callback,
    bool& suppress_message)
{
    if (dialog_type == JSDIALOGTYPE_ALERT)
    {
#ifdef OS_WIN
        //  TODO:  Look up from the string table.
        MessageBox(m_MainHwnd, message_text.c_str(), FULL_PRODUCT, MB_OK);
#else
        wstring msg = message_text;
        alertMessage(msg);
#endif

        callback->Continue(true, message_text);
        return true;
    }


    return false;
}
bool ContentResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
	CEF_REQUIRE_IO_THREAD();

	callback->Continue();

	return true;
}
void ClientHandler::OnRequestGeolocationPermission(
      CefRefPtr<CefBrowser> browser,
      const CefString& requesting_url,
      int request_id,
      CefRefPtr<CefGeolocationCallback> callback) {
  // Allow geolocation access from all websites.
  callback->Continue(true);
}
bool ClientHandler::OnQuotaRequest(CefRefPtr<CefBrowser> browser,
                                   const CefString& origin_url,
                                   int64 new_size,
                                   CefRefPtr<CefQuotaCallback> callback) {
  static const int64 max_size = 1024 * 1024 * 20;  // 20mb.

  // Grant the quota request if the size is reasonable.
  callback->Continue(new_size <= max_size);
  return true;
}
bool ClientHandler::OnRequestGeolocationPermission(
      CefRefPtr<CefBrowser> browser,
      const CefString& requesting_url,
      int request_id,
      CefRefPtr<CefGeolocationCallback> callback) {
  CEF_REQUIRE_UI_THREAD();

  // Allow geolocation access from all websites.
  callback->Continue(true);
  return true;
}
JNIEXPORT void JNICALL Java_org_cef_callback_CefAuthCallback_1N_N_1Continue
  (JNIEnv *env, jobject obj, jstring username, jstring password) {
  CefRefPtr<CefAuthCallback> callback =
      GetCefFromJNIObject<CefAuthCallback>(env, obj, "CefAuthCallback");
  if (!callback.get())
    return;
  callback->Continue(GetJNIString(env, username), GetJNIString(env, password));

  // Clear the reference added in RequestHandler::GetAuthCredentials
  SetCefForJNIObject<CefAuthCallback>(env, obj, NULL, "CefAuthCallback");
}
Пример #10
0
        bool ClientAdapter::OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& origin_url, const CefString& accept_lang,
            JSDialogType dialog_type, const CefString& message_text, const CefString& default_prompt_text,
            CefRefPtr<CefJSDialogCallback> callback, bool& suppress_message)
        {
            IJsDialogHandler^ handler = _browserControl->JsDialogHandler;

            if (handler == nullptr)
            {
                return false;
            }

            bool result;
            bool handled = false;

            switch (dialog_type)
            {
            case JSDIALOGTYPE_ALERT:
                handled = handler->OnJSAlert(_browserControl, StringUtils::ToClr(origin_url), StringUtils::ToClr(message_text));
                break;

            case JSDIALOGTYPE_CONFIRM:
                handled = handler->OnJSConfirm(_browserControl, StringUtils::ToClr(origin_url), StringUtils::ToClr(message_text), result);
                if(handled)
                {
                    callback->Continue(result, CefString());
                }
                break;

            case JSDIALOGTYPE_PROMPT:
                String^ resultString = nullptr;
                handled = handler->OnJSPrompt(_browserControl, StringUtils::ToClr(origin_url), StringUtils::ToClr(message_text),
                    StringUtils::ToClr(default_prompt_text), result, resultString);
                if(handled)
                {
                    callback->Continue(result, StringUtils::ToNative(resultString));
                }
                break;
            }

            return handled;
        }
void CBrowerDialogContextMenu::RunContextMenuProcess(CWebBrowserClient* client,
                                                     std::vector<std::pair<int, std::string>> entries,
                                                     CefRefPtr<CefRunContextMenuCallback> callback)
{
  int ret = kodi::gui::dialogs::ContextMenu::Show("", entries);
  if (ret >= 0)
    callback->Continue(entries[ret].first, EVENTFLAG_LEFT_MOUSE_BUTTON);
  else
    callback->Cancel();

  client->SetContextMenuOpen(false);
}
Пример #12
0
bool CaffeineClientHandler::OnRequestGeolocationPermission(
                                                            CefRefPtr<CefBrowser> browser,
                                                            const CefString& requesting_url,
                                                            int request_id,
                                                            CefRefPtr<CefGeolocationCallback> callback) {
    
    app->ShellLog(L"OnRequestGeolocationPermission was called");
    // Allow geolocation access from all websites.
    //    callback->Continue(true);
    callback->Continue(false);
    return true;
}
JNIEXPORT void JNICALL Java_org_cef_callback_CefJSDialogCallback_1N_N_1Continue
  (JNIEnv *env, jobject obj, jboolean jsuccess, jstring juser_input) {
  CefRefPtr<CefJSDialogCallback> jsDialogCallback =
      GetCefFromJNIObject<CefJSDialogCallback>(env, obj, "CefJSDialogCallback");
  if (!jsDialogCallback.get())
    return;
  jsDialogCallback->Continue((jsuccess != JNI_FALSE),
                             GetJNIString(env, juser_input));

  // Clear the reference added in JSDialogCallback::OnJSDialog and JSDialogCallback::OnBeforeUnloadDialog.
  SetCefForJNIObject<CefJSDialogCallback>(env, obj, NULL, "CefJSDialogCallback");
}
Пример #14
0
bool CaffeineClientHandler::OnQuotaRequest(CefRefPtr<CefBrowser> browser,
    const CefString& origin_url,
    int64 new_size,
    CefRefPtr<CefQuotaCallback> callback)
{
//    static const int64 max_size = 1024 * 1024 * 20;  // 20mb.

    // Grant the quota request if the size is reasonable.
//    callback->Continue(new_size <= max_size);
    //  TODO:  Revisit.  Do we really want to allow unlimited quota
    callback->Continue(true);
    return true;
}
Пример #15
0
JNIEXPORT void JNICALL
Java_org_cef_callback_CefPrintJobCallback_1N_N_1Continue(JNIEnv* env,
                                                         jobject obj) {
  CefRefPtr<CefPrintJobCallback> callback =
      GetCefFromJNIObject<CefPrintJobCallback>(env, obj, "CefPrintJobCallback");
  if (!callback.get())
    return;

  callback->Continue();

  // Clear the reference added in PrintHandler::OnPrintJob.
  SetCefForJNIObject<CefPrintJobCallback>(env, obj, NULL,
                                          "CefPrintJobCallback");
}
Пример #16
0
void CaffeineClientHandler::OnBeforeDownload(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefDownloadItem> download_item,
    const CefString& suggested_name,
    CefRefPtr<CefBeforeDownloadCallback> callback)
{
    REQUIRE_UI_THREAD();
    wstring filePath = GetDownloadPath(suggested_name);

    RenameOldFile(filePath);
    downloadedFiles.insert(filePath);

    // Continue the download and show the "Save As" dialog.
    callback->Continue(filePath, app->showFileSaveAsDialog);
}
Пример #17
0
bool CaffeineClientHandler::OnFileDialog(CefRefPtr<CefBrowser> browser,
                                          FileDialogMode mode,
                                          const CefString& title,
                                          const CefString& default_file_name,
                                          const vector<CefString>& accept_types,
                                          CefRefPtr<CefFileDialogCallback> callback)
{
    vector<CefString> files;

    if ( FileDlg(files, mode, title, default_file_name, accept_types) )
        callback->Continue(files);
    else
        callback->Cancel();

    return true;
}
void DownloadHandler::OnBeforeDownload(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDownloadItem> download_item, const CefString& suggested_name, CefRefPtr<CefBeforeDownloadCallback> callback)
{
	std::string strUrl = download_item->GetURL();

	if (GetCallbackV2())
	{
		std::string strMimeType = download_item->GetMimeType();
		int64 contentLength = download_item->GetTotalBytes();
		
		GetCallbackV2()->onDownloadFile(strUrl.c_str(), strMimeType.c_str(), contentLength);
	}
		
	std::transform(strUrl.begin(), strUrl.end(), strUrl.begin(), ::tolower);

	if (strUrl.find_last_of(".swf") == strUrl.size() - 1)
		callback->Continue("", false);
}
Пример #19
0
JNIEXPORT void JNICALL
Java_org_cef_callback_CefFileDialogCallback_1N_N_1Continue(
    JNIEnv* env,
    jobject obj,
    jint selectedAcceptFilter,
    jobject jFilePaths) {
  CefRefPtr<CefFileDialogCallback> callback =
      GetCefFromJNIObject<CefFileDialogCallback>(env, obj,
                                                 "CefFileDialogCallback");
  if (!callback.get())
    return;

  std::vector<CefString> filePaths;
  GetJNIStringVector(env, jFilePaths, filePaths);
  callback->Continue(selectedAcceptFilter, filePaths);

  // Clear the reference added in DialogHandler::OnFileDialog.
  SetCefForJNIObject<CefFileDialogCallback>(env, obj, NULL,
                                            "CefFileDialogCallback");
}
Пример #20
0
bool ClientHandler::GetAuthCredentials(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isProxy, const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr<CefAuthCallback> callback)
{
	// The frame window will be the parent of the browser window
	HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

	CEFAuthenticationValues values;
	values.lpszHost = host.c_str();
	values.lpszRealm = realm.c_str();
	_tcscpy_s(values.szUserName, _T(""));
	_tcscpy_s(values.szUserPass, _T(""));

	// send info
	if(::SendMessage( hWindow, WM_APP_CEF_AUTHENTICATE, (WPARAM)&values, (LPARAM)NULL ) == S_OK)
	{
		callback->Continue( values.szUserName, values.szUserPass );
		return TRUE;
	}
	// canceled
	return FALSE;
}
JNIEXPORT void JNICALL
Java_org_cef_callback_CefPrintDialogCallback_1N_N_1Continue(
    JNIEnv* env,
    jobject obj,
    jobject jprintsettings) {
  CefRefPtr<CefPrintDialogCallback> callback =
      GetCefFromJNIObject<CefPrintDialogCallback>(env, obj,
                                                  "CefPrintDialogCallback");
  if (!callback.get())
    return;

  CefRefPtr<CefPrintSettings> settings = GetCefFromJNIObject<CefPrintSettings>(
      env, jprintsettings, "CefPrintSettings");

  callback->Continue(settings);

  // Clear the reference added in PrintHandler::OnPrintDialog.
  SetCefForJNIObject<CefPrintDialogCallback>(env, obj, NULL,
                                             "CefPrintDialogCallback");
}
Пример #22
0
        bool ClientAdapter::OnFileDialog(CefRefPtr<CefBrowser> browser, FileDialogMode mode, const CefString& title,
            const CefString& default_file_name, const std::vector<CefString>& accept_types,
            CefRefPtr<CefFileDialogCallback> callback)
        {
            IDialogHandler^ handler = _browserControl->DialogHandler;

            if (handler == nullptr)
            {
                return false;
            }

            bool handled;

            List<System::String ^>^ resultString = nullptr;

            handled = handler->OnFileDialog(_browserControl, (CefFileDialogMode)mode, StringUtils::ToClr(title), StringUtils::ToClr(default_file_name), StringUtils::ToClr(accept_types), resultString);
            callback->Continue(StringUtils::ToNative(resultString));

            return handled;
        }
Пример #23
0
// First method called
bool BrowserSchemeHandler::ProcessRequest(CefRefPtr<CefRequest> request,
		CefRefPtr<CefCallback> callback)
{
	CefURLParts parts;
	CefParseURL(request->GetURL(), parts);

	std::string path = CefString(&parts.path);
	fileName = path.substr(path.find_last_of("/") + 1);

	inputStream.open(path, std::ifstream::binary);
	if (!inputStream.is_open()) {
		callback->Cancel();
		return false;
	}

	inputStream.seekg(0, std::ifstream::end);
	length = remaining = inputStream.tellg();
	inputStream.seekg(0, std::ifstream::beg);
	callback->Continue();
	return true;
}
Пример #24
0
bool ClientAdapter::GetAuthCredentials(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isProxy,
                                       const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr<CefAuthCallback> callback)
{
    IRequestHandler^ handler = _browserControl->RequestHandler;
    if (handler == nullptr)
    {
        return false;
    }

    String^ usernameString = nullptr;
    String^ passwordString = nullptr;
    bool handled = handler->GetAuthCredentials(_browserControl, isProxy, StringUtils::ToClr(host), port, StringUtils::ToClr(realm), StringUtils::ToClr(scheme), usernameString, passwordString);

    if (handled)
    {
        CefString username;
        CefString password;

        if (usernameString != nullptr)
        {
            username = StringUtils::ToNative(usernameString);
        }

        if (passwordString != nullptr)
        {
            password = StringUtils::ToNative(passwordString);
        }

        callback->Continue(username, password);
    }
    else
    {
        // TOOD: Should we call Cancel() here or not? At first glance, I believe we should since there will otherwise be no
        // way to cancel the auth request from an IRequestHandler.
        callback->Cancel();
    }

    return handled;
}
bool JSDialogHandler::OnJSDialog(CefRefPtr<CefBrowser> browser,
	const CefString& origin_url,
	const CefString& accept_lang,
	JSDialogType dialog_type,
	const CefString& message_text,
	const CefString& default_prompt_text,
	CefRefPtr<CefJSDialogCallback> callback,
	bool& suppress_message)
{
	if (!GetCallback())
		return false;

	char resultBuff[255] = { 0 };
	bool success = false;
	bool res = false;

	CefStringUTF8 m(ConvertToUtf8(message_text));

	if (dialog_type == JSDIALOGTYPE_ALERT)
	{
		res = GetCallback()->onJScriptAlert(m.c_str());
		success = true;
	}
	else if (dialog_type == JSDIALOGTYPE_CONFIRM)
	{
		res = GetCallback()->onJScriptConfirm(m.c_str(), &success);
	}
	else if (dialog_type == JSDIALOGTYPE_PROMPT)
	{
		CefStringUTF8 d(ConvertToUtf8(default_prompt_text));
		res = GetCallback()->onJScriptPrompt(m.c_str(), d.c_str(), &success, resultBuff);
	}

	if (res)
		callback->Continue(success, resultBuff);

	return res;
}
bool FCEFWebBrowserWindow::OnJSDialog(CefJSDialogHandler::JSDialogType DialogType, const CefString& MessageText, const CefString& DefaultPromptText, CefRefPtr<CefJSDialogCallback> Callback, bool& OutSuppressMessage)
{
	bool Retval = false;
	if ( OnShowDialog().IsBound() )
	{
		TSharedPtr<IWebBrowserDialog> Dialog(new FCEFWebBrowserDialog(DialogType, MessageText, DefaultPromptText, Callback));
		EWebBrowserDialogEventResponse EventResponse = OnShowDialog().Execute(TWeakPtr<IWebBrowserDialog>(Dialog));
		switch (EventResponse)
		{
		case EWebBrowserDialogEventResponse::Handled:
			Retval = true;
			break;
		case EWebBrowserDialogEventResponse::Continue:
			if (DialogType == JSDIALOGTYPE_ALERT)
			{
				// Alert dialogs don't return a value, so treat Continue the same way as Ingore
				OutSuppressMessage = true;
				Retval = false;
			}
			else
			{
				Callback->Continue(true, DefaultPromptText);
				Retval = true;
			}
			break;
		case EWebBrowserDialogEventResponse::Ignore:
			OutSuppressMessage = true;
			Retval = false;
			break;
		case EWebBrowserDialogEventResponse::Unhandled:
		default:
			Retval = false;
			break;
		}
	}
	return Retval;
}
Пример #27
0
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;
}
Пример #28
0
bool ClientHandler::OnCertificateError(cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefAllowCertificateErrorCallback> callback)
{
	CString szMessage;

	// no file, or empty, show the default
	if( szMessage.IsEmpty() )
	{
		szMessage.Format(_T("The site's security certificate is not trusted!\n\n You attempted to reach \"%s\""), request_url.c_str() );
	
		szMessage += _T("but the server presented a certificate issued by an entity that is not trusted by your computer's operating system.");
		szMessage += _T("This may mean that the server has generated its own security credentials, ");
		szMessage += _T("which Chrome cannot rely on for identity information, or an attacker may be ");
		szMessage += _T("trying to intercept your communications.\n\n");
		szMessage += _T("You should not proceed, especially if you have never seen this warning before for this site.");
	}

	if( MessageBox(NULL, szMessage, _T("The site's security certificate is not trusted:"), MB_YESNO ) == IDNO )
		return FALSE;

	// continue
	callback->Continue( true );

	return TRUE;
}
bool FWebBrowserByteResource::ProcessRequest(CefRefPtr<CefRequest> Request, CefRefPtr<CefCallback> Callback)
{
	Callback->Continue();
	return true;
}
Пример #30
0
bool Client::OnQuotaRequest( CefRefPtr<CefBrowser> browser, const CefString& origin_url, int64 new_size, CefRefPtr<CefRequestCallback> callback)
{
  callback->Continue(true);
  return true;
}