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; }
//////////////////////////////////////////////////////////////////// // // // Implementation: CefRequestHandler::OnBeforeResourceLoad // // http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRequestHandler.html#OnBeforeResourceLoad(CefRefPtr%3CCefBrowser%3E,CefRefPtr%3CCefFrame%3E,CefRefPtr%3CCefRequest%3E) // // // //////////////////////////////////////////////////////////////////// CefRequestHandler::ReturnValue CWebView::OnBeforeResourceLoad ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRefPtr<CefRequestCallback> callback ) { // Mostly the same as CWebView::OnBeforeBrowse CefURLParts urlParts; if ( !CefParseURL ( request->GetURL (), urlParts ) ) return RV_CANCEL; // Cancel if invalid URL (this line will normally not be executed) // Add some information to the HTTP header { CefRequest::HeaderMap headerMap; request->GetHeaderMap ( headerMap ); auto iter = headerMap.find ( "User-Agent" ); if ( iter != headerMap.end () ) { // Add MTA:SA "watermark" iter->second = iter->second.ToString () + "; " MTA_CEF_USERAGENT; // Add 'Android' to get the mobile version SString strPropertyValue; if ( GetProperty ( "mobile", strPropertyValue ) && strPropertyValue == "1" ) iter->second = iter->second.ToString () + "; Mobile Android"; request->SetHeaderMap ( headerMap ); } } WString scheme = urlParts.scheme.str; if ( scheme == L"http" || scheme == L"https" ) { SString domain = UTF16ToMbUTF8 ( urlParts.host.str ); if ( domain != "mta" ) { if ( IsLocal () ) return RV_CANCEL; // Block remote requests in local mode generally eURLState urlState = g_pCore->GetWebCore ()->GetURLState ( domain, true ); if ( urlState != eURLState::WEBPAGE_ALLOWED ) { // Trigger onClientBrowserResourceBlocked event auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnResourceBlocked, m_pEventsInterface, SString ( request->GetURL () ), domain, urlState == eURLState::WEBPAGE_NOT_LISTED ? 0 : 1 ); g_pCore->GetWebCore ()->AddEventToEventQueue ( func, this, "OnResourceBlocked" ); return RV_CANCEL; // Block if explicitly forbidden } // Allow return RV_CONTINUE; } else return RV_CONTINUE; } else if ( scheme == L"mtalocal" ) { // Allow :) return RV_CONTINUE; } // Trigger onClientBrowserResourceBlocked event auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnResourceBlocked, m_pEventsInterface, SString ( request->GetURL () ), "", 2 ); // reason 1 := blocked protocol scheme g_pCore->GetWebCore ()->AddEventToEventQueue ( func, this, "OnResourceBlocked" ); // Block everything else return RV_CANCEL; }