public class

XhrLoadingStrategy

extends Object
implements AsyncFragmentLoader.LoadingStrategy
java.lang.Object
   ↳ com.google.gwt.core.client.impl.XhrLoadingStrategy

Class Overview

The standard loading strategy used in a web browser. The linker it is used with should provide JavaScript-level functions to indicate how to handle downloading and installing code. There is support to use XHR for the download. Linkers should always provide a function __gwtStartLoadingFragment. This function is called by AsyncFragmentLoader with two arguments: an integer fragment number that needs to be downloaded, and a one-argument loadFinished function. If the load fails, that function should be called with a descriptive exception as the argument. If the load succeeds, that function may also be called, so long as it isn't called until the downloaded code has been installed. If the mechanism for loading the contents of fragments is provided by the linker, the __gwtStartLoadingFragment function should return null or undefined. Alternatively, the function can return a URL designating from where the code for the requested fragment can be downloaded. In that case, the linker should also provide a function __gwtInstallCode for actually installing the code once it is downloaded. That function will be passed the loaded code once it has been downloaded.

Summary

Nested Classes
class XhrLoadingStrategy.RequestData Since LoadingStrategy must support concurrent requests, including figuring which is which in the onLoadError handling, we need to keep track of this data for each outstanding request, which we index by xhr object. 
Public Constructors
XhrLoadingStrategy()
Public Methods
void startLoadingFragment(int fragment, AsyncFragmentLoader.LoadTerminatedHandler loadErrorHandler)
Protected Methods
XhrLoadingStrategy.MockableXMLHttpRequest createXhr()
Overridable for tests.
void gwtInstallCode(String text)
Call the linker-supplied __gwtInstallCode method.
String gwtStartLoadingFragment(int fragment, AsyncFragmentLoader.LoadTerminatedHandler loadErrorHandler)
Call the linker-supplied __gwtStartLoadingFragment function.
void onLoadError(XhrLoadingStrategy.RequestData request, Throwable e, boolean mayRetry)
Error recovery from loading or installing code.
void tryLoad(XhrLoadingStrategy.RequestData request)
Makes a single load-and-install attempt.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.gwt.core.client.impl.AsyncFragmentLoader.LoadingStrategy

Public Constructors

public XhrLoadingStrategy ()

Public Methods

public void startLoadingFragment (int fragment, AsyncFragmentLoader.LoadTerminatedHandler loadErrorHandler)

Protected Methods

protected XhrLoadingStrategy.MockableXMLHttpRequest createXhr ()

Overridable for tests.

protected void gwtInstallCode (String text)

Call the linker-supplied __gwtInstallCode method. See the class comment for more details.

protected String gwtStartLoadingFragment (int fragment, AsyncFragmentLoader.LoadTerminatedHandler loadErrorHandler)

Call the linker-supplied __gwtStartLoadingFragment function. It should either start the download and return null or undefined, or it should return a URL that should be downloaded to get the code. If it starts the download itself, it can synchronously load it, e.g. from cache, if that makes sense.

protected void onLoadError (XhrLoadingStrategy.RequestData request, Throwable e, boolean mayRetry)

Error recovery from loading or installing code.

Parameters
request the requestData of this request
e exception of the error
mayRetry true if retrying might be helpful

protected void tryLoad (XhrLoadingStrategy.RequestData request)

Makes a single load-and-install attempt.