summaryrefslogtreecommitdiffstats
path: root/webkit/port
diff options
context:
space:
mode:
authordglazkov@google.com <dglazkov@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 16:53:57 +0000
committerdglazkov@google.com <dglazkov@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 16:53:57 +0000
commita8584d1e50d984f782bcc5d67a3efff83057255a (patch)
tree1a3d3e6bff5a6f4910d5636ceb26cf73b482da10 /webkit/port
parent1dca0cbebf145b2982842798ea25808b81b81bee (diff)
downloadchromium_src-a8584d1e50d984f782bcc5d67a3efff83057255a.zip
chromium_src-a8584d1e50d984f782bcc5d67a3efff83057255a.tar.gz
chromium_src-a8584d1e50d984f782bcc5d67a3efff83057255a.tar.bz2
Scrubbing HTML options/collections, Chromium side.
R=darin Review URL: http://codereview.chromium.org/21237 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r--webkit/port/bindings/v8/v8_custom.cpp229
-rw-r--r--webkit/port/bindings/v8/v8_custom.h25
-rw-r--r--webkit/port/bindings/v8/v8_vectornodelist.cpp58
-rw-r--r--webkit/port/bindings/v8/v8_vectornodelist.h34
4 files changed, 26 insertions, 320 deletions
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp
index d238471..5001a4a 100644
--- a/webkit/port/bindings/v8/v8_custom.cpp
+++ b/webkit/port/bindings/v8/v8_custom.cpp
@@ -30,7 +30,6 @@
#include "v8_events.h"
#include "v8_binding.h"
#include "v8_npobject.h"
-#include "v8_vectornodelist.h"
#include "v8_custom.h"
#include "V8Attr.h"
@@ -93,6 +92,7 @@
#include "MessagePort.h"
#include "MouseEvent.h"
#include "NodeIterator.h"
+#include "NodeList.h"
#include "Page.h"
#include "PlatformScreen.h"
#include "RGBColor.h"
@@ -127,31 +127,6 @@ static const int kPopupTilePixels = 10;
namespace WebCore {
-#define NAMED_PROPERTY_GETTER(NAME) \
-v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertyGetter(\
- v8::Local<v8::String> name, const v8::AccessorInfo& info)
-
-#define NAMED_PROPERTY_SETTER(NAME) \
-v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertySetter(\
- v8::Local<v8::String> name, v8::Local<v8::Value> value, \
- const v8::AccessorInfo& info)
-
-#define NAMED_PROPERTY_DELETER(NAME) \
-v8::Handle<v8::Boolean> V8Custom::v8##NAME##NamedPropertyDeleter(\
- v8::Local<v8::String> name, const v8::AccessorInfo& info)
-
-#define NAMED_ACCESS_CHECK(NAME) \
-bool V8Custom::v8##NAME##NamedSecurityCheck(v8::Local<v8::Object> host, \
- v8::Local<v8::Value> key, \
- v8::AccessType type, \
- v8::Local<v8::Value> data)
-
-#define INDEXED_ACCESS_CHECK(NAME) \
-bool V8Custom::v8##NAME##IndexedSecurityCheck(v8::Local<v8::Object> host, \
- uint32_t index, \
- v8::AccessType type, \
- v8::Local<v8::Value> data)
-
class V8ScheduledAction : public ScheduledAction {
public:
V8ScheduledAction(v8::Handle<v8::Function> func, int argc,
@@ -644,179 +619,6 @@ ACCESSOR_GETTER(EventClipboardData) {
}
-static v8::Handle<v8::Value> HTMLCollectionGetNamedItems(
- HTMLCollection* collection, String name) {
- Vector<RefPtr<Node> > namedItems;
- collection->namedItems(name, namedItems);
- switch (namedItems.size()) {
- case 0:
- return v8::Handle<v8::Value>();
- case 1:
- return V8Proxy::NodeToV8Object(namedItems.at(0).get());
- default:
- NodeList* list = new V8VectorNodeList(namedItems);
- return V8Proxy::ToV8Object(V8ClassIndex::NODELIST, list);
- }
-}
-
-
-static v8::Handle<v8::Value> HTMLCollectionGetItem(
- HTMLCollection* collection, v8::Handle<v8::Value> argument) {
- v8::Local<v8::Uint32> index = argument->ToArrayIndex();
- if (index.IsEmpty()) {
- v8::Handle<v8::String> str = argument->ToString();
- v8::Handle<v8::Value> result =
- HTMLCollectionGetNamedItems(collection, ToWebCoreString(str));
- if (result.IsEmpty())
- return v8::Undefined();
- else
- return result;
- }
- unsigned i = index->Uint32Value();
- RefPtr<Node> result = collection->item(i);
- return V8Proxy::NodeToV8Object(result.get());
-}
-
-
-NAMED_PROPERTY_GETTER(HTMLCollection) {
- INC_STATS("DOM.HTMLCollection.NamedPropertyGetter");
- // Search the prototype chain first.
- v8::Handle<v8::Value> value =
- info.Holder()->GetRealNamedPropertyInPrototypeChain(name);
-
- if (!value.IsEmpty()) {
- return value;
- }
-
- // Search local callback properties next to find IDL defined
- // properties.
- if (info.Holder()->HasRealNamedCallbackProperty(name)) {
- return v8::Handle<v8::Value>();
- }
-
- // Finally, search the DOM structure.
- HTMLCollection* imp = V8Proxy::ToNativeObject<HTMLCollection>(
- V8ClassIndex::HTMLCOLLECTION, info.Holder());
- String key = ToWebCoreString(name);
- return HTMLCollectionGetNamedItems(imp, key);
-}
-
-
-CALLBACK_FUNC_DECL(HTMLCollectionItem) {
- INC_STATS("DOM.HTMLCollection.item()");
- HTMLCollection* imp = V8Proxy::ToNativeObject<HTMLCollection>(
- V8ClassIndex::HTMLCOLLECTION, args.Holder());
- return HTMLCollectionGetItem(imp, args[0]);
-}
-
-
-CALLBACK_FUNC_DECL(HTMLCollectionNamedItem) {
- INC_STATS("DOM.HTMLCollection.namedItem()");
- HTMLCollection* imp = V8Proxy::ToNativeObject<HTMLCollection>(
- V8ClassIndex::HTMLCOLLECTION, args.Holder());
- String name = ToWebCoreString(args[0]);
- v8::Handle<v8::Value> result =
- HTMLCollectionGetNamedItems(imp, name);
- if (result.IsEmpty())
- return v8::Undefined();
- else
- return result;
-}
-
-
-CALLBACK_FUNC_DECL(HTMLCollectionCallAsFunction) {
- INC_STATS("DOM.HTMLCollection.callAsFunction()");
- if (args.Length() < 1) return v8::Undefined();
-
- HTMLCollection* imp = V8Proxy::ToNativeObject<HTMLCollection>(
- V8ClassIndex::HTMLCOLLECTION, args.Holder());
-
- if (args.Length() == 1) {
- return HTMLCollectionGetItem(imp, args[0]);
- }
-
- // If there is a second argument it is the index of the item we
- // want.
- String name = ToWebCoreString(args[0]);
- v8::Local<v8::Uint32> index = args[1]->ToArrayIndex();
- if (index.IsEmpty()) return v8::Undefined();
- unsigned i = index->Uint32Value();
- Node* node = imp->namedItem(name);
- while (node) {
- if (i == 0) return V8Proxy::NodeToV8Object(node);
- node = imp->nextNamedItem(name);
- i--;
- }
-
- return v8::Undefined();
-}
-
-
-static v8::Handle<v8::Value> V8HTMLSelectElementRemoveHelper(
- HTMLSelectElement* imp, const v8::Arguments& args) {
- if (V8HTMLOptionElement::HasInstance(args[0])) {
- HTMLOptionElement* element =
- V8Proxy::DOMWrapperToNode<HTMLOptionElement>(args[0]);
- imp->remove(element->index());
- return v8::Undefined();
- }
-
- imp->remove(ToInt32(args[0]));
- return v8::Undefined();
-}
-
-CALLBACK_FUNC_DECL(HTMLSelectElementRemove) {
- INC_STATS("DOM.HTMLSelectElement.remove");
- HTMLSelectElement* imp =
- V8Proxy::DOMWrapperToNode<HTMLSelectElement>(args.Holder());
- return V8HTMLSelectElementRemoveHelper(imp, args);
-}
-
-CALLBACK_FUNC_DECL(HTMLOptionsCollectionRemove) {
- INC_STATS("DOM.HTMLOptionsCollection.remove()");
- HTMLOptionsCollection* imp =
- V8Proxy::ToNativeObject<HTMLOptionsCollection>(
- V8ClassIndex::HTMLOPTIONSCOLLECTION, args.Holder());
- HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base());
- return V8HTMLSelectElementRemoveHelper(base, args);
-}
-
-
-CALLBACK_FUNC_DECL(HTMLOptionsCollectionAdd) {
- INC_STATS("DOM.HTMLOptionsCollection.add()");
- if (!V8HTMLOptionElement::HasInstance(args[0])) {
- V8Proxy::SetDOMException(TYPE_MISMATCH_ERR);
- return v8::Undefined();
- }
- HTMLOptionsCollection* imp =
- V8Proxy::ToNativeObject<HTMLOptionsCollection>(
- V8ClassIndex::HTMLOPTIONSCOLLECTION, args.Holder());
- HTMLOptionElement* option =
- V8Proxy::DOMWrapperToNode<HTMLOptionElement>(args[0]);
-
- ExceptionCode ec = 0;
- if (args.Length() < 2) {
- imp->add(option, ec);
- } else {
- bool ok;
- v8::TryCatch try_catch;
- int index = ToInt32(args[1], ok);
- if (try_catch.HasCaught()) {
- return v8::Undefined();
- }
- if (!ok) {
- ec = TYPE_MISMATCH_ERR;
- } else {
- imp->add(option, index, ec);
- }
- }
- if (ec != 0) {
- V8Proxy::SetDOMException(ec);
- }
- return v8::Undefined();
-}
-
-
INDEXED_PROPERTY_GETTER(DOMStringList) {
INC_STATS("DOM.DOMStringList.IndexedPropertyGetter");
DOMStringList* imp =
@@ -1503,35 +1305,6 @@ NAMED_PROPERTY_GETTER(HTMLFrameSetElement)
}
-NAMED_PROPERTY_GETTER(HTMLFormElement) {
- INC_STATS("DOM.HTMLFormElement.NamedPropertyGetter");
- HTMLFormElement* imp =
- V8Proxy::DOMWrapperToNode<HTMLFormElement>(info.Holder());
- String v = ToWebCoreString(name);
-
- // Call getNamedElements twice, first time check if it has a value
- // and let HTMLFormElement update its cache.
- // See issue: 867404
- {
- Vector<RefPtr<Node> > elements;
- imp->getNamedElements(v, elements);
- if (elements.size() == 0)
- return v8::Handle<v8::Value>();
- }
- // Second call may return different results from the first call,
- // but if the first the size cannot be zero.
- Vector<RefPtr<Node> > elements;
- imp->getNamedElements(v, elements);
- ASSERT(elements.size() != 0);
- if (elements.size() == 1) {
- return V8Proxy::NodeToV8Object(elements.at(0).get());
- } else {
- NodeList* collection = new V8VectorNodeList(elements);
- return V8Proxy::ToV8Object(V8ClassIndex::NODELIST, collection);
- }
-}
-
-
INDEXED_PROPERTY_GETTER(NamedNodeMap) {
INC_STATS("DOM.NamedNodeMap.IndexedPropertyGetter");
NamedNodeMap* imp = V8Proxy::ToNativeObject<NamedNodeMap>(
diff --git a/webkit/port/bindings/v8/v8_custom.h b/webkit/port/bindings/v8/v8_custom.h
index d27ed41..ea6c1da 100644
--- a/webkit/port/bindings/v8/v8_custom.h
+++ b/webkit/port/bindings/v8/v8_custom.h
@@ -34,6 +34,31 @@ v8::Handle<v8::Value> V8Custom::v8##NAME##IndexedPropertySetter(\
v8::Handle<v8::Boolean> V8Custom::v8##NAME##IndexedPropertyDeleter(\
uint32_t index, const v8::AccessorInfo& info)
+#define NAMED_PROPERTY_GETTER(NAME) \
+ v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertyGetter(\
+ v8::Local<v8::String> name, const v8::AccessorInfo& info)
+
+#define NAMED_PROPERTY_SETTER(NAME) \
+ v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertySetter(\
+ v8::Local<v8::String> name, v8::Local<v8::Value> value, \
+ const v8::AccessorInfo& info)
+
+#define NAMED_PROPERTY_DELETER(NAME) \
+ v8::Handle<v8::Boolean> V8Custom::v8##NAME##NamedPropertyDeleter(\
+ v8::Local<v8::String> name, const v8::AccessorInfo& info)
+
+#define NAMED_ACCESS_CHECK(NAME) \
+ bool V8Custom::v8##NAME##NamedSecurityCheck(v8::Local<v8::Object> host, \
+ v8::Local<v8::Value> key, \
+ v8::AccessType type, \
+ v8::Local<v8::Value> data)
+
+#define INDEXED_ACCESS_CHECK(NAME) \
+ bool V8Custom::v8##NAME##IndexedSecurityCheck(v8::Local<v8::Object> host, \
+ uint32_t index, \
+ v8::AccessType type, \
+ v8::Local<v8::Value> data)
+
namespace WebCore {
class Frame;
diff --git a/webkit/port/bindings/v8/v8_vectornodelist.cpp b/webkit/port/bindings/v8/v8_vectornodelist.cpp
deleted file mode 100644
index f9341aa..0000000
--- a/webkit/port/bindings/v8/v8_vectornodelist.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "config.h"
-
-#include "v8_vectornodelist.h"
-#include "Element.h"
-#include "NamedAttrMap.h" // Node::attributes
-
-namespace WebCore {
-
-unsigned V8VectorNodeList::length() const {
- return m_nodes.size();
-}
-
-Node* V8VectorNodeList::item(unsigned index) const {
- if (index < m_nodes.size())
- return m_nodes[index].get();
- return 0;
-}
-
-Node* V8VectorNodeList::itemWithName(const AtomicString& id) const {
- for (unsigned i = 0; i < m_nodes.size(); i++) {
- Node* node = m_nodes[i].get();
- if (node->hasAttributes() && node->attributes()->id() == id) {
- return node;
- }
- }
- return 0;
-}
-
-} // namespace WebCore
diff --git a/webkit/port/bindings/v8/v8_vectornodelist.h b/webkit/port/bindings/v8/v8_vectornodelist.h
deleted file mode 100644
index 2b7d0c6..0000000
--- a/webkit/port/bindings/v8/v8_vectornodelist.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef V8_VECTORNODELIST_H__
-#define V8_VECTORNODELIST_H__
-
-#include "config.h"
-#include <v8.h>
-#include "Node.h"
-#include "NodeList.h"
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-// A NodeList backed by a Vector of Nodes.
-class V8VectorNodeList : public NodeList {
- public:
- explicit V8VectorNodeList(const Vector<RefPtr<Node> >& nodes)
- : m_nodes(nodes) { }
- virtual unsigned length() const;
- virtual Node* item(unsigned index) const;
- virtual Node* itemWithName(const AtomicString& name) const;
-
- private:
- Vector<RefPtr<Node> > m_nodes;
-};
-
-
-} // namespace WebCore
-
-#endif // V8_VECTORNODELIST_H__
-