- Expose command line parsing support with a new CefCommandLine class (issue #422).

- cefclient: Add the ability to specify CefSettings and CefBrowserSettings values on the command line.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@378 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2011-11-14 23:43:52 +00:00
parent 0e4c6a648c
commit cc175e4fbe
21 changed files with 1383 additions and 43 deletions

View File

@ -306,6 +306,7 @@
'libcef_dll_wrapper',
],
'sources': [
'tests/unittests/command_line_unittest.cc',
'tests/unittests/content_filter_unittest.cc',
'tests/unittests/cookie_unittest.cc',
'tests/unittests/dom_unittest.cc',
@ -389,6 +390,8 @@
'libcef_dll/cef_logging.h',
'libcef_dll/cpptoc/browser_cpptoc.cc',
'libcef_dll/cpptoc/browser_cpptoc.h',
'libcef_dll/cpptoc/command_line_cpptoc.cc',
'libcef_dll/cpptoc/command_line_cpptoc.h',
'libcef_dll/cpptoc/cpptoc.h',
'libcef_dll/cpptoc/domdocument_cpptoc.cc',
'libcef_dll/cpptoc/domdocument_cpptoc.h',
@ -711,6 +714,7 @@
'libcef/cef_thread.h',
'libcef/cef_time.cc',
'libcef/cef_time_util.h',
'libcef/command_line_impl.cc',
'libcef/drag_data_impl.cc',
'libcef/drag_data_impl.h',
'libcef/drag_download_file.cc',

View File

@ -44,6 +44,8 @@
'tests/cefclient/binding_test.h',
'tests/cefclient/cefclient.cpp',
'tests/cefclient/cefclient.h',
'tests/cefclient/cefclient_switches.cpp',
'tests/cefclient/cefclient_switches.h',
'tests/cefclient/client_handler.cpp',
'tests/cefclient/client_handler.h',
'tests/cefclient/client_popup_handler.cpp',
@ -183,6 +185,8 @@
'libcef_dll/ctocpp/base_ctocpp.h',
'libcef_dll/ctocpp/browser_ctocpp.cc',
'libcef_dll/ctocpp/browser_ctocpp.h',
'libcef_dll/ctocpp/command_line_ctocpp.cc',
'libcef_dll/ctocpp/command_line_ctocpp.h',
'libcef_dll/ctocpp/ctocpp.h',
'libcef_dll/ctocpp/domdocument_ctocpp.cc',
'libcef_dll/ctocpp/domdocument_ctocpp.h',

View File

@ -3751,4 +3751,120 @@ public:
virtual bool GetFileNames(std::vector<CefString>& names) =0;
};
///
// Class used to create and/or parse command line arguments. Arguments with
// '--', '-' and, on Windows, '/' prefixes are considered switches. Switches
// will always precede any arguments without switch prefixes. Switches can
// optionally have a value specified using the '=' delimiter (e.g.
// "-switch=value"). An argument of "--" will terminate switch parsing with all
// subsequent tokens, regardless of prefix, being interpreted as non-switch
// arguments. Switch names are considered case-insensitive. This class can be
// used before CefInitialize() is called.
///
/*--cef(source=library)--*/
class CefCommandLine : public virtual CefBase
{
public:
typedef std::vector<CefString> ArgumentList;
typedef std::map<CefString,CefString> SwitchMap;
///
// Create a new CefCommandLine instance.
///
/*--cef()--*/
static CefRefPtr<CefCommandLine> CreateCommandLine();
///
// Initialize the command line with the specified |argc| and |argv| values.
// The first argument must be the name of the program. This method is only
// supported on non-Windows platforms.
///
/*--cef()--*/
virtual void InitFromArgv(int argc, const char* const* argv) =0;
///
// Initialize the command line with the string returned by calling
// GetCommandLineW(). This method is only supported on Windows.
///
/*--cef()--*/
virtual void InitFromString(const CefString& command_line) =0;
///
// Constructs and returns the represented command line string. Use this method
// cautiously because quoting behavior is unclear.
///
/*--cef()--*/
virtual CefString GetCommandLineString() =0;
///
// Get the program part of the command line string (the first item).
///
/*--cef()--*/
virtual CefString GetProgram() =0;
///
// Set the program part of the command line string (the first item).
///
/*--cef()--*/
virtual void SetProgram(const CefString& program) =0;
///
// Returns true if the command line has switches.
///
/*--cef()--*/
virtual bool HasSwitches() =0;
///
// Returns true if the command line contains the given switch.
///
/*--cef()--*/
virtual bool HasSwitch(const CefString& name) =0;
///
// Returns the value associated with the given switch. If the switch has no
// value or isn't present this method returns the empty string.
///
/*--cef()--*/
virtual CefString GetSwitchValue(const CefString& name) =0;
///
// Returns the map of switch names and values. If a switch has no value an
// empty string is returned.
///
/*--cef()--*/
virtual void GetSwitches(SwitchMap& switches) =0;
///
// Add a switch to the end of the command line. If the switch has no value
// pass an empty value string.
///
/*--cef()--*/
virtual void AppendSwitch(const CefString& name) =0;
///
// Add a switch with the specified value to the end of the command line.
///
/*--cef()--*/
virtual void AppendSwitchWithValue(const CefString& name,
const CefString& value) =0;
///
// True if there are remaining command line arguments.
///
/*--cef()--*/
virtual bool HasArguments() =0;
///
// Get the remaining command line arguments.
///
/*--cef()--*/
virtual void GetArguments(ArgumentList& arguments) =0;
///
// Add an argument to the end of the command line.
///
/*--cef()--*/
virtual void AppendArgument(const CefString& argument) =0;
};
#endif // _CEF_H

View File

