Skip to content

Commit

Permalink
Support 'nwfaketop' attribute of iframe
Browse files Browse the repository at this point in the history
With 'nwfaketop' attribute window.parent and window.top
would return the iframe object rather than the parent frame
and the top frame.

See nwjs/nw.js#534
  • Loading branch information
rogerwang committed Apr 25, 2013
1 parent 7dcd14c commit 12d8e15
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singl
return v8Integer(id, args.GetIsolate());
}

v8::Handle<v8::Value> V8DOMWindow::parentAttrGetterCustom(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
DOMWindow* imp = V8DOMWindow::toNative(info.Holder());
Frame* frame = imp->frame();
if (frame->isNwFakeTop())
return toV8Fast(imp, info, imp);
else
return toV8Fast(imp->parent(), info, imp);
}

v8::Handle<v8::Value> V8DOMWindow::topAttrGetterCustom(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
DOMWindow* imp = V8DOMWindow::toNative(info.Holder());
Frame* frame = imp->frame();
if (frame->isNwFakeTop())
return toV8Fast(imp, info, imp);
else
return toV8Fast(imp->top(), info, imp);
}

v8::Handle<v8::Value> V8DOMWindow::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8DOMWindow::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())));
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/HTMLAttributeNames.in
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ novalidate
nowrap
nwdirectory
nwdisable
nwfaketop
nwsaveas
nwworkingdir
object
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/HTMLIFrameElement.idl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface HTMLIFrameElement : HTMLElement {
[Reflect] attribute DOMString srcdoc;
[Reflect] attribute DOMString width;
[Reflect] attribute boolean nwdisable;
[Reflect] attribute boolean nwfaketop;

// Introduced in DOM Level 2:
[CheckSecurityForNode] readonly attribute Document contentDocument;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/DOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
[Replaceable, DoNotCheckSecurityOnGetter] readonly attribute DOMWindow frames;

[Replaceable, DoNotCheckSecurityOnGetter, V8CustomSetter] readonly attribute DOMWindow opener;
[Replaceable, DoNotCheckSecurityOnGetter] readonly attribute DOMWindow parent;
[DoNotCheckSecurityOnGetter, V8Unforgeable] readonly attribute DOMWindow top;
[Replaceable, DoNotCheckSecurityOnGetter, V8CustomGetter] readonly attribute DOMWindow parent;
[DoNotCheckSecurityOnGetter, V8Unforgeable, V8CustomGetter] readonly attribute DOMWindow top;

// DOM Level 2 AbstractView Interface
readonly attribute Document document;
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/page/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,13 @@ bool Frame::isNwDisabledChildFrame() const
return false;
}

bool Frame::isNwFakeTop() const
{
if (m_ownerElement && m_ownerElement->fastHasAttribute(nwfaketopAttr))
return true;
return false;
}

bool Frame::isNodeJS() const
{
return m_nodejs;
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ namespace WebCore {
void setNodeJS(bool node) { m_nodejs = node; }
bool isNodeJS() const;
bool isNwDisabledChildFrame() const;
bool isNwFakeTop() const;

#if USE(ACCELERATED_COMPOSITING)
void deviceOrPageScaleFactorChanged();
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/chromium/public/WebFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ class WebFrame {
virtual void setNodeJS(bool) = 0;
virtual bool isNodeJS() const = 0;
virtual bool isNwDisabledChildFrame() const = 0;
virtual bool isNwFakeTop() const = 0;
protected:
~WebFrame() { }
};
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/chromium/src/WebFrameImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class WebFrameImpl
void setNodeJS(bool node) { frame()->setNodeJS(node); }
bool isNodeJS() const { return frame()->isNodeJS(); }
bool isNwDisabledChildFrame() const { return frame()->isNwDisabledChildFrame(); }
bool isNwFakeTop() const { return frame()->isNwFakeTop(); }
private:
class DeferredScopeStringMatches;
friend class DeferredScopeStringMatches;
Expand Down

0 comments on commit 12d8e15

Please sign in to comment.