Convert atom global to a window binding

This commit is contained in:
Corey Johnson & Nathan Sobo
2013-01-23 12:14:38 -07:00
committed by Kevin Sawicki
parent a5f72c8a2d
commit faaaaec846
4 changed files with 22 additions and 15 deletions

View File

@@ -10,7 +10,6 @@
#include <iostream>
void AtomCefRenderProcessHandler::OnWebKitInitialized() {
new v8_extensions::Atom();
new v8_extensions::OnigRegExp();
new v8_extensions::OnigScanner();
new v8_extensions::Git();
@@ -20,6 +19,7 @@ void AtomCefRenderProcessHandler::OnWebKitInitialized() {
void AtomCefRenderProcessHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
v8_extensions::Atom::CreateContextBinding(context);
v8_extensions::Native::CreateContextBinding(context);
}

View File

@@ -4,8 +4,7 @@
namespace v8_extensions {
class Atom : public CefV8Handler {
public:
Atom();
static void CreateContextBinding(CefRefPtr<CefV8Context> context);
virtual bool Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
@@ -14,5 +13,11 @@ namespace v8_extensions {
// Provide the reference counting implementation for this class.
IMPLEMENT_REFCOUNTING(Atom);
private:
static CefRefPtr<CefV8Handler> GetInstance();
Atom();
Atom(Atom const&);
void operator=(Atom const&);
};
}

View File

@@ -1,9 +0,0 @@
(function () {
native function sendMessageToBrowserProcess(name, array);
this.atom = {
sendMessageToBrowserProcess: sendMessageToBrowserProcess
};
})();

View File

@@ -7,9 +7,20 @@
namespace v8_extensions {
Atom::Atom() : CefV8Handler() {
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"v8_extensions/atom.js"];
NSString *extensionCode = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
CefRegisterExtension("v8/atom", [extensionCode UTF8String], this);
}
void Atom::CreateContextBinding(CefRefPtr<CefV8Context> context) {
CefRefPtr<CefV8Value> function = CefV8Value::CreateFunction("sendMessageToBrowserProcess", GetInstance());
CefRefPtr<CefV8Value> atomObject = CefV8Value::CreateObject(NULL);
atomObject->SetValue("sendMessageToBrowserProcess", function, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> global = context->GetGlobal();
global->SetValue("atom", atomObject, V8_PROPERTY_ATTRIBUTE_NONE);
}
CefRefPtr<CefV8Handler> Atom::GetInstance() {
static Atom instance;
static CefRefPtr<CefV8Handler> instancePtr = CefRefPtr<CefV8Handler>(&instance);
return instancePtr;
}
bool Atom::Execute(const CefString& name,