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

Commit 71219a3

Browse files
committed
[[ BrowserWidget ]] Can't persist handler list in render process so resend from browser process on each load start.
1 parent 3145c1e commit 71219a3

File tree

3 files changed

+41
-75
lines changed

3 files changed

+41
-75
lines changed

libbrowser/src/libbrowser_cef.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
783783
if (nil == m_owner)
784784
return;
785785

786+
// render process may have restarted so resend js handler list
787+
m_owner->SyncJavaScriptHandlers();
788+
786789
CefString t_url;
787790
t_url = p_frame->GetURL();
788791

@@ -911,6 +914,7 @@ MCCefBrowserBase::MCCefBrowserBase()
911914
m_allow_new_window = false;
912915

913916
m_javascript_handlers = nil;
917+
m_js_handler_list = CefListValue::Create();
914918
}
915919

916920
MCCefBrowserBase::~MCCefBrowserBase(void)
@@ -1337,15 +1341,15 @@ bool MCCefBrowserBase::GoForward(void)
13371341
return true;
13381342
}
13391343

1340-
bool MCCefBrowserBase::SetJavaScriptHandlers(CefRefPtr<CefListValue> p_handlers)
1344+
bool MCCefBrowserBase::SyncJavaScriptHandlers()
13411345
{
13421346
CefRefPtr<CefProcessMessage> t_message;
13431347
t_message = CefProcessMessage::Create(MC_CEFMSG_SET_JS_HANDLER_LIST);
13441348

13451349
CefRefPtr<CefListValue> t_args;
13461350
t_args = t_message->GetArgumentList();
13471351

1348-
t_args->SetList(0, p_handlers);
1352+
t_args->SetList(0, m_js_handler_list->Copy());
13491353

13501354
m_browser->SendProcessMessage(PID_RENDERER, t_message);
13511355

@@ -1392,7 +1396,10 @@ bool MCCefBrowserBase::SetJavaScriptHandlers(const char *p_handlers)
13921396
}
13931397

13941398
if (t_success)
1395-
t_success = SetJavaScriptHandlers(t_handler_list);
1399+
{
1400+
m_js_handler_list = t_handler_list;
1401+
/* UNCHECKED */ SyncJavaScriptHandlers();
1402+
}
13961403

