bool CWebView::LoadURL ( const SString& strURL, bool bFilterEnabled, const SString& strPostData, bool bURLEncoded ) { if ( !m_pWebView ) return false; CefURLParts urlParts; if ( !CefParseURL ( strURL, urlParts ) ) return false; // Invalid URL // Are we allowed to browse this website? if ( bFilterEnabled && g_pCore->GetWebCore ()->GetURLState ( UTF16ToMbUTF8 ( urlParts.host.str ), true ) != eURLState::WEBPAGE_ALLOWED ) return false; // Load it! auto pFrame = m_pWebView->GetMainFrame (); if ( strPostData.empty () ) { pFrame->LoadURL ( strURL ); } else { // Load URL first, see https://bitbucket.org/chromiumembedded/cef/issue/579 pFrame->LoadURL ( "about:blank" ); // Perform HTTP POST auto request = CefRequest::Create (); auto postData = CefPostData::Create (); auto postDataElement = CefPostDataElement::Create (); postDataElement->SetToBytes ( strPostData.size (), strPostData.c_str () ); postData->AddElement ( postDataElement ); if ( bURLEncoded ) { CefRequest::HeaderMap headerMap; headerMap.insert ( std::make_pair ( "Content-Type", "application/x-www-form-urlencoded" ) ); headerMap.insert ( std::make_pair ( "Content-Length", std::to_string ( strPostData.size () ) ) ); //headerMap.insert ( std::make_pair ( "Connection", "close" ) ); request->SetHeaderMap ( headerMap ); } request->SetURL ( strURL ); request->SetMethod ( "POST" ); request->SetPostData ( postData ); pFrame->LoadRequest ( request ); } return true; }
void RunRequestTest(CefRefPtr<CefBrowser> browser) { // Create a new request CefRefPtr<CefRequest> request(CefRequest::CreateRequest()); // Set the request URL request->SetURL("http://tests/request"); // Add post data to the request. The correct method and content- // type headers will be set by CEF. CefRefPtr<CefPostDataElement> postDataElement( CefPostDataElement::CreatePostDataElement()); std::string data = "arg1=val1&arg2=val2"; postDataElement->SetToBytes(data.length(), data.c_str()); CefRefPtr<CefPostData> postData(CefPostData::CreatePostData()); postData->AddElement(postDataElement); request->SetPostData(postData); // Add a custom header CefRequest::HeaderMap headerMap; headerMap.insert( std::make_pair("X-My-Header", "My Header Value")); request->SetHeaderMap(headerMap); // Load the request browser->GetMainFrame()->LoadRequest(request); }
bool CaffeineClientHandler::OnBeforeResourceLoad( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) { // REQUIRE_IO_THREAD(); CefRequest::HeaderMap x; request->GetHeaderMap(x); x.erase(TEXT("User-Agent")); x.insert(CefRequest::HeaderMap::value_type(TEXT("User-Agent"), user_agent)); request->SetHeaderMap(x); return !ValidateRequestLoad(browser, frame, request); }
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; }
bool FWebBrowserHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefFrame> Frame, CefRefPtr<CefRequest> Request) { const FString LanguageHeaderText(TEXT("Accept-Language")); const FString LocaleCode = FWebBrowserSingleton::GetCurrentLocaleCode(); CefRequest::HeaderMap HeaderMap; Request->GetHeaderMap(HeaderMap); auto LanguageHeader = HeaderMap.find(*LanguageHeaderText); if (LanguageHeader != HeaderMap.end()) { (*LanguageHeader).second = *LocaleCode; } else { HeaderMap.insert(std::pair<CefString, CefString>(*LanguageHeaderText, *LocaleCode)); } Request->SetHeaderMap(HeaderMap); return false; }