@ -3541,6 +3541,123 @@ typedef struct _cef_drag_data_t
} cef_drag_data_t;
///
// Structure used to create and/or parse command line arguments. Arguments with
// '--', '-' and, on Windows, '/' prefixes are considered switches. Switches
// will always precede any arguments without switch prefixes. Switches can
// optionally have a value specified using the '=' delimiter (e.g.
// "-switch=value"). An argument of "--" will terminate switch parsing with all
// subsequent tokens, regardless of prefix, being interpreted as non-switch
// arguments. Switch names are considered case-insensitive. This structure can
// be used before cef_initialize() is called.
///
typedef struct _cef_command_line_t
{
// Base structure.
cef_base_t base;
///
// Initialize the command line with the specified |argc| and |argv| values.
// The first argument must be the name of the program. This function is only
// supported on non-Windows platforms.
///
void (CEF_CALLBACK *init_from_argv)(struct _cef_command_line_t* self,
int argc, const char* const* argv);
///
// Initialize the command line with the string returned by calling
// GetCommandLineW(). This function is only supported on Windows.
///
void (CEF_CALLBACK *init_from_string)(struct _cef_command_line_t* self,
const cef_string_t* command_line);
///
// Constructs and returns the represented command line string. Use this
// function cautiously because quoting behavior is unclear.
///
// The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_command_line_string)(
struct _cef_command_line_t* self);
///
// Get the program part of the command line string (the first item).
///
// The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_program)(
struct _cef_command_line_t* self);
///
// Set the program part of the command line string (the first item).
///
void (CEF_CALLBACK *set_program)(struct _cef_command_line_t* self,
const cef_string_t* program);
///
// Returns true (1) if the command line has switches.
///
int (CEF_CALLBACK *has_switches)(struct _cef_command_line_t* self);
///
// Returns true (1) if the command line contains the given switch.
///
int (CEF_CALLBACK *has_switch)(struct _cef_command_line_t* self,
const cef_string_t* name);
///
// Returns the value associated with the given switch. If the switch has no
// value or isn't present this function returns the NULL string.
///
// The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_switch_value)(
struct _cef_command_line_t* self, const cef_string_t* name);
///
// Returns the map of switch names and values. If a switch has no value an
// NULL string is returned.
///
void (CEF_CALLBACK *get_switches)(struct _cef_command_line_t* self,
cef_string_map_t switches);
///
// Add a switch to the end of the command line. If the switch has no value
// pass an NULL value string.
///
void (CEF_CALLBACK *append_switch)(struct _cef_command_line_t* self,
const cef_string_t* name);
///
// Add a switch with the specified value to the end of the command line.
///
void (CEF_CALLBACK *append_switch_with_value)(
struct _cef_command_line_t* self, const cef_string_t* name,
const cef_string_t* value);
///
// True if there are remaining command line arguments.
///
int (CEF_CALLBACK *has_arguments)(struct _cef_command_line_t* self);
///
// Get the remaining command line arguments.
///
void (CEF_CALLBACK *get_arguments)(struct _cef_command_line_t* self,
cef_string_list_t arguments);
///
// Add an argument to the end of the command line.
///
void (CEF_CALLBACK *append_argument)(struct _cef_command_line_t* self,
const cef_string_t* argument);
} cef_command_line_t;
///
// Create a new cef_command_line_t instance.
///
CEF_EXPORT cef_command_line_t* cef_command_line_create();
#ifdef __cplusplus
}
#endif

132
libcef/command_line_impl.cc Normal file
View File

@ -0,0 +1,132 @@
// 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/cef.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
namespace {
class CefCommandLineImpl : public CefCommandLine
{
public:
CefCommandLineImpl()
: command_line_(CommandLine::NO_PROGRAM)
{
}
virtual void InitFromArgv(int argc, const char* const* argv) OVERRIDE
{
#if !defined(OS_WIN)
AutoLock lock_scope(this);
command_line_.InitFromArgv(argc, argv);
#else
NOTREACHED() << "method not supported on this platform";
#endif
}
virtual void InitFromString(const CefString& command_line) OVERRIDE
{
#if defined(OS_WIN)
AutoLock lock_scope(this);
command_line_.ParseFromString(command_line);
#else
NOTREACHED() << "method not supported on this platform";
#endif
}
virtual CefString GetCommandLineString() OVERRIDE
{
AutoLock lock_scope(this);
return command_line_.GetCommandLineString();
}
virtual CefString GetProgram() OVERRIDE
{
AutoLock lock_scope(this);
return command_line_.GetProgram().value();
}
virtual void SetProgram(const CefString& program) OVERRIDE
{
AutoLock lock_scope(this);
command_line_.SetProgram(FilePath(program));
}
virtual bool HasSwitches() OVERRIDE
{
AutoLock lock_scope(this);
return (command_line_.GetSwitches().size() > 0);
}
virtual bool HasSwitch(const CefString& name) OVERRIDE
{
AutoLock lock_scope(this);
return command_line_.HasSwitch(name);
}
virtual CefString GetSwitchValue(const CefString& name) OVERRIDE
{
AutoLock lock_scope(this);
return command_line_.GetSwitchValueNative(name);
}
virtual void GetSwitches(SwitchMap& switches) OVERRIDE
{
AutoLock lock_scope(this);
const CommandLine::SwitchMap& map = command_line_.GetSwitches();
CommandLine::SwitchMap::const_iterator it = map.begin();
for (; it != map.end(); ++it)
switches.insert(std::make_pair(it->first, it->second));
}
virtual void AppendSwitch(const CefString& name) OVERRIDE
{
AutoLock lock_scope(this);
command_line_.AppendSwitch(name);
}
virtual void AppendSwitchWithValue(const CefString& name,
const CefString& value) OVERRIDE
{
AutoLock lock_scope(this);
command_line_.AppendSwitchNative(name, value);
}
virtual bool HasArguments() OVERRIDE
{
AutoLock lock_scope(this);
return (command_line_.GetArgs().size() > 0);
}
virtual void GetArguments(ArgumentList& arguments) OVERRIDE
{
AutoLock lock_scope(this);
const CommandLine::StringVector& vec = command_line_.GetArgs();
CommandLine::StringVector::const_iterator it = vec.begin();
for (; it != vec.end(); ++it)
arguments.push_back(*it);
}
virtual void AppendArgument(const CefString& argument) OVERRIDE
{
AutoLock lock_scope(this);
command_line_.AppendArgNative(argument);
}
private:
CommandLine command_line_;
IMPLEMENT_REFCOUNTING(CefCommandLineImpl);
IMPLEMENT_LOCKING(CefCommandLineImpl);
};
} // namespace
// static
CefRefPtr<CefCommandLine> CefCommandLine::CreateCommandLine()
{
return new CefCommandLineImpl();
}

View File

