mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Update cef3 artifacts
This commit is contained in:
77
Atom-Linux/atom_cef_render_process_handler.cpp
Normal file
77
Atom-Linux/atom_cef_render_process_handler.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "atom_cef_render_process_handler.h"
|
||||
#include "atom_handler.h"
|
||||
#include "native_handler.h"
|
||||
#include "onig_regexp_extension.h"
|
||||
#include "io_utils.h"
|
||||
#include "message_translation.h"
|
||||
#include <iostream>
|
||||
|
||||
void AtomCefRenderProcessHandler::OnWebKitInitialized() {
|
||||
new AtomHandler();
|
||||
new NativeHandler();
|
||||
new OnigRegexpExtension();
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::OnContextCreated(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
CefRefPtr<CefV8Value> resourcePath = CefV8Value::CreateString(
|
||||
io_util_app_directory());
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
CefRefPtr<CefV8Value> atom = global->GetValue("atom");
|
||||
atom->SetValue("resourcePath", resourcePath, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
bool AtomCefRenderProcessHandler::OnProcessMessageReceived(
|
||||
CefRefPtr<CefBrowser> browser, CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) {
|
||||
return CallMessageReceivedHandler(browser->GetMainFrame()->GetV8Context(),
|
||||
message);
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::Reload(CefRefPtr<CefBrowser> browser) {
|
||||
CefRefPtr<CefV8Context> context = browser->GetMainFrame()->GetV8Context();
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
context->Enter();
|
||||
CefV8ValueList arguments;
|
||||
|
||||
CefRefPtr<CefV8Value> reloadFunction = global->GetValue("reload");
|
||||
reloadFunction->ExecuteFunction(global, arguments);
|
||||
if (reloadFunction->HasException()) {
|
||||
browser->ReloadIgnoreCache();
|
||||
}
|
||||
context->Exit();
|
||||
}
|
||||
|
||||
bool AtomCefRenderProcessHandler::CallMessageReceivedHandler(
|
||||
CefRefPtr<CefV8Context> context, CefRefPtr<CefProcessMessage> message) {
|
||||
context->Enter();
|
||||
|
||||
CefRefPtr<CefV8Value> atom = context->GetGlobal()->GetValue("atom");
|
||||
CefRefPtr<CefV8Value> receiveFn = atom->GetValue(
|
||||
"receiveMessageFromBrowserProcess");
|
||||
|
||||
CefV8ValueList arguments;
|
||||
arguments.push_back(CefV8Value::CreateString(message->GetName().ToString()));
|
||||
|
||||
CefRefPtr<CefListValue> messageArguments = message->GetArgumentList();
|
||||
if (messageArguments->GetSize() > 0) {
|
||||
CefRefPtr<CefV8Value> data = CefV8Value::CreateArray(
|
||||
messageArguments->GetSize());
|
||||
TranslateList(messageArguments, data);
|
||||
arguments.push_back(data);
|
||||
}
|
||||
|
||||
receiveFn->ExecuteFunction(atom, arguments);
|
||||
context->Exit();
|
||||
|
||||
if (receiveFn->HasException()) {
|
||||
std::cout << "ERROR: Exception in JS receiving message "
|
||||
<< message->GetName().ToString() << "\n";
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user