Skip to content

Commit

Permalink
Merge 3b5498b into 020404f
Browse files Browse the repository at this point in the history
  • Loading branch information
amaitland authored Jun 14, 2019
2 parents 020404f + 3b5498b commit 927bcda
Show file tree
Hide file tree
Showing 87 changed files with 1,222 additions and 1,498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace CefSharp
bool JavascriptAsyncMethodHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
auto context = CefV8Context::GetCurrentContext();
auto browser = context->GetBrowser();
auto frame = context->GetFrame();

CefRefPtr<CefV8Value> promiseData;
CefRefPtr<CefV8Exception> promiseException;
Expand Down Expand Up @@ -59,13 +59,12 @@ namespace CefSharp
SerializeV8Object(arguments[i], params, i, _callbackRegistry);
}

SetInt64(argList, 0, context->GetFrame()->GetIdentifier());
SetInt64(argList, 1, _objectId);
SetInt64(argList, 2, callbackId);
argList->SetString(3, name);
argList->SetList(4, params);
SetInt64(argList, 0, _objectId);
SetInt64(argList, 1, callbackId);
argList->SetString(2, name);
argList->SetList(3, params);

browser->SendProcessMessage(CefProcessId::PID_BROWSER, request);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, request);

return true;
}
Expand Down
88 changes: 37 additions & 51 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace CefSharp
};

// CefRenderProcessHandler
void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr<CefBrowser> browser)
void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo)
{
auto wrapper = gcnew CefBrowserWrapper(browser);
_onBrowserCreated->Invoke(wrapper);
Expand Down Expand Up @@ -123,9 +123,7 @@ namespace CefSharp
//have been created
auto contextCreatedMessage = CefProcessMessage::Create(kOnContextCreatedRequest);

SetInt64(contextCreatedMessage->GetArgumentList(), 0, frame->GetIdentifier());

browser->SendProcessMessage(CefProcessId::PID_BROWSER, contextCreatedMessage);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, contextCreatedMessage);
};

void CefAppUnmanagedWrapper::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
Expand All @@ -141,9 +139,7 @@ namespace CefSharp

auto contextReleasedMessage = CefProcessMessage::Create(kOnContextReleasedRequest);

SetInt64(contextReleasedMessage->GetArgumentList(), 0, frame->GetIdentifier());

browser->SendProcessMessage(CefProcessId::PID_BROWSER, contextReleasedMessage);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, contextReleasedMessage);

auto browserWrapper = FindBrowserWrapper(browser->GetIdentifier());

Expand Down Expand Up @@ -172,19 +168,16 @@ namespace CefSharp
auto focusedNodeChangedMessage = CefProcessMessage::Create(kOnFocusedNodeChanged);
auto list = focusedNodeChangedMessage->GetArgumentList();

// Needed in the browser process to get the frame.
SetInt64(list, 0, frame->GetIdentifier());

// The node will be empty if an element loses focus but another one
// doesn't gain focus. Only transfer information if the node is an
// element.
if (node != nullptr && node->IsElement())
{
// True when a node exists, false if it doesn't.
list->SetBool(1, true);
list->SetBool(0, true);

// Store the tag name.
list->SetString(2, node->GetElementTagName());
list->SetString(1, node->GetElementTagName());

// Transfer the attributes in a Dictionary.
auto attributes = CefDictionaryValue::Create();
Expand All @@ -195,24 +188,22 @@ namespace CefSharp
attributes->SetString(iter.first, iter.second);
}

list->SetDictionary(3, attributes);
list->SetDictionary(2, attributes);
}
else
{
list->SetBool(1, false);
list->SetBool(0, false);
}

browser->SendProcessMessage(CefProcessId::PID_BROWSER, focusedNodeChangedMessage);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, focusedNodeChangedMessage);
}

void CefAppUnmanagedWrapper::OnUncaughtException(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Exception> exception, CefRefPtr<CefV8StackTrace> stackTrace)
{
auto uncaughtExceptionMessage = CefProcessMessage::Create(kOnUncaughtException);
auto list = uncaughtExceptionMessage->GetArgumentList();

// Needed in the browser process to get the frame.
SetInt64(list, 0, frame->GetIdentifier());
list->SetString(1, exception->GetMessage());
list->SetString(0, exception->GetMessage());

auto frames = CefListValue::Create();
for (auto i = 0; i < stackTrace->GetFrameCount(); i++)
Expand All @@ -228,9 +219,9 @@ namespace CefSharp
frames->SetList(i, frame);
}

