本文整理汇总了C++中CefRefPtr::Enter方法的典型用法代码示例。如果您正苦于以下问题:C++ CefRefPtr::Enter方法的具体用法?C++ CefRefPtr::Enter怎么用?C++ CefRefPtr::Enter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CefRefPtr
的用法示例。
在下文中一共展示了CefRefPtr::Enter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// synchronously send a string from Node to browser, then return string result from browser to Node
Handle<Value> Window::SendSync(const Arguments& args) {
HandleScope scope;
NativeWindow *window = ObjectWrap::Unwrap<NativeWindow> (args.This());
if (window->GetBrowser()) {
// find browser's v8 context
CefRefPtr<CefV8Context> context = window->GetBrowser()->GetMainFrame()->GetV8Context();
// ensure it's usable and enter
if (context.get() && context->Enter()) {
// try to get "appjs.onmessage" function
CefRefPtr<CefV8Value> appjsObject = context->GetGlobal()->GetValue("appjs");
CefRefPtr<CefV8Value> callback = appjsObject->GetValue("onmessage");
if (callback.get()) {
// convert Node V8 string to Cef V8 string
CefV8ValueList argsOut;
argsOut.push_back(CefV8Value::CreateString(V8StringToChar(args[0]->ToString())));
// execute window.appjs fuction, passing in the string,
// then convert the return value from a CefValue to a Node V8 string
Handle<String> ret = CefStringToV8(callback->ExecuteFunction(appjsObject, argsOut)->GetStringValue());
// exit browser v8 context, return string result to Node caller
context->Exit();
return scope.Close(ret);
}
}
}
// likely error condition
return scope.Close(Undefined());
}
示例2: registerFunctions
void OverloadApp::registerFunctions(CefRefPtr<CefListValue> functionNames)
{
if (_browser != nullptr)
{
CefRefPtr<CefV8Context> currentContext = _browser->GetMainFrame()->GetV8Context();
currentContext->Enter();
CefRefPtr<CefV8Value> object = currentContext->GetGlobal();
for (std::size_t i = 0; i < functionNames->GetSize(); i++)
{
std::string functionName = functionNames->GetString(i).ToString();
object->SetValue(functionName, CefV8Value::CreateFunction(functionName, _v8Handler.get()), V8_PROPERTY_ATTRIBUTE_NONE);
_functionNames.push_back(functionName);
}
currentContext->Exit();
}
else
{
for (std::size_t i = 0; i < functionNames->GetSize(); i++)
{
_functionNames.push_back(functionNames->GetString(i).ToString());
}
}
}
示例3: UIT_Evaluate
void ScriptCore::UIT_Evaluate(CefRefPtr<CefBrowser> browser, CefString script)
{
CefRefPtr<CefFrame> mainFrame;
if (TryGetMainFrame(browser, mainFrame))
{
CefRefPtr<CefV8Context> context = mainFrame->GetV8Context();
if (context.get() && context->Enter())
{
CefRefPtr<CefV8Value> result;
CefRefPtr<CefV8Exception> exception;
bool success = context->Eval(script, result, exception);
if (success)
{
try
{
_result = convertFromCef(result);
}
catch (Exception^ ex)
{
_exceptionMessage = ex->Message;
}
}
else if (exception.get())
{
_exceptionMessage = toClr(exception->GetMessage());
}
else
{
_exceptionMessage = "Failed to evaluate script";
}
context->Exit();
}
示例4: ReadContainerObjectsAndWriteToIPCMsg
void IPC_Container::ReadContainerObjectsAndWriteToIPCMsg(
CefRefPtr<CefV8Context> context,
std::string container_array_variable,
std::vector<int> amounts,
int64 frameID,
CefRefPtr<CefProcessMessage> msg
)
{
CefRefPtr<CefListValue> args = msg->GetArgumentList();
int index = 0;
// Write frameID at position #0
args->SetDouble(index++, (double) frameID);
// Write different amount of different node types at position #1
args->SetInt(index++, amounts.size());
// Write amount of each node type at first positions
for (int i = 0; i < (int)amounts.size(); i++)
{
args->SetInt(index++, amounts[i]);
}
if (context->Enter())
{
int all_objects_done = 0;
for (int i = 0; i < (int)amounts.size(); i++)
{
// Read each container object
for (int j = 0; j < amounts[i]; j++)
{
// Read every attribute and get their value
for (int k = 0; k < (int)_scheme.size(); k++)
{
// DLOG(INFO) << "Reading object #" << j << ", Attribute #" << k << "), writing to IPC args index #" << index;
// Get each attribute as V8Value
CefRefPtr<CefV8Value> attribute = GetAttributesV8Value( // TODO: There HAS TO BE a bug concerning the object's position in the array
context,
container_array_variable,
j+all_objects_done,
_scheme[k]
);
// Write each attribute to IPC message
SetIPCArgumentsValue(
args,
index,
attribute,
_scheme[k]
);
}
}
all_objects_done += amounts[i];
}
context->Exit();
}
}
示例5: OnProcessMessageReceived
bool ClientApp::OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
ASSERT(source_process == PID_BROWSER);
bool handled = false;
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end() && !handled; ++it) {
handled = (*it)->OnProcessMessageReceived(this, browser, source_process,
message);
}
if (handled)
return true;
// Execute the registered JavaScript callback if any.
if (!callback_map_.empty()) {
CefString message_name = message->GetName();
CallbackMap::const_iterator it = callback_map_.find(
std::make_pair(message_name.ToString(),
browser->GetIdentifier()));
if (it != callback_map_.end()) {
// Keep a local reference to the objects. The callback may remove itself
// from the callback map.
CefRefPtr<CefV8Context> context = it->second.first;
CefRefPtr<CefV8Value> callback = it->second.second;
// Enter the context.
context->Enter();
CefV8ValueList arguments;
// First argument is the message name.
arguments.push_back(CefV8Value::CreateString(message_name));
// Second argument is the list of message arguments.
CefRefPtr<CefListValue> list = message->GetArgumentList();
CefRefPtr<CefV8Value> args =
CefV8Value::CreateArray(static_cast<int>(list->GetSize()));
SetList(list, args);
arguments.push_back(args);
// Execute the callback.
CefRefPtr<CefV8Value> retval = callback->ExecuteFunction(NULL, arguments);
if (retval.get()) {
if (retval->IsBool())
handled = retval->GetBoolValue();
}
// Exit the context.
context->Exit();
}
}
return handled;
}
示例6: OnContextCreated
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) {
REQUIRE_UI_THREAD();
if (!browser->IsPopup()) {
context->Enter();
CefRefPtr<CefV8Value> appjsObj = CefV8Value::CreateObject(NULL);
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction("send", new AppjsSyncHandler(browser));
context->GetGlobal()->SetValue("appjs", appjsObj, V8_PROPERTY_ATTRIBUTE_NONE);
appjsObj->SetValue("send", func, V8_PROPERTY_ATTRIBUTE_NONE);
context->Exit();
}
}
示例7:
void V8_Container::AddContainerArray(CefRefPtr<CefV8Context> context, std::string js_var_name, int arraySize)
{
if (context->Enter())
{
CefRefPtr<CefV8Value> array = CefV8Value::CreateArray(arraySize);
for (int i = 0; i < arraySize; i++)
{
array->SetValue(i, CreateContainerV8Object());
}
// Add empty array of container objects to context's global object
context->GetGlobal()->SetValue(js_var_name, array, V8_PROPERTY_ATTRIBUTE_NONE);
context->Exit();
}
}
示例8: OnProcessMessageReceived
bool ClientApp::OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
ASSERT(source_process == PID_BROWSER);
bool handled = false;
// Execute delegate callbacks.
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end() && !handled; ++it) {
handled = (*it)->OnProcessMessageReceived(this, browser, source_process, message);
}
if (!handled) {
if (message->GetName() == "invokeCallback") {
// This is called by the appshell extension handler to invoke the asynchronous
// callback function
CefRefPtr<CefListValue> messageArgs = message->GetArgumentList();
int32 callbackId = messageArgs->GetInt(0);
CefRefPtr<CefV8Context> context = callback_map_[callbackId].first;
CefRefPtr<CefV8Value> callbackFunction = callback_map_[callbackId].second;
CefV8ValueList arguments;
context->Enter();
// Sanity check to make sure the context is still attched to a browser.
// Async callbacks could be initiated after a browser instance has been deleted,
// which can lead to bad things. If the browser instance has been deleted, don't
// invoke this callback.
if (context->GetBrowser()) {
for (size_t i = 1; i < messageArgs->GetSize(); i++) {
arguments.push_back(ListValueToV8Value(messageArgs, i));
}
callbackFunction->ExecuteFunction(NULL, arguments);
}
context->Exit();
callback_map_.erase(callbackId);
} else if (message->GetName() == "executeCommand") {
// This is called by the browser process to execute a command via JavaScript
//
// The first argument is the command name. This is required.
// The second argument is a message id. This is optional. If set, a response
// message will be sent back to the browser process.
CefRefPtr<CefListValue> messageArgs = message->GetArgumentList();
CefString commandName = messageArgs->GetString(0);
int messageId = messageArgs->GetSize() > 1 ? messageArgs->GetInt(1) : -1;
bool handled = false;
StContextScope ctx(browser->GetMainFrame()->GetV8Context());
CefRefPtr<CefV8Value> global = ctx.GetContext()->GetGlobal();
if (global->HasValue("brackets")) {
CefRefPtr<CefV8Value> brackets = global->GetValue("brackets");
if (brackets->HasValue("shellAPI")) {
CefRefPtr<CefV8Value> shellAPI = brackets->GetValue("shellAPI");
if (shellAPI->HasValue("executeCommand")) {
CefRefPtr<CefV8Value> executeCommand = shellAPI->GetValue("executeCommand");
if (executeCommand->IsFunction()) {
CefRefPtr<CefV8Value> retval;
CefV8ValueList args;
args.push_back(CefV8Value::CreateString(commandName));
retval = executeCommand->ExecuteFunction(global, args);
if (retval) {
handled = retval->GetBoolValue();
}
}
}
}
}
// Return a message saying whether or not the command was handled
if (messageId != -1) {
CefRefPtr<CefProcessMessage> result = CefProcessMessage::Create("executeCommandCallback");
result->GetArgumentList()->SetInt(0, messageId);
result->GetArgumentList()->SetBool(1, handled);
browser->SendProcessMessage(PID_BROWSER, result);
}
}
}
return handled;
}
示例9: StContextScope
StContextScope( const CefRefPtr<CefV8Context>& ctx )
: m_ctx(NULL) {
if( ctx && ctx->Enter() ) {
m_ctx = ctx;
}
}