Skip to content

Commit

Permalink
Merge pull request #27 from CodeBrig/javascript-integration
Browse files Browse the repository at this point in the history
Javascript Integration
  • Loading branch information
BFergerson authored Dec 1, 2019
2 parents 3949291 + 8820744 commit cea99e4
Show file tree
Hide file tree
Showing 21 changed files with 553 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ deploy:
provider: releases
api_key: $GH_TOKEN
file:
- /home/travis/build/CodeBrig/Journey/build/libs/journey-browser-0.3.3.jar
- /home/travis/build/CodeBrig/Journey/jcef/binary_distrib/jcef-distrib-linux64.zip
- /Users/travis/build/CodeBrig/Journey/jcef/binary_distrib/jcef-distrib-macintosh64.zip
- "$TRAVIS_BUILD_DIR/build/libs/journey-browser-0.4.0.jar"
- "$TRAVIS_BUILD_DIR/jcef/binary_distrib/jcef-distrib-linux64.zip"
- "$TRAVIS_BUILD_DIR/jcef/binary_distrib/jcef-distrib-macintosh64.zip"
skip_cleanup: true
on:
tags: true
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ repositories {
}
dependencies {
compile 'com.github.codebrig:journey:0.3.3-online'
compile 'com.github.codebrig:journey:0.4.0-online'
//or use the offline version (includes native CEF files for all platforms; ~300MB)
//compile 'com.github.codebrig:journey:0.3.3-offline'
//compile 'com.github.codebrig:journey:0.4.0-offline'
}
```

Expand All @@ -46,10 +46,10 @@ dependencies {
<dependency>
<groupId>com.github.codebrig</groupId>
<artifactId>journey</artifactId>
<version>0.3.3-online</version>
<version>0.4.0-online</version>

<!-- or use the offline version (includes native CEF files for all platforms; ~300MB) -->
<!-- <version>0.3.3-offline</version> -->
<!-- <version>0.4.0-offline</version> -->
</dependency>
```

