@@ -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-
539508private:
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