Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit dbf7fe0

Browse files
Merge pull request #6457 from montegoulding/bugfix-21121
[[ Bug 21121 ]] Use temp directory for CEF cache
2 parents d63e4fa + 4719a22 commit dbf7fe0

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

engine/src/widget-ref.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,11 @@ bool MCWidgetRoot::IsRoot(void) const
10591059

10601060
MCWidget *MCWidgetRoot::GetHost(void) const
10611061
{
1062+
if (!m_host.IsValid())
1063+
{
1064+
return nullptr;
1065+
}
1066+
10621067
return m_host;
10631068
}
10641069

engine/src/widget-ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class MCWidgetRoot: public MCWidgetBase
191191
virtual bool CopyFont(MCFontRef& r_font);
192192

193193
private:
194-
MCWidget *m_host;
194+
MCWidgetHandle m_host;
195195
};
196196

197197
class MCWidgetChild: public MCWidgetBase

extensions/widgets/browser/browser.lcb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,10 @@ public handler OnCreate()
456456
end handler
457457

458458
--
459-
460-
variable mOpenComplete as Boolean
459+
constant kOpenStateClosed is 0
460+
constant kOpenStateOpen is 1
461+
constant kOpenStateFailed is -1
462+
variable mOpenState as Number
461463

462464
private unsafe handler InitBrowserView()
463465
variable tParent as Pointer
@@ -467,16 +469,19 @@ private unsafe handler InitBrowserView()
467469

468470
variable tFactory as MCBrowserFactoryRef
469471
if not MCBrowserFactoryGet(the empty string, tFactory) then
472+
put kOpenStateFailed into mOpenState
470473
throw "error getting browser factory"
471474
end if
472475

473476
variable tDisplay as optional Pointer
474477
MCWidgetGetMyStackNativeDisplay(tDisplay)
475478

476479
if not MCBrowserFactoryCreateBrowser(tFactory, tDisplay, tParent, mBrowser) then
480+
put kOpenStateFailed into mOpenState
477481
throw "error creating browser"
478482
end if
479-
483+
put kOpenStateOpen into mOpenState
484+
480485
variable tBrowserView as Pointer
481486
put MCBrowserGetNativeLayer(mBrowser) into tBrowserView
482487
set my native layer to tBrowserView
@@ -488,18 +493,18 @@ private unsafe handler InitBrowserView()
488493
MCBrowserSetJavaScriptHandler(mBrowser, OnJavaScriptCallback, nothing)
489494

490495
applyProperties(mProperties)
491-
492-
put true into mOpenComplete
493496
end handler
494497

495498
private unsafe handler FinalizeBrowserView()
496-
if mOpenComplete then
499+
if mOpenState is not kOpenStateClosed then
497500
set my native layer to nothing
498501

499-
MCBrowserRelease(mBrowser)
500-
put nothing into mBrowser
502+
if mBrowser is not nothing then
503+
MCBrowserRelease(mBrowser)
504+
put nothing into mBrowser
505+
end if
501506

502-
put false into mOpenComplete
507+
put kOpenStateClosed into mOpenState
503508
else
504509
schedule timer in 0.1 seconds
505510
end if
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure the browser widget does not create any cache folders in the current working directory

libbrowser/src/libbrowser_cef.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "libbrowser_cef.h"
2222

2323
#include <include/cef_app.h>
24-
24+
#include <include/wrapper/cef_scoped_temp_dir.h>
2525
#include <list>
2626
#include <set>
2727

@@ -270,6 +270,8 @@ static bool s_cefbrowser_initialised = false;
270270

271271
static uint32_t s_instance_count = 0;
272272

273+
static CefScopedTempDir s_temp_cache;
274+
273275
void MCCefBrowserExternalInit(void)
274276
{
275277
// set up static vars
@@ -502,12 +504,18 @@ bool MCCefInitialise(void)
502504
if (t_success)
503505
t_success = __MCCefBuildPath(t_library_path, kCefProcessName, &t_settings.browser_subprocess_path);
504506
#endif
505-
506-
if (t_success)
507-
t_success = __MCCefBuildPath(t_library_path, "locales", &t_settings.locales_dir_path);
508-
if (t_success)
509-
t_success = __MCCefBuildPath(t_library_path, "", &t_settings.resources_dir_path);
507+
508+
if (t_success)
509+
t_success = __MCCefBuildPath(t_library_path, "locales", &t_settings.locales_dir_path);
510+
if (t_success)
511+
t_success = __MCCefBuildPath(t_library_path, "", &t_settings.resources_dir_path);
512+
513+
if (t_success)
514+
t_success = s_temp_cache.CreateUniqueTempDir();
510515

516+
if (t_success)
517+
CefString(&t_settings.cache_path).FromString(s_temp_cache.GetPath());
518+
511519
CefRefPtr<CefApp> t_app = new (nothrow) MCCefBrowserApp();
512520

513521
if (t_success)
@@ -567,9 +575,14 @@ void MCCefFinalise(void)
567575
{
568576
if (!s_cef_initialised)
569577
return;
578+
579+
if (s_temp_cache.IsValid())
580+
{
581+
s_temp_cache.Delete();
582+
}
570583

571584
CefShutdown();
572-
585+
573586
s_cef_initialised = false;
574587
}
575588

0 commit comments

Comments
 (0)