Review Board 1.7.22


rpc does not support communicating with gadget created on an dom node in existing iframe

Review Request #3908 - Created Feb. 15, 2012 and updated

Yao Zhang
SHINDIG-1704
Reviewers
shindig
ddumont, hsaputra, lixu, ssievers
shindig
When you try to render a gadget to a dom node inside an existing iframe, rpc does not work as the code is using document.getElementById to get the domnode

 
http://svn.apache.org/repos/asf/shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js
Revision 1238149 New Change
[20] 158 lines
[+20]
159
    var subs = {};
159
    var subs = {};
160
    var securityToken;
160
    var securityToken;
161
    var internalID;
161
    var internalID;
162
    var timeout = params.IframeContainer.timeout || 15000;
162
    var timeout = params.IframeContainer.timeout || 15000;
163
    var loadTimer;
163
    var loadTimer;

    
   
164
    var ownerDocument = params.IframeContainer.parent.ownerDocument;
164

    
   
165

   
165
    if ( params.Container.log ) {
166
    if ( params.Container.log ) {
166
        var log = function( msg ) {
167
        var log = function( msg ) {
167
            try {
168
            try {
168
                params.Container.log.call( scope, "IframeContainer::" + clientID + ": " + msg );
169
                params.Container.log.call( scope, "IframeContainer::" + clientID + ": " + msg );
[+20] [20] 46 lines
[+20] [+] log = function() {};
215

    
   
216

   
216
    this.remove = function() {
217
    this.remove = function() {
217
        finishDisconnect();
218
        finishDisconnect();
218
        clearTimeout( loadTimer );
219
        clearTimeout( loadTimer );
219
        OpenAjax.gadgets.rpc.removeReceiver( internalID );
220
        OpenAjax.gadgets.rpc.removeReceiver( internalID );
220
        var iframe = document.getElementById( internalID );
221
        var iframe = ownerDocument.getElementById( internalID );
221
        iframe.parentNode.removeChild( iframe );
222
        iframe.parentNode.removeChild( iframe );
222
        OpenAjax.hub.IframeContainer._rpcRouter.remove( internalID );
223
        OpenAjax.hub.IframeContainer._rpcRouter.remove( internalID );
223
    };
224
    };
224

    
   
225

   
225
    this.isConnected = function() {
226
    this.isConnected = function() {
[+20] [20] 40 lines
[+20] log = function() {};
266
     * 
267
     * 
267
     * @returns iframeElement
268
     * @returns iframeElement
268
     * @type {Object}
269
     * @type {Object}
269
     */
270
     */
270
    this.getIframe = function() {
271
    this.getIframe = function() {
271
        return document.getElementById( internalID );
272
        return ownerDocument.getElementById( internalID );
272
    };
273
    };
273
    
274
    
274
    
275
    
275
  /*** private functions ***/
276
  /*** private functions ***/
276

    
   
277

   
[+20] [20] 110 lines
[+20] [+] function createIframe() {
387
        var idText = "";
388
        var idText = "";
388
        if ( internalID !== clientID ) {
389
        if ( internalID !== clientID ) {
389
            idText = "&oahId=" + internalID.substring( internalID.lastIndexOf('_') + 1 );
390
            idText = "&oahId=" + internalID.substring( internalID.lastIndexOf('_') + 1 );
390
        }
391
        }
391

    
   
392

   
392
        var iframe = document.getElementById( internalID );
393
        var iframe = ownerDocument.getElementById( internalID );
393
        if(iframe.attachEvent) {
394
        if(iframe.attachEvent) {
394
          //Works for IE
395
          //Works for IE
395
          iframe.attachEvent('onload', function(){
396
          iframe.attachEvent('onload', function(){
396
            window[params.IframeContainer.onGadgetLoad]();
397
            window[params.IframeContainer.onGadgetLoad]();
397
          });
398
          });
398
        } else {
399
        } else {
399
          iframe.onload = function(){window[params.IframeContainer.onGadgetLoad]();};
400
          iframe.onload = function(){window[params.IframeContainer.onGadgetLoad]();};
400
        }
401
        }
401
        iframe.src = params.IframeContainer.uri +
402
        

    
   
403
        //calculate embedded level

    
   
404
        var p = params.IframeContainer.parent.ownerDocument.defaultView;

    
   
405
        var embeddedlevel = 0;

    
   
406
        while (p && p !== window) {

    
   
407
        	p = p.parent;

    
   
408
        	embeddedlevel++;

    
   
409
        }

    
   
410
        iframe.src = params.IframeContainer.uri + "#embeddedlevel="+ embeddedlevel +
402
                "#rpctoken=" + securityToken + tunnelText + idText;
411
                "#rpctoken=" + securityToken + tunnelText + idText;
403
    }
412
    }
404

    
   
413

   
405
    // If the relay iframe used by RPC has not been loaded yet, then we won't have unload protection
414
    // If the relay iframe used by RPC has not been loaded yet, then we won't have unload protection
406
    // at this point.  Since we can't detect when the relay iframe has loaded, we use a two stage
415
    // at this point.  Since we can't detect when the relay iframe has loaded, we use a two stage
[+20] [20] 5 lines
[+20] function createIframe() {
412
        // connect acknowledgement
421
        // connect acknowledgement
413
        function callback( result ) {
422
        function callback( result ) {
414
            if ( result ) {
423
            if ( result ) {
415
                connected = true;
424
                connected = true;
416
                clearTimeout( loadTimer );
425
                clearTimeout( loadTimer );
417
                document.getElementById( internalID ).style.visibility = "visible";
426
                ownerDocument.getElementById( internalID ).style.visibility = "visible";
418
                if ( params.Container.onConnect ) {
427
                if ( params.Container.onConnect ) {
419
                    try {
428
                    try {
420
                        params.Container.onConnect.call( scope, container );
429
                        params.Container.onConnect.call( scope, container );
421
                    } catch( e ) {
430
                    } catch( e ) {
422
                        OpenAjax.hub._debugger();
431
                        OpenAjax.hub._debugger();
[+20] [20] 6 lines
[+20] function callback( result ) {
429
    }
438
    }
430
    
439
    
431
    function finishDisconnect() {
440
    function finishDisconnect() {
432
        if ( connected ) {
441
        if ( connected ) {
433
            connected = false;
442
            connected = false;
434
            document.getElementById( internalID ).style.visibility = "hidden";
443
            ownerDocument.getElementById( internalID ).style.visibility = "hidden";
435
        
444
        
436
            // unsubscribe from all subs
445
            // unsubscribe from all subs
437
            for ( var s in subs ) {
446
            for ( var s in subs ) {
438
                hub.unsubscribeForClient( container, subs[s] );
447
                hub.unsubscribeForClient( container, subs[s] );
439
            }
448
            }
[+20] [20] 445 lines
http://svn.apache.org/repos/asf/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js
Revision 1238149 New Change
 
  1. http://svn.apache.org/repos/asf/shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js: Loading...
  2. http://svn.apache.org/repos/asf/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js: Loading...