This repository was archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 601
Expand file tree
/
Copy pathcefclient.cpp
More file actions
119 lines (98 loc) · 4.19 KB
/
cefclient.cpp
File metadata and controls
119 lines (98 loc) · 4.19 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
// Copyright (c) 2010 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.
#include "cefclient.h"
#include <stdio.h>
#include <cstdlib>
#include <sstream>
#include <string>
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_web_plugin.h"
#include "include/base/cef_logging.h"
#include "client_handler.h"
#include "appshell/common/client_switches.h"
#include "appshell/appshell_helpers.h"
#include "config.h"
CefRefPtr<ClientHandler> g_handler;
bool g_force_enable_acc = false;
CefRefPtr<CefBrowser> AppGetBrowser() {
if (!g_handler.get())
return NULL;
return g_handler->GetBrowser();
}
CefWindowHandle AppGetMainHwnd() {
if (!g_handler.get())
return NULL;
return g_handler->GetMainHwnd();
}
// CefCommandLine::HasSwitch is unable to report the presense of switches,
// in the command line properly. This is a generic function that could be
// used to check for any particular switch, passed as a command line argument.
bool HasSwitch(CefRefPtr<CefCommandLine> command_line , CefString& switch_name)
{
if (command_line) {
ExtensionString cmdLine = command_line->GetCommandLineString();
size_t idx = cmdLine.find(switch_name);
return idx > 0 && idx < cmdLine.length();
} else {
return false;
}
}
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<CefCommandLine> command_line) {
DCHECK(command_line.get());
if (!command_line.get())
return;
#if defined(OS_WIN)
settings.multi_threaded_message_loop =
command_line->HasSwitch(client::switches::kMultiThreadedMessageLoop);
#endif
CefString(&settings.cache_path) =
command_line->GetSwitchValue(client::switches::kCachePath);
CefString(&settings.log_file) =
command_line->GetSwitchValue(client::switches::kLogFile);
{
std::string str = command_line->GetSwitchValue(client::switches::kLogSeverity);
// Default to LOGSEVERITY_DISABLE
settings.log_severity = LOGSEVERITY_DISABLE;
if (!str.empty()) {
if (str == client::switches::kLogSeverity_Verbose)
settings.log_severity = LOGSEVERITY_VERBOSE;
else if (str == client::switches::kLogSeverity_Info)
settings.log_severity = LOGSEVERITY_INFO;
else if (str == client::switches::kLogSeverity_Warning)
settings.log_severity = LOGSEVERITY_WARNING;
else if (str == client::switches::kLogSeverity_Error)
settings.log_severity = LOGSEVERITY_ERROR;
else if (str == client::switches::kLogSeverity_Disable)
settings.log_severity = LOGSEVERITY_DISABLE;
}
}
// Don't update the settings.locale with the locale that we detected from the OS.
// Otherwise, CEF will use it to find the resources and when it fails in finding resources
// for some locales that are not available in resources, it crashes.
//CefString(&settings.locale) = appshell::GetCurrentLanguage( );
CefString(&settings.javascript_flags) =
command_line->GetSwitchValue(client::switches::kJavascriptFlags);
// Enable dev tools
settings.remote_debugging_port = REMOTE_DEBUGGING_PORT;
std::wstring versionStr = appshell::AppGetProductVersionString();
if (!versionStr.empty()) {
// Explicitly append the Chromium version to our own product version string
// since assigning product version always replaces the Chromium version in
// the User Agent string.
versionStr.append(L" ");
versionStr.append(appshell::AppGetChromiumVersionString());
// Set product version, which gets added to the User Agent string
CefString(&settings.product_version) = versionStr;
}
// We disable renderer accessibility by default as it is known to cause performance
// issues. But if any one wants to enable it back, then we need to honor the flag.
CefString force_acc_switch_name("--force-renderer-accessibility");
CefString enable_acc_switch_name("--enable-renderer-accessibility");
if (HasSwitch(command_line, force_acc_switch_name) || HasSwitch(command_line, enable_acc_switch_name))
g_force_enable_acc = true;
}