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
114 lines (96 loc) · 3.68 KB
/
cefclient.cpp
File metadata and controls
114 lines (96 loc) · 3.68 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
// 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_runnable.h"
#include "include/cef_web_plugin.h"
#include "client_handler.h"
#include "client_switches.h"
#include "string_util.h"
#include "util.h"
#include "config.h"
CefRefPtr<ClientHandler> g_handler;
CefRefPtr<CefCommandLine> g_command_line;
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();
}
void AppInitCommandLine(int argc, const char* const* argv) {
g_command_line = CefCommandLine::CreateCommandLine();
#if defined(OS_WIN)
g_command_line->InitFromString(::GetCommandLineW());
#else
g_command_line->InitFromArgv(argc, argv);
#endif
}
// Returns the application command line object.
CefRefPtr<CefCommandLine> AppGetCommandLine() {
return g_command_line;
}
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) {
ASSERT(app.get());
ASSERT(g_command_line.get());
if (!g_command_line.get())
return;
#if defined(OS_WIN)
settings.multi_threaded_message_loop =
g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop);
#endif
settings.persist_session_cookies = true;
CefString(&settings.cache_path) =
g_command_line->GetSwitchValue(cefclient::kCachePath);
CefString(&settings.log_file) =
g_command_line->GetSwitchValue(cefclient::kLogFile);
{
std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity);
// Default to LOGSEVERITY_DISABLE
settings.log_severity = LOGSEVERITY_DISABLE;
if (!str.empty()) {
if (str == cefclient::kLogSeverity_Verbose)
settings.log_severity = LOGSEVERITY_VERBOSE;
else if (str == cefclient::kLogSeverity_Info)
settings.log_severity = LOGSEVERITY_INFO;
else if (str == cefclient::kLogSeverity_Warning)
settings.log_severity = LOGSEVERITY_WARNING;
else if (str == cefclient::kLogSeverity_Error)
settings.log_severity = LOGSEVERITY_ERROR;
else if (str == cefclient::kLogSeverity_ErrorReport)
settings.log_severity = LOGSEVERITY_ERROR_REPORT;
else if (str == cefclient::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) = app->GetCurrentLanguage( );
CefString(&settings.javascript_flags) =
g_command_line->GetSwitchValue(cefclient::kJavascriptFlags);
// Enable dev tools
settings.remote_debugging_port = REMOTE_DEBUGGING_PORT;
std::wstring versionStr = 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(AppGetChromiumVersionString());
// Set product version, which gets added to the User Agent string
CefString(&settings.product_version) = versionStr;
}
}