Skip to content

Commit

Permalink
nwfaketop: Fix for more cases
Browse files Browse the repository at this point in the history
The following should be emulated as a top level window:

"_top" navigation target
window.frameElement
location.ancestorOrigins

see the comments in nwjs/nw.js#534
  • Loading branch information
rogerwang committed Apr 26, 2013
1 parent 12d8e15 commit ba7fc34
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
21 changes: 18 additions & 3 deletions Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "V8GCForContextDispose.h"
#include "V8HiddenPropertyName.h"
#include "V8HTMLCollection.h"
#include "V8HTMLFrameElement.h"
#include "V8Node.h"
#include "V8Utilities.h"
#include "WindowFeatures.h"
Expand Down Expand Up @@ -156,15 +157,29 @@ v8::Handle<v8::Value> V8DOMWindow::parentAttrGetterCustom(v8::Local<v8::String>
}

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();
for (Frame* f = frame; f; f = f->tree()->parent()) {
if (f->isNwFakeTop())
return toV8Fast(f->document()->domWindow(), info, imp);
}
return toV8Fast(imp->top(), info, imp);
}

v8::Handle<v8::Value> V8DOMWindow::frameElementAttrGetterCustom(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);
return v8::Handle<v8::Value>(v8Null(info.GetIsolate()));
if (!BindingSecurity::shouldAllowAccessToNode(BindingState::instance(), imp->frameElement()))
return v8::Handle<v8::Value>(v8Null(info.GetIsolate()));

return toV8Fast(imp->frameElement(), 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
4 changes: 2 additions & 2 deletions Source/WebCore/page/DOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,10 +1935,10 @@ PassRefPtr<DOMWindow> DOMWindow::open(const String& urlString, const AtomicStrin
// In those cases, we schedule a location change right now and return early.
Frame* targetFrame = 0;
if (frameName == "_top")
targetFrame = m_frame->tree()->top();
targetFrame = m_frame->isNwFakeTop() ? m_frame : m_frame->tree()->top();
else if (frameName == "_parent") {
if (Frame* parent = m_frame->tree()->parent())
targetFrame = parent;
targetFrame = m_frame->isNwFakeTop() ? m_frame : parent;
else
targetFrame = m_frame;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/DOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

DOMSelection getSelection();

readonly attribute [CheckSecurityForNode] Element frameElement;
readonly attribute [CheckSecurityForNode, V8CustomGetter] Element frameElement;

[DoNotCheckSecurity, CallWith=ScriptExecutionContext] void focus();
[DoNotCheckSecurity] void blur();
Expand Down
16 changes: 12 additions & 4 deletions Source/WebCore/page/FrameTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,20 @@ Frame* FrameTree::find(const AtomicString& name) const
{
if (name == "_self" || name == "_current" || name.isEmpty())
return m_thisFrame;

if (name == "_top")

if (name == "_top") {
for (Frame* f = m_thisFrame; f; f = f->tree()->parent()) {
if (f->isNwFakeTop())
return f;
}
return top();

if (name == "_parent")
}

if (name == "_parent") {
if (m_thisFrame->isNwFakeTop())
return m_thisFrame;
return parent() ? parent() : m_thisFrame;
}

// Since "_blank" should never be any frame's name, the following just amounts to an optimization.
if (name == "_blank")
Expand Down
7 changes: 5 additions & 2 deletions Source/WebCore/page/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ String Location::origin() const
PassRefPtr<DOMStringList> Location::ancestorOrigins() const
{
RefPtr<DOMStringList> origins = DOMStringList::create();
if (!m_frame)
if (!m_frame || m_frame->isNwFakeTop())
return origins.release();
for (Frame* frame = m_frame->tree()->parent(); frame; frame = frame->tree()->parent())
for (Frame* frame = m_frame->tree()->parent(); frame; frame = frame->tree()->parent()) {
origins->append(frame->document()->securityOrigin()->toString());
if (frame->isNwFakeTop())
break;
}
return origins.release();
}

Expand Down

0 comments on commit ba7fc34

Please sign in to comment.