1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
37 #ifndef CEF_INCLUDE_CEF_COMMAND_LINE_H_
38 #define CEF_INCLUDE_CEF_COMMAND_LINE_H_
41 #include "include/cef_base.h"
46 // Class used to create and/or parse command line arguments. Arguments with
47 // '--', '-' and, on Windows, '/' prefixes are considered switches. Switches
48 // will always precede any arguments without switch prefixes. Switches can
49 // optionally have a value specified using the '=' delimiter (e.g.
50 // "-switch=value"). An argument of "--" will terminate switch parsing with all
51 // subsequent tokens, regardless of prefix, being interpreted as non-switch
52 // arguments. Switch names are considered case-insensitive. This class can be
53 // used before CefInitialize() is called.
55 /*--cef(source=library,no_debugct_check)--*/
56 class CefCommandLine : public virtual CefBase {
58 typedef std::vector<CefString> ArgumentList;
59 typedef std::map<CefString, CefString> SwitchMap;
62 // Create a new CefCommandLine instance.
64 /*--cef(api_hash_check)--*/
65 static CefRefPtr<CefCommandLine> CreateCommandLine();
68 // Returns the singleton global CefCommandLine object. The returned object
71 /*--cef(api_hash_check)--*/
72 static CefRefPtr<CefCommandLine> GetGlobalCommandLine();
75 // Returns true if this object is valid. Do not call any other methods if this
76 // function returns false.
79 virtual bool IsValid() =0;
82 // Returns true if the values of this object are read-only. Some APIs may
83 // expose read-only objects.
86 virtual bool IsReadOnly() =0;
89 // Returns a writable copy of this object.
92 virtual CefRefPtr<CefCommandLine> Copy() =0;
95 // Initialize the command line with the specified |argc| and |argv| values.
96 // The first argument must be the name of the program. This method is only
97 // supported on non-Windows platforms.
100 virtual void InitFromArgv(int argc, const char* const* argv) =0;
103 // Initialize the command line with the string returned by calling
104 // GetCommandLineW(). This method is only supported on Windows.
107 virtual void InitFromString(const CefString& command_line) =0;
110 // Reset the command-line switches and arguments but leave the program
111 // component unchanged.
114 virtual void Reset() =0;
117 // Retrieve the original command line string as a vector of strings.
118 // The argv array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* }
121 virtual void GetArgv(std::vector<CefString>& argv) =0;
124 // Constructs and returns the represented command line string. Use this method
125 // cautiously because quoting behavior is unclear.
128 virtual CefString GetCommandLineString() =0;
131 // Get the program part of the command line string (the first item).
134 virtual CefString GetProgram() =0;
137 // Set the program part of the command line string (the first item).
140 virtual void SetProgram(const CefString& program) =0;
143 // Returns true if the command line has switches.
146 virtual bool HasSwitches() =0;
149 // Returns true if the command line contains the given switch.
152 virtual bool HasSwitch(const CefString& name) =0;
155 // Returns the value associated with the given switch. If the switch has no
156 // value or isn't present this method returns the empty string.
159 virtual CefString GetSwitchValue(const CefString& name) =0;
162 // Returns the map of switch names and values. If a switch has no value an
163 // empty string is returned.
166 virtual void GetSwitches(SwitchMap& switches) =0;
169 // Add a switch to the end of the command line. If the switch has no value
170 // pass an empty value string.
173 virtual void AppendSwitch(const CefString& name) =0;
176 // Add a switch with the specified value to the end of the command line.
179 virtual void AppendSwitchWithValue(const CefString& name,
180 const CefString& value) =0;
183 // True if there are remaining command line arguments.
186 virtual bool HasArguments() =0;
189 // Get the remaining command line arguments.
192 virtual void GetArguments(ArgumentList& arguments) =0;
195 // Add an argument to the end of the command line.
198 virtual void AppendArgument(const CefString& argument) =0;
201 // Insert a command before the current command.
202 // Common for debuggers, like "valgrind" or "gdb --args".
205 virtual void PrependWrapper(const CefString& wrapper) =0;
208 #endif // CEF_INCLUDE_CEF_COMMAND_LINE_H_