Expand Down Expand Up @@ -92,7 +92,7 @@ public class JourneyBrowser {

### Linux (64bit)
```sh
curl -L -O https://github.com/CodeBrig/Journey/releases/download/0.3.3-75-assets/jcef-distrib-linux64.zip
curl -L -O https://github.com/CodeBrig/Journey/releases/download/0.4.0-78-assets/jcef-distrib-linux64.zip
unzip jcef-distrib-linux64.zip

export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64:$(pwd)/linux64/bin/lib/linux64
Expand All @@ -101,7 +101,7 @@ java -cp "linux64/bin/*" tests.detailed.MainFrame

### macOS (64bit)
```sh
curl -L -O https://github.com/CodeBrig/Journey/releases/download/0.3.3-69-assets/jcef-distrib-macintosh64.zip
curl -L -O https://github.com/CodeBrig/Journey/releases/download/0.4.0-69-assets/jcef-distrib-macintosh64.zip
unzip jcef-distrib-macintosh64.zip
mv ./macosx64/bin/jcef_app.app .

Expand All @@ -114,7 +114,7 @@ java -cp "$JAVA_PATH:$JAVA_PATH/*" -Djava.library.path=$JAVA_PATH tests.detailed
### Windows (64bit) [PowerShell]
```
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
wget https://github.com/CodeBrig/Journey/releases/download/0.3.3-75-assets/jcef-distrib-windows64.zip -OutFile jcef-distrib-windows64.zip
wget https://github.com/CodeBrig/Journey/releases/download/0.4.0-78-assets/jcef-distrib-windows64.zip -OutFile jcef-distrib-windows64.zip
Expand-Archive jcef-distrib-windows64.zip .
java -cp "./win64/bin;./win64/bin/*" "-Djava.library.path=./win64/bin/lib/win64" tests.detailed.MainFrame
Expand All @@ -124,6 +124,7 @@ java -cp "./win64/bin;./win64/bin/*" "-Djava.library.path=./win64/bin/lib/win64"

| Journey Version | JCEF Version (Linux) | JCEF Version (macOS) | JCEF Version (Windows) |
|---------------------|----------------------|----------------------|----------------------|
| 0.4.0 (2019-11-30) | [78.2.7.237](https://bitbucket.org/chromiumembedded/java-cef/commits/1e3a9146226d3df8a7f0c9c03989d220ac26ca49) (2019-11-14) | [69.0.3497.100](https://bitbucket.org/chromiumembedded/java-cef/commits/235e3a844380b72761643324e1d9b7713cae3b63) (2018-11-01) | [78.2.7.237](https://bitbucket.org/chromiumembedded/java-cef/commits/1e3a9146226d3df8a7f0c9c03989d220ac26ca49) (2019-11-14) |
| 0.3.3 (2019-07-13) | [75.0.13.220](https://bitbucket.org/chromiumembedded/java-cef/commits/13ae2d6074bc00a31888fb752dd45f9cf254725d) (2019-07-09) | [69.0.3497.100](https://bitbucket.org/chromiumembedded/java-cef/commits/235e3a844380b72761643324e1d9b7713cae3b63) (2018-11-01) | [75.0.13.220](https://bitbucket.org/chromiumembedded/java-cef/commits/13ae2d6074bc00a31888fb752dd45f9cf254725d) (2019-07-09) |
| 0.2.18 (2019-06-30)<br>0.2.17 (2019-06-12) | [73.1.11.216](https://bitbucket.org/chromiumembedded/java-cef/commits/6b140efeef4e566b6a68025b1dcea9b2da6e6e57) (2019-05-21) | [69.0.3497.100](https://bitbucket.org/chromiumembedded/java-cef/commits/235e3a844380b72761643324e1d9b7713cae3b63) (2018-11-01) | [73.1.11.216](https://bitbucket.org/chromiumembedded/java-cef/commits/6b140efeef4e566b6a68025b1dcea9b2da6e6e57) (2019-05-21) |
| 0.2.16 (2019-06-10) | [73.1.11.215](https://bitbucket.org/chromiumembedded/java-cef/commits/d348788e3347fa4d2a421773463f7dd62da60991) (2019-05-10) | [69.0.3497.100](https://bitbucket.org/chromiumembedded/java-cef/commits/235e3a844380b72761643324e1d9b7713cae3b63) (2018-11-01) | [73.1.11.215](https://bitbucket.org/chromiumembedded/java-cef/commits/d348788e3347fa4d2a421773463f7dd62da60991) (2019-05-10) |
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java'

version '0.4.0'
group 'com.codebrig'
version '0.3.3'

sourceCompatibility = 1.8
archivesBaseName = 'journey-browser'
Expand All @@ -13,13 +13,15 @@ ext {
'67': '67.0.3396.62',
'69': '69.0.3497.100',
'73': '73.1.11.216',
'75': '75.0.13.220'
'75': '75.0.13.220',
'78': '78.2.7.237'
]
jcefCommit = [
'67': '1fda5d8f948670d08ef86bc4e8637b8581995ce9',
'69': '235e3a844380b72761643324e1d9b7713cae3b63',
'73': '6b140efeef4e566b6a68025b1dcea9b2da6e6e57',
'75': '13ae2d6074bc00a31888fb752dd45f9cf254725d'
'75': '13ae2d6074bc00a31888fb752dd45f9cf254725d',
'78': '1e3a9146226d3df8a7f0c9c03989d220ac26ca49'
]
}

Expand Down Expand Up @@ -71,7 +73,7 @@ jar {
}

task initEnvironment {
def chromiumMajorVersion = "75"
def chromiumMajorVersion = "78"
if (System.getenv("TRAVIS_OS_NAME") == "osx") {
chromiumMajorVersion = "73"
}
Expand Down Expand Up @@ -151,7 +153,7 @@ task patchJCEF {

task checkoutJCEF {
doFirst {
def chromiumMajorVersion = "75"
def chromiumMajorVersion = "78"
if (System.getenv("TRAVIS_OS_NAME") == "osx") {
chromiumMajorVersion = "73"
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/codebrig/journey/JourneyBrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* Wraps CefApp/CefClient/CefBrowser and extends JComponent for ease of implementation.
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.1.1
*/
@SuppressWarnings({"JavaReflectionInvocation", "WeakerAccess"})
@SuppressWarnings({"WeakerAccess", "unused"})
public class JourneyBrowserView extends JComponent {

public static final String ABOUT_BLANK = "about:blank";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/codebrig/journey/JourneyLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Downloads and loads the necessary CEF files for the current OS.
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.1.1
*/
@SuppressWarnings({"WeakerAccess", "unused", "JavaReflectionMemberAccess"})
Expand All @@ -32,7 +32,7 @@ public class JourneyLoader extends URLClassLoader {
public static final String PROJECT_URL = BUILD.getString("project_url");
public static File NATIVE_DIRECTORY = new File((System.getProperty("os.name").toLowerCase().startsWith("mac"))
? "/tmp" : System.getProperty("java.io.tmpdir"),
"journey-" + (System.getProperty("os.name").toLowerCase().startsWith("mac") ? "69" : "75"));
"journey-" + (System.getProperty("os.name").toLowerCase().startsWith("mac") ? "69" : "78"));

private static JourneyLoader JOURNEY_CLASS_LOADER;
private static JourneyLoaderListener JOURNEY_LOADER_LISTENER = new JourneyLoaderAdapter() {
Expand All @@ -58,7 +58,7 @@ public static void setup() throws RuntimeException {
if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
jcefVersion = "69.0.3497.100";
} else {
jcefVersion = "75.0.13.220";
jcefVersion = "78.2.7.237";
}
JOURNEY_LOADER_LISTENER.journeyLoaderStarted(VERSION, jcefVersion);
if (!NATIVE_DIRECTORY.exists()) NATIVE_DIRECTORY.mkdirs();
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/codebrig/journey/JourneySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* Note: This doesn't use a real proxy because CefSettings exposes configuration through fields instead of methods.
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.2.0
*/
@SuppressWarnings("WeakerAccess")
@SuppressWarnings({"WeakerAccess", "unused"})
public class JourneySettings {

public static Class CEF_SETTINGS_CLASS = JourneyLoader.getJourneyClassLoader().loadClass("org.cef.CefSettings");
Expand Down Expand Up @@ -210,15 +210,12 @@ public void setIgnoreCertificateErrors(boolean ignore_certificate_errors) {
// }
// }

public static enum LogSeverity {
public enum LogSeverity {
LOGSEVERITY_DEFAULT,
LOGSEVERITY_VERBOSE,
LOGSEVERITY_INFO,
LOGSEVERITY_WARNING,
LOGSEVERITY_ERROR,
LOGSEVERITY_DISABLE;

private LogSeverity() {
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/codebrig/journey/proxy/CefAppProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Javadoc taken from: https://bitbucket.org/chromiumembedded/java-cef
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.2.0
*/
@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Javadoc taken from: https://bitbucket.org/chromiumembedded/java-cef
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.2.0
*/
@SuppressWarnings("unused")
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/codebrig/journey/proxy/CefClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.codebrig.journey.proxy;

import com.codebrig.journey.proxy.browser.CefMessageRouterProxy;
import com.codebrig.journey.proxy.handler.CefJSDialogHandlerProxy;
import com.codebrig.journey.proxy.handler.CefLifeSpanHandlerProxy;
import org.joor.Reflect;

Expand All @@ -11,7 +13,7 @@
* Javadoc taken from: https://bitbucket.org/chromiumembedded/java-cef
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.2.0
*/
@SuppressWarnings("unused")
Expand All @@ -20,6 +22,10 @@ public interface CefClientProxy extends Reflect.ProxyObject {
Reflect.ProxyArgumentsConverter PROXY_ARGUMENTS_CONVERTER = (methodName, args) -> {
if ("addLifeSpanHandler".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
} else if ("addJSDialogHandler".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
} else if ("addMessageRouter".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
}
};

Expand All @@ -28,6 +34,8 @@ public interface CefClientProxy extends Reflect.ProxyObject {
return Reflect.on(returnValue).as(CefBrowserProxy.class);
} else if ("addLifeSpanHandler".equals(methodName)) {
return Reflect.on(returnValue).as(CefClientProxy.class);
} else if ("addJSDialogHandler".equals(methodName)) {
return Reflect.on(returnValue).as(CefClientProxy.class);
}
return returnValue;
};
Expand All @@ -38,6 +46,10 @@ public interface CefClientProxy extends Reflect.ProxyObject {

CefClientProxy addLifeSpanHandler(CefLifeSpanHandlerProxy handler);

CefClientProxy addJSDialogHandler(CefJSDialogHandlerProxy handler);

void addMessageRouter(CefMessageRouterProxy messageRouter);

void removeContextMenuHandler();

void removeDialogHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Javadoc taken from: https://bitbucket.org/chromiumembedded/java-cef
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.3.3
* @version 0.4.0
* @since 0.2.18
*/
@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.codebrig.journey.proxy.browser;

import com.codebrig.journey.JourneyLoader;
import com.codebrig.journey.proxy.CefBrowserProxy;
import com.codebrig.journey.proxy.handler.CefMessageRouterHandlerProxy;
import org.joor.Reflect;
import org.joor.Reflect.ProxyArgumentsConverter;
import org.joor.Reflect.ProxyValueConverter;

import java.lang.reflect.Proxy;

/**
* Journey local proxy for CefMessageRouter.
* <p>
* Javadoc taken from: https://bitbucket.org/chromiumembedded/java-cef
*
* @author <a href="mailto:dhruvit.raithatha@gmail.com">Dhruvit Raithatha</a>
* @version 0.4.0
* @since 0.4.0
*/
public interface CefMessageRouterProxy extends Reflect.ProxyObject {

ProxyArgumentsConverter PROXY_ARGUMENTS_CONVERTER = (methodName, args) -> {
if ("addHandler".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
} else if ("removeHandler".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
} else if ("cancelPending".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
} else if ("getPendingCount".equals(methodName)) {
args[0] = ((Reflect.ProxyInvocationHandler) Proxy.getInvocationHandler(args[0])).getUnderlyingObject();
}
};

ProxyValueConverter PROXY_VALUE_CONVERTER = (methodName, returnValue) -> returnValue;

/**
* Must be called if the CefMessageRouterProxy instance isn't used any more
*/
void dispose();

/**
* Add a new query handler. If |first| is true it will be added as the first
* handler, otherwise it will be added as the last handler. Returns true if the
* handler is added successfully or false if the handler has already been added.
* Must be called on the browser process UI thread. The Handler object must
* either outlive the router or be removed before deletion.
*
* @param handler the according handler to be added
* @param first if If set to true it will be added as the first handler
* @return true if the handler is added successfully
*/
boolean addHandler(CefMessageRouterHandlerProxy handler, boolean first);

/**
* Remove an existing query handler. Any pending queries associated with the
* handler will be canceled. Handler.OnQueryCanceled will be called and the
* associated JavaScript onFailure callback will be executed with an error code
* of -1. Returns true if the handler is removed successfully or false if the
* handler is not found. Must be called on the browser process UI thread.
*
* @param handler the according handler to be removed
* @return true if the handler is removed successfully
*/
boolean removeHandler(CefMessageRouterHandlerProxy handler);

/**
* Cancel all pending queries associated with either |browser| or |handler|. If
* both |browser| and |handler| are NULL all pending queries will be canceled.
* Handler::OnQueryCanceled will be called and the associated JavaScript
* onFailure callback will be executed in all cases with an error code of -1.
*
* @param browser may be empty
* @param handler may be empty
*/
void cancelPending(CefBrowserProxy browser, CefMessageRouterHandlerProxy handler);

/**
* Returns the number of queries currently pending for the specified |browser|
* and/or |handler|. Either or both values may be empty. Must be called on the
* browser process UI thread.
*
* @param browser may be empty
* @param handler may be empty
* @return the number of queries currently pending
*/
int getPendingCount(CefBrowserProxy browser, CefMessageRouterHandlerProxy handler);

static CefMessageRouterProxy createRouter() {
JourneyLoader classLoader = JourneyLoader.getJourneyClassLoader();
Object realCefMessageRouter = Reflect.onClass(classLoader.loadClass("org.cef.browser.CefMessageRouter"))
.call("create").get();
return Reflect.on(realCefMessageRouter).as(CefMessageRouterProxy.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.codebrig.journey.proxy.callback;

import org.joor.Reflect;

/**
* Journey local proxy for CefJSDialogCallback.
* <p>
* Javadoc taken from: https://bitbucket.org/chromiumembedded/java-cef
*
* @author <a href="mailto:brandon.fergerson@codebrig.com">Brandon Fergerson</a>
* @version 0.4.0
* @since 0.4.0
*/
public interface CefJSDialogCallbackProxy {

Reflect.ProxyArgumentsConverter PROXY_ARGUMENTS_CONVERTER = (methodName, args) -> {
};

Reflect.ProxyValueConverter PROXY_VALUE_CONVERTER = (methodName, returnValue) -> returnValue;

/**
* Continue the JS dialog request.
*
* @param success Set to true if the OK button was pressed.
* @param userInput The value should be specified for prompt dialogs.
*/
void Continue(boolean success, String userInput);
}
Loading

0 comments on commit cea99e4

Please sign in to comment.