-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathCefSettings.h
More file actions
437 lines (394 loc) · 19.6 KB
/
CefSettings.h
File metadata and controls
437 lines (394 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#pragma once
#include "Stdafx.h"
using namespace System::Collections::Generic;
namespace CefSharp
{
/// <summary>
/// Initialization settings. Many of these and other settings can also configured
/// using command-line switches.
/// </summary>
public ref class CefSettings
{
private:
List<CefExtension^>^ _cefExtensions;
IDictionary<String^, String^>^ _cefCommandLineArgs;
internal:
::CefSettings* _cefSettings;
List<CefCustomScheme^>^ _cefCustomSchemes;
bool _focusedNodeChangedEnabled;
public:
/// <summary>
/// Default Constructor
/// </summary>
CefSettings() : _cefSettings(new ::CefSettings())
{
_cefSettings->multi_threaded_message_loop = true;
_cefSettings->no_sandbox = true;
BrowserSubprocessPath = "CefSharp.BrowserSubprocess.exe";
_cefCustomSchemes = gcnew List<CefCustomScheme^>();
_cefExtensions = gcnew List<CefExtension^>();
_cefCommandLineArgs = gcnew Dictionary<String^, String^>();
//Automatically discovered and load a system-wide installation of Pepper Flash.
_cefCommandLineArgs->Add("enable-system-flash", "1");
//Temp workaround for https://github.com/cefsharp/CefSharp/issues/1203
_cefCommandLineArgs->Add("process-per-tab", "1");
_focusedNodeChangedEnabled = false;
}
!CefSettings()
{
delete _cefSettings;
}
~CefSettings()
{
this->!CefSettings();
}
/// <summary>
/// Add Customs schemes to this collection
/// </summary>
property IEnumerable<CefCustomScheme^>^ CefCustomSchemes
{
IEnumerable<CefCustomScheme^>^ get() { return _cefCustomSchemes; }
}
/// <summary>
/// Add CefExtensions to be registered
/// </summary>
virtual property IEnumerable<CefExtension^>^ Extensions
{
IEnumerable<CefExtension^>^ get() { return _cefExtensions; }
}
/// <summary>
/// Add custom command line argumens to this collection, they will be
/// added in OnBeforeCommandLineProcessing.
// The CefSettings.command_line_args_disabled value can be used to start with an empty command-line object. Any values specified in CefSettings that equate to command-line arguments will be set before this method is called.
/// </summary>
virtual property IDictionary<String^, String^>^ CefCommandLineArgs
{
IDictionary<String^, String^>^ get() { return _cefCommandLineArgs; }
}
/// <summary>
/// Set to true to disable configuration of browser process features using
/// standard CEF and Chromium command-line arguments. Configuration can still
/// be specified using CEF data structures or by adding to CefCommandLineArgs
/// </summary>
property bool CommandLineArgsDisabled
{
bool get() { return _cefSettings->command_line_args_disabled == 1; }
void set(bool value) { _cefSettings->command_line_args_disabled = value; }
}
/// <summary>
/// Set to true to control browser process main (UI) thread message pump
/// scheduling via the IBrowserProcessHandler.OnScheduleMessagePumpWork
/// callback. This option is recommended for use in combination with the
/// Cef.DoMessageLoopWork() function in cases where the CEF message loop must be
/// integrated into an existing application message loop (see additional
/// comments and warnings on Cef.DoMessageLoopWork). Enabling this option is not
/// recommended for most users; leave this option disabled and use either
/// MultiThreadedMessageLoop (the default) if possible.
/// </summary>
property bool ExternalMessagePump
{
bool get() { return _cefSettings->external_message_pump == 1; }
void set(bool value) { _cefSettings->external_message_pump = value; }
}
/// <summary>
//// Set to true to have the browser process message loop run in a separate
/// thread. If false than the CefDoMessageLoopWork() function must be
/// called from your application message loop. This option is only supported on
/// Windows. The default value is true
/// </summary>
property bool MultiThreadedMessageLoop
{
bool get() { return _cefSettings->multi_threaded_message_loop == 1; }
void set(bool value) { _cefSettings->multi_threaded_message_loop = value; }
}
/// <summary>
/// The path to a separate executable that will be launched for sub-processes.
/// By default the browser process executable is used. See the comments on
/// Cef.ExecuteProcess() for details. Also configurable using the
/// "browser-subprocess-path" command-line switch. Default is CefSharp.BrowserSubprocess.exe
/// </summary>
property String^ BrowserSubprocessPath
{
String^ get() { return StringUtils::ToClr(_cefSettings->browser_subprocess_path); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->browser_subprocess_path, value); }
}
/// <summary>
/// The location where cache data will be stored on disk. If empty then
/// browsers will be created in "incognito mode" where in-memory caches are
/// used for storage and no data is persisted to disk. HTML5 databases such as
/// localStorage will only persist across sessions if a cache path is
/// specified. Can be overridden for individual CefRequestContext instances via
/// the RequestContextSettings.CachePath value.
/// </summary>
property String^ CachePath
{
String^ get() { return StringUtils::ToClr(_cefSettings->cache_path); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->cache_path, value); }
}
/// <summary>
/// The location where user data such as spell checking dictionary files will
/// be stored on disk. If empty then the default platform-specific user data
/// directory will be used ("~/.cef_user_data" directory on Linux,
/// "~/Library/Application Support/CEF/User Data" directory on Mac OS X,
/// "Local Settings\Application Data\CEF\User Data" directory under the user
/// profile directory on Windows).
/// </summary>
property String^ UserDataPath
{
String^ get() { return StringUtils::ToClr(_cefSettings->user_data_path); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->user_data_path, value); }
}
/// <summary>
/// Set to true in order to completely ignore SSL certificate errors.
/// This is NOT recommended.
/// </summary>
property bool IgnoreCertificateErrors
{
bool get() { return _cefSettings->ignore_certificate_errors == 1; }
void set(bool value) { _cefSettings->ignore_certificate_errors = value; }
}
/// <summary>
/// The locale string that will be passed to WebKit. If empty the default
/// locale of "en-US" will be used. Also configurable using the "lang"
/// command-line switch.
/// </summary>
property String^ Locale
{
String^ get() { return StringUtils::ToClr(_cefSettings->locale); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->locale, value); }
}
/// <summary>
/// The fully qualified path for the locales directory. If this value is empty
/// the locales directory must be located in the module directory.
/// Also configurable using the "locales-dir-path" command-line switch.
/// </summary>
property String^ LocalesDirPath
{
String^ get() { return StringUtils::ToClr(_cefSettings->locales_dir_path); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->locales_dir_path, value); }
}
/// <summary>
/// The fully qualified path for the resources directory. If this value is
/// empty the cef.pak and/or devtools_resources.pak files must be located in
/// the module directory. Also configurable using the "resources-dir-path" command-line
/// switch.
/// </summary>
property String^ ResourcesDirPath
{
String^ get() { return StringUtils::ToClr(_cefSettings->resources_dir_path); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->resources_dir_path, value); }
}
/// <summary>
/// The directory and file name to use for the debug log. If empty a default
/// log file name and location will be used. On Windows and Linux a "debug.log"
/// file will be written in the main executable directory.
/// Also configurable using the"log-file" command-line switch.
/// </summary>
property String^ LogFile
{
String^ get() { return StringUtils::ToClr(_cefSettings->log_file); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->log_file, value); }
}
/// <summary>
/// The log severity. Only messages of this severity level or higher will be
/// logged. Also configurable using the "log-severity" command-line switch with
/// a value of "verbose", "info", "warning", "error", "error-report" or
/// "disable".
/// </summary>
property CefSharp::LogSeverity LogSeverity
{
CefSharp::LogSeverity get() { return (CefSharp::LogSeverity)_cefSettings->log_severity; }
void set(CefSharp::LogSeverity value) { _cefSettings->log_severity = (cef_log_severity_t)value; }
}
/// <summary>
/// Custom flags that will be used when initializing the V8 JavaScript engine.
/// The consequences of using custom flags may not be well tested. Also
/// configurable using the "js-flags" command-line switch.
/// </summary>
property String^ JavascriptFlags
{
String^ get() { return StringUtils::ToClr(_cefSettings->javascript_flags); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->javascript_flags, value); }
}
/// <summary>
/// Set to true to disable loading of pack files for resources and locales.
/// A resource bundle handler must be provided for the browser and render
/// processes via CefApp::GetResourceBundleHandler() if loading of pack files
/// is disabled. Also configurable using the "disable-pack-loading" command-
/// line switch.
/// </summary>
property bool PackLoadingDisabled
{
bool get() { return _cefSettings->pack_loading_disabled == 1; }
void set(bool value) { _cefSettings->pack_loading_disabled = value; }
}
/// <summary>
/// Value that will be inserted as the product portion of the default
/// User-Agent string. If empty the Chromium product version will be used. If
/// |userAgent| is specified this value will be ignored. Also configurable
/// using the "product-version" command-line switch.
/// </summary>
property String^ ProductVersion
{
String^ get() { return StringUtils::ToClr(_cefSettings->product_version); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->product_version, value); }
}
/// <summary>
/// Set to a value between 1024 and 65535 to enable remote debugging on the
/// specified port. For example, if 8080 is specified the remote debugging URL
/// will be http://localhost:8080. CEF can be remotely debugged from any CEF or
/// Chrome browser window. Also configurable using the "remote-debugging-port"
/// command-line switch.
/// </summary>
property int RemoteDebuggingPort
{
int get() { return _cefSettings->remote_debugging_port; }
void set(int value) { _cefSettings->remote_debugging_port = value; }
}
/// <summary>
/// The number of stack trace frames to capture for uncaught exceptions.
/// Specify a positive value to enable the CefRenderProcessHandler::
/// OnUncaughtException() callback. Specify 0 (default value) and
/// OnUncaughtException() will not be called. Also configurable using the
/// "uncaught-exception-stack-size" command-line switch.
/// </summary>
property int UncaughtExceptionStackSize
{
int get() { return _cefSettings->uncaught_exception_stack_size; }
void set(int value) { _cefSettings->uncaught_exception_stack_size = value; }
}
/// <summary>
/// Value that will be returned as the User-Agent HTTP header. If empty the
/// default User-Agent string will be used. Also configurable using the
/// "user-agent" command-line switch.
/// </summary>
property String^ UserAgent
{
String^ get() { return StringUtils::ToClr(_cefSettings->user_agent); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->user_agent, value); }
}
/// <summary>
/// Set to true (1) to enable windowless (off-screen) rendering support. Do not
/// enable this value if the application does not use windowless rendering as
/// it may reduce rendering performance on some systems.
/// </summary>
property bool WindowlessRenderingEnabled
{
bool get() { return _cefSettings->windowless_rendering_enabled == 1; }
void set(bool value) { _cefSettings->windowless_rendering_enabled = value; }
}
/// <summary>
/// To persist session cookies (cookies without an expiry date or validity
/// interval) by default when using the global cookie manager set this value to
/// true. Session cookies are generally intended to be transient and most
/// Web browsers do not persist them. A CachePath value must also be
/// specified to enable this feature. Also configurable using the
/// "persist-session-cookies" command-line switch. Can be overridden for
/// individual RequestContext instances via the
/// RequestContextSettings.PersistSessionCookies value.
/// </summary>
property bool PersistSessionCookies
{
bool get() { return _cefSettings->persist_session_cookies == 1; }
void set(bool value) { _cefSettings->persist_session_cookies = value; }
}
/// <summary>
/// To persist user preferences as a JSON file in the cache path directory set
/// this value to true. A CachePath value must also be specified
/// to enable this feature. Also configurable using the
/// "persist-user-preferences" command-line switch. Can be overridden for
/// individual RequestContext instances via the
/// RequestContextSettings.PersistUserPreferences value.
/// </summary>
property bool PersistUserPreferences
{
bool get() { return _cefSettings->persist_user_preferences == 1; }
void set(bool value) { _cefSettings->persist_user_preferences = value; }
}
/// <summary>
/// Comma delimited ordered list of language codes without any whitespace that
/// will be used in the "Accept-Language" HTTP header. May be set globally
/// using the CefSettings.AcceptLanguageList value. If both values are
/// empty then "en-US,en" will be used.
/// </summary>
property String^ AcceptLanguageList
{
String^ get() { return StringUtils::ToClr(_cefSettings->accept_language_list); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->accept_language_list, value); }
}
/// <summary>
/// If true a message will be sent from the render subprocess to the
/// browser when a DOM node (or no node) gets focus. The default is
/// false.
/// </summary>
property bool FocusedNodeChangedEnabled
{
bool get() { return _focusedNodeChangedEnabled; }
void set(bool value) { _focusedNodeChangedEnabled = value; }
}
/// <summary>
/// Registers a custom scheme using the provided settings.
/// </summary>
/// <param name="cefCustomScheme">The CefCustomScheme which provides the details about the scheme.</param>
void RegisterScheme(CefCustomScheme^ cefCustomScheme)
{
_cefCustomSchemes->Add(cefCustomScheme);
}
/// <summary>
/// Registers an extension with the provided settings.
/// </summary>
/// <param name="extension">The CefExtension that contains the extension code.</param>
void RegisterExtension(CefExtension^ extension)
{
if (_cefExtensions->Contains(extension))
{
throw gcnew ArgumentException("An extension with the same name is already registered.", "extension");
}
_cefExtensions->Add(extension);
}
/// <summary>
/// Set command line argument to disable GPU Acceleration, this will disable WebGL.
/// </summary>
void DisableGpuAcceleration()
{
if (!_cefCommandLineArgs->ContainsKey("disable-gpu"))
{
_cefCommandLineArgs->Add("disable-gpu", "1");
}
}
/// <summary>
/// Set command line arguments for best OSR (Offscreen and WPF) Rendering performance
/// This will disable WebGL, look at the source to determine which flags best suite
/// your requirements.
/// </summary>
void SetOffScreenRenderingBestPerformanceArgs()
{
// Use software rendering and compositing (disable GPU) for increased FPS
// and decreased CPU usage. This will also disable WebGL so remove these
// switches if you need that capability.
// See https://bitbucket.org/chromiumembedded/cef/issues/1257 for details.
if (!_cefCommandLineArgs->ContainsKey("disable-gpu"))
{
_cefCommandLineArgs->Add("disable-gpu", "1");
}
if (!_cefCommandLineArgs->ContainsKey("disable-gpu-compositing"))
{
_cefCommandLineArgs->Add("disable-gpu-compositing", "1");
}
// Synchronize the frame rate between all processes. This results in
// decreased CPU usage by avoiding the generation of extra frames that
// would otherwise be discarded. The frame rate can be set at browser
// creation time via CefBrowserSettings.windowless_frame_rate or changed
// dynamically using CefBrowserHost::SetWindowlessFrameRate. In cefclient
// it can be set via the command-line using `--off-screen-frame-rate=XX`.
// See https://bitbucket.org/chromiumembedded/cef/issues/1368 for details.
if (!_cefCommandLineArgs->ContainsKey("enable-begin-frame-scheduling"))
{
_cefCommandLineArgs->Add("enable-begin-frame-scheduling", "1");
}
}
};
}