Skip to content

Commit

Permalink
JavascriptCallback - Hack to work around upstream issue
Browse files Browse the repository at this point in the history
JavascriptCallback's are limited to only working in the main frame
Frame ids aren't the same between processes, so makes it almost impossible to handle callbacks in sub frames

https://bitbucket.org/chromiumembedded/cef/issues/2687/cefframe-getidentifier-differs-between
#2743 (comment)

This should be reverted after the problem has been resolved.
  • Loading branch information
amaitland committed Jun 17, 2019
1 parent 2ee4fd5 commit 9d47c2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
18 changes: 16 additions & 2 deletions CefSharp.BrowserSubprocess.Core/JavascriptCallbackRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ namespace CefSharp
auto result = gcnew JavascriptCallback();
result->Id = newId;
result->BrowserId = _browserId;
result->FrameId = context->GetFrame()->GetIdentifier();
result->FrameId = -1;

auto frame = context->GetFrame();

if (frame.get() && frame->IsValid())
{
//Issue https://bitbucket.org/chromiumembedded/cef/issues/2687/cefframe-getidentifier-differs-between
//prevents callbacks from working properly
//As a hack to get callbacks working we'll only return an Id for the main frame
//https://github.com/cefsharp/CefSharp/issues/2743#issuecomment-502566136
if (frame->IsMain())
{
result->FrameId = frame->GetIdentifier();
}
}
return result;
}

Expand All @@ -41,4 +55,4 @@ namespace CefSharp
}

}
}
}
23 changes: 20 additions & 3 deletions CefSharp.Core/Internals/JavascriptCallbackProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ namespace CefSharp
}
argList->SetList(2, paramList);

auto frame = browserWrapper->Browser->GetFrame(_callback->FrameId);
if (_callback->FrameId < 0)
{
auto invalidFrameResponse = gcnew JavascriptResponse();
invalidFrameResponse->Success = false;
invalidFrameResponse->Message = "Javascript callbacks are only supported via the main frame until an upstream issue is resolved, see https://github.com/cefsharp/CefSharp/issues/2743#issuecomment-502566136";

return Task::FromResult(invalidFrameResponse);
}

auto frame = browserWrapper->Browser->GetMainFrame();

if (frame.get() && frame->IsValid())
{
Expand All @@ -55,7 +64,7 @@ namespace CefSharp
invalidFrameResponse->Success = false;
invalidFrameResponse->Message = "Frame with Id:" + _callback->FrameId + " is no longer valid.";

Task::FromResult(invalidFrameResponse);
return Task::FromResult(invalidFrameResponse);
}
}

Expand Down Expand Up @@ -106,8 +115,16 @@ namespace CefSharp
return false;
}

//https://github.com/cefsharp/CefSharp/issues/2743#issuecomment-502566136
if (_callback->FrameId < 0)
{
//We're only able to support callbacks in the main frame until the above issue
//is resolved.
return false;
}

//If the frame Id is still valid then we can attemp to execute the callback
auto frame = browser->GetFrame(_callback->FrameId);
auto frame = browser->MainFrame;
if (frame == nullptr)
{
return false;
Expand Down

0 comments on commit 9d47c2e

Please sign in to comment.