Skip to content
Permalink
Browse files

Tweak CEF resource loading

  • Loading branch information...
Jusonex committed Aug 9, 2019
1 parent 3b85dd6 commit 970bd8f3aee124347acaf9d486e2847e872023cf
@@ -178,11 +178,15 @@ CefRefPtr<CefResourceHandler> CWebApp::Create(CefRefPtr<CefBrowser> browser, Cef
return HandleError("404 - Not found", 404);

// Verify local files
if (!pWebView->VerifyFile(path))
CBuffer fileData;
if (!pWebView->VerifyFile(path, fileData))
return HandleError("403 - Access Denied", 403);

// Finally, load the file stream
auto stream = CefStreamReader::CreateForFile(path);
if (fileData.GetData() == nullptr || fileData.GetSize() == 0)
fileData = CBuffer("", sizeof(""));

auto stream = CefStreamReader::CreateForData(fileData.GetData(), fileData.GetSize());
if (stream.get())
return new CefStreamResourceHandler(mimeType, stream);
return HandleError("404 - Not found", 404);
@@ -478,9 +478,9 @@ bool CWebView::ToggleDevTools(bool visible)
return CWebDevTools::Close(this);
}

bool CWebView::VerifyFile(const SString& strPath)
bool CWebView::VerifyFile(const SString& strPath, CBuffer& outFileData)
{
return m_pEventsInterface->Events_OnResourceFileCheck(strPath);
return m_pEventsInterface->Events_OnResourceFileCheck(strPath, outFileData);
}

bool CWebView::CanGoBack()
@@ -89,7 +89,7 @@ class CWebView : public CWebViewInterface,
virtual CVector2D GetSize() override;

bool GetFullPathFromLocal(SString& strPath);
bool VerifyFile(const SString& strPath);
bool VerifyFile(const SString& strPath, CBuffer& outFileData);

virtual bool RegisterAjaxHandler(const SString& strURL) override;
virtual bool UnregisterAjaxHandler(const SString& strURL) override;
@@ -266,7 +266,7 @@ bool CClientWebBrowser::Events_OnResourcePathCheck(SString& strURL)
return false;
}

bool CClientWebBrowser::Events_OnResourceFileCheck(const SString& strPath)
bool CClientWebBrowser::Events_OnResourceFileCheck(const SString& strPath, CBuffer& outFileData)
{
// If no resource is set, we do not require to verify the file
if (!m_pResource)
@@ -278,7 +278,7 @@ bool CClientWebBrowser::Events_OnResourceFileCheck(const SString& strPath)
if (pFile == nullptr)
return true;

pFile->GenerateClientChecksum();
pFile->GenerateClientChecksum(outFileData);
return pFile->DoesClientAndServerChecksumMatch();
}

@@ -80,7 +80,7 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa
void Events_OnTooltip(const SString& strTooltip) override;
void Events_OnInputFocusChanged(bool bGainedFocus) override;
bool Events_OnResourcePathCheck(SString& strURL) override;
bool Events_OnResourceFileCheck(const SString& strURL) override;
bool Events_OnResourceFileCheck(const SString& strURL, CBuffer& outFileData) override;
void Events_OnResourceBlocked(const SString& strURL, const SString& strDomain, unsigned char reason) override;
void Events_OnAjaxRequest(CAjaxResourceHandlerInterface* pHandler, const SString& strURL) override;

@@ -47,6 +47,15 @@ CChecksum CDownloadableResource::GenerateClientChecksum()
return m_LastClientChecksum;
}

CChecksum CDownloadableResource::GenerateClientChecksum(CBuffer& outFileData)
{
// If LoadFromFile fails, a default initialized checksum is returned (just like GenerateClientChecksum() behaves)
if (outFileData.LoadFromFile(m_strName))
m_LastClientChecksum = CChecksum::GenerateChecksumFromBuffer(outFileData.GetData(), outFileData.GetSize());

return m_LastClientChecksum;
}

CChecksum CDownloadableResource::GetServerChecksum()
{
return m_ServerChecksum;
@@ -52,6 +52,7 @@ class CDownloadableResource
void SetHttpServerIndex(uint uiHttpServerIndex) { m_uiHttpServerIndex = uiHttpServerIndex; }

CChecksum GenerateClientChecksum();
CChecksum GenerateClientChecksum(CBuffer& outFileData);
CChecksum GetServerChecksum();

bool IsAutoDownload() { return m_bAutoDownload; };
@@ -25,7 +25,7 @@ class CWebBrowserEventsInterface
virtual void Events_OnTooltip(const SString& strTooltip) = 0;
virtual void Events_OnInputFocusChanged(bool bGainedFocus) = 0;
virtual bool Events_OnResourcePathCheck(SString& strURL) = 0;
virtual bool Events_OnResourceFileCheck(const SString& strURL) = 0;
virtual bool Events_OnResourceFileCheck(const SString& strURL, CBuffer& outFileData) = 0;
virtual void Events_OnResourceBlocked(const SString& strURL, const SString& strDomain, unsigned char reason) = 0;
virtual void Events_OnAjaxRequest(CAjaxResourceHandlerInterface* pHandler, const SString& strURL) = 0;
};

0 comments on commit 970bd8f

Please sign in to comment.
You can’t perform that action at this time.