org.mozilla.jrex.liveconnect
Class JRexLiveConnectSessionImpl

java.lang.Object
  extended byorg.mozilla.jrex.liveconnect.JRexLiveConnectSessionImpl
All Implemented Interfaces:
JRexLiveConnectSession

public final class JRexLiveConnectSessionImpl
extends Object
implements JRexLiveConnectSession

Implementation of JRexLiveConnectSession. JRexLiveConnectSessionImpl is public for accesibility from jni.

See Also:
JRexLiveConnectSession

Constructor Summary
JRexLiveConnectSessionImpl()
          Creates an instance of JRexLiveConnectSessionImpl.
JRexLiveConnectSessionImpl(JRexCanvas browser)
          Creates an instance of JRexLiveConnectSessionImpl and invokes setBrowser.
JRexLiveConnectSessionImpl(JRexCanvas browser, boolean useRootDocShell)
          Creates an instance of JRexLiveConnectSessionImpl and invokes setBrowser.
 
Method Summary
 boolean equals(Object obj)
           
 String evalUntrusted(String script)
          Evaluates javascript in the browser.
protected  void finalize()
           
 int getJRexPeerID()
           
 netscape.javascript.JSObject getJSWindow()
          Retrieves a JSObject implementation for the JRexCanvas window.
 int getSessionID()
           
 void grantBrowserAccessToJVM()
          Makes the LiveConnectSession a 2-way session.
 int hashCode()
           
 String invokeStringMethod(String functionName, String arg)
          Invokes a javascript method which accepts a single string and returns a string.
 void setBrowser(JRexCanvas browser)
          Sets the browser and intializes live connect for the browser.
 void setBrowser(JRexCanvas browser, boolean useRootDocShell)
          Sets the browser and intializes live connect for the browser.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRexLiveConnectSessionImpl

public JRexLiveConnectSessionImpl()
Creates an instance of JRexLiveConnectSessionImpl. The method setBrowser(org.mozilla.jrex.ui.JRexCanvas) must be called before any javascript can be invoked.


JRexLiveConnectSessionImpl

public JRexLiveConnectSessionImpl(JRexCanvas browser)
                           throws JRexException
Creates an instance of JRexLiveConnectSessionImpl and invokes setBrowser.

Parameters:
browser - the JRexCanvas used to access javascript
Throws:
JRexException - if an error occurs while initializing the javascript bridge.

JRexLiveConnectSessionImpl

public JRexLiveConnectSessionImpl(JRexCanvas browser,
                                  boolean useRootDocShell)
                           throws JRexException
Creates an instance of JRexLiveConnectSessionImpl and invokes setBrowser.

Parameters:
browser - the JRexCanvas used to access javascript
useRootDocShell - whether or not to use the root doc shell, or the primary content doc shell
Throws:
JRexException - if an error occurs while initializing the javascript bridge.
Method Detail

getSessionID

public int getSessionID()

getJRexPeerID

public int getJRexPeerID()

equals

public boolean equals(Object obj)

hashCode

public int hashCode()

finalize

protected void finalize()

setBrowser

public void setBrowser(JRexCanvas browser)
                throws JRexException
Description copied from interface: JRexLiveConnectSession
Sets the browser and intializes live connect for the browser. This method initializes the JRexLiveConnectSession to only work with the document's primary content nsIDocShell.

Specified by:
setBrowser in interface JRexLiveConnectSession
Parameters:
browser - the JRexCanvas, which must already be initialized
Throws:
JRexException - if an error occurs while initializing live connect
See Also:
JRexLiveConnectSession.setBrowser(JRexCanvas, boolean)

setBrowser

public void setBrowser(JRexCanvas browser,
                       boolean useRootDocShell)
                throws JRexException
Description copied from interface: JRexLiveConnectSession
Sets the browser and intializes live connect for the browser. This method also lets you speicfy whether or not to use the root doc shell, or the primary content doc shell.

