Rolling back r4917 to clear the build for a pending 1.6 -> trunk merge.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@4918 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java b/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
index 3684a0d..a02d487 100644
--- a/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
+++ b/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
@@ -155,18 +155,13 @@
out.newlineOpt();
if (supportRunAsync) {
out.print("function __gwtStartLoadingFragment(frag) {");
+ out.newlineOpt();
out.indentIn();
+ out.print(" var script = document.createElement('script');");
out.newlineOpt();
- out.print(" return $moduleBase + '" + FRAGMENT_SUBDIR
- + "/' + $strongName + '/' + frag + '" + FRAGMENT_EXTENSION + "';");
- out.indentOut();
- out.newlineOpt();
- out.print("};");
- out.newlineOpt();
- out.print("function __gwtInstallCode(code) {");
- out.indentIn();
- out.newlineOpt();
- out.print("$wnd.eval(code)");
+ out.print(" script.src = '" + FRAGMENT_SUBDIR + "/" + strongName
+ + "/' + frag + '" + FRAGMENT_EXTENSION + "';");
+ out.print(" document.getElementsByTagName('head').item(0).appendChild(script);");
out.indentOut();
out.newlineOpt();
out.print("};");
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/FragmentLoaderCreator.java b/dev/core/src/com/google/gwt/dev/jjs/impl/FragmentLoaderCreator.java
index c5344bd..ea097c9 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/FragmentLoaderCreator.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/FragmentLoaderCreator.java
@@ -180,13 +180,7 @@
srcWriter.println("}");
srcWriter.println("if (!loading) {");
srcWriter.println("loading = true;");
- srcWriter.println("AsyncFragmentLoader.inject(" + entryNumber + ",");
- srcWriter.println(" new AsyncFragmentLoader.LoadErrorHandler() {");
- srcWriter.println(" public void loadFailed(Throwable reason) {");
- srcWriter.println(" loading = false;");
- srcWriter.println(" runCallbackOnFailures(reason);");
- srcWriter.println(" }");
- srcWriter.println(" });");
+ srcWriter.println("AsyncFragmentLoader.inject(" + entryNumber + ");");
srcWriter.println("}");
srcWriter.println("}");
}
diff --git a/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java b/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java
index bc80c03..ee1f6a2 100644
--- a/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java
+++ b/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java
@@ -120,21 +120,6 @@
private HTML styleWidget = null;
/**
- * Whether the demo widget has been initialized.
- */
- private boolean widgetInitialized;
-
- /**
- * Whether the demo widget is (asynchronously) initializing.
- */
- private boolean widgetInitializing;
-
- /**
- * A vertical panel that holds the demo widget once it is initialized.
- */
- private VerticalPanel widgetVpanel;
-
- /**
* Constructor.
*
* @param constants the constants
@@ -156,12 +141,6 @@
deckPanel.add(w);
}
- @Override
- public void ensureWidget() {
- super.ensureWidget();
- ensureWidgetInitialized(widgetVpanel);
- }
-
/**
* Get the description of this example.
*
@@ -276,7 +255,6 @@
* Initialize this widget by creating the elements that should be added to the
* page.
*/
- @Override
protected final Widget createWidget() {
deckPanel = new DeckPanel();
@@ -286,18 +264,18 @@
tabBar.addSelectionHandler(this);
// Create a container for the main example
- widgetVpanel = new VerticalPanel();
- add(widgetVpanel, constants.contentWidgetExample());
+ final VerticalPanel vPanel = new VerticalPanel();
+ add(vPanel, constants.contentWidgetExample());
// Add the name
HTML nameWidget = new HTML(getName());
nameWidget.setStyleName(DEFAULT_STYLE_NAME + "-name");
- widgetVpanel.add(nameWidget);
+ vPanel.add(nameWidget);
// Add the description
HTML descWidget = new HTML(getDescription());
descWidget.setStyleName(DEFAULT_STYLE_NAME + "-description");
- widgetVpanel.add(descWidget);
+ vPanel.add(descWidget);
// Add source code tab
if (hasSource()) {
@@ -314,6 +292,22 @@
add(styleWidget, constants.contentWidgetStyle());
}
+ asyncOnInitialize(new AsyncCallback<Widget>() {
+
+ public void onFailure(Throwable caught) {
+ Window.alert("exception: " + caught);
+ }
+
+ public void onSuccess(Widget result) {
+ // Initialize the showcase widget (if any) and add it to the page
+ Widget widget = result;
+ if (widget != null) {
+ vPanel.add(widget);
+ }
+ onInitializeComplete();
+ }
+ });
+
return deckPanel;
}
@@ -373,34 +367,4 @@
realCallback.onError(request, e);
}
}
-
- /**
- * Ensure that the demo widget has been initialized. Note that initialization
- * can fail if there is a network failure.
- */
- private void ensureWidgetInitialized(final VerticalPanel vPanel) {
- if (widgetInitializing || widgetInitialized) {
- return;
- }
-
- widgetInitializing = true;
-
- asyncOnInitialize(new AsyncCallback<Widget>() {
- public void onFailure(Throwable reason) {
- widgetInitializing = false;
- Window.alert("Failed to download code for this widget (" + reason + ")");
- }
-
- public void onSuccess(Widget result) {
- widgetInitializing = false;
- widgetInitialized = true;
-
- Widget widget = result;
- if (widget != null) {
- vPanel.add(widget);
- }
- onInitializeComplete();
- }
- });
- }
}
diff --git a/user/src/com/google/gwt/core/client/AsyncFragmentLoader.java b/user/src/com/google/gwt/core/client/AsyncFragmentLoader.java
index 65d9d69..829cfc6 100644
--- a/user/src/com/google/gwt/core/client/AsyncFragmentLoader.java
+++ b/user/src/com/google/gwt/core/client/AsyncFragmentLoader.java
@@ -15,12 +15,7 @@
*/
package com.google.gwt.core.client;
-import com.google.gwt.xhr.client.ReadyStateChangeHandler;
-import com.google.gwt.xhr.client.XMLHttpRequest;
-
-import java.util.ArrayList;
import java.util.LinkedList;
-import java.util.List;
import java.util.Queue;
/**
@@ -46,32 +41,14 @@
* </ul>
*
* <p>
- * Since the precise way to load code depends on the linker, each linker should
- * provide functions for fragment loading for any compilation that includes more
- * than one fragment. Linkers should always provide a function
- * <code>__gwtStartLoadingFragment</code>. This function is called by
- * AsyncFragmentLoader with an integer fragment number that needs to be
- * downloaded. If the mechanism for loading the contents of fragments is
- * provided by the linker, this function should return <code>null</code> or
- * <code>undefined</code>.
- * </p>
- * <p>
- * 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 <code>__gwtInstallCode</code> for actually installing
- * the code once it is downloaded. That function will be passed the loaded code
- * once it has been downloaded.
- * </p>
+ * Different linkers have different requirements about how the code is
+ * downloaded and installed. Thus, when it is time to actually download the
+ * code, this class defers to a JavaScript function named
+ * <code>__gwtStartLoadingFragment</code>. Linkers must arrange that a suitable
+ * <code>__gwtStartLoadingFragment</code> function is in scope.
*/
public class AsyncFragmentLoader {
/**
- * An interface for handlers of load errors.
- */
- public static interface LoadErrorHandler {
- void loadFailed(Throwable reason);
- }
-
- /**
* Labels used for runAsync lightweight metrics.
*/
public static class LwmLabels {
@@ -91,73 +68,6 @@
}
/**
- * Handles a failure to download a base fragment.
- */
- private static class BaseDownloadFailed implements LoadErrorHandler {
- private final LoadErrorHandler chainedHandler;
-
- public BaseDownloadFailed(LoadErrorHandler chainedHandler) {
- this.chainedHandler = chainedHandler;
- }
-
- public void loadFailed(Throwable reason) {
- baseLoading = false;
- chainedHandler.loadFailed(reason);
- }
- }
-
- /**
- * An exception indicating than at HTTP download failed.
- */
- private static class HttpDownloadFailure extends RuntimeException {
- private final int statusCode;
-
- public HttpDownloadFailure(int statusCode) {
- super("HTTP download failed with status " + statusCode);
- this.statusCode = statusCode;
- }
-
- public int getStatusCode() {
- return statusCode;
- }
- }
-
- /**
- * Handles a failure to download a leftovers fragment.
- */
- private static class LeftoversDownloadFailed implements LoadErrorHandler {
- public void loadFailed(Throwable reason) {
- leftoversLoading = false;
-
- /*
- * Cancel all other pending downloads. If any exception is thrown while
- * cancelling any of them, throw only the last one.
- */
- RuntimeException lastException = null;
-
- assert waitingForLeftovers.size() == waitingForLeftoversErrorHandlers.size();
-
- // Copy the list in case a handler makes another runAsync call
- List<LoadErrorHandler> handlersToRun = new ArrayList<LoadErrorHandler>(
- waitingForLeftoversErrorHandlers);
- waitingForLeftoversErrorHandlers.clear();
- waitingForLeftovers.clear();
-
- for (LoadErrorHandler handler : handlersToRun) {
- try {
- handler.loadFailed(reason);
- } catch (RuntimeException e) {
- lastException = e;
- }
- }
-
- if (lastException != null) {
- throw lastException;
- }
- }
- }
-
- /**
* The first entry point reached after the program started.
*/
private static int base = -1;
@@ -167,10 +77,6 @@
*/
private static boolean baseLoading = false;
- private static final String HTTP_GET = "GET";
-
- private static final int HTTP_STATUS_OK = 200;
-
/**
* Whether the leftovers fragment has loaded yet.
*/
@@ -195,11 +101,6 @@
private static Queue<Integer> waitingForLeftovers = new LinkedList<Integer>();
/**
- * Error handlers for the above queue.
- */
- private static Queue<LoadErrorHandler> waitingForLeftoversErrorHandlers = new LinkedList<LoadErrorHandler>();
-
- /**
* Inform the loader that the code for an entry point has now finished
* loading.
*
@@ -216,7 +117,10 @@
baseLoading = false;
// Go ahead and download the appropriate leftovers fragment
- startLoadingLeftovers();
+ leftoversLoading = true;
+ logEventProgress(LwmLabels.LEFTOVERS_DOWNLOAD, LwmLabels.BEGIN,
+ leftoversFragmentNumber(), null);
+ startLoadingFragment(leftoversFragmentNumber());
}
}
@@ -225,7 +129,7 @@
*
* @param splitPoint the fragment to load
*/
- public static void inject(int splitPoint, LoadErrorHandler loadErrorHandler) {
+ public static void inject(int splitPoint) {
if (leftoversLoaded) {
/*
* A base and a leftovers fragment have loaded. Load an exclusively live
@@ -233,7 +137,7 @@
*/
logEventProgress(LwmLabels.downloadGroup(splitPoint), LwmLabels.BEGIN,
splitPoint, null);
- startLoadingFragment(splitPoint, loadErrorHandler);
+ startLoadingFragment(splitPoint);
return;
}
@@ -242,15 +146,6 @@
* Wait until the leftovers fragment has loaded before loading this one.
*/
waitingForLeftovers.add(splitPoint);
- waitingForLeftoversErrorHandlers.add(loadErrorHandler);
-
- /*
- * Also, restart the leftovers download if it previously failed.
- */
- if (!leftoversLoading) {
- startLoadingLeftovers();
- }
-
return;
}
@@ -258,8 +153,7 @@
baseLoading = true;
logEventProgress(LwmLabels.downloadGroup(splitPoint), LwmLabels.BEGIN,
baseFragmentNumber(splitPoint), null);
- startLoadingFragment(baseFragmentNumber(splitPoint),
- new BaseDownloadFailed(loadErrorHandler));
+ startLoadingFragment(baseFragmentNumber(splitPoint));
}
/**
@@ -271,10 +165,8 @@
logEventProgress(LwmLabels.LEFTOVERS_DOWNLOAD, LwmLabels.END,
leftoversFragmentNumber(), null);
- assert (waitingForLeftovers.size() == waitingForLeftoversErrorHandlers.size());
while (!waitingForLeftovers.isEmpty()) {
- inject(waitingForLeftovers.remove(),
- waitingForLeftoversErrorHandlers.remove());
+ inject(waitingForLeftovers.remove());
}
}
@@ -311,17 +203,8 @@
return evt;
}-*/;
- /**
- * Use 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.
- * */
- private static native String gwtStartLoadingFragment(int fragment) /*-{
- return __gwtStartLoadingFragment(fragment);
- }-*/;
-
- private static native void installCode(String text) /*-{
- __gwtInstallCode(text);
+ private static native void gwtStartLoadingFragment(int fragment) /*-{
+ __gwtStartLoadingFragment(fragment);
}-*/;
private static native boolean isStatsAvailable() /*-{
@@ -349,43 +232,8 @@
&& stats(createStatsEvent(eventGroup, type, fragment, size));
}
- private static void startLoadingFragment(int fragment,
- final LoadErrorHandler loadErrorHandler) {
- String fragmentUrl = gwtStartLoadingFragment(fragment);
-
- if (fragmentUrl != null) {
- // use XHR
- final XMLHttpRequest xhr = XMLHttpRequest.create();
-
- xhr.open(HTTP_GET, fragmentUrl);
-
- xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
- public void onReadyStateChange(XMLHttpRequest xhr) {
- if (xhr.getReadyState() == XMLHttpRequest.DONE) {
- xhr.clearOnReadyStateChange();
- if (xhr.getStatus() == HTTP_STATUS_OK) {
- try {
- installCode(xhr.getResponseText());
- } catch (RuntimeException e) {
- loadErrorHandler.loadFailed(e);
- }
- } else {
- loadErrorHandler.loadFailed(new HttpDownloadFailure(xhr.getStatus()));
- }
- }
- }
- });
-
- xhr.send();
- }
- }
-
- private static void startLoadingLeftovers() {
- leftoversLoading = true;
- logEventProgress(LwmLabels.LEFTOVERS_DOWNLOAD, LwmLabels.BEGIN,
- leftoversFragmentNumber(), null);
- startLoadingFragment(leftoversFragmentNumber(),
- new LeftoversDownloadFailed());
+ private static void startLoadingFragment(int fragment) {
+ gwtStartLoadingFragment(fragment);
}
/**
diff --git a/user/src/com/google/gwt/core/client/RunAsyncCallback.java b/user/src/com/google/gwt/core/client/RunAsyncCallback.java
index 0ec253a..4c76817 100644
--- a/user/src/com/google/gwt/core/client/RunAsyncCallback.java
+++ b/user/src/com/google/gwt/core/client/RunAsyncCallback.java
@@ -22,9 +22,9 @@
public interface RunAsyncCallback {
/**
* Called when, for some reason, the necessary code cannot be loaded. For
- * example, the web browser might no longer have network access.
+ * example, the user might no longer be on the network.
*/
- void onFailure(Throwable reason);
+ void onFailure(Throwable caught);
/**
* Called once the necessary code for it has been loaded.