diff --git a/atom/atom_controller.h b/atom/atom_controller.h index 805d1a2b8..c0ef4afb8 100644 --- a/atom/atom_controller.h +++ b/atom/atom_controller.h @@ -15,7 +15,8 @@ class ClientHandler; @property (nonatomic, retain) IBOutlet NSView *webView; -- (void)populateBrowserSettings:(CefBrowserSettings &)settings; - (id)initWithPath:(NSString *)path atomContext:(CefRefPtr)atomContext; +- (id)initSpecsWithAtomContext:(CefRefPtr)atomContext; +- (id)initBenchmarksWithAtomContext:(CefRefPtr)atomContext; @end \ No newline at end of file diff --git a/atom/atom_controller.mm b/atom/atom_controller.mm index 38b833375..32cc093da 100644 --- a/atom/atom_controller.mm +++ b/atom/atom_controller.mm @@ -86,7 +86,7 @@ settings.remote_fonts_disabled = true; settings.encoding_detector_enabled = false; settings.javascript_disabled = false; - settings.javascript_open_windows_disallowed = true; + settings.javascript_open_windows_disallowed = false; settings.javascript_close_windows_disallowed = false; settings.javascript_access_clipboard_disallowed = false; settings.dom_paste_disabled = true; diff --git a/atom/atom_mac.h b/atom/atom_mac.h index fe0f122a0..f27e15781 100644 --- a/atom/atom_mac.h +++ b/atom/atom_mac.h @@ -2,10 +2,16 @@ @interface Atom : NSApplication { @private + NSWindow *_hiddenWindow; + + CefRefPtr _clientHandler; + BOOL handlingSendEvent_; } + (void)populateAppSettings:(CefSettings &)settings; -- (void)createWindow; +- (void)open:(NSString *)path; +- (IBAction)runSpecs:(id)sender; +- (IBAction)runBenchmarks:(id)sender; @end \ No newline at end of file diff --git a/atom/atom_mac.mm b/atom/atom_mac.mm index ab9f80883..954c013a3 100644 --- a/atom/atom_mac.mm +++ b/atom/atom_mac.mm @@ -29,17 +29,102 @@ } -// Create the application on the UI thread. -- (void)createWindow { - AtomController *controller = [[AtomController alloc] initWithPath:@"" atomContext:NULL]; +- (void)dealloc { + [_hiddenWindow release]; + [super dealloc]; } +- (void)createAtomContext { + _clientHandler = new ClientHandler(); + + CefWindowInfo window_info; + _hiddenWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 0, 0) styleMask:nil backing:nil defer:YES]; + window_info.SetAsChild([_hiddenWindow contentView], 0, 0, 0, 0); + + CefBrowserSettings settings; + NSURL *resourceDirURL = [[NSBundle mainBundle] resourceURL]; + NSString *indexURLString = [[resourceDirURL URLByAppendingPathComponent:@"index.html"] absoluteString]; + CefBrowserHost::CreateBrowser(window_info, _clientHandler.get(), [indexURLString UTF8String], settings); +} + +- (void)open:(NSString *)path { + [[AtomController alloc] initWithPath:path atomContext:[self atomContext]]; +} + +- (IBAction)runSpecs:(id)sender { + [[AtomController alloc] initSpecsWithAtomContext:[self atomContext]]; +} + +- (IBAction)runBenchmarks:(id)sender { + [[AtomController alloc] initBenchmarksWithAtomContext:[self atomContext]]; +} + +- (void)modifyJavaScript:(void(^)(CefRefPtr, CefRefPtr))callback { + CefRefPtr context = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context(); + CefRefPtr global = context->GetGlobal(); + + context->Enter(); + + callback(context, global); + + context->Exit(); +} + +- (CefRefPtr)atomContext { + return _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context(); +} + +#pragma mark BrowserDelegate + +- (void)loadStart { + [self modifyJavaScript:^(CefRefPtr context, CefRefPtr global) { + CefRefPtr bootstrapScript = CefV8Value::CreateString("atom-bootstrap"); + global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE); + + CefRefPtr atom = CefV8Value::CreateObject(NULL); + global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE); + + +#ifdef LOAD_RESOURCES_FROM_DIR + char path[] = LOAD_RESOURCES_FROM_DIR; +#else + const char *path = [[[NSBundle mainBundle] resourcePath] UTF8String]; +#endif + + CefRefPtr loadPath = CefV8Value::CreateString(path); + atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE); + }]; +} + +- (void)loadEnd { + if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--headless"]) { + [self modifyJavaScript:^(CefRefPtr context, CefRefPtr global) { + CefRefPtr atom = context->GetGlobal()->GetValue("atom"); + atom->SetValue("headless", CefV8Value::CreateBool(YES), V8_PROPERTY_ATTRIBUTE_NONE); + }]; + } + + if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--benchmark"]) { + [self runBenchmarks:self]; + } + + if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--test"]) { + [self runSpecs:self]; + } +} + + # pragma mark NSApplicationDelegate -// Sent by the default notification center immediately before the application terminates. -- (void)applicationWillTerminate:(NSNotification *)notification { +- (void)applicationWillFinishLaunching:(NSNotification *)notification { +// new NativeHandler(); +// new OnigRegexpExtension(); + + [self createAtomContext]; +} + +- (void)applicationWillTerminate:(NSNotification *)notification { CefShutdown(); - [self release]; } # pragma mark CefAppProtocol @@ -54,7 +139,15 @@ - (void)sendEvent:(NSEvent*)event { CefScopedSendingEvent sendingEventScoper; - [super sendEvent:event]; + if ([[self mainMenu] performKeyEquivalent:event]) return; + + if (_clientHandler && ![self keyWindow] && [event type] == NSKeyDown) { + [_hiddenWindow makeKeyAndOrderFront:self]; + [_hiddenWindow sendEvent:event]; + } + else { + [super sendEvent:event]; + } } @end \ No newline at end of file diff --git a/atom/client_handler.cpp b/atom/client_handler.cpp index 8a0ead3e9..b7a8e32c0 100644 --- a/atom/client_handler.cpp +++ b/atom/client_handler.cpp @@ -9,8 +9,8 @@ #include "include/cef_runnable.h" #include "atom/client_handler.h" -ClientHandler::ClientHandler() - : m_MainHwnd(NULL) { +ClientHandler::ClientHandler(){ + } ClientHandler::~ClientHandler() { @@ -24,11 +24,6 @@ void ClientHandler::OnBeforeContextMenu( model->AddItem(MENU_ID_USER_FIRST, "&Show DevTools"); CefString devtools_url = browser->GetHost()->GetDevToolsURL(true); - - // Disable the menu option if DevTools isn't enabled or if a window already open for the current URL. - if (devtools_url.empty() || m_OpenDevToolsURLs.find(devtools_url) != m_OpenDevToolsURLs.end()) { - model->SetEnabled(MENU_ID_USER_FIRST, false); - } } bool ClientHandler::OnContextMenuCommand( @@ -39,7 +34,7 @@ bool ClientHandler::OnContextMenuCommand( EventFlags event_flags) { if (command_id == MENU_ID_USER_FIRST) { - printf("show dev tools stub\n"); + ShowDevTools(browser); return true; } else { @@ -60,13 +55,6 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr browser, void ClientHandler::OnBeforeClose(CefRefPtr browser) { REQUIRE_UI_THREAD(); - - if (browser->IsPopup()) { - // Remove the record for DevTools popup windows. - std::set::iterator it = m_OpenDevToolsURLs.find(browser->GetMainFrame()->GetURL()); - if (it != m_OpenDevToolsURLs.end()) - m_OpenDevToolsURLs.erase(it); - } } void ClientHandler::OnAfterCreated(CefRefPtr browser) { @@ -101,12 +89,8 @@ void ClientHandler::OnLoadError(CefRefPtr browser, } void ClientHandler::ShowDevTools(CefRefPtr browser) { - std::string devtools_url = browser->GetHost()->GetDevToolsURL(true); + std::string devtools_url = "chrome-devtools://devtools/devtools.html?docked=true";//browser->GetHost()->GetDevToolsURL(true); if (!devtools_url.empty()) { - if (m_OpenDevToolsURLs.find(devtools_url) == m_OpenDevToolsURLs.end()) { - // Open DevTools in a popup window. - m_OpenDevToolsURLs.insert(devtools_url); - browser->GetMainFrame()->ExecuteJavaScript("window.open('" + devtools_url + "');", "about:blank", 0); - } + browser->GetMainFrame()->ExecuteJavaScript("window.open('" + devtools_url + "');", "about:blank", 0); } } diff --git a/atom/client_handler.h b/atom/client_handler.h index 09747348f..19a2f5833 100644 --- a/atom/client_handler.h +++ b/atom/client_handler.h @@ -27,6 +27,25 @@ class ClientHandler : public CefClient, CefRefPtr GetBrowser() { return m_Browser; } + virtual CefRefPtr GetContextMenuHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetDisplayHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetKeyboardHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetLoadHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetRequestHandler() OVERRIDE { + return this; + } + // CefContextMenuHandler methods virtual void OnBeforeContextMenu(CefRefPtr browser, CefRefPtr frame, @@ -59,21 +78,11 @@ class ClientHandler : public CefClient, const CefString& failedUrl) OVERRIDE; protected: - // The child browser window CefRefPtr m_Browser; - // The main frame window handle - CefWindowHandle m_MainHwnd; - - // List of open DevTools URLs if not using an external browser window. - std::set m_OpenDevToolsURLs; - void ShowDevTools(CefRefPtr browser); - // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(ClientHandler); - - // Include the default locking implementation. IMPLEMENT_LOCKING(ClientHandler); }; diff --git a/atom/main_mac.mm b/atom/main_mac.mm index 878e7afbc..4b45b173c 100644 --- a/atom/main_mac.mm +++ b/atom/main_mac.mm @@ -18,7 +18,7 @@ int main(int argc, char* argv[]) { NSNib *mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:[NSBundle mainBundle]]; [mainNib instantiateNibWithOwner:application topLevelObjects:nil]; // Execute the secondary process, if any. - [application createWindow]; + [application open:""]; // Run the application message loop. CefRunMessageLoop(); diff --git a/static/index.html b/static/index.html index ddfe986c6..a67e5d3c1 100644 --- a/static/index.html +++ b/static/index.html @@ -5,17 +5,18 @@ - MOTHER FUCKER! + MOTHER FUCKER! +