Author: mhermanto
Date: Tue Oct 26 22:19:10 2010
New Revision: 1027761

URL: http://svn.apache.org/viewvc?rev=1027761&view=rev
Log:
Common container: 2 small rpc updates.
- allow container client to register rpc and work with calling GadgetSite.
- removed unused (by Shindig) onload rpc service.

http://codereview.appspot.com/2623041/

Modified:
    shindig/trunk/features/src/main/javascript/features/container/container.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=1027761&r1=1027760&r2=1027761&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js 
(original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js 
Tue Oct 26 22:19:10 2010
@@ -246,6 +246,26 @@ shindig.container.Container.prototype.ge
 
 
 /**
+ * @param {string} service name of RPC service to register.
+ * @param {Function} callback post-RPC function to call, with RPC-related
+ *                   arguments (with the calling GadgetSite augmented) and the
+ *                   callback response itself.
+ */
+shindig.container.Container.prototype.rpcRegister = function(service, 
callback) {
+  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']);
+    var argsCopy = [ this ];
+    for (var i = 0; i < arguments.length; ++i) {
+      argsCopy.push(arguments[i]);
+    }
+    callback.apply(self, argsCopy);
+  });
+};
+
+
+/**
  * Callback that occurs after instantiation/construction of this. Override to
  * provide your specific functionalities.
  * @param {Object=} opt_config Configuration JSON.
@@ -399,11 +419,11 @@ shindig.container.Container.prototype.is
  * @private
  */
 shindig.container.Container.prototype.registerRpcServices_ = function() {
-  var self = this;
-  gadgets.rpc.register('resize_iframe', function(height) {
-    // this['f'] is set by calling iframe via gadgets.rpc.
-    var site = self.getGadgetSite(this['f']);
-    site.setHeight(height);
+  this.rpcRegister('resize_iframe', function(rpcArgs, data) {
+    var site = rpcArgs[shindig.container.GadgetSite.RPC_ARG_KEY];
+    if (site) { // Check if site is not already closed.
+      site.setHeight(data);
+    }
   });
 };
 
@@ -452,7 +472,6 @@ shindig.container.Container.prototype.ge
 };
 
 
-
 /**
  * Refresh security tokens immediately. This will fetch gadget metadata, along
  * with its token and have the token cache updated.

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=1027761&r1=1027760&r2=1027761&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 
Tue Oct 26 22:19:10 2010
@@ -195,7 +195,7 @@ shindig.container.GadgetSite.prototype.g
  * Render a gadget in the site, by URI of the gadget XML.
  * @param {string} gadgetUrl The absolute URL to gadget.
  * @param {Object} viewParams Look at shindig.container.ViewParam.
- * @param {Object} renderParams. Look at shindig.container.RenderParam.
+ * @param {Object} renderParams Look at shindig.container.RenderParam.
  * @param {function(Object)=} opt_callback Function called with gadget info
  *     after navigation has occurred.
  */
@@ -222,7 +222,7 @@ shindig.container.GadgetSite.prototype.n
  * Render a gadget in this site, using a JSON gadget description.
  * @param {Object} gadgetInfo the JSON gadget description.
  * @param {Object} viewParams Look at shindig.container.ViewParam.
- * @param {Object} renderParams. Look at shindig.container.RenderParam.
+ * @param {Object} renderParams Look at shindig.container.RenderParam.
  */
 shindig.container.GadgetSite.prototype.render = function(
     gadgetInfo, viewParams, renderParams) {
@@ -251,18 +251,11 @@ shindig.container.GadgetSite.prototype.r
     throw [ 'Unsupported view ', view, ' for gadget ', gadgetInfo_['url'], '.' 
].join('');
   }
 
-  var delayLoad = this.getFeature('loadstate', gadgetInfo) ||
-      this.getFeature('shell', gadgetInfo);
-
   var localRenderParams = {};
   for (var key in renderParams) {
     localRenderParams[key] = renderParams[key];
   }
 
-  // Delay load for now means we autosize.
-  if (delayLoad) {
-    localRenderParams[shindig.container.RenderParam.HEIGHT] = '0';
-  }
   localRenderParams[shindig.container.RenderParam.VIEW] = view;
   localRenderParams[shindig.container.RenderParam.HEIGHT]
       = renderParams[shindig.container.RenderParam.HEIGHT]
@@ -279,14 +272,26 @@ shindig.container.GadgetSite.prototype.r
 
   this.loadingGadgetHolder_.render(gadgetInfo, viewParams, localRenderParams);
 
-  this.loaded_ = false;
+  this.onRender(gadgetInfo, viewParams, renderParams);
+};
+
 
