Skip to content

Commit fbfa920

Browse files
jjlauermagreenblatt
authored andcommitted
Add SystemBootstrap class to support custom implementation of loadLibrary.
Client can provide their own implementation that calls System.load with absolute paths instead of using the default System.loadLibrary implementation.
1 parent 0270948 commit fbfa920

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

java/org/cef/CefApp.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ private CefApp(String[] args, CefSettings settings) throws UnsatisfiedLinkError
140140
super(args);
141141
if (settings != null) settings_ = settings.clone();
142142
if (OS.isWindows()) {
143-
System.loadLibrary("jawt");
144-
System.loadLibrary("chrome_elf");
145-
System.loadLibrary("libcef");
143+
SystemBootstrap.loadLibrary("jawt");
144+
SystemBootstrap.loadLibrary("chrome_elf");
145+
SystemBootstrap.loadLibrary("libcef");
146146

147147
// Other platforms load this library in CefApp.startup().
148-
System.loadLibrary("jcef");
148+
SystemBootstrap.loadLibrary("jcef");
149149
} else if (OS.isLinux()) {
150-
System.loadLibrary("cef");
150+
SystemBootstrap.loadLibrary("cef");
151151
}
152152
if (appHandler_ == null) {
153153
appHandler_ = this;
@@ -520,7 +520,7 @@ public void actionPerformed(ActionEvent evt) {
520520
*/
521521
public static final boolean startup() {
522522
if (OS.isLinux() || OS.isMacintosh()) {
523-
System.loadLibrary("jcef");
523+
SystemBootstrap.loadLibrary("jcef");
524524
return N_Startup();
525525
}
526526
return true;

java/org/cef/SystemBootstrap.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2020 The Chromium Embedded Framework Authors. All rights
2+
// reserved. Use of this source code is governed by a BSD-style license that
3+
// can be found in the LICENSE file.
4+
package org.cef;
5+
6+
/**
7+
* To allow customization of System.load() calls by supplying a different
8+
* implementation. You'll want to call <code>setLoader</code> with your custom
9+
* implementation before calling into any other CEF classes which then in turn
10+
* will start triggering libraries to be loaded at runtime.
11+
*/
12+
public class SystemBootstrap {
13+
/**
14+
* Simple interface for how a library by name should be loaded.
15+
*/
16+
static public interface Loader { public void loadLibrary(String libname); }
17+
18+
/**
19+
* Default implementation is to call System.loadLibrary
20+
*/
21+
static private Loader loader_ = new Loader() {
22+
@Override
23+
public void loadLibrary(String libname) {
24+
System.loadLibrary(libname);
25+
}
26+
};
27+
28+
static public void setLoader(Loader loader) {
29+
if (loader == null) {
30+
throw new NullPointerException("Loader cannot be null");
31+
}
32+
loader_ = loader;
33+
}
34+
35+
static public void loadLibrary(String libname) {
36+
loader_.loadLibrary(libname);
37+
}
38+
}

0 commit comments

Comments
 (0)