Author: mhermanto Date: Mon Nov 15 20:42:07 2010 New Revision: 1035438 URL: http://svn.apache.org/viewvc?rev=1035438&view=rev Log: Common container fixes - Consolidate getting gadget site/holder by IDs. - Better handling of Oaa and normal iframe HTMLs.
http://codereview.appspot.com/2897041/ http://codereview.appspot.com/3120041/ Modified: shindig/trunk/features/src/main/javascript/features/container/container.js shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js shindig/trunk/features/src/main/javascript/features/container/gadget_site.js 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=1035438&r1=1035437&r2=1035438&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container/container.js (original) +++ shindig/trunk/features/src/main/javascript/features/container/container.js Mon Nov 15 20:42:07 2010 @@ -131,36 +131,6 @@ shindig.container.Container.prototype.ne /** - * @param {string} id Iframe ID of gadget site to get. - * @return {shindig.container.GadgetSite} The gadget site with the given id. - */ -shindig.container.Container.prototype.getGadgetSite = function(id) { - // TODO: Support getting only the loading/active gadget in 2x buffers. - for (var siteId in this.sites_) { - var site = this.sites_[siteId]; - if (site.getGadgetHolder(id)) { - return site; - } - } - return null; -}; - - -/** - * @param {string} id Iframe ID of gadget holder to get. - * @return {shindig.container.GadgetHolder} The gadget holder with iframe id. - */ -shindig.container.Container.prototype.getGadgetHolder = function(id) { - var site = this.getGadgetSite(id); - if (site) { - return site.getGadgetHolder(id); - } else { - return null; - } -}; - - -/** * Called when gadget is navigated. * * @param {shindig.container.GadgetSite} site destination gadget to navigate to. @@ -272,7 +242,8 @@ shindig.container.Container.prototype.rp var self = this; gadgets.rpc.register(service, function() { // this['f'] is set by calling iframe via gadgets.rpc. - this[shindig.container.GadgetSite.RPC_ARG_KEY] = self.getGadgetSite(this['f']); + this[shindig.container.GadgetSite.RPC_ARG_KEY] = + self.getGadgetSiteByIframeId_(this['f']); var argsCopy = [this]; for (var i = 0; i < arguments.length; ++i) { argsCopy.push(arguments[i]); @@ -393,6 +364,24 @@ shindig.container.ContainerRender.WIDTH /** + * @param {string} id Iframe ID of gadget holder contained in the gadget site to get. + * @return {shindig.container.GadgetSite} The gadget site. + * @private + */ +shindig.container.Container.prototype.getGadgetSiteByIframeId_ = function(iframeId) { + // TODO: Support getting only the loading/active gadget in 2x buffers. + for (var siteId in this.sites_) { + var site = this.sites_[siteId]; + var holder = site.getActiveGadgetHolder(); + if (holder && holder.getIframeId() === iframeId) { + return site; + } + } + return null; +}; + + +/** * Start to schedule refreshing of tokens. * @private */ @@ -483,8 +472,8 @@ shindig.container.Container.prototype.ge } // Collect active gadget urls. - for (var siteIndex in this.sites_) { - var holder = this.sites_[siteIndex].getActiveGadgetHolder(); + for (var siteId in this.sites_) { + var holder = this.sites_[siteId].getActiveGadgetHolder(); var url = holder.getUrl(); var metadata = this.service_.getCachedGadgetMetadata(url); if (metadata[shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) { @@ -510,8 +499,8 @@ shindig.container.Container.prototype.re // Update active token-requiring gadgets with new tokens. Do not need to // update pre-loaded gadgets, since new tokens will take effect when they // are navigated to, from cache. - for (var key in self.sites_) { - var holder = self.sites_[key].getActiveGadgetHolder(); + for (var siteId in self.sites_) { + var holder = self.sites_[siteId].getActiveGadgetHolder(); var gadgetInfo = self.service_.getCachedGadgetMetadata(holder.getUrl()); if (gadgetInfo[shindig.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) { var tokenInfo = response[holder.getUrl()]; Modified: shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js?rev=1035438&r1=1035437&r2=1035438&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js (original) +++ shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js Mon Nov 15 20:42:07 2010 @@ -44,28 +44,28 @@ shindig.container.GadgetHolder = functio /** * JSON metadata for gadget - * @type {Object?} + * @type {Object} * @private */ this.gadgetInfo_ = null; /** * View parameters to pass to gadget. - * @type {Object?} + * @type {Object} * @private */ this.viewParams_ = null; /** * Gadget rendering parameters - * @type {Object?} + * @type {Object} * @private */ this.renderParams_ = null; /** * Unique string gadget ID. Used for DOM IDs/names. - * @type {string?} + * @type {string} * @private */ this.iframeId_ = null; @@ -74,7 +74,7 @@ shindig.container.GadgetHolder = functio * A dynamically set social/security token. * Social tokens are sent with original view URLs but may need * to be refreshed for long lived gadgets. - * @type {string?} + * @type {string} * @private */ this.securityToken_ = null; @@ -99,7 +99,7 @@ shindig.container.GadgetHolder.prototype /** - * @return {?string} The unique string ID for gadget iframe. + * @return {string} The unique string ID for gadget iframe. */ shindig.container.GadgetHolder.prototype.getIframeId = function() { return this.iframeId_; @@ -107,7 +107,7 @@ shindig.container.GadgetHolder.prototype /** - * @return {?Object} The metadata of gadget. + * @return {Object} The metadata of gadget. */ shindig.container.GadgetHolder.prototype.getGadgetInfo = function() { return this.gadgetInfo_; @@ -123,7 +123,7 @@ shindig.container.GadgetHolder.prototype /** - * @return {?string} The URL of current gadget. + * @return {string} The URL of current gadget. */ shindig.container.GadgetHolder.prototype.getUrl = function() { return (this.gadgetInfo_) ? this.gadgetInfo_['url'] : null; @@ -131,7 +131,7 @@ shindig.container.GadgetHolder.prototype /** - * @return {?string} The view of current gadget. + * @return {string} The view of current gadget. */ shindig.container.GadgetHolder.prototype.getView = function() { return this.renderParams_[shindig.container.RenderParam.VIEW]; @@ -169,24 +169,12 @@ shindig.container.GadgetHolder.prototype this.gadgetInfo_ = gadgetInfo; this.viewParams_ = viewParams; this.renderParams_ = renderParams; - this.el_.innerHTML = this.getIframeHtml_(); if (this.hasFeature_(gadgetInfo, 'pubsub-2')) { - this.doOAAIframeHtml_(); + this.doOaaIframeHtml_(); } else { - this.el_.innerHTML = this.getIframeHtml_(); + this.doNormalIframeHtml_(); } - - // Set up RPC channel. RPC relay url is on gmodules, relative to base of the - // container. Assumes container has set up forwarding to gmodules at /gadgets. - var iframeUri = shindig.uri( - this.gadgetInfo_[shindig.container.MetadataResponse.IFRAME_URL]); - var relayUri = shindig.uri() - .setSchema(iframeUri.getSchema()) - .setAuthority(iframeUri.getAuthority()) - .setPath('/gadgets/files/container/rpc_relay.html'); - gadgets.rpc.setupReceiver(this.iframeId_, relayUri.toString(), - iframeUri.getFP('rpctoken')); }; @@ -206,7 +194,26 @@ shindig.container.GadgetHolder.IFRAME_ID /** * @private */ -shindig.container.GadgetHolder.prototype.doOAAIframeHtml_ = function() { +shindig.container.GadgetHolder.prototype.doNormalIframeHtml_ = function() { + this.el_.innerHTML = this.getIframeHtml_(); + + // Set up RPC channel. RPC relay url is on gmodules, relative to base of the + // container. Assumes container has set up forwarding to gmodules at /gadgets. + var iframeUri = shindig.uri( + this.gadgetInfo_[shindig.container.MetadataResponse.IFRAME_URL]); + var relayUri = shindig.uri() + .setSchema(iframeUri.getSchema()) + .setAuthority(iframeUri.getAuthority()) + .setPath('/gadgets/files/container/rpc_relay.html'); + gadgets.rpc.setupReceiver(this.iframeId_, relayUri.toString(), + iframeUri.getFP('rpctoken')); +}; + + +/** + * @private + */ +shindig.container.GadgetHolder.prototype.doOaaIframeHtml_ = function() { var iframeAttrs = { frameborder: 'no', scrolling: 'no' @@ -221,7 +228,7 @@ shindig.container.GadgetHolder.prototype source.getIframe().src = 'about:blank'; }, onConnect: function(container) { - gadgets.log("++ connected: " + container.getClientID()); + gadgets.log(['connected: ', container.getClientID()].join('')); } }, IframeContainer: { Modified: shindig/trunk/features/src/main/javascript/features/container/gadget_site.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_site.js?rev=1035438&r1=1035437&r2=1035438&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container/gadget_site.js (original) +++ shindig/trunk/features/src/main/javascript/features/container/gadget_site.js Mon Nov 15 20:42:07 2010 @@ -173,22 +173,6 @@ shindig.container.GadgetSite.prototype.g /** - * Returns the loading or visible gadget with the given ID. - * @param {string} id The iframe ID of gadget to return. - * @return {shindig.container.GadgetHolder?} The gadget. Null, if not exist. - */ -shindig.container.GadgetSite.prototype.getGadgetHolder = function(id) { - if (this.currentGadgetHolder_ && this.currentGadgetHolder_.getIframeId() == id) { - return this.currentGadgetHolder_; - } - if (this.loadingGadgetHolder_ && this.loadingGadgetHolder_.getIframeId() == id) { - return this.loadingGadgetHolder_; - } - return null; -}; - - -/** * @return {string?} ID parent element containing this site. */ shindig.container.GadgetSite.prototype.getParentId = function() {
