Search in sources :

Example 1 with CefSettings

use of org.cef.CefSettings in project CodenameOne by codenameone.

the class CEFBrowserComponent method create.

public static CEFBrowserComponent create(final String startingURL, final CEFBrowserComponentListener parent) {
    CefSettings settings = new CefSettings();
    String[] args = createArgs();
    // Perform startup initialization on platforms that require it.
    if (!"true".equals(System.getProperty("cef.started", "false"))) {
        if (!CefApp.startup(args)) {
            System.err.println("CEFStartup initialization failed");
            throw new RuntimeException("CEF Startup initialization failed!");
        }
        System.setProperty("cef.started", "true");
    }
    // OSR mode is enabled by default on Linux.
    // and disabled by default on Windows and Mac OS X.
    boolean osrEnabledArg = true;
    boolean transparentPaintingEnabledArg = true;
    boolean createImmediately = true;
    for (String arg : args) {
        arg = arg.toLowerCase();
        if (arg.equals("--off-screen-rendering-enabled")) {
            osrEnabledArg = true;
        } else if (arg.equals("--transparent-painting-enabled")) {
            transparentPaintingEnabledArg = true;
        } else if (arg.equals("--create-immediately")) {
            createImmediately = true;
        }
    }
    CEFPeerComponentBuffer buffer = new CEFPeerComponentBuffer();
    final WeakReference<CEFBrowserComponentListener> parentRef = new WeakReference<CEFBrowserComponentListener>(parent);
    BrowserNavigationCallback navigationCallback = new BrowserNavigationCallback() {

        private CEFBrowserComponentListener l = parentRef.get();

        @Override
        public boolean shouldNavigate(String url) {
            // CEFBrowserComponentListener l = parentRef.get();
            if (l != null) {
                return l.shouldNavigate(url);
            }
            return false;
        }
    };
    final BrowserPanel panel = new BrowserPanel(startingURL, buffer, navigationCallback, osrEnabledArg, transparentPaintingEnabledArg, createImmediately, args) {

        private CEFBrowserComponentListener p = parentRef.get();

        @Override
        protected void onError(ActionEvent l) {
            // CEFBrowserComponentListener p = parentRef.get();
            if (p != null) {
                p.onError(l);
            }
        }

        @Override
        protected void onStart(ActionEvent l) {
            if (p != null) {
                p.onStart(l);
            }
        }

        @Override
        protected void onLoad(ActionEvent l) {
            if (p != null) {
                p.onLoad(l);
            }
        }
    };
    java.awt.Container cnt = JavaSEPort.instance.getCanvas().getParent();
    while (!(cnt instanceof JFrame)) {
        cnt = cnt.getParent();
        if (cnt == null) {
            System.err.println("CEFBrowserComponent requires a JFrame as an ancestor.  None found.  Returning null");
            return null;
        }
    }
    final CEFBrowserComponent out = new CEFBrowserComponent((JFrame) cnt, panel);
    out.setPeerComponentBuffer(buffer);
    final WeakReference<CEFBrowserComponent> weakRef = new WeakReference<CEFBrowserComponent>(out);
    panel.setReadyCallback(new Runnable() {

        public void run() {
            CEFBrowserComponent callback = weakRef.get();
            if (callback != null) {
                callback.fireReady();
            }
        }
    });
    return out;
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) BrowserNavigationCallback(com.codename1.ui.events.BrowserNavigationCallback) CefSettings(org.cef.CefSettings) JFrame(javax.swing.JFrame) WeakReference(java.lang.ref.WeakReference)

Example 2 with CefSettings

use of org.cef.CefSettings in project launcher by MyFTB.

the class CefFrame method getApp.

public static CefApp getApp() {
    if (!CefApp.startup()) {
        return null;
    }
    CefSettings settings = new CefSettings();
    settings.user_agent = "MyFTB Launcher";
    settings.windowless_rendering_enabled = false;
    CefApp cefApp = CefApp.getInstance(settings);
    CefApp.addAppHandler(new LauncherCefAppHandler());
    return cefApp;
}
Also used : CefSettings(org.cef.CefSettings) LauncherCefAppHandler(de.myftb.launcher.cef.LauncherCefAppHandler) CefApp(org.cef.CefApp)

Aggregations

CefSettings (org.cef.CefSettings)2 ActionEvent (com.codename1.ui.events.ActionEvent)1 BrowserNavigationCallback (com.codename1.ui.events.BrowserNavigationCallback)1 LauncherCefAppHandler (de.myftb.launcher.cef.LauncherCefAppHandler)1 WeakReference (java.lang.ref.WeakReference)1 JFrame (javax.swing.JFrame)1 CefApp (org.cef.CefApp)1