-  // Resize on load only if load is delayed. If immediate, height is 0
-  this.resizeOnLoad_ = delayLoad;
+/**
+ * Called when a gadget loads in the site. Uses double buffer, if present.
+ * @param {Object} gadgetInfo the JSON gadget description.
+ * @param {Object} viewParams Look at shindig.container.ViewParam.
+ * @param {Object} renderParams Look at shindig.container.RenderParam.
+ */
+shindig.container.GadgetSite.prototype.onRender = function(
+    gadgetInfo, viewParams, renderParams) {
+  this.swapBuffers_();
 
-  if (!delayLoad) {
-    this.setLoadState_('loaded');
+  if (this.currentGadgetHolder_) {
+    this.currentGadgetHolder_.dispose();
   }
+
+  this.currentGadgetHolder_ = this.loadingGadgetHolder_;
+  this.loadingGadgetHolder_ = null;
 };
 
 
@@ -309,7 +314,7 @@ shindig.container.GadgetSite.prototype.r
  * If token has been fetched at least once, set the token to the most recent
  * one. Otherwise, leave it.
  * @param {Object} gadgetInfo The gadgetInfo used to update security token.
- * @param {Object} renderParams. Look at shindig.container.RenderParam.
+ * @param {Object} renderParams Look at shindig.container.RenderParam.
  */
 shindig.container.GadgetSite.prototype.updateSecurityToken_
     = function(gadgetInfo, renderParams) {
@@ -351,46 +356,6 @@ shindig.container.GadgetSite.nextUniqueI
 
 
 /**
- * Sets the load state of the currently loading / visible gadget.
- * @param {string} state The current state.
- * @private
- */
-shindig.container.GadgetSite.prototype.setLoadState_ = function(state) {
-  if (!this.loaded_ && state == 'loaded') {
-    this.onload_();
-  }
-};
-
-
-/**
- * Called when a gadget loads in the site. Uses double buffer, if present.
- * @private
- */
-shindig.container.GadgetSite.prototype.onload_ = function() {
-  this.loaded_ = true;
-  try {
-    gadgets.rpc.call(this.loadingGadgetHolder_.getIframeId(), 'onLoad', null);
-    if (this.resizeOnLoad_) {
-      // TODO need a value for setHeight
-      this.setHeight();
-    }
-  } catch (e) {
-    // This can throw for same domain, although it shouldn't
-    gadgets.log(e);
-  }
-
-  this.swapBuffers_();
-
-  if (this.currentGadgetHolder_) {
-    this.currentGadgetHolder_.dispose();
-  }
-
-  this.currentGadgetHolder_ = this.loadingGadgetHolder_;
-  this.loadingGadgetHolder_ = null;
-};
-
-
-/**
  * Swap the double buffer elements, if there is a double buffer.
  * @private
  */
@@ -411,6 +376,13 @@ shindig.container.GadgetSite.prototype.s
 
 
 /**
+ * Key to identify the calling gadget site.
+ * @type {string}
+ */
+shindig.container.GadgetSite.RPC_ARG_KEY = 'gs';
+
+
+/**
  * Default height of gadget. Refer to --
  * http://code.google.com/apis/gadgets/docs/legacy/reference.html.
  * @type {number}


Reply via email to