Index: third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp b/third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp |
index b74f0d9bab846ddf1c1f1d0cb4cba67677557bbf..7b6d9481037862a9ae2daf4096626ba8ec1464c3 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp |
@@ -478,6 +478,79 @@ |
updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); |
} |
+static v8::Local<v8::Value> getNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) |
+{ |
+ if (!htmlDocument->hasNamedItem(key) && !htmlDocument->hasExtraNamedItem(key)) |
+ return v8Undefined(); |
+ |
+ DocumentNameCollection* items = htmlDocument->documentNamedItems(key); |
+ if (items->isEmpty()) |
+ return v8Undefined(); |
+ |
+ if (items->hasExactlyOneItem()) { |
+ HTMLElement* element = items->item(0); |
+ ASSERT(element); |
+ Frame* frame = isHTMLIFrameElement(*element) ? toHTMLIFrameElement(*element).contentFrame() : 0; |
+ if (frame) |
+ return toV8(frame->domWindow(), creationContext, isolate); |
+ return toV8(element, creationContext, isolate); |
+ } |
+ return toV8(items, creationContext, isolate); |
+} |
+ |
+static void getter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) |
+{ |
+ if (!property->IsString()) |
+ return; |
+ // FIXME: Consider passing StringImpl directly. |
+ AtomicString name = toCoreAtomicString(property.As<v8::String>()); |
+ HTMLDocument* htmlDocument = V8HTMLDocument::toImpl(info.Holder()); |
+ ASSERT(htmlDocument); |
+ v8::Local<v8::Value> result = getNamedProperty(htmlDocument, name, info.Holder(), info.GetIsolate()); |
+ if (!result.IsEmpty()) { |
+ v8SetReturnValue(info, result); |
+ return; |
+ } |
+ v8::Local<v8::Value> prototype = info.Holder()->GetPrototype(); |
+ if (prototype->IsObject()) { |
+ v8::Local<v8::Value> value; |
+ if (prototype.As<v8::Object>()->Get(info.GetIsolate()->GetCurrentContext(), property).ToLocal(&value)) |
+ v8SetReturnValue(info, value); |
+ } |
+} |
+ |
+void WindowProxy::namedItemAdded(HTMLDocument* document, const AtomicString& name) |
+{ |
+ ASSERT(m_world->isMainWorld()); |
+ |
+ if (!isContextInitialized() || !m_scriptState->contextIsValid()) |
+ return; |
+ |
+ ScriptState::Scope scope(m_scriptState.get()); |
+ ASSERT(!m_document.isEmpty()); |
+ v8::Local<v8::Context> context = m_scriptState->context(); |
+ v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); |
+ checkDocumentWrapper(documentHandle, document); |
+ documentHandle->SetAccessor(context, v8String(m_isolate, name), getter); |
+} |
+ |
+void WindowProxy::namedItemRemoved(HTMLDocument* document, const AtomicString& name) |
+{ |
+ ASSERT(m_world->isMainWorld()); |
+ |
+ if (!isContextInitialized()) |
+ return; |
+ |
+ if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) |
+ return; |
+ |
+ ScriptState::Scope scope(m_scriptState.get()); |
+ ASSERT(!m_document.isEmpty()); |
+ v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); |
+ checkDocumentWrapper(documentHandle, document); |
+ documentHandle->Delete(m_isolate->GetCurrentContext(), v8String(m_isolate, name)); |
+} |
+ |
void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) |
{ |
if (!isContextInitialized()) |