-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathCefApp.cpp
118 lines (101 loc) · 4.18 KB
/
CefApp.cpp
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
// Copyright (c) 2013 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 "CefApp.h"
#include <string>
#include "include/cef_app.h"
#include "include/cef_version.h"
#include "context.h"
#include "jcef_version.h"
#include "jni_util.h"
#include "scheme_handler_factory.h"
#include "util.h"
#if defined(OS_LINUX)
#include <X11/Xlib.h>
#endif
JNIEXPORT jboolean JNICALL Java_org_cef_CefApp_N_1PreInitialize(JNIEnv* env,
jobject c) {
#if !defined(OS_MACOSX)
// On macOS this is called from Startup().
Context::Create();
#endif
return Context::GetInstance()->PreInitialize(env, c) ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jboolean JNICALL
Java_org_cef_CefApp_N_1Initialize(JNIEnv* env,
jobject c,
jobject appHandler,
jobject jsettings) {
return Context::GetInstance()->Initialize(env, c, appHandler, jsettings)
? JNI_TRUE
: JNI_FALSE;
}
JNIEXPORT void JNICALL Java_org_cef_CefApp_N_1Shutdown(JNIEnv* env, jobject) {
Context::GetInstance()->Shutdown();
Context::Destroy();
}
JNIEXPORT void JNICALL Java_org_cef_CefApp_N_1DoMessageLoopWork(JNIEnv* env,
jobject) {
Context::GetInstance()->DoMessageLoopWork();
}
JNIEXPORT jobject JNICALL Java_org_cef_CefApp_N_1GetVersion(JNIEnv* env,
jobject obj) {
return NewJNIObject(env, "org/cef/CefApp$CefVersion",
"(Lorg/cef/CefApp;IIIIIIIII)V", obj, JCEF_COMMIT_NUMBER,
cef_version_info(0), // CEF_VERSION_MAJOR
cef_version_info(1), // CEF_VERSION_MINOR
cef_version_info(2), // CEF_VERSION_PATCH
cef_version_info(3), // CEF_COMMIT_NUMBER
cef_version_info(4), // CHROME_VERSION_MAJOR
cef_version_info(5), // CHROME_VERSION_MINOR
cef_version_info(6), // CHROME_VERSION_BUILD
cef_version_info(7)); // CHROME_VERSION_PATCH
}
JNIEXPORT jboolean JNICALL
Java_org_cef_CefApp_N_1RegisterSchemeHandlerFactory(JNIEnv* env,
jobject,
jstring jSchemeName,
jstring jDomainName,
jobject jFactory) {
if (!jFactory)
return JNI_FALSE;
CefRefPtr<SchemeHandlerFactory> factory =
new SchemeHandlerFactory(env, jFactory);
if (!factory)
return JNI_FALSE;
bool result = CefRegisterSchemeHandlerFactory(GetJNIString(env, jSchemeName),
GetJNIString(env, jDomainName),
factory.get());
return result ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jboolean JNICALL
Java_org_cef_CefApp_N_1ClearSchemeHandlerFactories(JNIEnv*, jobject) {
return CefClearSchemeHandlerFactories() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jboolean JNICALL
Java_org_cef_CefApp_N_1Startup(JNIEnv* env,
jclass,
jstring pathToCefFramework) {
#if defined(OS_LINUX)
XInitThreads();
#elif defined(OS_MACOSX)
// Can't use GetJNIString before the CEF library is loaded.
std::string framework_path;
if (pathToCefFramework) {
const char* chr = env->GetStringUTFChars(pathToCefFramework, nullptr);
if (chr) {
framework_path = chr;
env->ReleaseStringUTFChars(pathToCefFramework, chr);
}
}
framework_path += "/Chromium Embedded Framework";
// Load the CEF framework library at runtime instead of linking directly
// as required by the macOS sandbox implementation.
if (!cef_load_library(framework_path.c_str()))
return JNI_FALSE;
// The Context object has members that can't be initialized until after the
// CEF framework is loaded.
Context::Create();
#endif // defined(OS_MACOSX)
return JNI_TRUE;
}