44
55package org .cef ;
66
7+ import org .cef .callback .CefSchemeHandlerFactory ;
8+ import org .cef .handler .CefAppHandler ;
9+ import org .cef .handler .CefAppHandlerAdapter ;
10+
711import java .awt .event .ActionEvent ;
812import java .awt .event .ActionListener ;
913import java .io .File ;
1014import java .io .FilenameFilter ;
1115import java .nio .file .Path ;
1216import java .nio .file .Paths ;
1317import java .util .HashSet ;
18+
1419import javax .swing .SwingUtilities ;
1520import javax .swing .Timer ;
1621
17- import org .cef .callback .CefSchemeHandlerFactory ;
18- import org .cef .handler .CefAppHandler ;
19- import org .cef .handler .CefAppHandlerAdapter ;
20-
2122/**
2223 * Exposes static methods for managing the global CEF context.
2324 */
@@ -51,8 +52,8 @@ private CefVersion(int jcefCommitNo, int cefMajor, int cefMinor, int cefPatch,
5152 }
5253
5354 public String getJcefVersion () {
54- return CEF_VERSION_MAJOR + "." + CEF_VERSION_MINOR + "." + CEF_VERSION_PATCH
55- + "." + JCEF_COMMIT_NUMBER ;
55+ return CEF_VERSION_MAJOR + "." + CEF_VERSION_MINOR + "." + CEF_VERSION_PATCH + "."
56+ + JCEF_COMMIT_NUMBER ;
5657 }
5758
5859 public String getCefVersion () {
@@ -140,14 +141,14 @@ private CefApp(String[] args, CefSettings settings) throws UnsatisfiedLinkError
140141 super (args );
141142 if (settings != null ) settings_ = settings .clone ();
142143 if (OS .isWindows ()) {
143- System .loadLibrary ("jawt" );
144- System .loadLibrary ("chrome_elf" );
145- System .loadLibrary ("libcef" );
144+ SystemBootstrap .loadLibrary ("jawt" );
145+ SystemBootstrap .loadLibrary ("chrome_elf" );
146+ SystemBootstrap .loadLibrary ("libcef" );
146147
147148 // Other platforms load this library in CefApp.startup().
148- System .loadLibrary ("jcef" );
149+ SystemBootstrap .loadLibrary ("jcef" );
149150 } else if (OS .isLinux ()) {
150- System .loadLibrary ("cef" );
151+ SystemBootstrap .loadLibrary ("cef" );
151152 }
152153 if (appHandler_ == null ) {
153154 appHandler_ = this ;
@@ -312,7 +313,7 @@ public synchronized CefClient createClient() {
312313 case NEW :
313314 setState (CefAppState .INITIALIZING );
314315 initialize ();
315- // FALL THRU
316+ // FALL THRU
316317
317318 case INITIALIZING :
318319 case INITIALIZED :
@@ -401,19 +402,29 @@ public void run() {
401402 }
402403 } else if (OS .isWindows ()) {
403404 if (settings .browser_subprocess_path == null ) {
404- settings .browser_subprocess_path = library_path + "\\ jcef_helper.exe" ;
405+ Path path = Paths .get (library_path , "jcef_helper.exe" );
406+ settings .browser_subprocess_path =
407+ path .normalize ().toAbsolutePath ().toString ();
405408 }
406409 } else if (OS .isLinux ()) {
407- if (settings .browser_subprocess_path == null )
408- settings .browser_subprocess_path = library_path + "/jcef_helper" ;
409- if (settings .resources_dir_path == null )
410- settings .resources_dir_path = library_path ;
411- if (settings .locales_dir_path == null )
412- settings .locales_dir_path = library_path + "/locales" ;
410+ if (settings .browser_subprocess_path == null ) {
411+ Path path = Paths .get (library_path , "jcef_helper" );
412+ settings .browser_subprocess_path =
413+ path .normalize ().toAbsolutePath ().toString ();
414+ }
415+ if (settings .resources_dir_path == null ) {
416+ Path path = Paths .get (library_path );
417+ settings .resources_dir_path =
418+ path .normalize ().toAbsolutePath ().toString ();
419+ }
420+ if (settings .locales_dir_path == null ) {
421+ Path path = Paths .get (library_path , "locales" );
422+ settings .locales_dir_path =
423+ path .normalize ().toAbsolutePath ().toString ();
424+ }
413425 }
414426
415- if (N_Initialize (library_path , appHandler_ , settings ))
416- setState (CefAppState .INITIALIZED );
427+ if (N_Initialize (appHandler_ , settings )) setState (CefAppState .INITIALIZED );
417428 }
418429 };
419430 if (SwingUtilities .isEventDispatchThread ())
@@ -517,11 +528,13 @@ public void actionPerformed(ActionEvent evt) {
517528 * This method must be called at the beginning of the main() method to perform platform-
518529 * specific startup initialization. On Linux this initializes Xlib multithreading and on
519530 * macOS this dynamically loads the CEF framework.
531+ * @param args Command-line arguments massed to main().
532+ * @return True on successful startup.
520533 */
521- public static final boolean startup () {
534+ public static final boolean startup (String [] args ) {
522535 if (OS .isLinux () || OS .isMacintosh ()) {
523- System .loadLibrary ("jcef" );
524- return N_Startup ();
536+ SystemBootstrap .loadLibrary ("jcef" );
537+ return N_Startup (OS . isMacintosh () ? getCefFrameworkPath ( args ) : null );
525538 }
526539 return true ;
527540 }
@@ -530,7 +543,7 @@ public static final boolean startup() {
530543 * Get the path which contains the jcef library
531544 * @return The path to the jcef library
532545 */
533- private final String getJcefLibPath () {
546+ private static final String getJcefLibPath () {
534547 String library_path = System .getProperty ("java.library.path" );
535548 String [] paths = library_path .split (System .getProperty ("path.separator" ));
536549 for (String path : paths ) {
@@ -548,10 +561,27 @@ public boolean accept(File dir, String name) {
548561 return library_path ;
549562 }
550563
551- private final static native boolean N_Startup ();
564+ /**
565+ * Get the path that contains the CEF Framework on macOS.
566+ * @return The path to the CEF Framework.
567+ */
568+ private static final String getCefFrameworkPath (String [] args ) {
569+ // Check for the path on the command-line.
570+ String switchPrefix = "--framework-dir-path=" ;
571+ for (String arg : args ) {
572+ if (arg .startsWith (switchPrefix )) {
573+ return new File (arg .substring (switchPrefix .length ())).getAbsolutePath ();
574+ }
575+ }
576+
577+ // Determine the path relative to the JCEF lib location in the app bundle.
578+ return new File (getJcefLibPath () + "/../Frameworks/Chromium Embedded Framework.framework" )
579+ .getAbsolutePath ();
580+ }
581+
582+ private final static native boolean N_Startup (String pathToCefFramework );
552583 private final native boolean N_PreInitialize ();
553- private final native boolean N_Initialize (
554- String pathToJavaDLL , CefAppHandler appHandler , CefSettings settings );
584+ private final native boolean N_Initialize (CefAppHandler appHandler , CefSettings settings );
555585 private final native void N_Shutdown ();
556586 private final native void N_DoMessageLoopWork ();
557587 private final native CefVersion N_GetVersion ();
0 commit comments