99#include < vector>
1010#include " v8utils.h"
1111#include " javascript_callback.h"
12- #include " python_callback .h"
12+ #include " v8function_handler .h"
1313
1414CefRefPtr<CefBrowser> g_mainBrowser;
1515
@@ -187,9 +187,13 @@ void CefPythonApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
187187 CefRefPtr<CefV8Context> context) {
188188 DebugLog (" Renderer: OnContextReleased()" );
189189 if (g_mainBrowser.get ()) {
190- CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create (
191- " OnContextReleased" );
192- CefRefPtr<CefListValue> arguments = message->GetArgumentList ();
190+ CefRefPtr<CefProcessMessage> message;
191+ CefRefPtr<CefListValue> arguments;
192+ // --------------------------------------------------------------------
193+ // 1. Send "OnContextReleased" message.
194+ // --------------------------------------------------------------------
195+ message = CefProcessMessage::Create (" OnContextReleased" );
196+ arguments = message->GetArgumentList ();
193197 arguments->SetInt (0 , browser->GetIdentifier ());
194198 // TODO: losing int64 precision, the solution is to convert
195199 // it to string and then in the Browser process back
@@ -201,6 +205,14 @@ void CefPythonApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
201205 // when this is not the main frame? It could fail, so
202206 // it is more reliable to always use the main browser.
203207 g_mainBrowser->SendProcessMessage (PID_BROWSER, message);
208+ // --------------------------------------------------------------------
209+ // 2. Remove python callbacks for a frame.
210+ // --------------------------------------------------------------------
211+ message = CefProcessMessage::Create (" RemovePythonCallbacksForFrame" );
212+ arguments = message->GetArgumentList ();
213+ // TODO: int64 precision lost
214+ arguments->SetInt (0 , (int )(frame->GetIdentifier ()));
215+ g_mainBrowser->SendProcessMessage (PID_BROWSER, message);
204216 } else {
205217 DebugLog (" Renderer: OnContextReleased(): ERROR: main browser not " \
206218 " found, cannot send process message to the browser process " \
@@ -209,7 +221,6 @@ void CefPythonApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
209221 }
210222 // Clear javascript callbacks.
211223 RemoveJavascriptCallbacksForFrame (frame);
212- RemovePythonCallbacksForFrame (frame);
213224}
214225
215226void CefPythonApp::OnUncaughtException (CefRefPtr<CefBrowser> browser,
@@ -424,7 +435,7 @@ void CefPythonApp::DoJavascriptBindingsForFrame(CefRefPtr<CefBrowser> browser,
424435 }
425436 CefRefPtr<CefV8Value> v8Window = context->GetGlobal ();
426437 CefRefPtr<CefV8Value> v8Function;
427- CefRefPtr<CefV8Handler> v8FunctionHandler (new V8FunctionHandler (this ));
438+ CefRefPtr<CefV8Handler> v8FunctionHandler (new V8FunctionHandler (this , 0 ));
428439 // FUNCTIONS.
429440 std::vector<CefString> functionsVector;
430441 if (!functions->GetKeys (functionsVector)) {
0 commit comments