You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Kam Kasravi <kk...@yahoo-inc.com> on 2010/04/05 10:29:11 UTC

container -> gadget error in rpc.js

Hi

rpc.js has a bug related to returning the window for container -> gadget channel communication

Original code
  function getTargetWin(id) {
    if (typeof id === "undefined" ||
        id === "..") {
      return window.parent;
    }

    // Cast to a String to avoid an index lookup.
    id = String(id);

    // Try window.frames first
    var target = window.frames[id];
    if (target) {
      return target;
    }

    // Fall back to getElementById()
    target = document.getElementById(id);
    if (target && target.contentWindow) {
      return target.contentWindow;
    }

    return null;
  }


Modified code
  function getTargetWin(id) {
    if (typeof id === "undefined" ||
        id === "..") {
      return window.parent;
    }

    // Cast to a String to avoid an index lookup.
    id = String(id);

    var target = window.frames[id] || document.getElementById(id);
    if (target && target.contentWindow) {
      return target.contentWindow;
    }

    return null;
  }

Analysis:

window.frame[id] will return an IFrameHTMLElement - to get to the window you must access contentWindow.
I've tested this on the following browsers

FF3.6, SF4.0.5, GC5.0,IE6,IE7,IE8,OP10.5


Thanks
Kam

Re: container -> gadget error in rpc.js

Posted by John Hjelmstad <jo...@gmail.com>.
Paul/Kam:

The update code breaks for me using the test harness (URL assumes you've
started up a Shindig instance on port 8080 and 8081), on Safari4 and
Chrome4.
http://localhost:8080/gadgets/files/container/rpctest_container.html?localhost:8081

Adding simple alert messaging in Safari4 shows that window.frames[id] yields
a DOMWindow object. document.getElementById(id) does yield an
IFrameHTMLElement, which requires contentWIndow retrieval. Code:
    // Try window.frames first
    var target = window.frames[id];
    if (target) {
      prompt('',target + ", win: " + target.contentWindow + ', idt: ' +
document.getElementById(id) + ', idtw: ' +
document.getElementById(id).contentWindow);
      return target;
    }

...shows:
[object DOMWindow], win: undefined, idt: [object HTMLIFrameElement], idtw:
[object DOMWindow]

MDC's documentation corroborates this:
https://developer.mozilla.org/en/DOM/window.frames
"each item in the window.frames pseudo-array represents the
window<https://developer.mozilla.org/en/DOM/window> object
corresponding to the given
<frame><https://developer.mozilla.org/en/HTML/Element/frame>'s
or <iframe> <https://developer.mozilla.org/en/HTML/Element/iframe>'s
content, not the (i)frame DOM element (i.e. window.frames[ 0 ] is the same
thing as document.getElementsByTagName( "iframe" )[ 0 ].contentWindow)"

Let me know if I'm missing something.
--j

On Tue, Apr 6, 2010 at 4:01 AM, Paul Lindner <li...@inuus.com> wrote:

> Hi Kam,
>
> Can you file a Jira for this issue at http://issues.apache.org/ ?
>
> +johnfargo who knows more about this code.  John can you evaluate?  Thanks!
>
> On Mon, Apr 5, 2010 at 1:29 AM, Kam Kasravi <kk...@yahoo-inc.com>wrote:
>
>> Hi
>>
>> rpc.js has a bug related to returning the window for container -> gadget
>> channel communication
>>
>> Original code
>>  function getTargetWin(id) {
>>    if (typeof id === "undefined" ||
>>        id === "..") {
>>      return window.parent;
>>    }
>>
>>    // Cast to a String to avoid an index lookup.
>>    id = String(id);
>>
>>    // Try window.frames first
>>    var target = window.frames[id];
>>    if (target) {
>>      return target;
>>    }
>>
>>    // Fall back to getElementById()
>>    target = document.getElementById(id);
>>    if (target && target.contentWindow) {
>>      return target.contentWindow;
>>    }
>>
>>    return null;
>>  }
>>
>>
>> Modified code
>>  function getTargetWin(id) {
>>    if (typeof id === "undefined" ||
>>        id === "..") {
>>      return window.parent;
>>    }
>>
>>    // Cast to a String to avoid an index lookup.
>>    id = String(id);
>>
>>    var target = window.frames[id] || document.getElementById(id);
>>    if (target && target.contentWindow) {
>>      return target.contentWindow;
>>    }
>>
>>    return null;
>>  }
>>
>> Analysis:
>>
>> window.frame[id] will return an IFrameHTMLElement - to get to the window
>> you must access contentWindow.
>> I've tested this on the following browsers
>>
>> FF3.6, SF4.0.5, GC5.0,IE6,IE7,IE8,OP10.5
>>
>>
>> Thanks
>> Kam
>>
>
>

Re: container -> gadget error in rpc.js

Posted by Paul Lindner <li...@inuus.com>.
Hi Kam,

Can you file a Jira for this issue at http://issues.apache.org/ ?

+johnfargo who knows more about this code.  John can you evaluate?  Thanks!

On Mon, Apr 5, 2010 at 1:29 AM, Kam Kasravi <kk...@yahoo-inc.com> wrote:

> Hi
>
> rpc.js has a bug related to returning the window for container -> gadget
> channel communication
>
> Original code
>  function getTargetWin(id) {
>    if (typeof id === "undefined" ||
>        id === "..") {
>      return window.parent;
>    }
>
>    // Cast to a String to avoid an index lookup.
>    id = String(id);
>
>    // Try window.frames first
>    var target = window.frames[id];
>    if (target) {
>      return target;
>    }
>
>    // Fall back to getElementById()
>    target = document.getElementById(id);
>    if (target && target.contentWindow) {
>      return target.contentWindow;
>    }
>
>    return null;
>  }
>
>
> Modified code
>  function getTargetWin(id) {
>    if (typeof id === "undefined" ||
>        id === "..") {
>      return window.parent;
>    }
>
>    // Cast to a String to avoid an index lookup.
>    id = String(id);
>
>    var target = window.frames[id] || document.getElementById(id);
>    if (target && target.contentWindow) {
>      return target.contentWindow;
>    }
>
>    return null;
>  }
>
> Analysis:
>
> window.frame[id] will return an IFrameHTMLElement - to get to the window
> you must access contentWindow.
> I've tested this on the following browsers
>
> FF3.6, SF4.0.5, GC5.0,IE6,IE7,IE8,OP10.5
>
>
> Thanks
> Kam
>