diff --git a/atom.gyp b/atom.gyp index 9635be40e..9181ec9dc 100644 --- a/atom.gyp +++ b/atom.gyp @@ -66,7 +66,6 @@ 'native/atom_cef_client.h', 'native/message_translation.cpp', 'native/message_translation.h', - 'native/util.h', ], 'mac_bundle_resources': [ 'native/mac/atom.icns', @@ -284,7 +283,6 @@ 'native/path_watcher.mm', 'native/path_watcher.h', 'native/main_helper_mac.mm', - 'native/util.h', 'native/v8_extensions/native.mm', 'native/v8_extensions/native.h', 'native/v8_extensions/onig_reg_exp.mm', diff --git a/native/atom_cef_app.h b/native/atom_cef_app.h index 8b0262fc1..faa5e9a15 100644 --- a/native/atom_cef_app.h +++ b/native/atom_cef_app.h @@ -1,5 +1,5 @@ -#ifndef CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ -#define CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ +#ifndef ATOM_CEF_APP_H_ +#define ATOM_CEF_APP_H_ #pragma once #include "include/cef_app.h" @@ -10,16 +10,13 @@ class AtomCefApp : public CefApp { - // CefApp methods - virtual CefRefPtr GetRenderProcessHandler() OVERRIDE { #ifdef PROCESS_HELPER_APP + virtual CefRefPtr GetRenderProcessHandler() OVERRIDE { return CefRefPtr(new AtomCefRenderProcessHandler); -#else - return NULL; -#endif } +#endif IMPLEMENT_REFCOUNTING(AtomCefApp); }; -#endif // CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ +#endif diff --git a/native/atom_cef_client.cpp b/native/atom_cef_client.cpp index ddec0219f..650616423 100644 --- a/native/atom_cef_client.cpp +++ b/native/atom_cef_client.cpp @@ -1,23 +1,23 @@ -// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - #include #include +#include #include "include/cef_path_util.h" #include "include/cef_process_util.h" +#include "include/cef_task.h" #include "include/cef_runnable.h" #include "native/atom_cef_client.h" #include "cef_v8.h" -AtomCefClient::AtomCefClient(){ +#define REQUIRE_UI_THREAD() assert(CefCurrentlyOn(TID_UI)); +#define REQUIRE_IO_THREAD() assert(CefCurrentlyOn(TID_IO)); +#define REQUIRE_FILE_THREAD() assert(CefCurrentlyOn(TID_FILE)); +AtomCefClient::AtomCefClient(){ } AtomCefClient::~AtomCefClient() { } - bool AtomCefClient::OnProcessMessageReceived(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { @@ -28,20 +28,14 @@ bool AtomCefClient::OnProcessMessageReceived(CefRefPtr browser, if (name == "open") { bool hasArguments = argumentList->GetSize() > 1; hasArguments ? Open(argumentList->GetString(1)) : Open(); - return true; } - - if (name == "newWindow") { + else if (name == "newWindow") { NewWindow(); - return true; } - - if (name == "toggleDevTools") { + else if (name == "toggleDevTools") { ToggleDevTools(browser); - return true; } - - if (name == "confirm") { + else if (name == "confirm") { std::string message = argumentList->GetString(1).ToString(); std::string detailedMessage = argumentList->GetString(2).ToString(); std::vector buttonLabels(argumentList->GetSize() - 3); @@ -50,18 +44,18 @@ bool AtomCefClient::OnProcessMessageReceived(CefRefPtr browser, } Confirm(messageId, message, detailedMessage, buttonLabels, browser); - return true; } - - if (name == "showSaveDialog") { + else if (name == "showSaveDialog") { ShowSaveDialog(messageId, browser); return true; } + else { + return false; + } - return false; + return true; } - void AtomCefClient::OnBeforeContextMenu( CefRefPtr browser, CefRefPtr frame, @@ -118,7 +112,7 @@ void AtomCefClient::OnBeforeClose(CefRefPtr browser) { REQUIRE_UI_THREAD(); - // this was in cefclient... was there a good reason? +// TODO: Ask Marshal. This was in cefclient... was there a good reason? // if(m_BrowserHwnd == browser->GetWindowHandle()) { // // Free the browser pointer so that the browser can be destroyed // m_Browser = NULL; @@ -144,18 +138,5 @@ void AtomCefClient::OnLoadError(CefRefPtr browser, const CefString& errorText, const CefString& failedUrl) { REQUIRE_UI_THREAD(); - - if (errorCode == ERR_ABORTED) { // Don't display an error for downloaded files. - return; - } - else if (errorCode == ERR_UNKNOWN_URL_SCHEME) { // Don't display an error for external protocols that we allow the OS to handle. See OnProtocolExecution(). - return; - } - else { - std::stringstream ss; - ss << "

Failed to load URL " << std::string(failedUrl) << - " with error " << std::string(errorText) << " (" << errorCode << - ").

"; - frame->LoadString(ss.str(), failedUrl); - } + frame->LoadString(std::string(errorText) + "
" + std::string(failedUrl), failedUrl); } diff --git a/native/atom_cef_client.h b/native/atom_cef_client.h index ce31ffad0..0d3e821b3 100644 --- a/native/atom_cef_client.h +++ b/native/atom_cef_client.h @@ -1,18 +1,11 @@ -// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ -#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ +#ifndef ATOM_CEF_CLIENT_H_ +#define ATOM_CEF_CLIENT_H_ #pragma once #include #include #include "include/cef_client.h" -#include "native/util.h" - -// AtomCefClient implementation. class AtomCefClient : public CefClient, public CefContextMenuHandler, public CefDisplayHandler, @@ -119,4 +112,4 @@ class AtomCefClient : public CefClient, IMPLEMENT_LOCKING(AtomCefClient); }; -#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ +#endif diff --git a/native/atom_window_controller.mm b/native/atom_window_controller.mm index 495c1fcad..c068b3848 100644 --- a/native/atom_window_controller.mm +++ b/native/atom_window_controller.mm @@ -20,7 +20,6 @@ - (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)background { self = [super initWithWindowNibName:@"AtomWindow"]; - _bootstrapScript = [bootstrapScript retain]; if (!background) { @@ -73,22 +72,32 @@ - (void)toggleDevTools { if (_devToolsView) { - [_devToolsView removeFromSuperview]; - [_devToolsView release]; - _devToolsView = nil; - _cefDevToolsClient = NULL; - _cefClient->GetBrowser()->GetHost()->SetFocus(true); - [_splitView adjustSubviews]; + [self hideDevTools]; } - else if (_cefClient && _cefClient->GetBrowser()) { - NSRect frame = NSMakeRect(0, 0, _splitView.frame.size.width, _splitView.frame.size.height); - _devToolsView = [[NSView alloc] initWithFrame:frame]; + else { + [self showDevTools]; + } +} + +- (void)showDevTools { + if (_cefClient && _cefClient->GetBrowser()) { + _devToolsView = [[NSView alloc] initWithFrame:_splitView.bounds]; [_splitView addSubview:_devToolsView]; [_splitView adjustSubviews]; - std::string devtools_url = _cefClient->GetBrowser()->GetHost()->GetDevToolsURL(true); + _cefDevToolsClient = new AtomCefClient(); + std::string devtools_url = _cefClient->GetBrowser()->GetHost()->GetDevToolsURL(true); [self addBrowserToView:_devToolsView url:devtools_url.c_str() cefHandler:_cefDevToolsClient]; - } + } +} + +- (void)hideDevTools { + [_devToolsView removeFromSuperview]; + [_splitView adjustSubviews]; + [_devToolsView release]; + _devToolsView = nil; + _cefDevToolsClient = NULL; + _cefClient->GetBrowser()->GetHost()->SetFocus(true); } # pragma mark NSWindowDelegate diff --git a/native/message_translation.cpp b/native/message_translation.cpp index a910cfbca..0913279b9 100644 --- a/native/message_translation.cpp +++ b/native/message_translation.cpp @@ -1,5 +1,5 @@ +#include #include "message_translation.h" -#include "util.h" // Transfer a V8 value to a List index. void TranslateListValue(CefRefPtr list, int index, CefRefPtr value) { @@ -20,7 +20,7 @@ void TranslateListValue(CefRefPtr list, int index, CefRefPtr source, CefRefPtr target) { - ASSERT(source->IsArray()); + assert(source->IsArray()); int arg_length = source->GetArrayLength(); if (arg_length == 0) @@ -70,7 +70,7 @@ void TranslateListValue(CefRefPtr list, int index, CefRefPtr source, CefRefPtr target) { - ASSERT(target->IsArray()); + assert(target->IsArray()); int arg_length = source->GetSize(); if (arg_length == 0) diff --git a/native/message_translation.h b/native/message_translation.h index 2ab399733..e6caaf332 100644 --- a/native/message_translation.h +++ b/native/message_translation.h @@ -1,5 +1,11 @@ +#ifndef ATOM_CEF_CLIENT_H_ +#define ATOM_CEF_CLIENT_H_ +#pragma once + #include "include/cef_v8.h" // IPC data translation functions: translate a V8 array to a List, and vice versa void TranslateList(CefRefPtr source, CefRefPtr target); void TranslateList(CefRefPtr source, CefRefPtr target); + +#endif \ No newline at end of file diff --git a/native/util.h b/native/util.h index 019cbbfd6..e69de29bb 100644 --- a/native/util.h +++ b/native/util.h @@ -1,19 +0,0 @@ -#ifndef CEF_TESTS_CEFCLIENT_UTIL_H_ -#define CEF_TESTS_CEFCLIENT_UTIL_H_ -#pragma once - -#include "include/cef_task.h" - -#include // NOLINT(build/include_order) - -#ifndef NDEBUG -#define ASSERT(condition) if (!(condition)) { assert(false); } -#else -#define ASSERT(condition) ((void)0) -#endif - -#define REQUIRE_UI_THREAD() ASSERT(CefCurrentlyOn(TID_UI)); -#define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO)); -#define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE)); - -#endif // CEF_TESTS_CEFCLIENT_UTIL_H_ diff --git a/native/v8_extensions/atom.mm b/native/v8_extensions/atom.mm index 541bdae01..de6c7abe1 100644 --- a/native/v8_extensions/atom.mm +++ b/native/v8_extensions/atom.mm @@ -3,7 +3,6 @@ #import "atom.h" #import "atom_application.h" -#import "util.h" #import "message_translation.h" namespace v8_extensions {