• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
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
12 // distribution.
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.
17 //
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.
29 //
30 // ---------------------------------------------------------------------------
31 //
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.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_COMMAND_LINE_H_
38 #define CEF_INCLUDE_CEF_COMMAND_LINE_H_
39 #pragma once
40 
41 #include <map>
42 #include <vector>
43 #include "include/cef_base.h"
44 
45 ///
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 should be lowercase ASCII and will be converted to
53 // such if necessary. Switch values will retain the original case and UTF8
54 // encoding. This class can be used before CefInitialize() is called.
55 ///
56 /*--cef(source=library,no_debugct_check)--*/
57 class CefCommandLine : public virtual CefBaseRefCounted {
58  public:
59   typedef std::vector<CefString> ArgumentList;
60   typedef std::map<CefString, CefString> SwitchMap;
61 
62   ///
63   // Create a new CefCommandLine instance.
64   ///
65   /*--cef(api_hash_check)--*/
66   static CefRefPtr<CefCommandLine> CreateCommandLine();
67 
68   ///
69   // Returns the singleton global CefCommandLine object. The returned object
70   // will be read-only.
71   ///
72   /*--cef(api_hash_check)--*/
73   static CefRefPtr<CefCommandLine> GetGlobalCommandLine();
74 
75   ///
76   // Returns true if this object is valid. Do not call any other methods if this
77   // function returns false.
78   ///
79   /*--cef()--*/
80   virtual bool IsValid() = 0;
81 
82   ///
83   // Returns true if the values of this object are read-only. Some APIs may
84   // expose read-only objects.
85   ///
86   /*--cef()--*/
87   virtual bool IsReadOnly() = 0;
88 
89   ///
90   // Returns a writable copy of this object.
91   ///
92   /*--cef()--*/
93   virtual CefRefPtr<CefCommandLine> Copy() = 0;
94 
95   ///
96   // Initialize the command line with the specified |argc| and |argv| values.
97   // The first argument must be the name of the program. This method is only
98   // supported on non-Windows platforms.
99   ///
100   /*--cef()--*/
101   virtual void InitFromArgv(int argc, const char* const* argv) = 0;
102 
103   ///
104   // Initialize the command line with the string returned by calling
105   // GetCommandLineW(). This method is only supported on Windows.
106   ///
107   /*--cef()--*/
108   virtual void InitFromString(const CefString& command_line) = 0;
109 
110   ///
111   // Reset the command-line switches and arguments but leave the program
112   // component unchanged.
113   ///
114   /*--cef()--*/
115   virtual void Reset() = 0;
116 
117   ///
118   // Retrieve the original command line string as a vector of strings.
119   // The argv array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* }
120   ///
121   /*--cef()--*/
122   virtual void GetArgv(std::vector<CefString>& argv) = 0;
123 
124   ///
125   // Constructs and returns the represented command line string. Use this method
126   // cautiously because quoting behavior is unclear.
127   ///
128   /*--cef()--*/
129   virtual CefString GetCommandLineString() = 0;
130 
131   ///
132   // Get the program part of the command line string (the first item).
133   ///
134   /*--cef()--*/
135   virtual CefString GetProgram() = 0;
136 
137   ///
138   // Set the program part of the command line string (the first item).
139   ///
140   /*--cef()--*/
141   virtual void SetProgram(const CefString& program) = 0;
142 
143   ///
144   // Returns true if the command line has switches.
145   ///
146   /*--cef()--*/
147   virtual bool HasSwitches() = 0;
148 
149   ///
150   // Returns true if the command line contains the given switch.
151   ///
152   /*--cef()--*/
153   virtual bool HasSwitch(const CefString& name) = 0;
154 
155   ///
156   // Returns the value associated with the given switch. If the switch has no
157   // value or isn't present this method returns the empty string.
158   ///
159   /*--cef()--*/
160   virtual CefString GetSwitchValue(const CefString& name) = 0;
161 
162   ///
163   // Returns the map of switch names and values. If a switch has no value an
164   // empty string is returned.
165   ///
166   /*--cef()--*/
167   virtual void GetSwitches(SwitchMap& switches) = 0;
168 
169   ///
170   // Add a switch to the end of the command line. If the switch has no value
171   // pass an empty value string.
172   ///
173   /*--cef()--*/
174   virtual void AppendSwitch(const CefString& name) = 0;
175 
176   ///
177   // Add a switch with the specified value to the end of the command line.
178   ///
179   /*--cef()--*/
180   virtual void AppendSwitchWithValue(const CefString& name,
181                                      const CefString& value) = 0;
182 
183   ///
184   // True if there are remaining command line arguments.
185   ///
186   /*--cef()--*/
187   virtual bool HasArguments() = 0;
188 
189   ///
190   // Get the remaining command line arguments.
191   ///
192   /*--cef()--*/
193   virtual void GetArguments(ArgumentList& arguments) = 0;
194 
195   ///
196   // Add an argument to the end of the command line.
197   ///
198   /*--cef()--*/
199   virtual void AppendArgument(const CefString& argument) = 0;
200 
201   ///
202   // Insert a command before the current command.
203   // Common for debuggers, like "valgrind" or "gdb --args".
204   ///
205   /*--cef()--*/
206   virtual void PrependWrapper(const CefString& wrapper) = 0;
207 };
208 
209 #endif  // CEF_INCLUDE_CEF_COMMAND_LINE_H_
210