@ -0,0 +1,213 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// A portion of this file was generated by the CEF translator tool. When
// making changes by hand only do so within the body of existing function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/command_line_cpptoc.h"
#include "libcef_dll/transfer_util.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_command_line_t* cef_command_line_create()
{
CefRefPtr<CefCommandLine> impl = CefCommandLine::CreateCommandLine();
if(impl.get())
return CefCommandLineCppToC::Wrap(impl);
return NULL;
}
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK command_line_init_from_argv(struct _cef_command_line_t* self,
int argc, const char* const* argv)
{
DCHECK(self);
if (!self)
return;
CefCommandLineCppToC::Get(self)->InitFromArgv(argc, argv);
}
void CEF_CALLBACK command_line_init_from_string(
struct _cef_command_line_t* self, const cef_string_t* command_line)
{
DCHECK(self);
if (!self)
return;
CefCommandLineCppToC::Get(self)->InitFromString(CefString(command_line));
}
cef_string_userfree_t CEF_CALLBACK command_line_get_command_line_string(
struct _cef_command_line_t* self)
{
DCHECK(self);
if (!self)
return NULL;
CefString str = CefCommandLineCppToC::Get(self)->GetCommandLineString();
return str.DetachToUserFree();
}
cef_string_userfree_t CEF_CALLBACK command_line_get_program(
struct _cef_command_line_t* self)
{
DCHECK(self);
if (!self)
return NULL;
CefString str = CefCommandLineCppToC::Get(self)->GetProgram();
return str.DetachToUserFree();
}
void CEF_CALLBACK command_line_set_program(struct _cef_command_line_t* self,
const cef_string_t* program)
{
DCHECK(self);
if (!self)
return;
CefCommandLineCppToC::Get(self)->SetProgram(CefString(program));
}
int CEF_CALLBACK command_line_has_switches(struct _cef_command_line_t* self)
{
DCHECK(self);
if (!self)
return 0;
return CefCommandLineCppToC::Get(self)->HasSwitches();
}
int CEF_CALLBACK command_line_has_switch(struct _cef_command_line_t* self,
const cef_string_t* name)
{
DCHECK(self);
DCHECK(name);
if (!self || !name)
return 0;
return CefCommandLineCppToC::Get(self)->HasSwitch(CefString(name));
}
cef_string_userfree_t CEF_CALLBACK command_line_get_switch_value(
struct _cef_command_line_t* self, const cef_string_t* name)
{
DCHECK(self);
DCHECK(name);
if (!self || !name)
return NULL;
CefString str = CefCommandLineCppToC::Get(self)->GetSwitchValue(
CefString(name));
return str.DetachToUserFree();
}
void CEF_CALLBACK command_line_get_switches(struct _cef_command_line_t* self,
cef_string_map_t switches)
{
DCHECK(self);
DCHECK(switches);
if (!self || !switches)
return;
CefCommandLine::SwitchMap map;
CefCommandLineCppToC::Get(self)->GetSwitches(map);
transfer_string_map_contents(map, switches);
}
void CEF_CALLBACK command_line_append_switch(struct _cef_command_line_t* self,
const cef_string_t* name)
{
DCHECK(self);
DCHECK(name);
if (!self || !name)
return;
CefCommandLineCppToC::Get(self)->AppendSwitch(CefString(name));
}
void CEF_CALLBACK command_line_append_switch_with_value(
struct _cef_command_line_t* self, const cef_string_t* name,
const cef_string_t* value)
{
DCHECK(self);
DCHECK(name);
DCHECK(value);
if (!self || !name || !value)
return;
CefCommandLineCppToC::Get(self)->AppendSwitchWithValue(CefString(name),
CefString(value));
}
int CEF_CALLBACK command_line_has_arguments(struct _cef_command_line_t* self)
{
DCHECK(self);
if (!self)
return 0;
return CefCommandLineCppToC::Get(self)->HasArguments();
}
void CEF_CALLBACK command_line_get_arguments(struct _cef_command_line_t* self,
cef_string_list_t arguments)
{
DCHECK(self);
if (!self)
return;
CefCommandLine::ArgumentList list;
CefCommandLineCppToC::Get(self)->GetArguments(list);
transfer_string_list_contents(list, arguments);
}
void CEF_CALLBACK command_line_append_argument(struct _cef_command_line_t* self,
const cef_string_t* argument)
{
DCHECK(self);
DCHECK(argument);
if (!self || !argument)
return;
CefCommandLineCppToC::Get(self)->AppendArgument(CefString(argument));
}
// CONSTRUCTOR - Do not edit by hand.
CefCommandLineCppToC::CefCommandLineCppToC(CefCommandLine* cls)
: CefCppToC<CefCommandLineCppToC, CefCommandLine, cef_command_line_t>(cls)
{
struct_.struct_.init_from_argv = command_line_init_from_argv;
struct_.struct_.init_from_string = command_line_init_from_string;
struct_.struct_.get_command_line_string =
command_line_get_command_line_string;
struct_.struct_.get_program = command_line_get_program;
struct_.struct_.set_program = command_line_set_program;
struct_.struct_.has_switches = command_line_has_switches;
struct_.struct_.has_switch = command_line_has_switch;
struct_.struct_.get_switch_value = command_line_get_switch_value;
struct_.struct_.get_switches = command_line_get_switches;
struct_.struct_.append_switch = command_line_append_switch;
struct_.struct_.append_switch_with_value =
command_line_append_switch_with_value;
struct_.struct_.has_arguments = command_line_has_arguments;
struct_.struct_.get_arguments = command_line_get_arguments;
struct_.struct_.append_argument = command_line_append_argument;
}
#ifndef NDEBUG
template<> long CefCppToC<CefCommandLineCppToC, CefCommandLine,
cef_command_line_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,34 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// 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 _COMMANDLINE_CPPTOC_H
#define _COMMANDLINE_CPPTOC_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef.h"
#include "include/cef_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefCommandLineCppToC
: public CefCppToC<CefCommandLineCppToC, CefCommandLine, cef_command_line_t>
{
public:
CefCommandLineCppToC(CefCommandLine* cls);
virtual ~CefCommandLineCppToC() {}
};
#endif // BUILDING_CEF_SHARED
#endif // _COMMANDLINE_CPPTOC_H

View File

@ -206,6 +206,9 @@ void CefBrowserCToCpp::GetFrameNames(std::vector<CefString>& names)
return;
cef_string_list_t list = cef_string_list_alloc();
if (!list)
return;
struct_->get_frame_names(struct_, list);
transfer_string_list_contents(list, names);

View File

