mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 19:54:53 +00:00
Inline most of the methods in EvaluateScriptDelegate - much easier to step through now (with the CefRefPtrs, it's a lot harder to step into a function than normal)
This commit is contained in:
@@ -9,13 +9,13 @@
|
||||
#include "Serialization/V8Serialization.h"
|
||||
#include "../CefAppUnmanagedWrapper.h"
|
||||
#include "EvaluateScriptDelegate.h"
|
||||
|
||||
using namespace CefSharp::Internals::Serialization;
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
namespace Internals
|
||||
{
|
||||
using namespace Serialization;
|
||||
|
||||
namespace Messaging
|
||||
{
|
||||
EvaluateScriptDelegate::EvaluateScriptDelegate(CefRefPtr<CefAppUnmanagedWrapper> appUnmanagedWrapper)
|
||||
@@ -24,7 +24,7 @@ namespace CefSharp
|
||||
|
||||
}
|
||||
|
||||
bool EvaluateScriptDelegate::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message)
|
||||
bool EvaluateScriptDelegate::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message)
|
||||
{
|
||||
auto handled = false;
|
||||
auto name = message->GetName();
|
||||
@@ -36,10 +36,48 @@ namespace CefSharp
|
||||
auto callbackId = GetInt64(argList, 2);
|
||||
auto script = argList->GetString(3);
|
||||
|
||||
auto response = EvaluateScript(browserId, frameId, callbackId, script);
|
||||
if (response.get())
|
||||
auto browserWrapper = _appUnmanagedWrapper->FindBrowserWrapper(browserId, true);
|
||||
auto browser = browserWrapper->GetWrapped();
|
||||
auto frame = browser->GetFrame(frameId);
|
||||
if (browser.get() && frame.get())
|
||||
{
|
||||
browser->SendProcessMessage(source_process, response);
|
||||
auto context = frame->GetV8Context();
|
||||
|
||||
if (context.get() && context->Enter())
|
||||
{
|
||||
try
|
||||
{
|
||||
CefRefPtr<CefV8Value> result;
|
||||
CefRefPtr<CefV8Exception> exception;
|
||||
auto success = context->Eval(script, result, exception);
|
||||
auto response = CefProcessMessage::Create(kEvaluateJavascriptResponse);
|
||||
auto argList = response->GetArgumentList();
|
||||
|
||||
argList->SetBool(0, success);
|
||||
SetInt64(callbackId, argList, 1);
|
||||
if (success)
|
||||
{
|
||||
SerializeV8Object(result, argList, 2, browserWrapper->CallbackRegistry);
|
||||
}
|
||||
else
|
||||
{
|
||||
argList->SetString(2, exception->GetMessage());
|
||||
}
|
||||
|
||||
if (response.get())
|
||||
{
|
||||
browser->SendProcessMessage(sourceProcessId, response);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
context->Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO handle error
|
||||
}
|
||||
|
||||
handled = true;
|
||||
@@ -47,66 +85,6 @@ namespace CefSharp
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
CefRefPtr<CefProcessMessage> EvaluateScriptDelegate::EvaluateScript(int browserId, int frameId, int64 callbackId, CefString script)
|
||||
{
|
||||
CefRefPtr<CefProcessMessage> result;
|
||||
auto browserWrapper = _appUnmanagedWrapper->FindBrowserWrapper(browserId, true);
|
||||
auto browser = browserWrapper->GetWrapped();
|
||||
auto frame = browser->GetFrame(frameId);
|
||||
if (browser.get() && frame.get())
|
||||
{
|
||||
result = EvaluateScriptInFrame(frame, callbackId, script, browserWrapper->CallbackRegistry);
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO handle error
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CefRefPtr<CefProcessMessage> EvaluateScriptDelegate::EvaluateScriptInFrame(CefRefPtr<CefFrame> frame, int64 callbackId, CefString script, JavascriptCallbackRegistry^ callbackRegistry)
|
||||
{
|
||||
CefRefPtr<CefProcessMessage> result;
|
||||
auto context = frame->GetV8Context();
|
||||
|
||||
if (context.get() && context->Enter())
|
||||
{
|
||||
try
|
||||
{
|
||||
result = EvaluateScriptInContext(context, callbackId, script, callbackRegistry);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context->Exit();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CefRefPtr<CefProcessMessage> EvaluateScriptDelegate::EvaluateScriptInContext(CefRefPtr<CefV8Context> context, int64 callbackId, CefString script, JavascriptCallbackRegistry^ callbackRegistry)
|
||||
{
|
||||
CefRefPtr<CefV8Value> result;
|
||||
CefRefPtr<CefV8Exception> exception;
|
||||
auto success = context->Eval(script, result, exception);
|
||||
auto response = CefProcessMessage::Create(kEvaluateJavascriptResponse);
|
||||
auto argList = response->GetArgumentList();
|
||||
|
||||
argList->SetBool(0, success);
|
||||
SetInt64(callbackId, argList, 1);
|
||||
if (success)
|
||||
{
|
||||
SerializeV8Object(result, argList, 2, callbackRegistry);
|
||||
}
|
||||
else
|
||||
{
|
||||
argList->SetString(2, exception->GetMessage());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,6 @@ namespace CefSharp
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(EvaluateScriptDelegate);
|
||||
|
||||
CefRefPtr<CefAppUnmanagedWrapper> _appUnmanagedWrapper;
|
||||
|
||||
CefRefPtr<CefProcessMessage> EvaluateScript(int browserId, int frameId, int64 callbackId, CefString script);
|
||||
CefRefPtr<CefProcessMessage> EvaluateScriptInFrame(CefRefPtr<CefFrame> frame, int64 callbackId, CefString script, JavascriptCallbackRegistry^ callbackRegistry);
|
||||
CefRefPtr<CefProcessMessage> EvaluateScriptInContext(CefRefPtr<CefV8Context> context, int64 callbackId, CefString script, JavascriptCallbackRegistry^ callbackRegistry);
|
||||
public:
|
||||
EvaluateScriptDelegate(CefRefPtr<CefAppUnmanagedWrapper> appUnmanagedWrapper);
|
||||
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) override;
|
||||
|
||||
Reference in New Issue
Block a user