NASA World Wind

gov.nasa.worldwind.util.webview
Class WindowsWebViewJNI

java.lang.Object
  extended by gov.nasa.worldwind.util.webview.WindowsWebViewJNI

public class WindowsWebViewJNI
extends Object

JNI bindings for the Windows WebView library. This library provides functions for creating and destroying native WebViews, sending user input to a WebView, and adding listeners to a WebView.

Message loops

WebViews created by this library must be managed by a message loop in native code. This class provides methods for creating and running a native message loop using a Java thread. Each WebView must be associated with one message loop. Each message loop can handle any number of WebViews.

To create a WebView message loop:

  1. Create a new Java thread to run the message loop.
  2. Call newMessageLoop() from the message loop thread.
  3. Call runMessageLoop(long) from the message loop thread. This enters a blocking loop in native code. It will not return until releaseMessageLoop(long) is called by another thread.

Here is an example of creating and running a message loop:

 long webViewMessageLoop = 0;
 

// Create a new thread to run the WebView message loop. webViewUI = new Thread("WebView UI") { public void run() { // Create a message loop in native code. This call must return // before any messages are sent to the WebView. webViewMessageLoop = WindowsWebViewJNI.newMessageLoop();

// Notify the outer thread that the message loop is ready. synchronized (webViewUILock) { webViewUILock.notify(); }

// Process messages in native code until the message loop // is terminated. WindowsWebViewJNI.runMessageLoop(webViewMessageloop); } }; webViewUI.start();

// Wait for the newly started thread to create the message loop. We cannot // safely use the WebView until the message loop has been initialized. while (webViewMessageLoop == 0) { try { webViewUILock.wait(); } catch (InterruptedException ignored) { } }


Constructor Summary
WindowsWebViewJNI()
           
 
Method Summary
static void addWindowUpdateObserver(long webViewWindowPtr, long observerPtr)
          Add an observer that will be notified when the rendered contents of the WebView change (due to animation, user input, etc)
static Dimension getContentSize(long webViewWindowPtr)
          Get the size of the scrollable WebView content.
static String getContentURL(long webViewWindowPtr)
          Get the URL of the page currently loaded in the WebView.
static AVList[] getLinks(long webViewWindowPtr)
           
static Dimension getMinContentSize(long webViewWindowPtr)
          Get minimum size of the WebView content.
static long getUpdateTime(long webViewWindowPtr)
          Get the time at which the WebView rendered contents last changed.
static void goBack(long webViewWindowPtr)
          Navigate a WebView window to the previous page in the navigation history.
static void goForward(long webViewWindowPtr)
          Navigate a WebView window to the next page in the navigation history.
protected static void initialize()
          Initialize the native library.
static void loadDisplayInGLTexture(long webViewWindowPtr, int target)
          Load the captured WebView image into an OpenGL texture.
static long newMessageLoop()
          Create a new native message loop.
static long newNotificationAdapter(PropertyChangeListener listener)
          Create a new notification adapter to bridge changes in the native WebView to PropertyChangeEvents.
static long newWebViewWindow(long messageLoop)
          Create a new WebView window.
static void releaseComObject(long unknownPtr)
          Release a COM object.
static void releaseMessageLoop(long messageLoop)
          Release a previously allocated message loop.
static void releaseWebView(long webViewWindowPtr)
          Release a WebView window.
static void removeWindowUpdateObserver(long webViewWindowPtr, long observerPtr)
          Remove an update observer from a WebView.
static void runMessageLoop(long messageLoop)
          Run a native message loop.
static void sendEvent(long webViewWindowPtr, InputEvent event)
          Send an input event to a WebView window.
static void setActive(long webViewWindowPtr, boolean active)
          Set a WebViewWindow to be active or inactive.
static void setBackgroundColor(long webViewWindowPtr, String colorString)
          Set the background color the WebView.
static void setFrameSize(long webViewWindowPtr, int width, int height)
          Set the size of a WebView window.
static void setHTMLString(long webViewWindowPtr, String htmlString, String baseUrlString)
          Set the HTML content of a WebView, with a base URL.
static void setHTMLStringWithResourceResolver(long webViewWindowPtr, String htmlString, WebResourceResolver resolver)
          Set the HTML content of a WebView, with a WebResourceResolver to resolve local references.
static void setMinContentSize(long webViewWindowPtr, int width, int height)
          Specifies the minimum size of the WebView content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WindowsWebViewJNI

public WindowsWebViewJNI()
Method Detail

addWindowUpdateObserver

public static void addWindowUpdateObserver(long webViewWindowPtr,
                                           long observerPtr)
Add an observer that will be notified when the rendered contents of the WebView change (due to animation, user input, etc)

Parameters:
webViewWindowPtr - pointer to native WebView to observe
observerPtr - notification adapter allocated by newNotificationAdapter(java.beans.PropertyChangeListener)

getContentSize

public static Dimension getContentSize(long webViewWindowPtr)
Get the size of the scrollable WebView content.

Parameters:
webViewWindowPtr - pointer to native WebView.
Returns:
Return the size of the WebView content.

getContentURL

public static String getContentURL(long webViewWindowPtr)
Get the URL of the page currently loaded in the WebView.

Parameters:
webViewWindowPtr - pointer to native WebView.
Returns:
The URL of the current page, or null if the WebView content has been loaded from a String.