@ -0,0 +1,172 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// A portion of this file was generated by the CEF translator tool. When
// making changes by hand only do so within the body of existing static and
// virtual method implementations. See the translator.README.txt file in the
// tools directory for more information.
//
#include "libcef_dll/ctocpp/command_line_ctocpp.h"
#include "libcef_dll/transfer_util.h"
// STATIC METHODS - Body may be edited by hand.
CefRefPtr<CefCommandLine> CefCommandLine::CreateCommandLine()
{
cef_command_line_t* impl = cef_command_line_create();
if(impl)
return CefCommandLineCToCpp::Wrap(impl);
return NULL;
}
// VIRTUAL METHODS - Body may be edited by hand.
void CefCommandLineCToCpp::InitFromArgv(int argc, const char* const* argv)
{
if (CEF_MEMBER_MISSING(struct_, init_from_argv))
return;
struct_->init_from_argv(struct_, argc, argv);
}
void CefCommandLineCToCpp::InitFromString(const CefString& command_line)
{
if (CEF_MEMBER_MISSING(struct_, init_from_string))
return;
struct_->init_from_string(struct_, command_line.GetStruct());
}
CefString CefCommandLineCToCpp::GetCommandLineString()
{
CefString str;
if (CEF_MEMBER_MISSING(struct_, get_command_line_string))
return str;
cef_string_userfree_t strPtr = struct_->get_command_line_string(struct_);
str.AttachToUserFree(strPtr);
return str;
}
CefString CefCommandLineCToCpp::GetProgram()
{
CefString str;
if (CEF_MEMBER_MISSING(struct_, get_program))
return str;
cef_string_userfree_t strPtr = struct_->get_program(struct_);
str.AttachToUserFree(strPtr);
return str;
}
void CefCommandLineCToCpp::SetProgram(const CefString& program)
{
if (CEF_MEMBER_MISSING(struct_, set_program))
return;
struct_->set_program(struct_, program.GetStruct());
}
bool CefCommandLineCToCpp::HasSwitches()
{
if (CEF_MEMBER_MISSING(struct_, has_switches))
return false;
return struct_->has_switches(struct_)?true:false;
}
bool CefCommandLineCToCpp::HasSwitch(const CefString& name)
{
if (CEF_MEMBER_MISSING(struct_, has_switch))
return false;
return struct_->has_switch(struct_, name.GetStruct())?true:false;
}
CefString CefCommandLineCToCpp::GetSwitchValue(const CefString& name)
{
CefString str;
if (CEF_MEMBER_MISSING(struct_, get_switch_value))
return str;
cef_string_userfree_t strPtr = struct_->get_switch_value(struct_,
name.GetStruct());
str.AttachToUserFree(strPtr);
return str;
}
void CefCommandLineCToCpp::GetSwitches(SwitchMap& switches)
{
if (CEF_MEMBER_MISSING(struct_, get_switches))
return;
cef_string_map_t map = cef_string_map_alloc();
if(!map)
return;
struct_->get_switches(struct_, map);
transfer_string_map_contents(map, switches);
cef_string_map_free(map);
}
void CefCommandLineCToCpp::AppendSwitch(const CefString& name)
{
if (CEF_MEMBER_MISSING(struct_, append_switch))
return;
struct_->append_switch(struct_, name.GetStruct());
}
void CefCommandLineCToCpp::AppendSwitchWithValue(const CefString& name,
const CefString& value)
{
if (CEF_MEMBER_MISSING(struct_, append_switch_with_value))
return;
struct_->append_switch_with_value(struct_, name.GetStruct(),
value.GetStruct());
}
bool CefCommandLineCToCpp::HasArguments()
{
if (CEF_MEMBER_MISSING(struct_, has_arguments))
return false;
return struct_->has_arguments(struct_)?true:false;
}
void CefCommandLineCToCpp::GetArguments(ArgumentList& arguments)
{
if (CEF_MEMBER_MISSING(struct_, get_arguments))
return;
cef_string_list_t list = cef_string_list_alloc();
if (!list)
return;
struct_->get_arguments(struct_, list);
transfer_string_list_contents(list, arguments);
cef_string_list_free(list);
}
void CefCommandLineCToCpp::AppendArgument(const CefString& argument)
{
if (CEF_MEMBER_MISSING(struct_, append_argument))
return;
struct_->append_argument(struct_, argument.GetStruct());
}
#ifndef NDEBUG
template<> long CefCToCpp<CefCommandLineCToCpp, CefCommandLine,
cef_command_line_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,54 @@
// 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.
//
// -------------------------------------------------------------------------
//
// 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 _COMMANDLINE_CTOCPP_H
#define _COMMANDLINE_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef.h"
#include "include/cef_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed wrapper-side only.
class CefCommandLineCToCpp
: public CefCToCpp<CefCommandLineCToCpp, CefCommandLine, cef_command_line_t>
{
public:
CefCommandLineCToCpp(cef_command_line_t* str)
: CefCToCpp<CefCommandLineCToCpp, CefCommandLine, cef_command_line_t>(
str) {}
virtual ~CefCommandLineCToCpp() {}
// CefCommandLine methods
virtual void InitFromArgv(int argc, const char* const* argv) OVERRIDE;
virtual void InitFromString(const CefString& command_line) OVERRIDE;
virtual CefString GetCommandLineString() OVERRIDE;
virtual CefString GetProgram() OVERRIDE;
virtual void SetProgram(const CefString& program) OVERRIDE;
virtual bool HasSwitches() OVERRIDE;
virtual bool HasSwitch(const CefString& name) OVERRIDE;
virtual CefString GetSwitchValue(const CefString& name) OVERRIDE;
virtual void GetSwitches(SwitchMap& switches) OVERRIDE;
virtual void AppendSwitch(const CefString& name) OVERRIDE;
virtual void AppendSwitchWithValue(const CefString& name,
const CefString& value) OVERRIDE;
virtual bool HasArguments() OVERRIDE;
virtual void GetArguments(ArgumentList& arguments) OVERRIDE;
virtual void AppendArgument(const CefString& argument) OVERRIDE;
};
#endif // USING_CEF_SHARED
#endif // _COMMANDLINE_CTOCPP_H

View File

