com.jniwrapper.win32.ie
Interface WebBrowser

All Superinterfaces:
ParentWindow, SingleThreadedComponent
All Known Implementing Classes:
Browser, HeadlessBrowser, com.jniwrapper.win32.ie.ReadyStateSupport

public interface WebBrowser
extends SingleThreadedComponent, ParentWindow

The WebBrowser defines the base web browser interface and its various capabilities.

See Also:
- Java component that implements this interface, - UI-less implementation of this interface

Nested Class Summary
static class WebBrowser.Properties
          Represents a set of event names that can be handled in the PropertyChangeListener listener.
 
Method Summary
 void addBrowserWindowListener(BrowserWindowListener listener)
          Adds window listener.
 void addNavigationListener(NavigationEventListener listener)
          Adds browser navigation event listener.
 void addNewWindowListener(NewWindowEventListener listener)
          Adds new window listener.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Adds a new property change listener.
 void addStatusListener(StatusEventListener listener)
          Adds browser status event listener.
 void close()
          Closes browser.
 void execute(BrowserCommand command)
          Executes specified command.
 java.lang.Object executeScript(java.lang.String javaScript)
          Executes specified JavaScript code in a currently opened document.
 AuthenticateHandler getAuthenticateHandler()
          Returns browser authenticate handler.
 java.lang.Object getBrowserPeer()
          Returns an instance of the native web browser peer.
 BrowserWindowListener[] getBrowserWindowListeners()
          Returns an array of window listeners.
 java.lang.String getContent()
          Returns the HTML content of a document, opened in a browser.
 java.util.Set getCookies(java.lang.String url)
          Returns cookies, that are associated with the specified URL.
 DialogEventHandler getDialogEventHandler()
          Gets dialog event handler.
 HTMLDocument getDocument()
          Returns DOM document for page loaded into the browser.
 WebBrowserEventsHandler getEventHandler()
          Returns browser event handler.
 KeyFilter getKeyFilter()
          Returns key filter.
 java.lang.String getLocationURL()
          Returns the URL of the resource that Internet Explorer is currently displaying.
 java.util.List getNavigationListeners()
          Returns browser navigation event listeners.
 NewWindowEventHandler getNewWindowHandler()
          Returns new window handler.
 java.util.List getNewWindowListeners()
          Returns new window listeners.
 WebBrowser getParentBrowser()
          Returns the parent of the browser.
 WebBrowser.Properties getProperties()
          Returns extended browser properties.
 ReadyState getReadyState()
          Returns the current ReadyState of the browser.
 ScriptErrorListener getScriptErrorListener()
          Returns script error listener for current page.
 java.util.List getStatusListeners()
          Returns browser status event listeners.
 java.lang.String getStatusText()
          Returns the status text of the browser.
 void goBack()
          Navigates backward one item in the history list.
 void goForward()
          Navigates forward one item in the history list.
 void goHome()
          Navigates to the home page.
 boolean isSilent()
          Return true if alert, confirmation and error dialogs are disabled else returns false.
 void navigate(java.lang.String location)
          Navigates to a resource specified by a URL or to the file identified by a full path.
 void navigate(java.lang.String location, java.lang.String postData)
          Navigates to a resource specified by a HTTP URL.
 void navigate(java.lang.String location, java.lang.String targetName, java.lang.String postData)
          Navigates the browser to a location that might not be able to be expressed as a URL, such as a pointer to an item identifier list (PIDL) for an entity in the Microsoft Windows shell namespace.
 void refresh()
          Reloads the file that is currently displayed in the object.
 void removeBrowserWindowListener(BrowserWindowListener listener)
          Removes window listener.
 void removeNavigationListener(NavigationEventListener listener)
          Removes browser navigation event listener.
 void removeNewWindowListener(NewWindowEventListener listener)
          Removes new window listener.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Removes a specified property change listener.
 void removeStatusListener(StatusEventListener listener)
          Removes browser status event listener.
 void setAuthenticateHandler(AuthenticateHandler handler)
          Sets browser authenticate handler.
 void setContent(java.lang.String htmlContent)
          Set new HTML content.
 void setCookie(java.lang.String url, Cookie cookie)
          Creates a new cookie for the specified URL using WinINet API.
 void setDialogEventHandler(DialogEventHandler handler)
          Sets dialog event handler.
 void setEventHandler(WebBrowserEventsHandler handler)
          Sets browser event handler.
 void setKeyFilter(KeyFilter keyFilter)
          Sets key filter.
 void setNewWindowHandler(NewWindowEventHandler newWindowHandler)
          Sets new window handler.
 void setParentBrowser(WebBrowser webBrowser)
          Sets the parent of the browser.
 void setScriptErrorListener(ScriptErrorListener listener)
          Setups javascript error listener for current page.
 void setSilent(boolean isSilent)
          Disables or enables alert, confirmation and error dialogs.
 void stop()
          Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.
 void waitReady()
          Causes a current thread to wait for the completion of the current operation in the browser.
 void waitReady(long timeout)
          Causes a current thread to wait for the completion of a current operation in the browser for a specified amount of milliseconds.
 