list->SetList(2, frames);
list->SetList(1, frames);

browser->SendProcessMessage(CefProcessId::PID_BROWSER, uncaughtExceptionMessage);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, uncaughtExceptionMessage);
}

JavascriptRootObjectWrapper^ CefAppUnmanagedWrapper::GetJsRootObjectWrapper(int browserId, int64 frameId)
Expand Down Expand Up @@ -269,7 +260,7 @@ namespace CefSharp
return wrapper;
}

bool CefAppUnmanagedWrapper::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message)
bool CefAppUnmanagedWrapper::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message)
{
auto handled = false;
auto name = message->GetName();
Expand Down Expand Up @@ -304,7 +295,7 @@ namespace CefSharp
throw gcnew Exception("Unsupported message type");
}

auto callbackId = GetInt64(argList, 1);
auto callbackId = GetInt64(argList, 0);
auto response = CefProcessMessage::Create(responseName);
auto responseArgList = response->GetArgumentList();
auto errorMessage = String::Format("Request BrowserId : {0} not found it's likely the browser is already closed", browser->GetIdentifier());
Expand All @@ -313,7 +304,7 @@ namespace CefSharp
responseArgList->SetBool(0, false);
SetInt64(responseArgList, 1, callbackId);
responseArgList->SetString(2, StringUtils::ToNative(errorMessage));
browser->SendProcessMessage(sourceProcessId, response);
frame->SendProcessMessage(sourceProcessId, response);

return true;
}
Expand All @@ -335,13 +326,12 @@ namespace CefSharp
response = CefProcessMessage::Create(kJavascriptCallbackResponse);
}

//both messages have the frameId stored at 0 and callbackId stored at index 1
auto frameId = GetInt64(argList, 0);
int64 callbackId = GetInt64(argList, 1);
//both messages have callbackId stored at index 0
auto frameId = frame->GetIdentifier();
int64 callbackId = GetInt64(argList, 0);