@ -134,6 +134,9 @@ bool CefDragDataCToCpp::GetFileNames(std::vector<CefString>& names)
return false;
cef_string_list_t list = cef_string_list_alloc();
if (!list)
return false;
if(struct_->get_file_names(struct_, list)) {
transfer_string_list_contents(list, names);
cef_string_list_free(list);

View File

@ -353,6 +353,9 @@ bool CefV8ValueCToCpp::GetKeys(std::vector<CefString>& keys)
return false;
cef_string_list_t list = cef_string_list_alloc();
if (!list)
return false;
if(struct_->get_keys(struct_, list)) {
transfer_string_list_contents(list, keys);
cef_string_list_free(list);

View File

@ -6,6 +6,7 @@
#include "include/cef_runnable.h"
#include "include/cef_wrapper.h"
#include "cefclient.h"
#include "cefclient_switches.h"
#include "client_handler.h"
#include "binding_test.h"
#include "string_util.h"
@ -61,9 +62,20 @@ void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
}
}
// Return the int representation of the specified string.
int GetIntValue(const CefString& str)
{
if (str.empty())
return 0;
std::string stdStr = str;
return atoi(stdStr.c_str());
}
} // namespace
CefRefPtr<ClientHandler> g_handler;
CefRefPtr<CefCommandLine> g_command_line;
CefRefPtr<CefBrowser> AppGetBrowser()
{
@ -79,6 +91,192 @@ CefWindowHandle AppGetMainHwnd()
return g_handler->GetMainHwnd();
}
void AppInitCommandLine(int argc, const char* const* argv)
{
g_command_line = CefCommandLine::CreateCommandLine();
#if defined(OS_WIN)
g_command_line->InitFromString(::GetCommandLineW());
#else
g_command_line->InitFromArgv(argc, argv);
#endif
}
// Returns the application command line object.
CefRefPtr<CefCommandLine> AppGetCommandLine()
{
return g_command_line;
}
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings)
{
ASSERT(g_command_line.get());
if (!g_command_line.get())
return;
CefString str;
#if defined(OS_WIN)
settings.multi_threaded_message_loop =
g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop);
#endif
CefString(&settings.cache_path) =
g_command_line->GetSwitchValue(cefclient::kCachePath);
CefString(&settings.user_agent) =
g_command_line->GetSwitchValue(cefclient::kUserAgent);
CefString(&settings.product_version) =
g_command_line->GetSwitchValue(cefclient::kProductVersion);
CefString(&settings.locale) =
g_command_line->GetSwitchValue(cefclient::kLocale);
CefString(&settings.log_file) =
g_command_line->GetSwitchValue(cefclient::kLogFile);
{
std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity);
bool invalid = false;
if (!str.empty()) {
if (str == cefclient::kLogSeverity_Verbose)
settings.log_severity = LOGSEVERITY_VERBOSE;
else if (str == cefclient::kLogSeverity_Info)
settings.log_severity = LOGSEVERITY_INFO;
else if (str == cefclient::kLogSeverity_Warning)
settings.log_severity = LOGSEVERITY_WARNING;
else if (str == cefclient::kLogSeverity_Error)
settings.log_severity = LOGSEVERITY_ERROR;
else if (str == cefclient::kLogSeverity_ErrorReport)
settings.log_severity = LOGSEVERITY_ERROR_REPORT;
else if (str == cefclient::kLogSeverity_Disable)
settings.log_severity = LOGSEVERITY_DISABLE;
else
invalid = true;
}
if (str.empty() || invalid) {
#ifdef NDEBUG
// Only log error messages and higher in release build.
settings.log_severity = LOGSEVERITY_ERROR;
#endif
}
}
{
std::string str = g_command_line->GetSwitchValue(cefclient::kGraphicsImpl);
if (!str.empty()) {
#if defined(OS_WIN)
if (str == cefclient::kGraphicsImpl_Angle)
settings.graphics_implementation = ANGLE_IN_PROCESS;
else if (str == cefclient::kGraphicsImpl_AngleCmdBuffer)
settings.graphics_implementation = ANGLE_IN_PROCESS_COMMAND_BUFFER;
else
#endif
if (str == cefclient::kGraphicsImpl_Desktop)
settings.graphics_implementation = DESKTOP_IN_PROCESS;
else if (str == cefclient::kGraphicsImpl_DesktopCmdBuffer)
settings.graphics_implementation = DESKTOP_IN_PROCESS_COMMAND_BUFFER;
}
}
settings.local_storage_quota = GetIntValue(
g_command_line->GetSwitchValue(cefclient::kLocalStorageQuota));
settings.session_storage_quota = GetIntValue(
g_command_line->GetSwitchValue(cefclient::kSessionStorageQuota));
CefString(&settings.javascript_flags) =
g_command_line->GetSwitchValue(cefclient::kJavascriptFlags);
}
// Returns the application browser settings based on command line arguments.
void AppGetBrowserSettings(CefBrowserSettings& settings)
{
ASSERT(g_command_line.get());
if (!g_command_line.get())
return;
settings.drag_drop_disabled =
g_command_line->HasSwitch(cefclient::kDragDropDisabled);
settings.load_drops_disabled =
g_command_line->HasSwitch(cefclient::kLoadDropsDisabled);
settings.remote_fonts_disabled =
g_command_line->HasSwitch(cefclient::kRemoteFontsDisabled);
CefString(&settings.default_encoding) =
g_command_line->GetSwitchValue(cefclient::kDefaultEncoding);
settings.encoding_detector_enabled =
g_command_line->HasSwitch(cefclient::kEncodingDetectorEnabled);
settings.javascript_disabled =
g_command_line->HasSwitch(cefclient::kJavascriptDisabled);
settings.javascript_open_windows_disallowed =
g_command_line->HasSwitch(cefclient::kJavascriptOpenWindowsDisallowed);
settings.javascript_close_windows_disallowed =
g_command_line->HasSwitch(cefclient::kJavascriptCloseWindowsDisallowed);
settings.javascript_access_clipboard_disallowed =
g_command_line->HasSwitch(
cefclient::kJavascriptAccessClipboardDisallowed);
settings.dom_paste_disabled =
g_command_line->HasSwitch(cefclient::kDomPasteDisabled);
settings.caret_browsing_enabled =
g_command_line->HasSwitch(cefclient::kCaretBrowsingDisabled);
settings.java_disabled =
g_command_line->HasSwitch(cefclient::kJavaDisabled);
settings.plugins_disabled =
g_command_line->HasSwitch(cefclient::kPluginsDisabled);
settings.universal_access_from_file_urls_allowed =
g_command_line->HasSwitch(cefclient::kUniversalAccessFromFileUrlsAllowed);
settings.file_access_from_file_urls_allowed =
g_command_line->HasSwitch(cefclient::kFileAccessFromFileUrlsAllowed);
settings.web_security_disabled =
g_command_line->HasSwitch(cefclient::kWebSecurityDisabled);
settings.xss_auditor_enabled =
g_command_line->HasSwitch(cefclient::kXssAuditorEnabled);
settings.image_load_disabled =
g_command_line->HasSwitch(cefclient::kImageLoadingDisabled);
settings.shrink_standalone_images_to_fit =
g_command_line->HasSwitch(cefclient::kShrinkStandaloneImagesToFit);
settings.site_specific_quirks_disabled =
g_command_line->HasSwitch(cefclient::kSiteSpecificQuirksDisabled);
settings.text_area_resize_disabled =
g_command_line->HasSwitch(cefclient::kTextAreaResizeDisabled);
settings.page_cache_disabled =
g_command_line->HasSwitch(cefclient::kPageCacheDisabled);
settings.tab_to_links_disabled =
g_command_line->HasSwitch(cefclient::kTabToLinksDisabled);
settings.hyperlink_auditing_disabled =
g_command_line->HasSwitch(cefclient::kHyperlinkAuditingDisabled);
settings.user_style_sheet_enabled =
g_command_line->HasSwitch(cefclient::kUserStyleSheetEnabled);
CefString(&settings.user_style_sheet_location) =
g_command_line->GetSwitchValue(cefclient::kUserStyleSheetLocation);
settings.author_and_user_styles_disabled =
g_command_line->HasSwitch(cefclient::kAuthorAndUserStylesDisabled);
settings.local_storage_disabled =
g_command_line->HasSwitch(cefclient::kLocalStorageDisabled);
settings.databases_disabled =
g_command_line->HasSwitch(cefclient::kDatabasesDisabled);
settings.application_cache_disabled =
g_command_line->HasSwitch(cefclient::kApplicationCacheDisabled);
settings.webgl_disabled =
g_command_line->HasSwitch(cefclient::kWebglDisabled);
settings.accelerated_compositing_enabled =
g_command_line->HasSwitch(cefclient::kAcceleratedCompositingEnabled);
settings.threaded_compositing_enabled =
g_command_line->HasSwitch(cefclient::kThreadedCompositingEnabled);
settings.accelerated_layers_disabled =
g_command_line->HasSwitch(cefclient::kAcceleratedLayersDisabled);
settings.accelerated_video_disabled =
g_command_line->HasSwitch(cefclient::kAcceleratedVideoDisabled);
settings.accelerated_2d_canvas_disabled =
g_command_line->HasSwitch(cefclient::kAcceledated2dCanvasDisabled);
settings.accelerated_drawing_disabled =
g_command_line->HasSwitch(cefclient::kAcceleratedDrawingDisabled);
settings.accelerated_plugins_disabled =
g_command_line->HasSwitch(cefclient::kAcceleratedPluginsDisabled);
settings.developer_tools_disabled =
g_command_line->HasSwitch(cefclient::kDeveloperToolsDisabled);
}
static void ExecuteGetSource(CefRefPtr<CefFrame> frame)
{
// Retrieve the current page source and display.

View File

@ -16,6 +16,18 @@ CefWindowHandle AppGetMainHwnd();
// Returns the application working directory.
std::string AppGetWorkingDirectory();
// Initialize the application command line.
void AppInitCommandLine(int argc, const char* const* argv);
// Returns the application command line object.
CefRefPtr<CefCommandLine> AppGetCommandLine();
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings);
// Returns the application browser settings based on command line arguments.
void AppGetBrowserSettings(CefBrowserSettings& settings);
// Implementations for various tests.
void RunGetSourceTest(CefRefPtr<CefBrowser> browser);
void RunGetTextTest(CefRefPtr<CefBrowser> browser);