Methods inherited from interface com.jniwrapper.win32.ie.SingleThreadedComponent
getOleMessageLoop
 
Methods inherited from interface com.jniwrapper.win32.ie.ParentWindow
getRecentChild, trackChildren, waitChildCreation, waitChildCreation
 

Method Detail

navigate

public void navigate(java.lang.String location)
Navigates to a resource specified by a URL or to the file identified by a full path.

Parameters:
location - URL to navigate to.

navigate

public void navigate(java.lang.String location,
                     java.lang.String postData)
Navigates to a resource specified by a HTTP URL.

Parameters:
location - URL to navigate to.
postData - HTTP post data (for example, "name=Alex&product=Pizza")

navigate

public void navigate(java.lang.String location,
                     java.lang.String targetName,
                     java.lang.String postData)
Navigates the browser to a location that might not be able to be expressed as a URL, such as a pointer to an item identifier list (PIDL) for an entity in the Microsoft Windows shell namespace.

Parameters:
location - URL to navigate to.
targetName - string that contains the name of the frame in which to display the resource.
postData - HTTP post data (for example, "name=Alex&product=Pizza").

getLocationURL

public java.lang.String getLocationURL()
Returns the URL of the resource that Internet Explorer is currently displaying.

Returns:
location URL

getDocument

public HTMLDocument getDocument()
Returns DOM document for page loaded into the browser.

Returns:
DOM document
Throws:
java.lang.IllegalStateException - if WebBrowser.waitReady() method isn't called after last call of WebBrowser.navigate() or WebBrowser.setContent() methods.
See Also:
waitReady(), navigate(String), setContent(String)

getParentBrowser

public WebBrowser getParentBrowser()
Returns the parent of the browser.

Returns:
the parent of the browser or null if the browser not has the parent.

setParentBrowser

public void setParentBrowser(WebBrowser webBrowser)
Sets the parent of the browser.

Parameters:
webBrowser - the parent of the browser.

goForward

public void goForward()
Navigates forward one item in the history list.


goBack

public void goBack()
Navigates backward one item in the history list.


goHome

public void goHome()
Navigates to the home page.


stop

public void stop()
Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.


refresh

public void refresh()
Reloads the file that is currently displayed in the object.


execute

public void execute(BrowserCommand command)
Executes specified command.

Parameters:
command - browser command.

setContent

public void setContent(java.lang.String htmlContent)
Set new HTML content.

Parameters:
htmlContent - HTML content to set.

getContent

public java.lang.String getContent()
Returns the HTML content of a document, opened in a browser.

Returns:
the HTML content of a document, opened in a browser.

executeScript

public java.lang.Object executeScript(java.lang.String javaScript)
Executes specified JavaScript code in a currently opened document.

Parameters:
javaScript - JavaScript to execute.
Returns:
the result of JavaScript execution, if any (String, or COM object).

getReadyState

public ReadyState getReadyState()
Returns the current ReadyState of the browser.

Returns:
the current state of the browser.

getStatusText

public java.lang.String getStatusText()
Returns the status text of the browser.

Returns:
the status text of the browser.

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Adds a new property change listener. The available property names are presented in the WebBrowser.Properties class.

Parameters:
propertyName - property name.
listener - listener instance.

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Removes a specified property change listener. The available property names are presented in the WebBrowser.Properties class.

Parameters:
propertyName - property name.
listener - listener instance.

waitReady

public void waitReady()
Causes a current thread to wait for the completion of the current operation in the browser.

Important: successful call of this method guaranties that you can get DOM document of loaded page. Please see typical usage of this method in the code below:

     // navigate to Google page
     browser.navigate("google.com");
 

// wait until page completely loaded browser.waitReady();

// DOM document is available Document document = browser.getDocument();

If you miss WebBrowser.waitReady() call after navigation call then IllegalStateException is thrown in WebBrowser.getDocument() call.

See Also:
navigate(String), setContent(String), getDocument()

waitReady

public void waitReady(long timeout)
Causes a current thread to wait for the completion of a current operation in the browser for a specified amount of milliseconds.

Parameters:
timeout - the number of milliseconds to wait.

getBrowserPeer

public java.lang.Object getBrowserPeer()
Returns an instance of the native web browser peer.

