From d2e517f5a3895cf764496cfe208a07723a83fc07 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 30 Aug 2012 08:47:21 -0700 Subject: [PATCH 1/3] :lipstick: --- native/atom_cef_app.h | 6 ++---- native/atom_cef_client.cpp | 37 +++++++++----------------------- native/atom_window_controller.mm | 33 +++++++++++++++++----------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/native/atom_cef_app.h b/native/atom_cef_app.h index 8b0262fc1..385236346 100644 --- a/native/atom_cef_app.h +++ b/native/atom_cef_app.h @@ -10,14 +10,12 @@ class AtomCefApp : public CefApp { +#ifdef PROCESS_HELPER_APP // CefApp methods virtual CefRefPtr GetRenderProcessHandler() OVERRIDE { -#ifdef PROCESS_HELPER_APP return CefRefPtr(new AtomCefRenderProcessHandler); -#else - return NULL; -#endif } +#endif IMPLEMENT_REFCOUNTING(AtomCefApp); }; diff --git a/native/atom_cef_client.cpp b/native/atom_cef_client.cpp index c1dc2cbe9..baa79abcf 100644 --- a/native/atom_cef_client.cpp +++ b/native/atom_cef_client.cpp @@ -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,10 +44,12 @@ bool AtomCefClient::OnProcessMessageReceived(CefRefPtr browser, } Confirm(messageId, message, detailedMessage, buttonLabels, browser); - return true; } - - return false; + else { + return false; + } + + return true; } @@ -113,7 +109,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; @@ -139,18 +135,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_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 From b4f617c657cd278eaf9eba45a35daa61ea55c3d6 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 30 Aug 2012 09:07:39 -0700 Subject: [PATCH 2/3] Remove util.h --- atom.gyp | 2 -- native/atom_cef_client.cpp | 8 ++++++-- native/atom_cef_client.h | 3 --- native/message_translation.cpp | 6 +++--- native/util.h | 19 ------------------- native/v8_extensions/atom.mm | 1 - 6 files changed, 9 insertions(+), 30 deletions(-) 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_client.cpp b/native/atom_cef_client.cpp index baa79abcf..cb3d8eb07 100644 --- a/native/atom_cef_client.cpp +++ b/native/atom_cef_client.cpp @@ -4,20 +4,24 @@ #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) { diff --git a/native/atom_cef_client.h b/native/atom_cef_client.h index 695fdce7d..236d216c9 100644 --- a/native/atom_cef_client.h +++ b/native/atom_cef_client.h @@ -9,10 +9,7 @@ #include #include #include "include/cef_client.h" -#include "native/util.h" - -// AtomCefClient implementation. class AtomCefClient : public CefClient, public CefContextMenuHandler, public CefDisplayHandler, 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/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 { From 9c7c95f413af1fcd3c40d27b581e86ed2b95bda5 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 30 Aug 2012 09:11:01 -0700 Subject: [PATCH 3/3] Update C++ headers --- native/atom_cef_app.h | 7 +++---- native/atom_cef_client.cpp | 4 ---- native/atom_cef_client.h | 10 +++------- native/message_translation.h | 6 ++++++ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/native/atom_cef_app.h b/native/atom_cef_app.h index 385236346..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" @@ -11,7 +11,6 @@ class AtomCefApp : public CefApp { #ifdef PROCESS_HELPER_APP - // CefApp methods virtual CefRefPtr GetRenderProcessHandler() OVERRIDE { return CefRefPtr(new AtomCefRenderProcessHandler); } @@ -20,4 +19,4 @@ class AtomCefApp : public CefApp { 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 cb3d8eb07..784e47263 100644 --- a/native/atom_cef_client.cpp +++ b/native/atom_cef_client.cpp @@ -1,7 +1,3 @@ -// 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 diff --git a/native/atom_cef_client.h b/native/atom_cef_client.h index 236d216c9..237256a76 100644 --- a/native/atom_cef_client.h +++ b/native/atom_cef_client.h @@ -1,9 +1,5 @@ -// 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 @@ -114,4 +110,4 @@ class AtomCefClient : public CefClient, IMPLEMENT_LOCKING(AtomCefClient); }; -#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ +#endif 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