mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
$native is now created once and registered as a CEF Extension.
This commit is contained in:
@@ -93,6 +93,7 @@
|
||||
}
|
||||
|
||||
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
|
||||
CefRefPtr<CefV8Handler> nativeHandler = new NativeHandler();
|
||||
[self createAtomContext];
|
||||
}
|
||||
|
||||
@@ -107,9 +108,6 @@
|
||||
CefRefPtr<CefV8Value> bootstrapScript = CefV8Value::CreateString("atom-bootstrap");
|
||||
global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<NativeHandler> nativeHandler = new NativeHandler();
|
||||
global->SetValue("$native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<CefV8Value> atom = CefV8Value::CreateObject(NULL, NULL);
|
||||
global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#import "include/cef_base.h"
|
||||
#import "client_handler.h"
|
||||
#import "native_handler.h"
|
||||
#import "PathWatcher.h"
|
||||
|
||||
@implementation AtomController
|
||||
@@ -76,9 +75,6 @@
|
||||
CefRefPtr<CefV8Value> bootstrapScript = CefV8Value::CreateString([_bootstrapScript UTF8String]);
|
||||
global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<NativeHandler> nativeHandler = new NativeHandler();
|
||||
global->SetValue("$native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<CefV8Value> pathToOpen = _pathToOpen ? CefV8Value::CreateString([_pathToOpen UTF8String]) : CefV8Value::CreateNull();
|
||||
global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
|
||||
@@ -14,18 +14,21 @@ NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& value) {
|
||||
}
|
||||
|
||||
NativeHandler::NativeHandler() : CefV8Handler() {
|
||||
m_object = CefV8Value::CreateObject(NULL, NULL);
|
||||
std::string extensionCode = "var $native = {}; (function() {";
|
||||
|
||||
const char *functionNames[] = {"exists", "alert", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory", "move", "moveToTrash"};
|
||||
const char *functionNames[] = {"exists", "alert", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory", "move", "moveToTrash"};
|
||||
NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *);
|
||||
for (NSUInteger i = 0; i < arrayLength; i++) {
|
||||
const char *functionName = functionNames[i];
|
||||
CefRefPtr<CefV8Value> function = CefV8Value::CreateFunction(functionName, this);
|
||||
m_object->SetValue(functionName, function, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
std::string functionName = std::string(functionNames[i]);
|
||||
extensionCode += "native function " + functionName + "(); $native." + functionName + " = " + functionName + ";";
|
||||
}
|
||||
|
||||
extensionCode += "})();";
|
||||
|
||||
// Register the extension.
|
||||
CefRegisterExtension("v8/test", extensionCode, this);
|
||||
}
|
||||
|
||||
|
||||
bool NativeHandler::Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
|
||||
Reference in New Issue
Block a user