2011-11-15 00:43:52 +01:00
|
|
|
// 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.
|
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_command_line.h"
|
2011-11-15 00:43:52 +01:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/file_path.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
class CefCommandLineImpl : public CefCommandLine {
|
|
|
|
public:
|
2011-11-15 00:43:52 +01:00
|
|
|
CefCommandLineImpl()
|
2012-01-10 00:46:23 +01:00
|
|
|
: command_line_(CommandLine::NO_PROGRAM) {
|
2011-11-15 00:43:52 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void InitFromArgv(int argc, const char* const* argv) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
#if !defined(OS_WIN)
|
|
|
|
AutoLock lock_scope(this);
|
|
|
|
command_line_.InitFromArgv(argc, argv);
|
|
|
|
#else
|
|
|
|
NOTREACHED() << "method not supported on this platform";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void InitFromString(const CefString& command_line) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
AutoLock lock_scope(this);
|
|
|
|
command_line_.ParseFromString(command_line);
|
|
|
|
#else
|
|
|
|
NOTREACHED() << "method not supported on this platform";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual CefString GetCommandLineString() OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return command_line_.GetCommandLineString();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual CefString GetProgram() OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return command_line_.GetProgram().value();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void SetProgram(const CefString& program) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
2013-02-26 00:44:37 +01:00
|
|
|
command_line_.SetProgram(base::FilePath(program));
|
2011-11-15 00:43:52 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual bool HasSwitches() OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return (command_line_.GetSwitches().size() > 0);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual bool HasSwitch(const CefString& name) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return command_line_.HasSwitch(name);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual CefString GetSwitchValue(const CefString& name) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return command_line_.GetSwitchValueNative(name);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void GetSwitches(SwitchMap& switches) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void AppendSwitch(const CefString& name) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
command_line_.AppendSwitch(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void AppendSwitchWithValue(const CefString& name,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& value) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
command_line_.AppendSwitchNative(name, value);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual bool HasArguments() OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return (command_line_.GetArgs().size() > 0);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void GetArguments(ArgumentList& arguments) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void AppendArgument(const CefString& argument) OVERRIDE {
|
2011-11-15 00:43:52 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
command_line_.AppendArgNative(argument);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
private:
|
2011-11-15 00:43:52 +01:00
|
|
|
CommandLine command_line_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefCommandLineImpl);
|
|
|
|
IMPLEMENT_LOCKING(CefCommandLineImpl);
|
|
|
|
};
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
} // namespace
|
2011-11-15 00:43:52 +01:00
|
|
|
|
|
|
|
// static
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefCommandLine> CefCommandLine::CreateCommandLine() {
|
2011-11-15 00:43:52 +01:00
|
|
|
return new CefCommandLineImpl();
|
|
|
|
}
|