Additional method for #248918 to allow selection of technologies when booting FXBrowsers with a Runnable
authorJaroslav Tulach <jtulach@netbeans.org>
Thu, 04 Dec 2014 21:53:48 +0100
changeset 889548982033730
parent 888 356ebecb09ba
child 891 8d12f85b0476
child 892 de02b7c13379
Additional method for #248918 to allow selection of technologies when booting FXBrowsers with a Runnable
boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java
     1.1 --- a/boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java	Thu Dec 04 11:04:28 2014 +0100
     1.2 +++ b/boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java	Thu Dec 04 21:53:48 2014 +0100
     1.3 @@ -141,8 +141,8 @@
     1.4      
     1.5      /** Enables the Java/JavaScript bridge (that supports {@link JavaScriptBody} and co.)
     1.6       * in the provided <code>webView</code>. This method returns 
     1.7 -     * immediately. Once the support is active, it calls back specified
     1.8 -     * method in <code>onPageLoad</code>'s run method. 
     1.9 +     * immediately. Once the support is active, it calls back {@link Runnable#run() run}
    1.10 +     * method in <code>onPageLoad</code>. 
    1.11       * This is more convenient way to initialize the webview, 
    1.12       * but it requires one to make sure
    1.13       * all {@link JavaScriptBody} methods has been post-processed during
    1.14 @@ -160,7 +160,37 @@
    1.15      public static void load(
    1.16          WebView webView, final URL url, Runnable onPageLoad, ClassLoader loader
    1.17      ) {
    1.18 -        BrowserBuilder.newBrowser(new Load(webView)).
    1.19 +        load(webView, url, onPageLoad, loader, new Object[0]);
    1.20 +    }
    1.21 +    
    1.22 +    /** Enables the Java/JavaScript bridge (that supports {@link JavaScriptBody} and co.)
    1.23 +     * in the provided <code>webView</code>. This method returns 
    1.24 +     * immediately. Once the support is active, it calls back {@link Runnable#run() run}
    1.25 +     * method in <code>onPageLoad</code>. 
    1.26 +     * This is more convenient way to initialize the webview, 
    1.27 +     * but it requires one to make sure
    1.28 +     * all {@link JavaScriptBody} methods has been post-processed during
    1.29 +     * compilation and there will be no need to instantiate new classloader.
    1.30 +     * <p>
    1.31 +     * This method sets {@link WebView#getUserData()} and {@link #runInBrowser(javafx.scene.web.WebView, java.lang.Runnable)}
    1.32 +     * relies on the value. Please don't alter it.
    1.33 +     * 
    1.34 +     * @param webView the instance of Web View to tweak
    1.35 +     * @param url the URL of the HTML page to load into the view
    1.36 +     * @param onPageLoad callback to call when the page is ready
    1.37 +     * @param loader the loader to use when constructing initial {@link BrwsrCtx} or <code>null</code>
    1.38 +     * @param context additonal configuration to pass to {@link BrowserBuilder#newBrowser(java.lang.Object...)}
    1.39 +     *   and {@link Contexts#newBuilder(java.lang.Object...)} factory methods 
    1.40 +     * @since 1.1
    1.41 +     */
    1.42 +    public static void load(
    1.43 +        WebView webView, final URL url, Runnable onPageLoad, ClassLoader loader,
    1.44 +        Object... context
    1.45 +    ) {
    1.46 +        Object[] newCtx = new Object[context.length + 1];
    1.47 +        System.arraycopy(context, 0, newCtx, 1, context.length);
    1.48 +        newCtx[0] = new Load(webView);
    1.49 +        BrowserBuilder.newBrowser(newCtx).
    1.50                  loadPage(url.toExternalForm()).
    1.51                  loadFinished(onPageLoad).
    1.52                  classloader(loader).