mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-16 20:20:51 +01:00
- Add example to cefclient of launching DevTools in an external browser window and process using new CefGetPath and CefLaunchProcess functions (issue #639).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@713 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
1dc36b0297
commit
9f708dfcd2
2
cef.gyp
2
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',
|
||||
|
@ -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',
|
||||
|
58
include/capi/cef_path_util_capi.h
Normal file
58
include/capi/cef_path_util_capi.h
Normal file
@ -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_
|
64
include/capi/cef_process_util_capi.h
Normal file
64
include/capi/cef_process_util_capi.h
Normal file
@ -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_
|
52
include/cef_path_util.h
Normal file
52
include/cef_path_util.h
Normal file
@ -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_
|
57
include/cef_process_util.h
Normal file
57
include/cef_process_util.h
Normal file
@ -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<CefCommandLine> command_line);
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_PROCESS_UTIL_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.
|
||||
///
|
||||
|
44
libcef/browser/path_util_impl.cc
Normal file
44
libcef/browser/path_util_impl.cc
Normal file
@ -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;
|
||||
}
|
31
libcef/browser/process_util_impl.cc
Normal file
31
libcef/browser/process_util_impl.cc
Normal file
@ -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<CefCommandLine> 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<CefCommandLineImpl*>(command_line.get());
|
||||
|
||||
CefValueController::AutoLock lock_scope(impl->controller());
|
||||
|
||||
base::LaunchOptions options;
|
||||
return base::LaunchProcess(impl->command_line(), options, NULL);
|
||||
}
|
@ -39,6 +39,9 @@ class CefCommandLineImpl : public CefValueBase<CefCommandLine, CommandLine> {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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<CefCommandLine> 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<CefSchemeHandlerFactory> factory) {
|
||||
|
@ -384,9 +384,8 @@ int main(int argc, char* argv[]) {
|
||||
window_info.SetAsChild(vbox);
|
||||
|
||||
CefBrowserHost::CreateBrowserSync(
|
||||
window_info,
|
||||
static_cast<CefRefPtr<CefClient> >(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));
|
||||
|
@ -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];
|
||||
|
@ -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<CefRefPtr<CefClient> >(g_handler),
|
||||
"http://www.google.com", settings);
|
||||
CefBrowserHost::CreateBrowser(info, g_handler.get(),
|
||||
g_handler->GetStartupURL(), settings);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,10 +9,14 @@
|
||||
#include <string>
|
||||
#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<CefCommandLine> 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<CefBrowser> browser,
|
||||
|
||||
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> 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<CefFrame> 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<CefResourceHandler> ClientHandler::GetResourceHandler(
|
||||
@ -402,11 +417,40 @@ std::string ClientHandler::GetLastDownloadFile() {
|
||||
|
||||
void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> 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<CefCommandLine> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,6 +189,12 @@ class ClientHandler : public CefClient,
|
||||
|
||||
void ShowDevTools(CefRefPtr<CefBrowser> 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<std::string> m_OpenDevToolsURLs;
|
||||
|
||||
// The startup URL.
|
||||
std::string m_StartupURL;
|
||||
|
||||
// Include the default reference counting implementation.
|
||||
IMPLEMENT_REFCOUNTING(ClientHandler);
|
||||
// Include the default locking implementation.
|
||||
|
@ -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";
|
||||
|
@ -10,6 +10,9 @@
|
||||
|
||||
namespace cefclient {
|
||||
|
||||
extern const char kUrl[];
|
||||
extern const char kExternalDevTools[];
|
||||
|
||||
// CefSettings attributes.
|
||||
extern const char kMultiThreadedMessageLoop[];
|
||||
extern const char kCachePath[];
|
||||
|
Loading…
x
Reference in New Issue
Block a user