You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by rb...@apache.org on 2011/12/12 16:27:15 UTC
svn commit: r1213277 - in /shindig/trunk:
content/samplecontainer/examples/embeddedexperiences/
features/src/main/javascript/features/container.util/
features/src/main/javascript/features/container/
features/src/main/javascript/features/embeddedexperie...
Author: rbaxter85
Date: Mon Dec 12 15:27:14 2011
New Revision: 1213277
URL: http://svn.apache.org/viewvc?rev=1213277&view=rev
Log:
SHINDIG-1669
Navigating to URLs in the common container has no indication of success or failure
Modified:
shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml
shindig/trunk/features/src/main/javascript/features/container.util/util.js
shindig/trunk/features/src/main/javascript/features/container/container.js
shindig/trunk/features/src/main/javascript/features/embeddedexperiences/embedded_experiences_container.js
shindig/trunk/features/src/main/javascript/features/open-views/viewenhancements-container.js
shindig/trunk/features/src/test/javascript/features/container.url/container_url_test.js
Modified: shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml?rev=1213277&r1=1213276&r2=1213277&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml (original)
+++ shindig/trunk/content/samplecontainer/examples/embeddedexperiences/PhotoList.xml Mon Dec 12 15:27:14 2011
@@ -95,7 +95,7 @@
}
};
}
- var navigateCallback = function(site, metadata){currentSite = site; console.log("Nagivate callback");};
+ var navigateCallback = function(site, result){currentSite = site; console.log("Nagivate callback");};
var returnCallback = function(returnValue){console.log("Return Value: " + returnValue);};
gadgets.views.openEmbeddedExperience(returnCallback, navigateCallback, eeDataModel, {'viewTarget' : 'preview'});
};
Modified: shindig/trunk/features/src/main/javascript/features/container.util/util.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.util/util.js?rev=1213277&r1=1213276&r2=1213277&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container.util/util.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container.util/util.js Mon Dec 12 15:27:14 2011
@@ -87,6 +87,18 @@ osapi.container.util.newMetadataRequest
};
};
+/**
+ * Creates a new head request to be made to the given URL.
+ * @param {String} url The URL to make the head request to.
+ * @return {osapi.Request} The request object.
+ */
+osapi.container.util.newHeadRequest = function(url) {
+ return osapi.http.head({
+ "href": url,
+ "refreshInterval": 0
+ });
+}
+
/**
* Construct a JSON request to get gadget token.
Modified: shindig/trunk/features/src/main/javascript/features/container/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=1213277&r1=1213276&r2=1213277&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js Mon Dec 12 15:27:14 2011
@@ -919,16 +919,34 @@ osapi.container.Container.prototype.newU
/**
- * Navigates to a URL
+ * Navigates to a URL. If an optional callback parameter is supplied the
+ * container will first make a HEAD request to the URL and return the result to
+ * the callback. If the callback is undefined than the container will try to
+ * render the URL in a site with out making any additional requests to the server.
+ * There are several consiquences of supply a callback,
+ * but the two most important ones are that there will be extra load on the server and
+ * that if the URL requires authentication the HEAD request will fail causing the URL
+ * not to render. As a result you should only supply a callback if you really need
+ * to know whether the URL is accessible or not.
* @param {osapi.container.UrlSite} site the URL site to render the URL in.
* @param {string} url the URL to render.
- * @param {Object} renderParams params to augment the rendering.
- * @return {osapi.container.UrlSite} the site you passed in.
+ * @param {Object} renderParams params to augment the rendering. Valid rendering parameters
+ * include osapi.container.RenderParam.CLASS, osapi.container.RenderParam.HEIGHT,
+ * and osapi.container.RenderParam.WIDTH.
+ * @param {function{Object}=} opt_callback optional callback called with the result of making a
+ * head request to the URL.
*
- * Valid rendering parameters include osapi.container.RenderParam.CLASS,
- * osapi.container.RenderParam.HEIGHT, and osapi.container.RenderParam.WIDTH.
*/
-osapi.container.Container.prototype.navigateUrl = function(site, url, renderParams) {
- site.render(url, renderParams);
- return site;
+osapi.container.Container.prototype.navigateUrl = function(site, url, renderParams,
+ opt_callback) {
+ if(opt_callback) {
+ osapi.container.util.newHeadRequest(url).execute(function(response) {
+ if(!response.error && (response.status >= 200 && response.status < 300)) {
+ site.render(url, renderParams);
+ }
+ callback(response);
+ });
+ } else {
+ site.render(url, renderParams);
+ }
};
Modified: shindig/trunk/features/src/main/javascript/features/embeddedexperiences/embedded_experiences_container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/embeddedexperiences/embedded_experiences_container.js?rev=1213277&r1=1213276&r2=1213277&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/embeddedexperiences/embedded_experiences_container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/embeddedexperiences/embedded_experiences_container.js Mon Dec 12 15:27:14 2011
@@ -77,10 +77,17 @@
var urlRenderParams =
renderParams[osapi.container.ee.RenderParam.URL_RENDER_PARAMS] || {};
var site = context.newUrlSite(element);
- var toReturn = context.navigateUrl(site, dataModel.url, urlRenderParams);
- if (opt_callback) {
- opt_callback(toReturn, null);
- }
+ context.navigateUrl(site, dataModel.url, urlRenderParams, function(response) {
+ if (opt_callback) {
+ if(response.status >= 400) {
+ //Format the response in a way that is similar to if we were navigating
+ //to a gadget, at least for error handling. Makes things slightly easier
+ //for callers.
+ response.error = {"code": response.status};
+ }
+ opt_callback(site, response);
+ }
+ });
};
/**
Modified: shindig/trunk/features/src/main/javascript/features/open-views/viewenhancements-container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/open-views/viewenhancements-container.js?rev=1213277&r1=1213276&r2=1213277&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/open-views/viewenhancements-container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/open-views/viewenhancements-container.js Mon Dec 12 15:27:14 2011
@@ -112,9 +112,9 @@
}
var renderParams = {},
- site = context.newGadgetSite(
- context.views.createElementForGadget(metadata, view, viewTarget)
- );
+ site = context.newGadgetSite(
+ context.views.createElementForGadget(metadata, view, viewTarget)
+ );
site.ownerId_ = siteOwnerId;
if (view !== undefined && view !== '') {
@@ -157,22 +157,7 @@
var navigateCallback = this.callback,
siteOwnerId = this.f,
gadgetUrl = dataModel.gadget;
-
- //Check to make sure we can actually reach the gadget we are going to try
- //to render before we do anything else
- context.preloadGadget(gadgetUrl, function(result) {
- if (result[gadgetUrl] == null ||
- (result[gadgetUrl] != null && result[gadgetUrl].error)) {
- //There was an error, check to see if there is still the option to
- //render the url, else just call the navigateCallback
- if (!dataModel.url) {
- if (navigateCallback != null) {
- navigateCallback([null, result[gadgetUrl]]);
- }
- return;
- }
- }
-
+ var navigateEE = function() {
var viewTarget = '';
var viewParams = {};
if (opt_params != undefined) {
@@ -203,16 +188,36 @@
eeRenderParams[osapi.container.ee.RenderParam.GADGET_VIEW_PARAMS] =
viewParams;
- context.ee.navigate(element, dataModel, eeRenderParams, function(site, metadata) {
+ context.ee.navigate(element, dataModel, eeRenderParams, function(site, result) {
site.ownerId_ = siteOwnerId;
- if (metadata) {
+ if (result) {
resultCallbackMap[site.getId()] = resultCallback;
}
if (navigateCallback) {
- navigateCallback([site.getId(), metadata]);
+ navigateCallback([site.getId(), result]);
}
});
- });
+ };
+
+ if(gadgetUrl) {
+ //Check to make sure we can actually reach the gadget we are going to try
+ //to render before we do anything else
+ context.preloadGadget(gadgetUrl, function(result) {
+ if (!result[gadgetUrl] || result[gadgetUrl].error) {
+ //There was an error, check to see if there is still the option to
+ //render the url, else just call the navigateCallback
+ if (!dataModel.url) {
+ if (navigateCallback != null) {
+ navigateCallback([null, result[gadgetUrl] || {"error" : result}]);
+ }
+ return;
+ }
+ }
+ navigateEE();
+ });
+ } else {
+ navigateEE();
+ }
}
Modified: shindig/trunk/features/src/test/javascript/features/container.url/container_url_test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/container.url/container_url_test.js?rev=1213277&r1=1213276&r2=1213277&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/container.url/container_url_test.js (original)
+++ shindig/trunk/features/src/test/javascript/features/container.url/container_url_test.js Mon Dec 12 15:27:14 2011
@@ -33,6 +33,7 @@ UrlContainerTest.prototype.setUp = funct
window.__CONTAINER_URI = shindig.uri('http://container.com');
this.shindigContainerGadgetSite = osapi.container.GadgetSite;
this.shindigContainerUrlSite = osapi.container.UrlSite;
+ this.shindigHttp = osapi.http;
this.gadgetsRpc = gadgets.rpc;
};
@@ -41,6 +42,7 @@ UrlContainerTest.prototype.tearDown = fu
window.__CONTAINER_URI = this.containerUri;
osapi.container.GadgetSite = this.shindigContainerGadgetSite;
osapi.container.UrlSite = this.shindigContainerUrlSite;
+ osapi.http = this.shindigHttp;
gadgets.rpc = this.gadgetsRpc;
};
@@ -54,6 +56,7 @@ UrlContainerTest.prototype.testNewUrlSit
UrlContainerTest.prototype.testNavigateUrl = function() {
this.setupGadgetsRpcRegister();
+ this.setupOsapiHttp();
var container = new osapi.container.Container({
'allowDefaultView' : true,
'renderCajole' : true,
@@ -85,4 +88,16 @@ UrlContainerTest.prototype.setupUrlSite
}
};
};
+};
+
+UrlContainerTest.prototype.setupOsapiHttp = function() {
+ osapi.http = {
+ "head" : function(params) {
+ return {
+ "execute" : function(callback) {
+ callback({"status" : 200});
+ }
+ };
+ }
+ };
};
\ No newline at end of file