View File

@ -323,7 +323,14 @@ int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
// Parse command line arguments.
AppInitCommandLine(argc, argv);
CefSettings settings;
// Populate the settings based on command line arguments.
AppGetSettings(settings);
CefInitialize(settings);
// Register the V8 extension handler.
@ -393,7 +400,10 @@ int main(int argc, char *argv[]) {
// Create the browser view.
CefWindowInfo window_info;
CefBrowserSettings browserSettings;
// Populate the settings based on command line arguments.
AppGetBrowserSettings(browserSettings);
window_info.SetAsChild(vbox);
CefBrowser::CreateBrowserSync(window_info,

View File

@ -371,6 +371,10 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
// Create the browser view.
CefWindowInfo window_info;
CefBrowserSettings settings;
// Populate the settings based on command line arguments.
AppGetBrowserSettings(settings);
window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight);
CefBrowser::CreateBrowser(window_info, g_handler.get(),
"http://www.google.com", settings);
@ -541,12 +545,15 @@ int main(int argc, char* argv[])
// Initialize the ClientApplication instance.
[ClientApplication sharedApplication];
// Parse command line arguments.
AppInitCommandLine(argc, argv);
// Initialize CEF.
CefSettings settings;
// Use the Chinese language locale.
// CefString(&settings.locale).FromASCII("zh-cn");
// Populate the settings based on command line arguments.
AppGetSettings(settings);
CefInitialize(settings);

View File

@ -0,0 +1,78 @@
// 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 "cefclient_switches.h"
namespace cefclient {
// CefSettings attributes.
const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop";
const char kCachePath[] = "cache-path";
const char kUserAgent[] = "user-agent";
const char kProductVersion[] = "product-version";
const char kLocale[] = "locale";
const char kLogFile[] = "log-file";
const char kLogSeverity[] = "log-severity";
const char kLogSeverity_Verbose[] = "verbose";
const char kLogSeverity_Info[] = "info";
const char kLogSeverity_Warning[] = "warning";
const char kLogSeverity_Error[] = "error";
const char kLogSeverity_ErrorReport[] = "error-report";
const char kLogSeverity_Disable[] = "disable";
const char kGraphicsImpl[] = "graphics-implementation";
const char kGraphicsImpl_Angle[] = "angle";
const char kGraphicsImpl_AngleCmdBuffer[] = "angle-command-buffer";
const char kGraphicsImpl_Desktop[] = "desktop";
const char kGraphicsImpl_DesktopCmdBuffer[] = "desktop-command-buffer";
const char kLocalStorageQuota[] = "local-storage-quota";
const char kSessionStorageQuota[] = "session-storage-quota";
const char kJavascriptFlags[] = "javascript-flags";
// CefBrowserSettings attributes.
const char kDragDropDisabled[] = "drag-drop-disabled";
const char kLoadDropsDisabled[] = "load-drops-disabled";
const char kRemoteFontsDisabled[] = "remote-fonts-disabled";
const char kDefaultEncoding[] = "default-encoding";
const char kEncodingDetectorEnabled[] = "encoding-detector-enabled";
const char kJavascriptDisabled[] = "javascript-disabled";
const char kJavascriptOpenWindowsDisallowed[] =
"javascript-open-windows-disallowed";
const char kJavascriptCloseWindowsDisallowed[] =
"javascript-close-windows-disallowed";
const char kJavascriptAccessClipboardDisallowed[] =
"javascript-access-clipboard-disallowed";
const char kDomPasteDisabled[] = "dom-paste-disabled";
const char kCaretBrowsingDisabled[] = "caret-browsing-enabled";
const char kJavaDisabled[] = "java-disabled";
const char kPluginsDisabled[] = "plugins-disabled";
const char kUniversalAccessFromFileUrlsAllowed[] =
"universal-access-from-file-urls-allowed";
const char kFileAccessFromFileUrlsAllowed[] =
"file-access-from-file-urls-allowed";
const char kWebSecurityDisabled[] = "web-security-disabled";
const char kXssAuditorEnabled[] = "xss-auditor-enabled";
const char kImageLoadingDisabled[] = "image-load-disabled";
const char kShrinkStandaloneImagesToFit[] = "shrink-standalone-images-to-fit";
const char kSiteSpecificQuirksDisabled[] = "site-specific-quirks-disabled";
const char kTextAreaResizeDisabled[] = "text-area-resize-disabled";
const char kPageCacheDisabled[] = "page-cache-disabled";
const char kTabToLinksDisabled[] = "tab-to-links-disabled";
const char kHyperlinkAuditingDisabled[] = "hyperlink-auditing-disabled";
const char kUserStyleSheetEnabled[] = "user-style-sheet-enabled";
const char kUserStyleSheetLocation[] = "user-style-sheet-location";
const char kAuthorAndUserStylesDisabled[] = "author-and-user-styles-disabled";
const char kLocalStorageDisabled[] = "local-storage-disabled";
const char kDatabasesDisabled[] = "databases-disabled";
const char kApplicationCacheDisabled[] = "application-cache-disabled";
const char kWebglDisabled[] = "webgl-disabled";
const char kAcceleratedCompositingEnabled[] = "accelerated-compositing-enabled";
const char kThreadedCompositingEnabled[] = "threaded-compositing-enabled";
const char kAcceleratedLayersDisabled[] = "accelerated-layers-disabled";
const char kAcceleratedVideoDisabled[] = "accelerated-video-disabled";
const char kAcceledated2dCanvasDisabled[] = "accelerated-2d-canvas-disabled";
const char kAcceleratedDrawingDisabled[] = "accelerated-drawing-disabled";
const char kAcceleratedPluginsDisabled[] = "accelerated-plugins-disabled";
const char kDeveloperToolsDisabled[] = "developer-tools-disabled";
} // namespace cefclient

View File

@ -0,0 +1,78 @@
// 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.
// Defines all of the command line switches used by cefclient.
#ifndef _CEFCLIENT_SWITCHES_H
#define _CEFCLIENT_SWITCHES_H
namespace cefclient {
// CefSettings attributes.
extern const char kMultiThreadedMessageLoop[];
extern const char kCachePath[];
extern const char kUserAgent[];
extern const char kProductVersion[];
extern const char kLocale[];
extern const char kLogFile[];
extern const char kLogSeverity[];
extern const char kLogSeverity_Verbose[];
extern const char kLogSeverity_Info[];
extern const char kLogSeverity_Warning[];
extern const char kLogSeverity_Error[];
extern const char kLogSeverity_ErrorReport[];
extern const char kLogSeverity_Disable[];
extern const char kGraphicsImpl[];
extern const char kGraphicsImpl_Angle[];
extern const char kGraphicsImpl_AngleCmdBuffer[];
extern const char kGraphicsImpl_Desktop[];
extern const char kGraphicsImpl_DesktopCmdBuffer[];
extern const char kLocalStorageQuota[];
extern const char kSessionStorageQuota[];
extern const char kJavascriptFlags[];
// CefBrowserSettings attributes.
extern const char kDragDropDisabled[];
extern const char kLoadDropsDisabled[];
extern const char kRemoteFontsDisabled[];
extern const char kDefaultEncoding[];
extern const char kEncodingDetectorEnabled[];
extern const char kJavascriptDisabled[];
extern const char kJavascriptOpenWindowsDisallowed[];
extern const char kJavascriptCloseWindowsDisallowed[];
extern const char kJavascriptAccessClipboardDisallowed[];
extern const char kDomPasteDisabled[];
extern const char kCaretBrowsingDisabled[];
extern const char kJavaDisabled[];
extern const char kPluginsDisabled[];
extern const char kUniversalAccessFromFileUrlsAllowed[];
extern const char kFileAccessFromFileUrlsAllowed[];
extern const char kWebSecurityDisabled[];
extern const char kXssAuditorEnabled[];
extern const char kImageLoadingDisabled[];
extern const char kShrinkStandaloneImagesToFit[];
extern const char kSiteSpecificQuirksDisabled[];
extern const char kTextAreaResizeDisabled[];
extern const char kPageCacheDisabled[];
extern const char kTabToLinksDisabled[];
extern const char kHyperlinkAuditingDisabled[];
extern const char kUserStyleSheetEnabled[];
extern const char kUserStyleSheetLocation[];
extern const char kAuthorAndUserStylesDisabled[];
extern const char kLocalStorageDisabled[];
extern const char kDatabasesDisabled[];
extern const char kApplicationCacheDisabled[];
extern const char kWebglDisabled[];
extern const char kAcceleratedCompositingEnabled[];
extern const char kThreadedCompositingEnabled[];
extern const char kAcceleratedLayersDisabled[];
extern const char kAcceleratedVideoDisabled[];
extern const char kAcceledated2dCanvasDisabled[];
extern const char kAcceleratedDrawingDisabled[];
extern const char kAcceleratedPluginsDisabled[];
extern const char kDeveloperToolsDisabled[];
} // namespace cefclient
#endif // _CEFCLIENT_SWITCHES_H

View File

@ -25,10 +25,6 @@
#define BUTTON_WIDTH 72
#define URLBAR_HEIGHT 24
// Define this value to run CEF with messages processed using the current
// application's message loop.
#define TEST_SINGLE_THREADED_MESSAGE_LOOP
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
@ -65,28 +61,15 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
if(_getcwd(szWorkingDir, MAX_PATH) == NULL)
szWorkingDir[0] = 0;
// Parse command line arguments. The passed in values are ignored on Windows.
AppInitCommandLine(0, NULL);
CefSettings settings;
// Specify a cache path value.
//CefString(&settings.cache_path).FromASCII("c:\\temp\\cache");
// Use the Chinese language locale.
// CefString(&settings.locale).FromASCII("zh-cn");
#ifdef NDEBUG
// Only log error messages and higher in release build.
settings.log_severity = LOGSEVERITY_ERROR;
#endif
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
// Initialize the CEF with messages processed using the current application's
// message loop.
settings.multi_threaded_message_loop = false;
#else
// Initialize the CEF with messages processed using a separate UI thread.
settings.multi_threaded_message_loop = true;
#endif
// Populate the settings based on command line arguments.
AppGetSettings(settings);
// Initialize CEF.
CefInitialize(settings);
// Register the internal client plugin.
@ -124,27 +107,27 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
int result = 0;
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
// Run the CEF message loop. This function will block until the application
// recieves a WM_QUIT message.
CefRunMessageLoop();
#else
MSG msg;
if (!settings.multi_threaded_message_loop) {
// Run the CEF message loop. This function will block until the application
// recieves a WM_QUIT message.
CefRunMessageLoop();
} else {
MSG msg;
// Run the application message loop.
while (GetMessage(&msg, NULL, 0, 0)) {
// Allow processing of find dialog messages.
if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
continue;
// Run the application message loop.
while (GetMessage(&msg, NULL, 0, 0)) {
// Allow processing of find dialog messages.
if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
continue;
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
result = (int)msg.wParam;
#endif
result = (int)msg.wParam;
}
// Shut down CEF.
CefShutdown();
@ -373,6 +356,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
CefWindowInfo info;
CefBrowserSettings settings;
// Populate the settings based on command line arguments.
AppGetBrowserSettings(settings);
// Initialize window info to the defaults for a child window
info.SetAsChild(hWnd, rect);

View File

@ -0,0 +1,115 @@
// 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/cef.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line)
{
std::string program = command_line->GetProgram();
EXPECT_EQ("test.exe", program);
EXPECT_TRUE(command_line->HasSwitches());
EXPECT_TRUE(command_line->HasSwitch("switch1"));
std::string switch1 = command_line->GetSwitchValue("switch1");
EXPECT_EQ("", switch1);
EXPECT_TRUE(command_line->HasSwitch("switch2"));
std::string switch2 = command_line->GetSwitchValue("switch2");
EXPECT_EQ("val2", switch2);
EXPECT_TRUE(command_line->HasSwitch("switch3"));
std::string switch3 = command_line->GetSwitchValue("switch3");
EXPECT_EQ("val3", switch3);
EXPECT_TRUE(command_line->HasSwitch("switch4"));
std::string switch4 = command_line->GetSwitchValue("switch4");
EXPECT_EQ("val 4", switch4);
EXPECT_FALSE(command_line->HasSwitch("switchnoexist"));
CefCommandLine::SwitchMap switches;
command_line->GetSwitches(switches);
EXPECT_EQ((size_t)4, switches.size());
bool has1 = false, has2 = false, has3 = false, has4 = false;
CefCommandLine::SwitchMap::const_iterator it = switches.begin();
for (; it != switches.end(); ++it) {
std::string name = it->first;
std::string val = it->second;
if (name == "switch1") {
has1 = true;
EXPECT_EQ("", val);
} else if (name == "switch2") {
has2 = true;
EXPECT_EQ("val2", val);
} else if (name == "switch3") {
has3 = true;
EXPECT_EQ("val3", val);
} else if (name == "switch4") {
has4 = true;
EXPECT_EQ("val 4", val);
}
}
EXPECT_TRUE(has1);
EXPECT_TRUE(has2);
EXPECT_TRUE(has3);
EXPECT_TRUE(has4);
EXPECT_TRUE(command_line->HasArguments());
CefCommandLine::ArgumentList args;
command_line->GetArguments(args);
EXPECT_EQ((size_t)2, args.size());
std::string arg0 = args[0];
EXPECT_EQ("arg1", arg0);
std::string arg1 = args[1];
EXPECT_EQ("arg 2", arg1);
}
}
// Test creating a command line from argc/argv or string.
TEST(CommandLineTest, Init)
{
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
EXPECT_TRUE(command_line.get() != NULL);
#if defined(OS_WIN)
command_line->InitFromString("test.exe --switch1 -switch2=val2 /switch3=val3 "
"-switch4=\"val 4\" arg1 \"arg 2\"");
#else
const char* args[] = {
"test.exe",
"--switch1",
"-switch2=val2",
"-switch3=val3",
"-switch4=\"val 4\"",
"arg1",
"\"arg 2\""
};
command_line->InitFromArgv(sizeof(args) / sizeof(char*), args);
#endif
VerifyCommandLine(command_line);
}
// Test creating a command line using set and append methods.
TEST(CommandLineTest, Manual)
{
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
EXPECT_TRUE(command_line.get() != NULL);
command_line->SetProgram("test.exe");
command_line->AppendSwitch("switch1");
command_line->AppendSwitchWithValue("switch2", "val2");
command_line->AppendSwitchWithValue("switch3", "val3");
command_line->AppendSwitchWithValue("switch4", "val 4");
command_line->AppendArgument("arg1");
command_line->AppendArgument("arg 2");
VerifyCommandLine(command_line);
}

View File

@ -1050,6 +1050,7 @@ class obj_analysis:
'size_t' : 'size_t',
'time_t' : 'time_t',
'bool' : 'int',
'char* const': 'char* const',
'CefCursorHandle' : 'cef_cursor_handle_t',
'CefWindowHandle' : 'cef_window_handle_t',
'CefRect' : 'cef_rect_t',