Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions flow-client/src/main/java/com/vaadin/client/DependencyLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,4 @@ private BiConsumer<String, ResourceLoadListener> getResourceLoader(
"Unknown dependency type " + resourceType);
}
}

/**
* Prevents eager dependencies from being considered as loaded until
* <code>HTMLImports.whenReady</code> has been run.
*/
public void requireHtmlImportsReady() {
startEagerDependencyLoading();
registry.getResourceLoader().runWhenHtmlImportsReady(
DependencyLoader::endEagerDependencyLoading);
}
}
150 changes: 1 addition & 149 deletions flow-client/src/main/java/com/vaadin/client/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.function.Supplier;

import com.google.gwt.core.client.Duration;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
import com.google.gwt.user.client.Timer;
Expand All @@ -36,7 +35,6 @@
import elemental.html.HeadElement;
import elemental.html.LinkElement;
import elemental.html.ScriptElement;
import elemental.html.SpanElement;
import elemental.html.StyleElement;

/**
Expand Down Expand Up @@ -81,39 +79,6 @@ public void onError(ResourceLoadEvent event) {
}
}

private class HtmlLoadListener implements ResourceLoadListener, Runnable {
private final ResourceLoadEvent event;

private boolean errorFired;

private HtmlLoadListener(ResourceLoadEvent event) {
this.event = event;
}

@Override
public void run() {
// Invoked through HTMLImports.whenReady
if (!errorFired) {
fireLoad(event);
}
}

@Override
public void onLoad(ResourceLoadEvent event) {
if (!supportsHtmlWhenReady) {
assert !errorFired;
fireLoad(event);
}
}

@Override
public void onError(ResourceLoadEvent event) {
assert !errorFired;
errorFired = true;
fireError(event);
}
}

private class SimpleLoadListener implements ResourceLoadListener {
@Override
public void onLoad(ResourceLoadEvent event) {
Expand Down Expand Up @@ -213,9 +178,6 @@ public interface ResourceLoadListener {

private Registry registry;

private final boolean supportsHtmlWhenReady = GWT.isClient()
&& supportsHtmlWhenReady();

/**
* Creates a new resource loader. You should not create you own resource
* loader, but instead use {@link Registry#getResourceLoader()} to get an
Expand Down Expand Up @@ -277,8 +239,7 @@ private void initLoadedResourcesFromDom() {
LinkElement linkElement = (LinkElement) links.item(i);
String rel = linkElement.getRel();
String href = linkElement.getHref();
if (("stylesheet".equalsIgnoreCase(rel)
|| "import".equalsIgnoreCase(rel)) && href != null
if ("stylesheet".equalsIgnoreCase(rel) && href != null
&& href.length() != 0) {
loadedResources.add(href);
// Handle stylesheet loaded by AppShellRegistry
Expand Down Expand Up @@ -419,115 +380,6 @@ private static HeadElement getHead() {
return getDocument().getHead();
}

/**
* Loads an HTML import and notify a listener when the HTML import is
* loaded. Calling this method when the HTML import is currently loading or
* already loaded doesn't cause the HTML import to be loaded again, but the
* listener will still be notified when appropriate.
*
* @param htmlUrl
* url of HTML import to load
* @param resourceLoadListener
* listener to notify when the HTML import is loaded
* @param async
* loads the import asynchronously, if {@code true},
* synchronously otherwise
*/
public void loadHtml(final String htmlUrl,
final ResourceLoadListener resourceLoadListener, boolean async) {
final String url = WidgetUtil.getAbsoluteUrl(htmlUrl);
ResourceLoadEvent event = new ResourceLoadEvent(this, url);
if (loadedResources.has(url)) {
if (resourceLoadListener != null) {
resourceLoadListener.onLoad(event);
}
return;
}

if (addListener(url, resourceLoadListener, loadListeners)) {
LinkElement linkTag = getDocument().createLinkElement();
linkTag.setAttribute("rel", "import");
linkTag.setAttribute("href", url);
if (async) {
linkTag.setAttribute("async", "true");
}

HtmlLoadListener listener = new HtmlLoadListener(event);

addOnloadHandler(linkTag, listener, event);
getHead().appendChild(linkTag);

if (supportsHtmlWhenReady) {
addHtmlImportsReadyHandler(listener);
}
}
}

