From 12d8e1562df785a978e792873ebab77ddf42b717 Mon Sep 17 00:00:00 2001 From: Roger WANG Date: Thu, 25 Apr 2013 22:36:46 +0800 Subject: [PATCH] Support 'nwfaketop' attribute of iframe With 'nwfaketop' attribute window.parent and window.top would return the iframe object rather than the parent frame and the top frame. See rogerwang/node-webkit#534 --- .../bindings/v8/custom/V8DOMWindowCustom.cpp | 20 +++++++++++++++++++ Source/WebCore/html/HTMLAttributeNames.in | 1 + Source/WebCore/html/HTMLIFrameElement.idl | 1 + Source/WebCore/page/DOMWindow.idl | 4 ++-- Source/WebCore/page/Frame.cpp | 7 +++++++ Source/WebCore/page/Frame.h | 1 + Source/WebKit/chromium/public/WebFrame.h | 1 + Source/WebKit/chromium/src/WebFrameImpl.h | 1 + 8 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp b/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp index 6cef2e56cec..4a128857f10 100644 --- a/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp +++ b/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp @@ -145,6 +145,26 @@ v8::Handle WindowSetTimeoutImpl(const v8::Arguments& args, bool singl return v8Integer(id, args.GetIsolate()); } +v8::Handle V8DOMWindow::parentAttrGetterCustom(v8::Local 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 V8DOMWindow::topAttrGetterCustom(v8::Local 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 V8DOMWindow::eventAttrGetterCustom(v8::Local name, const v8::AccessorInfo& info) { v8::Handle holder = info.This()->FindInstanceInPrototypeChain(V8DOMWindow::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate()))); diff --git a/Source/WebCore/html/HTMLAttributeNames.in b/Source/WebCore/html/HTMLAttributeNames.in index 0aaf8ab41d2..176b14dc5c4 100644 --- a/Source/WebCore/html/HTMLAttributeNames.in +++ b/Source/WebCore/html/HTMLAttributeNames.in @@ -166,6 +166,7 @@ novalidate nowrap nwdirectory nwdisable +nwfaketop nwsaveas nwworkingdir object diff --git a/Source/WebCore/html/HTMLIFrameElement.idl b/Source/WebCore/html/HTMLIFrameElement.idl index 48526fc2202..acee74a8ffa 100644 --- a/Source/WebCore/html/HTMLIFrameElement.idl +++ b/Source/WebCore/html/HTMLIFrameElement.idl @@ -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; diff --git a/Source/WebCore/page/DOMWindow.idl b/Source/WebCore/page/DOMWindow.idl index 134e48db931..76eb02c390d 100644 --- a/Source/WebCore/page/DOMWindow.idl +++ b/Source/WebCore/page/DOMWindow.idl @@ -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; diff --git a/Source/WebCore/page/Frame.cpp b/Source/WebCore/page/Frame.cpp index bdc268c0dec..d13316445ce 100644 --- a/Source/WebCore/page/Frame.cpp +++ b/Source/WebCore/page/Frame.cpp @@ -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; diff --git a/Source/WebCore/page/Frame.h b/Source/WebCore/page/Frame.h index 8404c406740..e92e0d88f32 100644 --- a/Source/WebCore/page/Frame.h +++ b/Source/WebCore/page/Frame.h @@ -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(); diff --git a/Source/WebKit/chromium/public/WebFrame.h b/Source/WebKit/chromium/public/WebFrame.h index 25c3453b78a..3c6b81f465a 100644 --- a/Source/WebKit/chromium/public/WebFrame.h +++ b/Source/WebKit/chromium/public/WebFrame.h @@ -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() { } }; diff --git a/Source/WebKit/chromium/src/WebFrameImpl.h b/Source/WebKit/chromium/src/WebFrameImpl.h index 63f82c49077..79852875ff7 100644 --- a/Source/WebKit/chromium/src/WebFrameImpl.h +++ b/Source/WebKit/chromium/src/WebFrameImpl.h @@ -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;