2012-04-03 03:34:16 +02:00
|
|
|
// 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 "libcef/common/command_line_impl.h"
|
|
|
|
|
2013-02-27 18:56:03 +01:00
|
|
|
#include "base/files/file_path.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
CefCommandLineImpl::CefCommandLineImpl(base::CommandLine* value,
|
2012-04-03 03:34:16 +02:00
|
|
|
bool will_delete,
|
|
|
|
bool read_only)
|
2017-05-17 11:29:28 +02:00
|
|
|
: CefValueBase<CefCommandLine, base::CommandLine>(
|
|
|
|
value,
|
2020-01-15 14:36:24 +01:00
|
|
|
nullptr,
|
2017-05-17 11:29:28 +02:00
|
|
|
will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
|
|
|
read_only,
|
2020-01-15 14:36:24 +01:00
|
|
|
nullptr) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
bool CefCommandLineImpl::IsValid() {
|
|
|
|
return !detached();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCommandLineImpl::IsReadOnly() {
|
|
|
|
return read_only();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefCommandLine> CefCommandLineImpl::Copy() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2017-05-17 11:29:28 +02:00
|
|
|
return new CefCommandLineImpl(new base::CommandLine(const_value().argv()),
|
|
|
|
true, false);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::InitFromArgv(int argc, const char* const* argv) {
|
|
|
|
#if !defined(OS_WIN)
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->InitFromArgv(argc, argv);
|
|
|
|
#else
|
|
|
|
NOTREACHED() << "method not supported on this platform";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::InitFromString(const CefString& command_line) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2019-02-21 01:42:36 +01:00
|
|
|
const base::string16& str16 = command_line;
|
|
|
|
mutable_value()->ParseFromString(str16);
|
2012-04-03 03:34:16 +02:00
|
|
|
#else
|
|
|
|
NOTREACHED() << "method not supported on this platform";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::Reset() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2015-01-09 18:22:10 +01:00
|
|
|
base::CommandLine::StringVector argv;
|
2012-04-03 03:34:16 +02:00
|
|
|
argv.push_back(mutable_value()->GetProgram().value());
|
|
|
|
mutable_value()->InitFromArgv(argv);
|
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine::SwitchMap& map = mutable_value()->GetSwitches();
|
|
|
|
const_cast<base::CommandLine::SwitchMap*>(&map)->clear();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 17:12:50 +02:00
|
|
|
void CefCommandLineImpl::GetArgv(std::vector<CefString>& argv) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(false);
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine::StringVector& cmd_argv = const_value().argv();
|
|
|
|
base::CommandLine::StringVector::const_iterator it = cmd_argv.begin();
|
2012-09-04 17:12:50 +02:00
|
|
|
for (; it != cmd_argv.end(); ++it)
|
|
|
|
argv.push_back(*it);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefString CefCommandLineImpl::GetCommandLineString() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetCommandLineString();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefCommandLineImpl::GetProgram() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetProgram().value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::SetProgram(const CefString& program) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2013-02-23 01:43:28 +01:00
|
|
|
mutable_value()->SetProgram(base::FilePath(program));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCommandLineImpl::HasSwitches() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return (const_value().GetSwitches().size() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCommandLineImpl::HasSwitch(const CefString& name) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2015-06-06 00:06:48 +02:00
|
|
|
return const_value().HasSwitch(name.ToString());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefCommandLineImpl::GetSwitchValue(const CefString& name) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
2015-06-06 00:06:48 +02:00
|
|
|
return const_value().GetSwitchValueNative(name.ToString());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::GetSwitches(SwitchMap& switches) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(false);
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine::SwitchMap& map = const_value().GetSwitches();
|
|
|
|
base::CommandLine::SwitchMap::const_iterator it = map.begin();
|
2012-04-03 03:34:16 +02:00
|
|
|
for (; it != map.end(); ++it)
|
|
|
|
switches.insert(std::make_pair(it->first, it->second));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::AppendSwitch(const CefString& name) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->AppendSwitch(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::AppendSwitchWithValue(const CefString& name,
|
|
|
|
const CefString& value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
mutable_value()->AppendSwitchNative(name, value.ToWString());
|
|
|
|
#else
|
|
|
|
mutable_value()->AppendSwitchNative(name, value.ToString());
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCommandLineImpl::HasArguments() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return (const_value().GetArgs().size() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::GetArguments(ArgumentList& arguments) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(false);
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine::StringVector& vec = const_value().GetArgs();
|
|
|
|
base::CommandLine::StringVector::const_iterator it = vec.begin();
|
2012-04-03 03:34:16 +02:00
|
|
|
for (; it != vec.end(); ++it)
|
|
|
|
arguments.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::AppendArgument(const CefString& argument) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->AppendArgNative(argument);
|
|
|
|
}
|
|
|
|
|
2012-09-27 19:07:31 +02:00
|
|
|
void CefCommandLineImpl::PrependWrapper(const CefString& wrapper) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->PrependWrapper(wrapper);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefCommandLine implementation.
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefCommandLine> CefCommandLine::CreateCommandLine() {
|
|
|
|
return new CefCommandLineImpl(
|
2015-01-09 18:22:10 +01:00
|
|
|
new base::CommandLine(base::CommandLine::NO_PROGRAM), true, false);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefCommandLine> CefCommandLine::GetGlobalCommandLine() {
|
|
|
|
// Uses a singleton reference object.
|
|
|
|
static CefRefPtr<CefCommandLineImpl> commandLinePtr;
|
|
|
|
if (!commandLinePtr.get()) {
|
2015-01-09 18:22:10 +01:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (command_line)
|
|
|
|
commandLinePtr = new CefCommandLineImpl(command_line, false, true);
|
|
|
|
}
|
|
|
|
return commandLinePtr.get();
|
|
|
|
}
|