/**
* Inlines an HTML import and notify a listener when the HTML import is
* loaded. Calling this method when the HTML import is currently loading or
* already loaded doesn't cause the HTML import to be loaded again, but the
* listener will still be notified when appropriate.
*
* @param htmlContents
* the html contents to inline
* @param resourceLoadListener
* listener to notify when the HTML import is loaded
*/
public void inlineHtml(String htmlContents,
final ResourceLoadListener resourceLoadListener) {
ResourceLoadEvent event = new ResourceLoadEvent(this, htmlContents);
if (loadedResources.has(htmlContents)) {
if (resourceLoadListener != null) {
resourceLoadListener.onLoad(event);
}
return;
}

if (addListener(htmlContents, resourceLoadListener, loadListeners)) {
SpanElement spanElement = getDocument().createSpanElement();
spanElement.setInnerHTML(htmlContents);
spanElement.setAttribute("hidden", "true");

HtmlLoadListener listener = new HtmlLoadListener(event);
getDocument().appendChild(spanElement);
addOnloadHandler(spanElement, listener, event);

if (supportsHtmlWhenReady) {
addHtmlImportsReadyHandler(listener);
}
}
}

/**
* Sets the provided task to be run by <code>HTMLImports.whenReady</code>.
* The task is run immediately if <code>HTMLImports.whenReady</code> is not
* supported.
*
* @param task
* the task to run, not <code>null</code>
*/
public void runWhenHtmlImportsReady(Runnable task) {
assert task != null;
if (supportsHtmlWhenReady) {
addHtmlImportsReadyHandler(task);
} else {
task.run();
}
}

private static native boolean supportsHtmlWhenReady()
/*-{
return !!($wnd.HTMLImports && $wnd.HTMLImports.whenReady);
}-*/;

private static native void addHtmlImportsReadyHandler(Runnable handler)
/*-{
$wnd.HTMLImports.whenReady($entry(function() {
handler.@Runnable::run()();
}));
}-*/;

/**
* Adds an onload listener to the given element, which should be a link or a
* script tag. The listener is called whenever loading is complete or an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.vaadin.client.flow.collection.JsCollections;
import com.vaadin.client.flow.collection.JsMap;
import com.vaadin.client.flow.collection.JsSet;
import com.vaadin.client.flow.dom.DomApi;
import com.vaadin.client.flow.reactive.Reactive;
import com.vaadin.flow.shared.ApplicationConstants;
import com.vaadin.flow.shared.JsonConstants;
Expand Down Expand Up @@ -366,27 +365,13 @@ protected void handleJSON(final ValueMap valueMap) {

handleDependencies(valueMap.cast());

if (!initialMessageHandled) {
/*
* When handling the initial JSON message, dependencies are embedded
* in the HTML document instead of being injected by
* DependencyLoader. We must still explicitly wait for all HTML
* imports from the HTML document to be loaded. It's not necessary
* to explicitly wait for JavaScript dependencies since the browser
* already takes care of that for us.
*/
registry.getDependencyLoader().requireHtmlImportsReady();
}

/*
* Hook for e.g. TestBench to get details about server performance
*/
if (valueMap.containsKey("timings")) {
serverTimingInfo = valueMap.getValueMap("timings");
}

DependencyLoader.runWhenEagerDependenciesLoaded(
DomApi::updateApiImplementation);
DependencyLoader.runWhenEagerDependenciesLoaded(
() -> processMessage(valueMap, lock, start));
}
Expand Down
41 changes: 1 addition & 40 deletions flow-client/src/main/java/com/vaadin/client/flow/dom/DomApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,17 @@
*/
package com.vaadin.client.flow.dom;

import com.vaadin.client.Console;

import elemental.dom.Node;

/**
* Access point for DOM API. All operations and interactions with DOM nodes and
* elements should go through this class.
* <p>
* This class delegates the operations to the actual DOM API implementations,
* which might be changed on the run, meaning after dependencies have been
* loaded.
*
* @author Vaadin Ltd
* @since 1.0
*/
public class DomApi {

/**
* Flag for tracking if Polymer-micro.html is loaded (contains dom).
*
* Package protected for testing reasons.
*/
static boolean polymerMicroLoaded = false;

/**
* The currently used DOM API implementation. By default just returns the
* same object.
*
* Package protected for testing reasons.
*/
static DomApiImpl impl;

private DomApi() {
// NOOP
}
Expand All @@ -60,25 +39,7 @@ private DomApi() {
* @return a wrapped element
*/
public static DomElement wrap(Node node) {
if (impl == null) {
return (DomElement) node;
}
return impl.wrap(node);
}

/**
* Updates the DOM API implementation used.
*/
public static void updateApiImplementation() {
if (!polymerMicroLoaded && PolymerDomApiImpl.isPolymerMicroLoaded()) {
polymerMicroLoaded();
}
}

private static void polymerMicroLoaded() {
polymerMicroLoaded = true;
Console.debug("Polymer micro is now loaded, using Polymer DOM API");
impl = new PolymerDomApiImpl();
return (DomElement) node;
}

}

This file was deleted.

Loading
Loading