-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from CodeBrig/javascript-integration
Javascript Integration
- Loading branch information
Showing
21 changed files
with
553 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/com/codebrig/journey/proxy/browser/CefMessageRouterProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/codebrig/journey/proxy/callback/CefJSDialogCallbackProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.