Chinaunix首页 | 论坛 | 博客
  • 博客访问: 304936
  • 博文数量: 174
  • 博客积分: 3061
  • 博客等级: 中校
  • 技术积分: 1740
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-04 22:43
文章分类

全部博文(174)

文章存档

2011年(54)

2010年(14)

2009年(30)

2008年(26)

2007年(27)

2006年(23)

我的朋友

分类: WINDOWS

2011-06-10 11:36:56

我之前有一篇文章,讲了如果将一个全局的domwindow暴露给任意的一个page,让它可以像使用window对象那样使用另外一个page的window。

现在需求又有了变化,即任何的page之间能够互相访问,这个任意指的是用我们系统的page 或者我们自己创建的page。

因此我特意看了看window.frames 的用法,一开始很容易发现,无非就是jsdomwindow 对象上暴露了一个frames的属性:

{ "frames", DontDelete, (intptr_t)static_cast(jsDOMWindowFrames), (intptr_t)setJSDOMWindowFrames },


void setJSDOMWindowFrames(ExecState* exec, JSObject* thisObject, JSValue value)
{
    if (!static_cast(thisObject)->allowsAccessFrom(exec))
        return;
    // Shadowing a built-in object
    static_cast(thisObject)->putDirect(Identifier(exec, "frames"), value);
}

也就是说如果你在js中写:

windows.frames["f1"] 那么frames这个拿到js中处理后就是变为了上述函数调用。


不过["f1"] 倒是让我找了一会儿,呵呵。

实际上js的执行无法就是拿到了一个名字或者成为js的token之后给引擎解析,比如window,document,或者自定义对象,这儿的 "f1" 就被作为一个属性投递给了引擎。

如下函数会被作为 "f1" 这个property的获取器被调用,而JSDOMWindow 就是frames属性调用时候返回的那个domwindow对象。


bool JSDOMWindow::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)

这个函数的实现, 
 // Check for child frames by name before built-in properties to
    // match Mozilla. This does not match IE, but some sites end up
    // naming frames things that conflict with window properties that
    // are in Moz but not IE. Since we have some of these, we have to do
    // it the Moz way.
    if (impl()->frame()->tree()->child(propertyName)) {
        slot.setCustom(this, childFrameGetter);
        return true;
    }
也就是说如果在window对象子集的proptable中寻找“f1”如果找不到就call上面的代码,即寻找子frame;
这样就是说frame的name不能起 "document", "self","top" 这些window对象本身已经具有的名字了。



到了这儿window.frames[key]的用法了解了。

那么回到我自己的需求,下来我无非就是让所有的自定以窗口成为某个global窗口的childframe就可以解决这个问题,同时令所有的child有一个唯一的名字即可。


阅读(527) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~