mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add method that takes a block for modifying JS vars from objective-c
This commit is contained in:
@@ -72,6 +72,18 @@
|
||||
[[AtomController alloc] initBenchmarksWithAtomContext:[self atomContext]];
|
||||
}
|
||||
|
||||
- (void)modifyJavaScript:(void(^)(CefRefPtr<CefV8Context>, CefRefPtr<CefV8Value>))callback {
|
||||
CefRefPtr<CefV8Context> context = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context();
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
context->Enter();
|
||||
|
||||
callback(context, global);
|
||||
|
||||
context->Exit();
|
||||
|
||||
}
|
||||
|
||||
- (CefRefPtr<CefV8Context>)atomContext {
|
||||
return _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context();
|
||||
}
|
||||
@@ -87,24 +99,19 @@
|
||||
#pragma mark BrowserDelegate
|
||||
|
||||
- (void)loadStart {
|
||||
CefRefPtr<CefV8Context> context = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context();
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
[self modifyJavaScript:^(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> global) {
|
||||
CefRefPtr<CefV8Value> bootstrapScript = CefV8Value::CreateString("atom-bootstrap");
|
||||
global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
context->Enter();
|
||||
CefRefPtr<NativeHandler> nativeHandler = new NativeHandler();
|
||||
global->SetValue("$native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
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);
|
||||
global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<CefV8Value> loadPath = CefV8Value::CreateString(PROJECT_DIR);
|
||||
atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
context->Exit();
|
||||
CefRefPtr<CefV8Value> atom = CefV8Value::CreateObject(NULL);
|
||||
global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<CefV8Value> loadPath = CefV8Value::CreateString(PROJECT_DIR);
|
||||
atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadEnd {
|
||||
|
||||
Reference in New Issue
Block a user