getLinks

public static AVList[] getLinks(long webViewWindowPtr)

getMinContentSize

public static Dimension getMinContentSize(long webViewWindowPtr)
Get minimum size of the WebView content.

Parameters:
webViewWindowPtr - pointer to native WebView.
Returns:
Return the minimum size of the WebView content.

getUpdateTime

public static long getUpdateTime(long webViewWindowPtr)
Get the time at which the WebView rendered contents last changed.

Parameters:
webViewWindowPtr - pointer to native WebView
Returns:
The time (in milliseconds since the system started) at which the WebView rendered content last changed.

goBack

public static void goBack(long webViewWindowPtr)
Navigate a WebView window to the previous page in the navigation history. Has no effect if there is no previous page.

Parameters:
webViewWindowPtr - pointer to native WebView.

goForward

public static void goForward(long webViewWindowPtr)
Navigate a WebView window to the next page in the navigation history. Has no effect if there is no next page.

Parameters:
webViewWindowPtr - WebView window to navigate.

initialize

protected static void initialize()
Initialize the native library. This method must be called before any of the other methods in this class.


loadDisplayInGLTexture

public static void loadDisplayInGLTexture(long webViewWindowPtr,
                                          int target)
Load the captured WebView image into an OpenGL texture.

Parameters:
webViewWindowPtr - pointer to native WebView to load into texture
target - GL texture identifier

newMessageLoop

public static long newMessageLoop()
Create a new native message loop.

Returns:
An identifier for the new loop, or zero if creation fails.

newNotificationAdapter

public static long newNotificationAdapter(PropertyChangeListener listener)
Create a new notification adapter to bridge changes in the native WebView to PropertyChangeEvents.

Parameters:
listener - listener that will receive PropertyChangeEvents caused by changes in the native WebView
Returns:
identifier for the new notification adapter, or zero if creation fails. The notification adapter must be freed by releaseComObject.
See Also:
releaseComObject(long)

newWebViewWindow

public static long newWebViewWindow(long messageLoop)
Create a new WebView window.

Parameters:
messageLoop - message loop that will handle events for the window.
Returns:
Identifier for the new window, or zero if creation fails.

releaseComObject

public static void releaseComObject(long unknownPtr)
Release a COM object.

Parameters:
unknownPtr - pointer to object to release

releaseMessageLoop

public static void releaseMessageLoop(long messageLoop)
Release a previously allocated message loop.

Parameters:
messageLoop - identifier of the message loop to release.
See Also:
newMessageLoop()

releaseWebView

public static void releaseWebView(long webViewWindowPtr)
Release a WebView window.

Parameters:
webViewWindowPtr - pointer to the window to release.

removeWindowUpdateObserver

public static void removeWindowUpdateObserver(long webViewWindowPtr,
                                              long observerPtr)
Remove an update observer from a WebView.

Parameters:
webViewWindowPtr - pointer to native WebView from which to remove observer
observerPtr - observer to remove

runMessageLoop

public static void runMessageLoop(long messageLoop)
Run a native message loop. This method call does not return until the message loop is terminated.

Parameters:
messageLoop - Identifier for the message loop. This value is returned by newMessageLoop().

sendEvent

public static void sendEvent(long webViewWindowPtr,
                             InputEvent event)
Send an input event to a WebView window. The AWT InputEvent will translated into native Windows input messages.

Parameters:
webViewWindowPtr - window to send input to.
event - input event to send.

setActive

public static void setActive(long webViewWindowPtr,
                             boolean active)
Set a WebViewWindow to be active or inactive. The window only handles simulated input when it is active.

Parameters:
webViewWindowPtr - window to set active or inactive.
active - true if the window is being activated. false if the window is being deactivated.

setBackgroundColor

public static void setBackgroundColor(long webViewWindowPtr,
                                      String colorString)
Set the background color the WebView.

Parameters:
webViewWindowPtr - WebView window to set color of
colorString - Color expressed as a string. Color strings must follow the format defined by the HTML specification.

setFrameSize

public static void setFrameSize(long webViewWindowPtr,
                                int width,
                                int height)
Set the size of a WebView window.

Parameters:
webViewWindowPtr - window to set size of
width - new width
height - new height

setHTMLString

public static void setHTMLString(long webViewWindowPtr,
                                 String htmlString,
                                 String baseUrlString)
Set the HTML content of a WebView, with a base URL.

Parameters:
webViewWindowPtr - WebView window to set content of
htmlString - new HTML content
baseUrlString - base URL against which to resolve relative links

setHTMLStringWithResourceResolver

public static void setHTMLStringWithResourceResolver(long webViewWindowPtr,
                                                     String htmlString,
                                                     WebResourceResolver resolver)
Set the HTML content of a WebView, with a WebResourceResolver to resolve local references.

Parameters:
webViewWindowPtr - WebView window to set content of
htmlString - new HTML content
resolver - WebResourceResolver that will resolve local references in the HTML content.

setMinContentSize

public static void setMinContentSize(long webViewWindowPtr,
                                     int width,
                                     int height)
Specifies the minimum size of the WebView content.

Parameters:
webViewWindowPtr - pointer to native WebView.
width - minimum width, in pixels.
height - minimum height, in pixels.

NASA World Wind