13971404
if (t_success)
13981405
{

libbrowser/src/libbrowser_cef.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ class MCCefBrowserBase : public MCBrowserBase
6161
CefString m_user_agent;
6262
char *m_javascript_handlers;
6363

64+
CefRefPtr<CefListValue> m_js_handler_list;
65+
6466
bool m_show_context_menu;
6567
bool m_allow_new_window;
6668
bool m_send_advanced_messages;
6769
int m_instance_id;
6870

69-
bool SetJavaScriptHandlers(CefRefPtr<CefListValue> p_handlers);
71+
bool SyncJavaScriptHandlers();
7072

7173
void WaitOnResult(void);
7274
bool GetMessageResult(CefProcessId p_target, CefRefPtr<CefProcessMessage> p_message, const MCCefMessageResult *&r_result);

libbrowser/src/libbrowser_cefprocess.cpp

Lines changed: 28 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,7 @@ class MCCefRenderApp : public CefApp, CefRenderProcessHandler
495495
{
496496
bool t_success;
497497

498-
CefRefPtr<CefListValue> t_handler_list;
499-
t_handler_list = p_message->GetArgumentList()->GetList(0);
500-
501-
t_success = SetLiveCodeHandlers(p_browser, t_handler_list);
498+
t_success = SetLiveCodeHandlers(p_browser, p_message->GetArgumentList()->GetList(0));
502499

503500
/* UNCHECKED */
504501

@@ -508,34 +505,6 @@ class MCCefRenderApp : public CefApp, CefRenderProcessHandler
508505
return CefRenderProcessHandler::OnProcessMessageReceived(p_browser, p_source_process, p_message);
509506
}
510507

511-
virtual void OnContextCreated(CefRefPtr<CefBrowser> p_browser, CefRefPtr<CefFrame> p_frame, CefRefPtr<CefV8Context> p_context)
512-
{
513-
if (m_handler_list != nil)
514-
{
515-
bool t_success;
516-
t_success = true;
517-
518-
bool t_entered;
519-
t_entered = false;
520-
521-
if (t_success)
522-
t_success = t_entered = p_context->Enter();
523-
524-
CefRefPtr<CefV8Value> t_livecode_obj;
525-
if (t_success)
526-
t_success = GetLiveCodeGlobalObj(p_context, t_livecode_obj);
527-
528-
// Add handlers
529-
if (t_success)
530-
t_success = AddHandlerList(t_livecode_obj, m_handler_list);
531-
532-
if (t_entered)
533-
p_context->Exit();
534-
535-
/* UNCHECKED */
536-
}
537-
}
538-
539508
private:
540509
bool GetV8Context(CefRefPtr<CefBrowser> p_browser, CefRefPtr<CefV8Context> &r_context)
541510
{
@@ -593,6 +562,27 @@ class MCCefRenderApp : public CefApp, CefRenderProcessHandler
593562
return t_success;
594563
}
595564

565+
bool DeleteLiveCodeGlobalObj(CefRefPtr<CefV8Context> p_context)
566+
{
567+
CefString t_obj_name("liveCode");
568+
569+
bool t_success;
570+
t_success = true;
571+
572+
CefRefPtr<CefV8Value> t_global;
573+
t_global = p_context->GetGlobal();
574+
575+
t_success = t_global != nil;
576+
577+
if (t_success)
578+
{
579+
if (t_global->HasValue(t_obj_name))
580+
t_success = t_global->DeleteValue(t_obj_name);
581+
}
582+
583+
return t_success;
584+
}
585+
596586
bool AddHandler(CefRefPtr<CefV8Value> p_container, const CefString &p_name)
597587
{
598588
bool t_success;
@@ -614,18 +604,7 @@ class MCCefRenderApp : public CefApp, CefRenderProcessHandler
614604
return t_success;
615605
}
616606

617-
bool RemoveHandler(CefRefPtr<CefV8Value> p_container, const CefString &p_name)
618-
{
619-
bool t_success;
620-
t_success = true;
621-
622-
if (p_container->HasValue(p_name))
623-
t_success = p_container->DeleteValue(p_name);
624-
625-
return t_success;
626-
}
627-
628-
bool AddHandlerList(CefRefPtr<CefV8Value> p_container, CefRefPtr<CefListValue> p_list)
607+
bool AddHandlerList(CefRefPtr<CefBrowser> p_browser, CefRefPtr<CefV8Value> p_container, CefRefPtr<CefListValue> p_list)
629608
{
630609
if (p_list == nil)
631610
return true;
@@ -646,23 +625,6 @@ class MCCefRenderApp : public CefApp, CefRenderProcessHandler
646625
return true;
647626
}
648627

649-
bool RemoveHandlerList(CefRefPtr<CefV8Value> p_container, CefRefPtr<CefListValue> p_list)
650-
{
651-
if (p_list == nil)
652-
return true;
653-
654-
size_t t_size;
655-
t_size = p_list->GetSize();
656-
657-
for (uint32_t i = 0; i < t_size; i++)
658-
{
659-
if (p_list->GetType(i) != VTYPE_STRING || !RemoveHandler(p_container, p_list->GetString(i)))
660-
return false;
661-
}
662-
663-
return true;
664-
}
665-
666628
bool SetLiveCodeHandlers(CefRefPtr<CefBrowser> p_browser, CefRefPtr<CefListValue> p_handlers)
667629
{
668630
bool t_success;
@@ -677,29 +639,24 @@ class MCCefRenderApp : public CefApp, CefRenderProcessHandler
677639
if (t_success)
678640
t_success = t_entered = t_context->Enter();
679641

680-
CefRefPtr<CefV8Value> t_livecode_obj;
681642
if (t_success)
682-
t_success = GetLiveCodeGlobalObj(t_context, t_livecode_obj);
643+
t_success = DeleteLiveCodeGlobalObj(t_context);
683644

684-
// Remove old handlers
645+
CefRefPtr<CefV8Value> t_livecode_obj;
685646
if (t_success)
686-
t_success = RemoveHandlerList(t_livecode_obj, m_handler_list);
647+
t_success = GetLiveCodeGlobalObj(t_context, t_livecode_obj);
687648

688649
// Add new handlers
689650
if (t_success)
690-
t_success = AddHandlerList(t_livecode_obj, p_handlers);
691-
692-
if (t_success)
693-
m_handler_list = p_handlers;
694-
651+
if (p_handlers != nil && p_handlers->GetSize() > 0)
652+
t_success = AddHandlerList(p_browser, t_livecode_obj, p_handlers);
695653

696654
if (t_entered)
697655
t_context->Exit();
698656

699657
return t_success;
700658
}
701659

702-
CefRefPtr<CefListValue> m_handler_list;
703660

704661
IMPLEMENT_REFCOUNTING(MCCefRenderApp)
705662
};

0 commit comments

Comments
 (0)