diff --git a/cef.gyp b/cef.gyp index 8d805ac4f..5ca6b1558 100644 --- a/cef.gyp +++ b/cef.gyp @@ -785,6 +785,8 @@ 'libcef/browser/navigate_params.h', 'libcef/browser/origin_whitelist_impl.cc', 'libcef/browser/origin_whitelist_impl.h', + 'libcef/browser/path_util_impl.cc', + 'libcef/browser/process_util_impl.cc', 'libcef/browser/resource_context.cc', 'libcef/browser/resource_context.h', 'libcef/browser/resource_dispatcher_host_delegate.cc', diff --git a/cef_paths.gypi b/cef_paths.gypi index f3b724d92..fadb0b106 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -31,7 +31,9 @@ 'include/cef_load_handler.h', 'include/cef_menu_model.h', 'include/cef_origin_whitelist.h', + 'include/cef_path_util.h', 'include/cef_process_message.h', + 'include/cef_process_util.h', 'include/cef_proxy_handler.h', 'include/cef_render_process_handler.h', 'include/cef_request.h', @@ -71,7 +73,9 @@ 'include/capi/cef_load_handler_capi.h', 'include/capi/cef_menu_model_capi.h', 'include/capi/cef_origin_whitelist_capi.h', + 'include/capi/cef_path_util_capi.h', 'include/capi/cef_process_message_capi.h', + 'include/capi/cef_process_util_capi.h', 'include/capi/cef_proxy_handler_capi.h', 'include/capi/cef_render_process_handler_capi.h', 'include/capi/cef_request_capi.h', diff --git a/include/capi/cef_path_util_capi.h b/include/capi/cef_path_util_capi.h new file mode 100644 index 000000000..3df1a100a --- /dev/null +++ b/include/capi/cef_path_util_capi.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_PATH_UTIL_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_PATH_UTIL_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Retrieve the path associated with the specified |key|. Returns true (1) on +// success. Can be called on any thread in the browser process. +/// +CEF_EXPORT int cef_get_path(enum cef_path_key_t key, cef_string_t* path); + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_PATH_UTIL_CAPI_H_ diff --git a/include/capi/cef_process_util_capi.h b/include/capi/cef_process_util_capi.h new file mode 100644 index 000000000..53ccbb2c1 --- /dev/null +++ b/include/capi/cef_process_util_capi.h @@ -0,0 +1,64 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_PROCESS_UTIL_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_PROCESS_UTIL_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Launches the process specified via |command_line|. Returns true (1) upon +// success. Must be called on the browser process TID_PROCESS_LAUNCHER thread. +// +// Unix-specific notes: - All file descriptors open in the parent process will +// be closed in the +// child process except for stdin, stdout, and stderr. +// - If the first argument on the command line does not contain a slash, +// PATH will be searched. (See man execvp.) +/// +CEF_EXPORT int cef_launch_process(struct _cef_command_line_t* command_line); + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_PROCESS_UTIL_CAPI_H_ diff --git a/include/cef_path_util.h b/include/cef_path_util.h new file mode 100644 index 000000000..552f4ba59 --- /dev/null +++ b/include/cef_path_util.h @@ -0,0 +1,52 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_PATH_UTIL_H_ +#define CEF_INCLUDE_CEF_PATH_UTIL_H_ +#pragma once + +#include "include/cef_base.h" + +typedef cef_path_key_t PathKey; + +/// +// Retrieve the path associated with the specified |key|. Returns true on +// success. Can be called on any thread in the browser process. +/// +/*--cef()--*/ +bool CefGetPath(PathKey key, CefString& path); + +#endif // CEF_INCLUDE_CEF_PATH_UTIL_H_ diff --git a/include/cef_process_util.h b/include/cef_process_util.h new file mode 100644 index 000000000..4fce778e7 --- /dev/null +++ b/include/cef_process_util.h @@ -0,0 +1,57 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_PROCESS_UTIL_H_ +#define CEF_INCLUDE_CEF_PROCESS_UTIL_H_ +#pragma once + +#include "include/cef_base.h" +#include "include/cef_command_line.h" + +/// +// Launches the process specified via |command_line|. Returns true upon +// success. Must be called on the browser process TID_PROCESS_LAUNCHER thread. +// +// Unix-specific notes: +// - All file descriptors open in the parent process will be closed in the +// child process except for stdin, stdout, and stderr. +// - If the first argument on the command line does not contain a slash, +// PATH will be searched. (See man execvp.) +/// +/*--cef()--*/ +bool CefLaunchProcess(CefRefPtr command_line); + +#endif // CEF_INCLUDE_CEF_PROCESS_UTIL_H_ diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 71bf20584..0d6cea0ff 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -600,6 +600,42 @@ enum cef_termination_status_t { TS_PROCESS_CRASHED, }; +/// +// Path key values. +/// +enum cef_path_key_t { + /// + // Current directory. + /// + PK_DIR_CURRENT, + + /// + // Directory containing PK_FILE_EXE. + /// + PK_DIR_EXE, + + /// + // Directory containing PK_FILE_MODULE. + /// + PK_DIR_MODULE, + + /// + // Temporary directory. + /// + PK_DIR_TEMP, + + /// + // Path and filename of the current executable. + /// + PK_FILE_EXE, + + /// + // Path and filename of the module containing the CEF code (usually the libcef + // module). + /// + PK_FILE_MODULE, +}; + /// // Storage types. /// diff --git a/libcef/browser/path_util_impl.cc b/libcef/browser/path_util_impl.cc new file mode 100644 index 000000000..f0832ee8d --- /dev/null +++ b/libcef/browser/path_util_impl.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2012 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/cef_path_util.h" + +#include "base/file_path.h" +#include "base/logging.h" +#include "base/path_service.h" + +bool CefGetPath(PathKey key, CefString& path) { + int pref_key = base::PATH_START; + switch(key) { + case PK_DIR_CURRENT: + pref_key = base::DIR_CURRENT; + break; + case PK_DIR_EXE: + pref_key = base::DIR_EXE; + break; + case PK_DIR_MODULE: + pref_key = base::DIR_MODULE; + break; + case PK_DIR_TEMP: + pref_key = base::DIR_TEMP; + break; + case PK_FILE_EXE: + pref_key = base::FILE_EXE; + break; + case PK_FILE_MODULE: + pref_key = base::FILE_MODULE; + break; + default: + NOTREACHED() << "invalid argument"; + return false; + } + + FilePath file_path; + if (PathService::Get(pref_key, &file_path)) { + path = file_path.value(); + return true; + } + + return false; +} diff --git a/libcef/browser/process_util_impl.cc b/libcef/browser/process_util_impl.cc new file mode 100644 index 000000000..3ddb407c0 --- /dev/null +++ b/libcef/browser/process_util_impl.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2012 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/cef_process_util.h" +#include "libcef/common/command_line_impl.h" + +#include "base/logging.h" +#include "base/process_util.h" +#include "content/public/browser/browser_thread.h" + +bool CefLaunchProcess(CefRefPtr command_line) { + if (!command_line.get()) { + NOTREACHED() << "invalid parameter"; + return false; + } + + if (!content::BrowserThread::CurrentlyOn( + content::BrowserThread::PROCESS_LAUNCHER)) { + NOTREACHED() << "called on invalid thread"; + return false; + } + + CefCommandLineImpl* impl = + static_cast(command_line.get()); + + CefValueController::AutoLock lock_scope(impl->controller()); + + base::LaunchOptions options; + return base::LaunchProcess(impl->command_line(), options, NULL); +} diff --git a/libcef/common/command_line_impl.h b/libcef/common/command_line_impl.h index cb6fff5e1..be9cf73cf 100644 --- a/libcef/common/command_line_impl.h +++ b/libcef/common/command_line_impl.h @@ -39,6 +39,9 @@ class CefCommandLineImpl : public CefValueBase { virtual void GetArguments(ArgumentList& arguments) OVERRIDE; virtual void AppendArgument(const CefString& argument) OVERRIDE; + // Must hold the controller lock while using this value. + const CommandLine& command_line() { return const_value(); } + DISALLOW_COPY_AND_ASSIGN(CefCommandLineImpl); }; diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index d8d7da271..c7e1af4ec 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -14,6 +14,10 @@ #include "include/capi/cef_app_capi.h" #include "include/cef_origin_whitelist.h" #include "include/capi/cef_origin_whitelist_capi.h" +#include "include/cef_path_util.h" +#include "include/capi/cef_path_util_capi.h" +#include "include/cef_process_util.h" +#include "include/capi/cef_process_util_capi.h" #include "include/cef_scheme.h" #include "include/capi/cef_scheme_capi.h" #include "include/cef_task.h" @@ -29,6 +33,7 @@ #include "libcef_dll/cpptoc/browser_cpptoc.h" #include "libcef_dll/cpptoc/browser_host_cpptoc.h" #include "libcef_dll/cpptoc/callback_cpptoc.h" +#include "libcef_dll/cpptoc/command_line_cpptoc.h" #include "libcef_dll/cpptoc/context_menu_params_cpptoc.h" #include "libcef_dll/cpptoc/cookie_manager_cpptoc.h" #include "libcef_dll/cpptoc/domdocument_cpptoc.h" @@ -286,6 +291,42 @@ CEF_EXPORT int cef_clear_cross_origin_whitelist() { return _retval; } +CEF_EXPORT int cef_get_path(enum cef_path_key_t key, cef_string_t* path) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: path; type: string_byref + DCHECK(path); + if (!path) + return 0; + + // Translate param: path; type: string_byref + CefString pathStr(path); + + // Execute + bool _retval = CefGetPath( + key, + pathStr); + + // Return type: bool + return _retval; +} + +CEF_EXPORT int cef_launch_process(struct _cef_command_line_t* command_line) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: command_line; type: refptr_same + DCHECK(command_line); + if (!command_line) + return 0; + + // Execute + bool _retval = CefLaunchProcess( + CefCommandLineCppToC::Unwrap(command_line)); + + // Return type: bool + return _retval; +} + CEF_EXPORT int cef_register_scheme_handler_factory( const cef_string_t* scheme_name, const cef_string_t* domain_name, struct _cef_scheme_handler_factory_t* factory) { diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index d9ab4013a..ef5a0aebc 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -14,6 +14,10 @@ #include "include/capi/cef_app_capi.h" #include "include/cef_origin_whitelist.h" #include "include/capi/cef_origin_whitelist_capi.h" +#include "include/cef_path_util.h" +#include "include/capi/cef_path_util_capi.h" +#include "include/cef_process_util.h" +#include "include/capi/cef_process_util_capi.h" #include "include/cef_scheme.h" #include "include/capi/cef_scheme_capi.h" #include "include/cef_task.h" @@ -57,6 +61,7 @@ #include "libcef_dll/ctocpp/browser_ctocpp.h" #include "libcef_dll/ctocpp/browser_host_ctocpp.h" #include "libcef_dll/ctocpp/callback_ctocpp.h" +#include "libcef_dll/ctocpp/command_line_ctocpp.h" #include "libcef_dll/ctocpp/context_menu_params_ctocpp.h" #include "libcef_dll/ctocpp/cookie_manager_ctocpp.h" #include "libcef_dll/ctocpp/domdocument_ctocpp.h" @@ -278,6 +283,34 @@ CEF_GLOBAL bool CefClearCrossOriginWhitelist() { return _retval?true:false; } +CEF_GLOBAL bool CefGetPath(PathKey key, CefString& path) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = cef_get_path( + key, + path.GetWritableStruct()); + + // Return type: bool + return _retval?true:false; +} + +CEF_GLOBAL bool CefLaunchProcess(CefRefPtr command_line) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: command_line; type: refptr_same + DCHECK(command_line.get()); + if (!command_line.get()) + return false; + + // Execute + int _retval = cef_launch_process( + CefCommandLineCToCpp::Unwrap(command_line)); + + // Return type: bool + return _retval?true:false; +} + CEF_GLOBAL bool CefRegisterSchemeHandlerFactory(const CefString& scheme_name, const CefString& domain_name, CefRefPtr factory) { diff --git a/tests/cefclient/cefclient_gtk.cpp b/tests/cefclient/cefclient_gtk.cpp index 05c1e7d87..118862711 100644 --- a/tests/cefclient/cefclient_gtk.cpp +++ b/tests/cefclient/cefclient_gtk.cpp @@ -384,9 +384,8 @@ int main(int argc, char* argv[]) { window_info.SetAsChild(vbox); CefBrowserHost::CreateBrowserSync( - window_info, - static_cast >(g_handler), - "http://www.google.com", browserSettings); + window_info, g_handler.get(), + g_handler->GetStartupURL(), browserSettings); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show_all(GTK_WIDGET(window)); diff --git a/tests/cefclient/cefclient_mac.mm b/tests/cefclient/cefclient_mac.mm index c474d9a29..b4c17da3d 100644 --- a/tests/cefclient/cefclient_mac.mm +++ b/tests/cefclient/cefclient_mac.mm @@ -360,7 +360,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight); CefBrowserHost::CreateBrowser(window_info, g_handler.get(), - "http://www.google.com", settings); + g_handler->GetStartupURL(), settings); // Show the window. [mainWnd makeKeyAndOrderFront: nil]; diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index 9e2a4427c..a380d9ce2 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -300,9 +300,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, info.SetAsChild(hWnd, rect); // Creat the new child browser window - CefBrowserHost::CreateBrowser(info, - static_cast >(g_handler), - "http://www.google.com", settings); + CefBrowserHost::CreateBrowser(info, g_handler.get(), + g_handler->GetStartupURL(), settings); return 0; } diff --git a/tests/cefclient/client_handler.cpp b/tests/cefclient/client_handler.cpp index 3d4020bd8..d09669150 100644 --- a/tests/cefclient/client_handler.cpp +++ b/tests/cefclient/client_handler.cpp @@ -9,10 +9,14 @@ #include #include "include/cef_browser.h" #include "include/cef_frame.h" +#include "include/cef_path_util.h" +#include "include/cef_process_util.h" +#include "include/cef_runnable.h" #include "include/wrapper/cef_stream_resource_handler.h" #include "cefclient/binding_test.h" #include "cefclient/cefclient.h" #include "cefclient/client_renderer.h" +#include "cefclient/client_switches.h" #include "cefclient/dom_test.h" #include "cefclient/resource_util.h" #include "cefclient/string_util.h" @@ -39,6 +43,17 @@ ClientHandler::ClientHandler() m_bFocusOnEditableField(false) { CreateProcessMessageDelegates(process_message_delegates_); CreateRequestDelegates(request_delegates_); + + // Read command line settings. + CefRefPtr command_line = + CefCommandLine::GetGlobalCommandLine(); + + if (command_line->HasSwitch(cefclient::kUrl)) + m_StartupURL = command_line->GetSwitchValue(cefclient::kUrl); + if (m_StartupURL.empty()) + m_StartupURL = "http://www.google.com/"; + + m_bExternalDevTools = command_line->HasSwitch(cefclient::kExternalDevTools); } ClientHandler::~ClientHandler() { @@ -293,14 +308,14 @@ void ClientHandler::OnLoadError(CefRefPtr browser, void ClientHandler::OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) { - // Load google.com if that's not the website that we terminated on. + // Load the startup URL if that's not the website that we terminated on. CefRefPtr frame = browser->GetMainFrame(); std::string url = frame->GetURL(); std::transform(url.begin(), url.end(), url.begin(), tolower); - const char kLoadURL[] = "http://www.google.com"; - if (url.find(kLoadURL) != 0) - frame->LoadURL(kLoadURL); + std::string startupURL = GetStartupURL(); + if (url.find(startupURL) != 0) + frame->LoadURL(startupURL); } CefRefPtr ClientHandler::GetResourceHandler( @@ -402,11 +417,40 @@ std::string ClientHandler::GetLastDownloadFile() { void ClientHandler::ShowDevTools(CefRefPtr browser) { std::string devtools_url = browser->GetHost()->GetDevToolsURL(true); - if (!devtools_url.empty() && - m_OpenDevToolsURLs.find(devtools_url) == m_OpenDevToolsURLs.end()) { - m_OpenDevToolsURLs.insert(devtools_url); - browser->GetMainFrame()->ExecuteJavaScript( - "window.open('" + devtools_url + "');", "about:blank", 0); + if (!devtools_url.empty()) { + if (m_bExternalDevTools) { + // Open DevTools in an external browser window. + LaunchExternalBrowser(devtools_url); + } else 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); + } + } +} + +// static +void ClientHandler::LaunchExternalBrowser(const std::string& url) { + if (CefCurrentlyOn(TID_PROCESS_LAUNCHER)) { + // Retrieve the current executable path. + CefString file_exe; + if (!CefGetPath(PK_FILE_EXE, file_exe)) + return; + + // Create the command line. + CefRefPtr command_line = + CefCommandLine::CreateCommandLine(); + command_line->SetProgram(file_exe); + command_line->AppendSwitchWithValue(cefclient::kUrl, url); + + // Launch the process. + CefLaunchProcess(command_line); + } else { + // Execute on the PROCESS_LAUNCHER thread. + CefPostTask(TID_PROCESS_LAUNCHER, + NewCefRunnableFunction(&ClientHandler::LaunchExternalBrowser, url)); } } diff --git a/tests/cefclient/client_handler.h b/tests/cefclient/client_handler.h index dd0936783..edd1c710a 100644 --- a/tests/cefclient/client_handler.h +++ b/tests/cefclient/client_handler.h @@ -189,6 +189,12 @@ class ClientHandler : public CefClient, void ShowDevTools(CefRefPtr browser); + // Returns the startup URL. + std::string GetStartupURL() { return m_StartupURL; } + + // Create an external browser window that loads the specified URL. + static void LaunchExternalBrowser(const std::string& url); + protected: void SetLoading(bool isLoading); void SetNavState(bool canGoBack, bool canGoForward); @@ -240,8 +246,15 @@ class ClientHandler : public CefClient, ProcessMessageDelegateSet process_message_delegates_; RequestDelegateSet request_delegates_; + // If true DevTools will be opened in an external browser window. + bool m_bExternalDevTools; + + // List of open DevTools URLs if not using an external browser window. std::set m_OpenDevToolsURLs; + // The startup URL. + std::string m_StartupURL; + // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(ClientHandler); // Include the default locking implementation. diff --git a/tests/cefclient/client_switches.cpp b/tests/cefclient/client_switches.cpp index 28eb637d5..a65f179f2 100644 --- a/tests/cefclient/client_switches.cpp +++ b/tests/cefclient/client_switches.cpp @@ -8,6 +8,9 @@ namespace cefclient { +const char kUrl[] = "url"; +const char kExternalDevTools[] = "external-devtools"; + // CefSettings attributes. const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop"; const char kCachePath[] = "cache-path"; diff --git a/tests/cefclient/client_switches.h b/tests/cefclient/client_switches.h index 12381c126..8a9751721 100644 --- a/tests/cefclient/client_switches.h +++ b/tests/cefclient/client_switches.h @@ -10,6 +10,9 @@ namespace cefclient { +extern const char kUrl[]; +extern const char kExternalDevTools[]; + // CefSettings attributes. extern const char kMultiThreadedMessageLoop[]; extern const char kCachePath[];