Skip to content

Commit 970bd8f

Browse files
committed
Tweak CEF resource loading
1 parent 3b85dd6 commit 970bd8f

File tree

8 files changed

+23
-9
lines changed

8 files changed

+23
-9
lines changed

Client/cefweb/CWebApp.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,15 @@ CefRefPtr<CefResourceHandler> CWebApp::Create(CefRefPtr<CefBrowser> browser, Cef
178178
return HandleError("404 - Not found", 404);
179179

180180
// Verify local files
181-
if (!pWebView->VerifyFile(path))
181+
CBuffer fileData;
182+
if (!pWebView->VerifyFile(path, fileData))
182183
return HandleError("403 - Access Denied", 403);
183184

184185
// Finally, load the file stream
185-
auto stream = CefStreamReader::CreateForFile(path);
186+
if (fileData.GetData() == nullptr || fileData.GetSize() == 0)
187+
fileData = CBuffer("", sizeof(""));
188+
189+
auto stream = CefStreamReader::CreateForData(fileData.GetData(), fileData.GetSize());
186190
if (stream.get())
187191
return new CefStreamResourceHandler(mimeType, stream);
188192
return HandleError("404 - Not found", 404);

Client/cefweb/CWebView.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ bool CWebView::ToggleDevTools(bool visible)
478478
return CWebDevTools::Close(this);
479479
}
480480

481-
bool CWebView::VerifyFile(const SString& strPath)
481+
bool CWebView::VerifyFile(const SString& strPath, CBuffer& outFileData)
482482
{
483-
return m_pEventsInterface->Events_OnResourceFileCheck(strPath);
483+
return m_pEventsInterface->Events_OnResourceFileCheck(strPath, outFileData);
484484
}
485485

486486
bool CWebView::CanGoBack()

Client/cefweb/CWebView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CWebView : public CWebViewInterface,
8989
virtual CVector2D GetSize() override;
9090

9191
bool GetFullPathFromLocal(SString& strPath);
92-
bool VerifyFile(const SString& strPath);
92+
bool VerifyFile(const SString& strPath, CBuffer& outFileData);
9393

9494
virtual bool RegisterAjaxHandler(const SString& strURL) override;
9595
virtual bool UnregisterAjaxHandler(const SString& strURL) override;

Client/mods/deathmatch/logic/CClientWebBrowser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool CClientWebBrowser::Events_OnResourcePathCheck(SString& strURL)
266266
return false;
267267
}
268268

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

281-
pFile->GenerateClientChecksum();
281+
pFile->GenerateClientChecksum(outFileData);
282282
return pFile->DoesClientAndServerChecksumMatch();
283283
}
284284

Client/mods/deathmatch/logic/CClientWebBrowser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa
8080
void Events_OnTooltip(const SString& strTooltip) override;
8181
void Events_OnInputFocusChanged(bool bGainedFocus) override;
8282
bool Events_OnResourcePathCheck(SString& strURL) override;
83-
bool Events_OnResourceFileCheck(const SString& strURL) override;
83+
bool Events_OnResourceFileCheck(const SString& strURL, CBuffer& outFileData) override;
8484
void Events_OnResourceBlocked(const SString& strURL, const SString& strDomain, unsigned char reason) override;
8585
void Events_OnAjaxRequest(CAjaxResourceHandlerInterface* pHandler, const SString& strURL) override;
8686

Client/mods/deathmatch/logic/CDownloadableResource.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ CChecksum CDownloadableResource::GenerateClientChecksum()
4747
return m_LastClientChecksum;
4848
}
4949

50+
CChecksum CDownloadableResource::GenerateClientChecksum(CBuffer& outFileData)
51+
{
52+
// If LoadFromFile fails, a default initialized checksum is returned (just like GenerateClientChecksum() behaves)
53+
if (outFileData.LoadFromFile(m_strName))
54+
m_LastClientChecksum = CChecksum::GenerateChecksumFromBuffer(outFileData.GetData(), outFileData.GetSize());
55+
56+
return m_LastClientChecksum;
57+
}
58+
5059
CChecksum CDownloadableResource::GetServerChecksum()
5160
{
5261
return m_ServerChecksum;

Client/mods/deathmatch/logic/CDownloadableResource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class CDownloadableResource
5252
void SetHttpServerIndex(uint uiHttpServerIndex) { m_uiHttpServerIndex = uiHttpServerIndex; }
5353

5454
CChecksum GenerateClientChecksum();
55+
CChecksum GenerateClientChecksum(CBuffer& outFileData);
5556
CChecksum GetServerChecksum();
5657

5758
bool IsAutoDownload() { return m_bAutoDownload; };

Client/sdk/core/CWebBrowserEventsInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CWebBrowserEventsInterface
2525
virtual void Events_OnTooltip(const SString& strTooltip) = 0;
2626
virtual void Events_OnInputFocusChanged(bool bGainedFocus) = 0;
2727
virtual bool Events_OnResourcePathCheck(SString& strURL) = 0;
28-
virtual bool Events_OnResourceFileCheck(const SString& strURL) = 0;
28+
virtual bool Events_OnResourceFileCheck(const SString& strURL, CBuffer& outFileData) = 0;
2929
virtual void Events_OnResourceBlocked(const SString& strURL, const SString& strDomain, unsigned char reason) = 0;
3030
virtual void Events_OnAjaxRequest(CAjaxResourceHandlerInterface* pHandler, const SString& strURL) = 0;
3131
};

0 commit comments

Comments
 (0)