Reviewers: unnurg,
Description:
Provides a wrapper around transforming a resource name (filename or URL)
into an absolute URL. By default, this tacks on the module base
to a relative URL and leaves other names alone. It could be used
in other environments to wrap the request with a proxy, such as
when a GWT module runs as a Gadget.
Please review this at http://gwt-code-reviews.appspot.com/1385801/
Affected files:
M dev/core/src/com/google/gwt/core/ext/linker/impl/HostedModeTemplate.js
A
dev/core/src/com/google/gwt/core/ext/linker/impl/computeUrlForResource.js
M dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptDirect.js
M
dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptEarlyDownload.js
M
dev/core/src/com/google/gwt/core/ext/linker/impl/loadExternalStylesheets.js
M dev/core/src/com/google/gwt/core/ext/linker/impl/permutations.js
M dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
M dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js
Index:
dev/core/src/com/google/gwt/core/ext/linker/impl/HostedModeTemplate.js
===================================================================
--- dev/core/src/com/google/gwt/core/ext/linker/impl/HostedModeTemplate.js
(revision 9841)
+++ dev/core/src/com/google/gwt/core/ext/linker/impl/HostedModeTemplate.js
(working copy)
@@ -355,7 +355,8 @@
// __SHELL_SERVLET_ONLY_BEGIN__
// Force shell servlet to serve compiled output for Production Mode
if (!isHostedMode()) {
- $doc.write('<script src="' + base
+ '__MODULE_NAME__.nocache.js?compiled"></script>');
+ var url = computeUrlForResource("__MODULE_NAME__.nocache.js");
+ $doc.write('<script src="' + url + '?compiled"></script>');
return;
}
Index:
dev/core/src/com/google/gwt/core/ext/linker/impl/computeUrlForResource.js
===================================================================
---
dev/core/src/com/google/gwt/core/ext/linker/impl/computeUrlForResource.js
(revision 0)
+++
dev/core/src/com/google/gwt/core/ext/linker/impl/computeUrlForResource.js
(revision 0)
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+
+/**
+ * Transform a resource into URL before making a request. This can be
overridden
+ * if some sort of proxy mechanism is needed. This is modeled after the
logic
+ * originally coded in ResourceInjectsionUtils.java
+ */
+function computeUrlForResource(resource) {
+ /* return an absolute path unmodified */
+ if (resource.match(/^\//)) {
+ return resource;
+ }
+ /* return a fully qualified URL unmodified */
+ if (resource.match(/^[a-zA-Z]+:\/\//)) {
+ return resource;
+ }
+ return __MODULE_FUNC__.__moduleBase + resource;
+}
Index:
dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptDirect.js
===================================================================
--- dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptDirect.js
(revision 9841)
+++ dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptDirect.js
(working copy)
@@ -7,11 +7,11 @@
// Provides the setupWaitForBodyLoad()function
__WAIT_FOR_BODY_LOADED__
- function installCode(code) {
+ function installCode(filename) {
var docbody = getInstallLocation();
var script = getInstallLocationDoc().createElement('script');
script.language='javascript';
- script.src = code;
+ script.src = computeUrlForResource(filename);
sendStats('moduleStartup', 'moduleRequested');
docbody.appendChild(script);
Index:
dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptEarlyDownload.js
===================================================================
---
dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptEarlyDownload.js
(revision 9841)
+++
dev/core/src/com/google/gwt/core/ext/linker/impl/installScriptEarlyDownload.js
(working copy)
@@ -30,6 +30,6 @@
};
sendStats('moduleStartup', 'moduleRequested');
var script = $doc.createElement('script');
- script.src = filename;
+ script.src = computeUrlForResource(filename);
$doc.getElementsByTagName('head')[0].appendChild(script);
}
Index:
dev/core/src/com/google/gwt/core/ext/linker/impl/loadExternalStylesheets.js
===================================================================
---
dev/core/src/com/google/gwt/core/ext/linker/impl/loadExternalStylesheets.js
(revision 9841)
+++
dev/core/src/com/google/gwt/core/ext/linker/impl/loadExternalStylesheets.js
(working copy)
@@ -4,11 +4,13 @@
// change across GWT versions.
if (!$wnd.__gwt_stylesLoaded) { $wnd.__gwt_stylesLoaded = {}; }
+ // hrefExpr argument is legacy - use the modular computeUrlForResource()
+ // method to transform stylesheetUrl instead.
function installOneStylesheet(stylesheetUrl, hrefExpr) {
if (!__gwt_stylesLoaded[stylesheetUrl]) {
var l = $doc.createElement('link');
l.setAttribute('rel', 'stylesheet');
- l.setAttribute('href', hrefExpr);
+ l.setAttribute('href', computeUrlForResource(stylesheetUrl));
$doc.getElementsByTagName('head')[0].appendChild(l);
__gwt_stylesLoaded[stylesheetUrl] = true;
}
Index: dev/core/src/com/google/gwt/core/ext/linker/impl/permutations.js
===================================================================
--- dev/core/src/com/google/gwt/core/ext/linker/impl/permutations.js
(revision 9841)
+++ dev/core/src/com/google/gwt/core/ext/linker/impl/permutations.js
(working copy)
@@ -42,7 +42,7 @@
sendStats('bootstrap', 'selectingPermutation');
if (isHostedMode()) {
- return __MODULE_FUNC__.__moduleBase + "__HOSTED_FILENAME__";
+ return "__HOSTED_FILENAME__";
}
var strongName;
try {
@@ -59,5 +59,5 @@
// intentionally silent on property failure
}
__MODULE_FUNC__.__softPermutationId = softPermutationId;
- return __MODULE_FUNC__.__moduleBase + strongName + '.cache.js';
+ return strongName + '.cache.js';
}
Index: dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
===================================================================
--- dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
(revision 9841)
+++ dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
(working copy)
@@ -67,19 +67,20 @@
protected String fillSelectionScriptTemplate(StringBuffer ss,
TreeLogger logger, LinkerContext context, ArtifactSet artifacts,
CompilationResult result) throws UnableToCompleteException {
-
+
// Must do installScript before installLocation and waitForBodyLoaded
includeJs(ss, logger,
getJsInstallScript(context), "__INSTALL_SCRIPT__");
includeJs(ss, logger,
getJsInstallLocation(context), "__INSTALL_LOCATION__");
includeJs(ss, logger,
getJsWaitForBodyLoaded(context), "__WAIT_FOR_BODY_LOADED__");
-
+
// Must do permutations before providers
includeJs(ss, logger, getJsPermutations(context), "__PERMUTATIONS__");
includeJs(ss, logger, getJsProperties(context), "__PROPERTIES__");
includeJs(ss, logger, getJsProcessMetas(context), "__PROCESS_METAS__");
includeJs(ss, logger,
getJsComputeScriptBase(context), "__COMPUTE_SCRIPT_BASE__");
+ includeJs(ss, logger,
getJsComputeUrlForResource(context), "__COMPUTE_URL_FOR_RESOURCE__");
includeJs(ss, logger,
getJsLoadExternalStylesheets(context), "__LOAD_STYLESHEETS__");
-
+
// This Linker does not support <script> tags in the gwt.xml
SortedSet<ScriptReference> scripts =
artifacts.find(ScriptReference.class);
if (!scripts.isEmpty()) {
@@ -156,7 +157,11 @@
protected String getJsLoadExternalStylesheets(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/loadExternalStylesheets.js";
}
-
+
+ protected String getJsComputeUrlForResource(LinkerContext context) {
+ return "com/google/gwt/core/ext/linker/impl/computeUrlForResource.js";
+ }
+
protected String getJsPermutations(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/permutations.js";
}
Index: dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js
===================================================================
--- dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js
(revision 9841)
+++ dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js
(working copy)
@@ -95,6 +95,9 @@
// Provides the computeScriptBase() function
__COMPUTE_SCRIPT_BASE__
+ // Provides the computeUrlForResource() function
+ __COMPUTE_URL_FOR_RESOURCE__
+
// Provides the getCompiledCodeFilename() function which sets the
// __gwt_isKnownPropertyValue, MODULE_FUNC__.__computePropValue and
// __MODULE_FUNC__.__softPermutationId variables if needed
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors