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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/command_line_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
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"
|
2021-09-27 12:36:08 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
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
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
CefCommandLineImpl::CefCommandLineImpl(const base::CommandLine& value)
|
|
|
|
: CefCommandLineImpl(const_cast<base::CommandLine*>(&value),
|
|
|
|
/*will_delete=*/false,
|
|
|
|
/*read_only=*/true) {}
|
|
|
|
|
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) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if !BUILDFLAG(IS_WIN)
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->InitFromArgv(argc, argv);
|
|
|
|
#else
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "method not supported on this platform";
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::InitFromString(const CefString& command_line) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::wstring& str16 = command_line;
|
2019-02-21 01:42:36 +01:00
|
|
|
mutable_value()->ParseFromString(str16);
|
2012-04-03 03:34:16 +02:00
|
|
|
#else
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "method not supported on this platform";
|
2012-04-03 03:34:16 +02:00
|
|
|
#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();
|
2023-01-02 23:59:03 +01:00
|
|
|
for (; it != cmd_argv.end(); ++it) {
|
2012-09-04 17:12:50 +02:00
|
|
|
argv.push_back(*it);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-09-04 17:12:50 +02:00
|
|
|
}
|
|
|
|
|
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);
|
2021-09-27 12:36:08 +02:00
|
|
|
return const_value().HasSwitch(base::ToLowerASCII(name.ToString()));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefCommandLineImpl::GetSwitchValue(const CefString& name) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
2021-09-27 12:36:08 +02:00
|
|
|
return const_value().GetSwitchValueNative(
|
|
|
|
base::ToLowerASCII(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();
|
2023-01-02 23:59:03 +01:00
|
|
|
for (; it != map.end(); ++it) {
|
2012-04-03 03:34:16 +02:00
|
|
|
switches.insert(std::make_pair(it->first, it->second));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::AppendSwitch(const CefString& name) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2021-06-04 03:34:56 +02:00
|
|
|
mutable_value()->AppendSwitch(name.ToString());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::AppendSwitchWithValue(const CefString& name,
|
|
|
|
const CefString& value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-04 03:34:56 +02:00
|
|
|
mutable_value()->AppendSwitchNative(name.ToString(), value.ToWString());
|
2020-08-29 00:39:23 +02:00
|
|
|
#else
|
2021-06-04 03:34:56 +02:00
|
|
|
mutable_value()->AppendSwitchNative(name.ToString(), value.ToString());
|
2020-08-29 00:39:23 +02:00
|
|
|
#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();
|
2023-01-02 23:59:03 +01:00
|
|
|
for (; it != vec.end(); ++it) {
|
2012-04-03 03:34:16 +02:00
|
|
|
arguments.push_back(*it);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefCommandLineImpl::AppendArgument(const CefString& argument) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-04 03:34:56 +02:00
|
|
|
mutable_value()->AppendArgNative(argument.ToWString());
|
|
|
|
#else
|
|
|
|
mutable_value()->AppendArgNative(argument.ToString());
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-09-27 19:07:31 +02:00
|
|
|
void CefCommandLineImpl::PrependWrapper(const CefString& wrapper) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-04 03:34:56 +02:00
|
|
|
mutable_value()->PrependWrapper(wrapper.ToWString());
|
|
|
|
#else
|
|
|
|
mutable_value()->PrependWrapper(wrapper.ToString());
|
|
|
|
#endif
|
2012-09-27 19:07:31 +02:00
|
|
|
}
|
|
|
|
|
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();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (command_line) {
|
2012-04-03 03:34:16 +02:00
|
|
|
commandLinePtr = new CefCommandLineImpl(command_line, false, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
return commandLinePtr.get();
|
|
|
|
}
|