Ejemplo n.º 1
0
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& target_url, const CefString& target_frame_name, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr<CefClient>& client, CefBrowserSettings& settings, bool* no_javascript_access)
{
	if(browser->GetHost()->IsWindowRenderingDisabled())
	{
		// Cancel popups in off-screen rendering mode.
		return true;
	}

	// set client
	client = this;

	// The frame window will be the parent of the browser window
	HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

	// send message
	LPCTSTR lpszURL(target_url.c_str());
	if( ::SendMessage( hWindow, WM_APP_CEF_WINDOW_CHECK, (WPARAM)&popupFeatures, (LPARAM)lpszURL) == S_FALSE )
		return true;

	// send message
	if( ::SendMessage( hWindow, WM_APP_CEF_NEW_WINDOW, (WPARAM)&popupFeatures, (LPARAM)&windowInfo) == S_FALSE )
		return true;

	// call parent
	return CefLifeSpanHandler::OnBeforePopup(browser, frame, target_url, target_frame_name, popupFeatures, windowInfo, client, settings, no_javascript_access);
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
	// CefDisplayHandler
	void OnTitleChange(
		CefRefPtr<CefBrowser> browser,
		const CefString& title
	) override
	{
		if (!owner_.on_cef_title_change(browser, title)) {
			auto hwnd = browser->GetHost()->GetWindowHandle();

			if (browser_list_.front()->IsSame(browser)) {
				auto hparent = ::GetAncestor(hwnd, GA_PARENT);
				if (hparent != nullptr) {
					::SetWindowTextW(hparent, title.c_str());
				}
			} else {
				::SetWindowTextW(hwnd, title.c_str());
			}
		}
	}
Ejemplo n.º 4
0
JNIEXPORT jstring JNICALL Java_org_limewire_cef_CefV8Value_1N_N_1GetStringValue
  (JNIEnv *env, jobject obj)
{
	CefRefPtr<CefV8Value> value(
		(CefV8Value*)GetCefBaseFromJNIObject(env, obj));
	if(!value.get())
		return NULL;

	CefString str = value->GetStringValue();
	return env->NewString((const jchar*)str.c_str(), str.length());
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
ChromiumDLL::JSObjHandle JavaScriptObject::executeFunction(ChromiumDLL::JavaScriptFunctionArgs *args)
{
	if (!isFunction())
		return GetJSFactory()->CreateException("Not a function!");

	if (!args)
		return GetJSFactory()->CreateException("Args are null for function call");

	JavaScriptContext* context = (JavaScriptContext*)args->context;
	JavaScriptObject* jso = (JavaScriptObject*)args->object.get();

	CefV8ValueList argList;

	for (int x=0; x<args->argc; x++)
	{
		JavaScriptObject* jsoa = (JavaScriptObject*)args->argv[x].get();

		if (jsoa)
			argList.push_back(jsoa->getCefV8());
		else
			argList.push_back(NULL);
	}

	CefRefPtr<CefV8Value> retval;
	CefString exception;

	bool res = m_pObject->ExecuteFunctionWithContext(context->getCefV8(), jso?jso->getCefV8():NULL, argList, retval, exception);

	if (!res)
	{
		if (exception.c_str())
			return GetJSFactory()->CreateException(exception.c_str());

		return GetJSFactory()->CreateException("failed to run function");
	}

	if (!retval)
		return NULL;

	return new JavaScriptObject(retval);
}
Ejemplo n.º 7
0
void FWebBrowserHandler::OnLoadError(CefRefPtr<CefBrowser> Browser,
	CefRefPtr<CefFrame> Frame,
	CefLoadHandler::ErrorCode InErrorCode,
	const CefString& ErrorText,
	const CefString& FailedUrl)
{
	// Don't display an error for downloaded files.
	if (InErrorCode == ERR_ABORTED)
		return;

	// Display a load error message.
	FFormatNamedArguments Args;
	Args.Add(TEXT("FailedUrl"), FText::FromString(FailedUrl.c_str()));
	Args.Add(TEXT("ErrorText"), FText::FromString(ErrorText.c_str()));
	Args.Add(TEXT("ErrorCode"), FText::AsNumber(InErrorCode));
	FText ErrorMsg = FText::Format(LOCTEXT("WebBrowserLoadError", "Failed to load URL {FailedUrl} with error {ErrorText} ({ErrorCode})."), Args);
	FString ErrorHTML = TEXT("<html><body bgcolor=\"white\"><h2>")
						+ ErrorMsg.ToString()
						+ TEXT("</h2></body></html>");
	Frame->LoadString(*ErrorHTML, FailedUrl);
}
Ejemplo n.º 8
0
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title)
{
	REQUIRE_UI_THREAD();

	// The frame window will be the parent of the browser window
	HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

	LPCTSTR pszTitle(title.c_str());
	::SendMessage( hWindow, WM_APP_CEF_TITLE_CHANGE, (WPARAM)pszTitle, NULL );

	// call parent
	CefDisplayHandler::OnTitleChange(browser, title);
}
Ejemplo n.º 9
0
void ClientHandler::OnStatusMessage(CefRefPtr<CefBrowser> browser, const CefString& value)
{
	REQUIRE_UI_THREAD();

	// The frame window will be the parent of the browser window
	HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

	LPCTSTR pszStatus(value.c_str());
	::SendMessage( hWindow, WM_APP_CEF_STATUS_MESSAGE, (WPARAM)pszStatus, NULL );

	// call parent
	CefDisplayHandler::OnStatusMessage(browser, value);
}
Ejemplo n.º 10
0
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& url)
{
	REQUIRE_UI_THREAD();

	// The frame window will be the parent of the browser window
	HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

	LPCTSTR pszURL(url.c_str());
	::SendMessage( hWindow, WM_APP_CEF_ADDRESS_CHANGE, (WPARAM)pszURL, NULL );

	// call parent
	CefDisplayHandler::OnAddressChange(browser, frame, url);
}
Ejemplo n.º 11
0
bool CaffeineClientApp::PostCrashLogs(CefString CrashLog, CefString AppVersion, CefString UserDescription)
{
    CefRefPtr<CefRequest> request = CefRequest::Create();
    wstring url(DIAGNOSTICS_URL);

    request->SetURL(url);
    request->SetMethod("POST");
    request->SetFlags(UR_FLAG_ALLOW_CACHED_CREDENTIALS|UR_FLAG_REPORT_UPLOAD_PROGRESS);
    
    // Add post data to the request.  The correct method and content-
    // type headers will be set by CEF.
    CefRefPtr<CefPostDataElement> Data = CefPostDataElement::Create();
//    Data->SetToFile(CrashLog);
    //  TODO:  Consider creating a memory mapped file
    HANDLE hZipFile = CreateFile(CrashLog.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    DWORD BigBufferSize = GetFileSize(hZipFile, NULL);
    if (BigBufferSize != INVALID_FILE_SIZE)
    {
        LPBYTE BigBuffer = new BYTE[BigBufferSize];

        DWORD dwBytesRead = 0;
        ReadFile(hZipFile, BigBuffer, BigBufferSize, &dwBytesRead, NULL);
        CloseHandle(hZipFile);
        Data->SetToBytes(dwBytesRead, BigBuffer);
    
        CefRefPtr<CefPostData> POSTBody = CefPostData::Create();
        POSTBody->AddElement(Data);
        request->SetPostData(POSTBody);

        CefRequest::HeaderMap headerMap;
        request->GetHeaderMap(headerMap);
        headerMap.insert(make_pair("Content-Type", "application/zip"));
        request->SetHeaderMap(headerMap);
    
//        CefV8Context::GetCurrentContext()->GetFrame()->LoadRequest(request);

        // Create the client instance.
        CefRefPtr<CaffeineRequestClient> client = new CaffeineRequestClient();
    
        // Start the request. MyRequestClient callbacks will be executed asynchronously.
        CefRefPtr<CefURLRequest> url_request = CefURLRequest::Create(request, client.get());
        
        delete [] BigBuffer;
    }

    return true;
}
Ejemplo n.º 12
0
void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl)
{
	REQUIRE_UI_THREAD();

	// net_error_list.h NAME_NOT_RESOLVED -105
	if( errorCode == -105)
	{
		// The frame window will be the parent of the browser window
		HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

		LPCTSTR pszSearch(failedUrl.c_str());
		::SendMessage( hWindow, WM_APP_CEF_SEARCH_URL, (WPARAM)pszSearch, NULL );
	}

	// call parent
	CefLoadHandler::OnLoadError(browser, frame, errorCode, errorText, failedUrl);
}
Ejemplo n.º 13
0
bool ClientHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool is_redirect)
{
	// The frame window will be the parent of the browser window
	HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() );

	// get URL requested
	CefString newURL = request->GetURL();

	LPCTSTR pszURL(newURL.c_str());
	if( ::SendMessage( hWindow, WM_APP_CEF_BEFORE_BROWSE, (WPARAM)pszURL, (LPARAM)is_redirect ) == S_FALSE )
	{
		// cancel navigation
		return TRUE;
	}

	// call parent
	return CefRequestHandler::OnBeforeBrowse(browser, frame, request, is_redirect);
}
Ejemplo n.º 14
0
HICON GetIcon(CefString url, CefString path){
	if (path.ToWString().find(L":") == -1){// 如果指定的路径是相对路径
		wstring _path;
		_path = url.ToWString();
		jw::replace_allW(_path, L"\\", L"/");
		_path = _path.substr(0, _path.find_last_of('/') + 1);
		path = _path.append(path);
	}
	Gdiplus::GdiplusStartupInput StartupInput;
	ULONG_PTR m_gdiplusToken;
	Gdiplus::Status sResult = Gdiplus::GdiplusStartup(&m_gdiplusToken, &StartupInput, NULL);
	if (sResult == Gdiplus::Ok){
		Gdiplus::Bitmap * bb = Gdiplus::Bitmap::FromFile(path.c_str(), false);
		HICON hIcon = NULL;
		bb->GetHICON(&hIcon);
		delete bb;
		Gdiplus::GdiplusShutdown(m_gdiplusToken);// 关闭gdi
		return hIcon;
	}
	return NULL;
}
	CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>,
										 const CefString& scheme_name,
										 CefRefPtr<CefRequest> request)
	{
		std::string url = request->GetURL();
		std::vector<size_t> slashes;

		for (size_t x=0; x<url.size(); x++)
		{
			if (url[x] == '/')
				slashes.push_back(x);
		}

		if (slashes.size() < 3)
			return NULL;

		std::string host = url.substr(slashes[1]+1, slashes[2]-slashes[1]-1);
		std::map<std::string, ChromiumDLL::SchemeExtenderI*>::iterator it = m_mSchemeMap.find(host);

		if (it == m_mSchemeMap.end())
			return NULL;

		return new SchemeExtender(it->second->clone(scheme_name.c_str()));
	}
Ejemplo n.º 16
0
String^ toClr(const CefString& cefStr)
{
    return gcnew String(cefStr.c_str());
}
Ejemplo n.º 17
0
Local<String> CefStringToV8(const CefString& str) {
  return String::New(reinterpret_cast<uint16_t*>(const_cast<CefString::char_type*>(str.c_str())), str.length());
}
Ejemplo n.º 18
0
void FWebBrowserWindow::SetTitle(const CefString& InTitle)
{
	Title = InTitle.c_str();
	OnTitleChangedDelegate.Broadcast(Title);
}
Ejemplo n.º 19
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;
}