Returns:
native peer object.
Throws:
java.lang.IllegalStateException - if the passed browser does not have a native peer.

addNavigationListener

public void addNavigationListener(NavigationEventListener listener)
Adds browser navigation event listener.

Parameters:
listener - browser event listener.

removeNavigationListener

public void removeNavigationListener(NavigationEventListener listener)
Removes browser navigation event listener.

Parameters:
listener - browser event listener.

getNavigationListeners

public java.util.List getNavigationListeners()
Returns browser navigation event listeners.

Returns:
list of browser event listeners

addStatusListener

public void addStatusListener(StatusEventListener listener)
Adds browser status event listener.

Parameters:
listener - browser event listener.

removeStatusListener

public void removeStatusListener(StatusEventListener listener)
Removes browser status event listener.

Parameters:
listener - browser event listener.

getStatusListeners

public java.util.List getStatusListeners()
Returns browser status event listeners.

Returns:
list of browser event listeners

setEventHandler

public void setEventHandler(WebBrowserEventsHandler handler)
Sets browser event handler.

Parameters:
handler - event handler

getEventHandler

public WebBrowserEventsHandler getEventHandler()
Returns browser event handler.

Returns:
browser event handler

setAuthenticateHandler

public void setAuthenticateHandler(AuthenticateHandler handler)
Sets browser authenticate handler.

Parameters:
handler - authenticate handler

getAuthenticateHandler

public AuthenticateHandler getAuthenticateHandler()
Returns browser authenticate handler.

Returns:
browser authenticate handler

setDialogEventHandler

public void setDialogEventHandler(DialogEventHandler handler)
Sets dialog event handler.

The setSilent() method call modifies dialog event handler.

Parameters:
handler - dialog event handler

getDialogEventHandler

public DialogEventHandler getDialogEventHandler()
Gets dialog event handler.

Returns:
dialog event handler

setScriptErrorListener

public void setScriptErrorListener(ScriptErrorListener listener)
Setups javascript error listener for current page.

Parameters:
listener - javascript error listener

getScriptErrorListener

public ScriptErrorListener getScriptErrorListener()
Returns script error listener for current page.

Returns:
script error listener

close

public void close()
Closes browser.


setSilent

public void setSilent(boolean isSilent)
Disables or enables alert, confirmation and error dialogs.

This method call modifies dialog event handler through setDialogEventHandler() call.

Parameters:
isSilent - if true then enter to silent mode else leave silent mode.

isSilent

public boolean isSilent()
Return true if alert, confirmation and error dialogs are disabled else returns false.

Returns:
true if in silent mode else returns false.

setCookie

public void setCookie(java.lang.String url,
                      Cookie cookie)
Creates a new cookie for the specified URL using WinINet API. This is an analogue of the InternetSetCookie native function.

Parameters:
url - specifies an URL, a new cookie will be associated with.
cookie - specifies a new cookie.

getCookies

public java.util.Set getCookies(java.lang.String url)
Returns cookies, that are associated with the specified URL. This is an analogue of the InternetGetCookie native function.

Parameters:
url - specifies an URL.
Returns:
cookies, that are associated with the specified URL.

setNewWindowHandler

public void setNewWindowHandler(NewWindowEventHandler newWindowHandler)
Sets new window handler.

Parameters:
newWindowHandler - new window handler

getNewWindowHandler

public NewWindowEventHandler getNewWindowHandler()
Returns new window handler.

Returns:
new window handler

addNewWindowListener

public void addNewWindowListener(NewWindowEventListener listener)
Adds new window listener.

Parameters:
listener - new window listener

removeNewWindowListener

public void removeNewWindowListener(NewWindowEventListener listener)
Removes new window listener.

Parameters:
listener - new window listener

getNewWindowListeners

public java.util.List getNewWindowListeners()
Returns new window listeners.

Returns:
new window listeners

setKeyFilter

public void setKeyFilter(KeyFilter keyFilter)
Sets key filter.

Parameters:
keyFilter - key filter

getKeyFilter

public KeyFilter getKeyFilter()
Returns key filter.

Returns:
key filter

getProperties

public WebBrowser.Properties getProperties()
Returns extended browser properties.

Returns:
extended browser properties.

addBrowserWindowListener

public void addBrowserWindowListener(BrowserWindowListener listener)
Adds window listener.

Parameters:
listener - the window listener

removeBrowserWindowListener

public void removeBrowserWindowListener(BrowserWindowListener listener)
Removes window listener.

Parameters:
listener - the window listener

getBrowserWindowListeners

public BrowserWindowListener[] getBrowserWindowListeners()
Returns an array of window listeners.

Returns:
an array of window listeners