Repository navigation
Expand file tree
/
Copy pathclient_app.cpp
More file actions
143 lines (126 loc) · 4.34 KB
/
Copy pathclient_app.cpp
File metadata and controls
143 lines (126 loc) · 4.34 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
// Copyright (c) 2014 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 "client_app.h"
#include "jni_util.h"
#include "util.h"
#if defined(OS_MACOSX)
#include "util_mac.h"
#endif
namespace {
std::set<std::string>& GetTempFilesSet() {
static std::set<std::string> tempFiles;
return tempFiles;
}
} // namespace
ClientApp::ClientApp(const std::string& module_dir, const jobject app_handler)
: module_dir_(module_dir), app_handler_(NULL) {
JNIEnv* env = GetJNIEnv();
if (env)
app_handler_ = env->NewGlobalRef(app_handler);
process_handler_ = new BrowserProcessHandler(app_handler_);
}
ClientApp::~ClientApp() {
if (!app_handler_)
return;
BEGIN_ENV(env)
env->DeleteGlobalRef(app_handler_);
END_ENV(env)
}
void ClientApp::OnBeforeCommandLineProcessing(
const CefString& process_type,
CefRefPtr<CefCommandLine> command_line) {
// If the java code has registered an AppHandler, we'll forward
// the commandline processing to it before we append the essential
// switches "locale_pak" and "use-core-animation".
if (app_handler_ != NULL && process_type.empty()) {
BEGIN_ENV(env)
jstring jprocess_type = NewJNIString(env, process_type);
jobject jcommand_line =
NewJNIObject(env, "org/cef/callback/CefCommandLine_N");
if (jcommand_line != NULL) {
SetCefForJNIObject(env, jcommand_line, command_line.get(),
"CefCommandLine");
JNI_CALL_VOID_METHOD(
env, app_handler_, "onBeforeCommandLineProcessing",
"(Ljava/lang/String;Lorg/cef/callback/CefCommandLine;)V",
jprocess_type, jcommand_line);
SetCefForJNIObject<CefCommandLine>(env, jcommand_line, NULL,
"CefCommandLine");
}
END_ENV(env)
}
if (process_type.empty()) {
#if defined(OS_MACOSX)
// Specify a path for the locale.pak file because CEF will fail to locate
// it based on the app bundle structure.
const std::string& locale_path = util_mac::GetAbsPath(
module_dir_ +
"/../Frameworks/Chromium Embedded Framework.framework/"
"Resources/en.lproj/locale.pak");
command_line->AppendSwitchWithValue("locale_pak", locale_path);
// If windowed rendering is used, we need the browser window as CALayer
// due Java7 is CALayer based instead of NSLayer based.
command_line->AppendSwitch("use-core-animation");
#endif // defined(OS_MACOSX)
#if defined(OS_WIN)
// To avoid shutdown issues extensions should not be used in combination
// with multi-threaded-message-loop.
command_line->AppendSwitch("disable-extensions");
#endif
}
}
void ClientApp::OnRegisterCustomSchemes(
CefRawPtr<CefSchemeRegistrar> registrar) {
if (!app_handler_)
return;
BEGIN_ENV(env)
jobject jregistrar =
NewJNIObject(env, "org/cef/callback/CefSchemeRegistrar_N");
if (jregistrar != NULL) {
SetCefForJNIObject(env, jregistrar, registrar, "CefSchemeRegistrar");
JNI_CALL_VOID_METHOD(env, app_handler_, "onRegisterCustomSchemes",
"(Lorg/cef/callback/CefSchemeRegistrar;)V",
jregistrar);
SetCefForJNIObject<CefSchemeRegistrar>(env, jregistrar, NULL,
"CefSchemeRegistrar");
}
END_ENV(env)
}
CefRefPtr<CefBrowserProcessHandler> ClientApp::GetBrowserProcessHandler() {
return process_handler_.get();
}
#if defined(OS_MACOSX)
bool ClientApp::HandleTerminate() {
BEGIN_ENV(env)
jclass cls = FindClass(env, "org/cef/CefApp");
if (!cls) {
return false;
}
jmethodID methodId =
env->GetStaticMethodID(cls, "getInstance", "()Lorg/cef/CefApp;");
if (!methodId) {
return false;
}
jobject jcefApp = env->CallStaticObjectMethod(cls, methodId);
if (!jcefApp) {
return false;
}
JNI_CALL_VOID_METHOD(env, jcefApp, "handleBeforeTerminate", "()V");
END_ENV(env)
return true;
}
#endif // defined(OS_MACOSX)
// static
void ClientApp::registerTempFile(const std::string& tmpFile) {
GetTempFilesSet().insert(tmpFile);
}
// static
void ClientApp::eraseTempFiles() {
std::set<std::string>& tempFiles = GetTempFilesSet();
std::set<std::string>::iterator iter;
for (iter = tempFiles.begin(); iter != tempFiles.end(); ++iter) {
remove((*iter).c_str());
}
tempFiles.clear();
}