if (name == kEvaluateJavascriptRequest)
{

JavascriptRootObjectWrapper^ rootObjectWrapper;
browserWrapper->JavascriptRootObjectWrappers->TryGetValue(frameId, rootObjectWrapper);

Expand All @@ -357,12 +347,11 @@ namespace CefSharp

auto callbackRegistry = rootObjectWrapper->CallbackRegistry;

auto script = argList->GetString(2);
auto scriptUrl = argList->GetString(3);
auto startLine = argList->GetInt(4);
auto script = argList->GetString(1);
auto scriptUrl = argList->GetString(2);
auto startLine = argList->GetInt(3);

auto frame = browser->GetFrame(frameId);
if (frame.get())
if (frame.get() && frame->IsValid())
{
auto context = frame->GetV8Context();

Expand Down Expand Up @@ -410,7 +399,7 @@ namespace CefSharp
}
else
{
auto jsCallbackId = GetInt64(argList, 2);
auto jsCallbackId = GetInt64(argList, 1);

auto callbackWrapper = callbackRegistry->FindWrapper(jsCallbackId);
if (callbackWrapper == nullptr)
Expand All @@ -426,7 +415,7 @@ namespace CefSharp
{
try
{
auto parameterList = argList->GetList(3);
auto parameterList = argList->GetList(2);
CefV8ValueList params;

//Needs to be called within the context as for Dictionary (mapped to struct)
Expand Down Expand Up @@ -471,14 +460,14 @@ namespace CefSharp
{
responseArgList->SetString(2, errorMessage);
}
browser->SendProcessMessage(sourceProcessId, response);
frame->SendProcessMessage(sourceProcessId, response);

handled = true;
}
else if (name == kJavascriptCallbackDestroyRequest)
{
auto jsCallbackId = GetInt64(argList, 0);
auto frameId = GetInt64(argList, 1);
auto frameId = frame->GetIdentifier();
JavascriptRootObjectWrapper^ rootObjectWrapper;
browserWrapper->JavascriptRootObjectWrappers->TryGetValue(frameId, rootObjectWrapper);
if (rootObjectWrapper != nullptr && rootObjectWrapper->CallbackRegistry != nullptr)
Expand Down Expand Up @@ -517,10 +506,10 @@ namespace CefSharp
}
else
{
auto browserId = argList->GetInt(1);
auto frameId = GetInt64(argList, 2);
auto callbackId = GetInt64(argList, 3);
auto javascriptObjects = DeserializeJsObjects(argList, 4);
auto browserId = browser->GetIdentifier();
auto frameId = frame->GetIdentifier();
auto callbackId = GetInt64(argList, 1);
auto javascriptObjects = DeserializeJsObjects(argList, 2);

//Caching of JavascriptObjects
//TODO: JSB Should caching be configurable? On a per object basis?
Expand All @@ -533,8 +522,7 @@ namespace CefSharp
_javascriptObjects->Add(obj->JavascriptName, obj);
}

auto frame = browser->GetFrame(frameId);
if (frame.get())
if (frame.get() && frame->IsValid())
{
auto rootObject = GetJsRootObjectWrapper(browser->GetIdentifier(), frameId);

Expand Down Expand Up @@ -594,7 +582,7 @@ namespace CefSharp

args->SetList(0, boundObjects);

browser->SendProcessMessage(CefProcessId::PID_BROWSER, msg);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, msg);
}
}
finally
Expand All @@ -609,8 +597,8 @@ namespace CefSharp
}
else if (name == kJavascriptAsyncMethodCallResponse)
{
auto frameId = GetInt64(argList, 0);
auto callbackId = GetInt64(argList, 1);
auto frameId = frame->GetIdentifier();
auto callbackId = GetInt64(argList, 0);

JavascriptRootObjectWrapper^ rootObjectWrapper;
browserWrapper->JavascriptRootObjectWrappers->TryGetValue(frameId, rootObjectWrapper);
Expand All @@ -620,26 +608,24 @@ namespace CefSharp
JavascriptAsyncMethodCallback^ callback;
if (rootObjectWrapper->TryGetAndRemoveMethodCallback(callbackId, callback))
{

try
{
auto frame = browser->GetFrame(frameId);
if (frame.get())
if (frame.get() && frame->IsValid())
{
auto context = frame->GetV8Context();

if (context.get() && context->Enter())
{
try
{
auto success = argList->GetBool(2);
auto success = argList->GetBool(1);
if (success)
{
callback->Success(DeserializeV8Object(argList, 3));
callback->Success(DeserializeV8Object(argList, 2));
}
else
{
callback->Fail(argList->GetString(3));
callback->Fail(argList->GetString(2));
}
}
finally
Expand Down
4 changes: 2 additions & 2 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ namespace CefSharp
JavascriptRootObjectWrapper^ GetJsRootObjectWrapper(int browserId, int64 frameId);

virtual DECL CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE;
virtual DECL void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual DECL void OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo) OVERRIDE;
virtual DECL void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual DECL void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
virtual DECL void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
virtual DECL bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message) OVERRIDE;
virtual DECL bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message) OVERRIDE;
virtual DECL void OnRenderThreadCreated(CefRefPtr<CefListValue> extraInfo) OVERRIDE;
virtual DECL void OnWebKitInitialized() OVERRIDE;
virtual DECL void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) OVERRIDE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\cef.sdk.74.1.13\build\cef.sdk.props" Condition="Exists('..\packages\cef.sdk.74.1.13\build\cef.sdk.props')" />
<Import Project="..\packages\cef.sdk.75.0.3\build\cef.sdk.props" Condition="Exists('..\packages\cef.sdk.75.0.3\build\cef.sdk.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down
10 changes: 4 additions & 6 deletions CefSharp.BrowserSubprocess.Core/JavascriptPostMessageHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace CefSharp
auto context = CefV8Context::GetCurrentContext();
if (context.get())
{
auto browser = context->GetBrowser();
auto frame = context->GetFrame();

if (context.get() && context->Enter())
if (frame.get() && frame->IsValid() && context->Enter())
{
try
{
Expand All @@ -53,18 +53,16 @@ namespace CefSharp
auto request = CefProcessMessage::Create(kJavascriptMessageReceived);
auto argList = request->GetArgumentList();

SetInt64(argList, 0, context->GetFrame()->GetIdentifier());

auto params = CefListValue::Create();
SerializeV8Object(arguments[0], params, 0, _javascriptCallbackRegistry);

//We're only interested in the first param
if (params->GetSize() > 0)
{
argList->SetValue(1, params->GetValue(0));
argList->SetValue(0, params->GetValue(0));
}

browser->SendProcessMessage(CefProcessId::PID_BROWSER, request);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, request);

retval = CefV8Value::CreateNull();
}
Expand Down
Loading

0 comments on commit 927bcda

Please sign in to comment.