Specified by:
setBrowser in interface JRexLiveConnectSession
Parameters:
browser - the JRexCanvas, which must already be initialized
useRootDocShell - if true, then the document's root nsIDocShell is used. If false, then the nsIDocShell for the primary content is used. If using JRexLiveConnectSession on a XUL window, and you want to invoke javascript on the XUL top-level window, this argument must be true. Otherwise, if you have an html document, or you only want to use JRexLiveConnectSession on the primary content, set this argument to False. Note that the primary content in a XUL window is the browser or editor tagged with "content-primary".
Throws:
JRexException - if an error occurs while initializing live connect

grantBrowserAccessToJVM

public void grantBrowserAccessToJVM()
                             throws JRexException
Description copied from interface: JRexLiveConnectSession
Makes the LiveConnectSession a 2-way session. Before this method is called, the LiveConnect session is only one-way, meaning that Java can call into javascript using any of the methods defined in this interface except for JRexLiveConnectSession.getJSWindow(). After this method is invoked, the javascript will be able to create java objects and invoke methods on those objects, and the caller will be able to use the method JRexLiveConnectSession.getJSWindow() to retrieve the JSObject instance for the javascript window.

Only call this method if the web page loaded into the JRexCanvas is trusted.

Specified by:
grantBrowserAccessToJVM in interface JRexLiveConnectSession
Throws:
JRexException - if an error occurs while granting access to the JRex JVM

invokeStringMethod

public String invokeStringMethod(String functionName,
                                 String arg)
                          throws JRexException
Description copied from interface: JRexLiveConnectSession
Invokes a javascript method which accepts a single string and returns a string. This method is provided as a simple way of invoking a javascript method and is useful for testing the JRexLiveConnectSession code. Note that for more complex javascript evaulations, the method JRexLiveConnectSession.evalUntrusted(java.lang.String) should be used for untrusted javascript, and the JSObject class returned from JRexLiveConnectSession.getJSWindow() should be used for trusted javascript.

Specified by:
invokeStringMethod in interface JRexLiveConnectSession
Parameters:
functionName - the name of the javascript function
arg - the argument to pass to the javascript function
Returns:
the result from the javascript function call, or null if the call failed
Throws:
JRexException - if an error occurs while invoking the javascript
See Also:
JRexLiveConnectSession.getJSWindow()

evalUntrusted

public String evalUntrusted(String script)
                     throws JRexException
Description copied from interface: JRexLiveConnectSession
Evaluates javascript in the browser. This method will evaluate unstrusted javascript and return the string result. If the javascript is trusted, it is better to call JRexLiveConnectSession.grantBrowserAccessToJVM() followed by JRexLiveConnectSession.getJSWindow() and invoke the eval method on the JSObject instance. Only use this method if the javascript is not trusted.

Specified by:
evalUntrusted in interface JRexLiveConnectSession
Parameters:
script - the javascript to evaluate
Returns:
the result of the evaulation as a string
Throws:
JRexException - if an error occurs while evaulating

getJSWindow

public netscape.javascript.JSObject getJSWindow()
                                         throws JRexException
Description copied from interface: JRexLiveConnectSession
Retrieves a JSObject implementation for the JRexCanvas window. The return JSObject can be used to make function calls and evaluate javascript. This method must be invoked after the document has been fully loaded into the browser. Failure to do so will result in unexpected errors.

Note that this method will throw a security violation exception unless the method JRexLiveConnectSession.grantBrowserAccessToJVM() is invoked before this method. Make sure to invoke JRexLiveConnectSession.grantBrowserAccessToJVM() before invoking this method.

Specified by:
getJSWindow in interface JRexLiveConnectSession
Returns:
a JSObject for invoking and manipulating javascript
Throws:
JRexException - if an error prevents the JSObject from being created
See Also:
JRexLiveConnectSession.grantBrowserAccessToJVM()


Copyright © 2004 C.N.Medappa. All Rights Reserved.