15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008 Apple Inc. All Rights Reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h" 2753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/storage/Storage.h" 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 29197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ExceptionState.h" 300019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch#include "wtf/PassOwnPtr.h" 31e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include "wtf/PassRefPtr.h" 32e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include "wtf/text/WTFString.h" 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 34c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 36d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)PassRefPtrWillBeRawPtr<Storage> Storage::create(LocalFrame* frame, PassOwnPtrWillBeRawPtr<StorageArea> storageArea) 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return adoptRefWillBeNoop(new Storage(frame, storageArea)); 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 41d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)Storage::Storage(LocalFrame* frame, PassOwnPtrWillBeRawPtr<StorageArea> storageArea) 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : DOMWindowProperty(frame) 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) , m_storageArea(storageArea) 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ASSERT(m_frame); 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ASSERT(m_storageArea); 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 497242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano TucciDEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Storage); 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)String Storage::anonymousIndexedGetter(unsigned index, ExceptionState& exceptionState) 5293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 5351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return anonymousNamedGetter(AtomicString::number(index), exceptionState); 5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)String Storage::anonymousNamedGetter(const AtomicString& name, ExceptionState& exceptionState) 5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 5851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool found = contains(name, exceptionState); 5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException() || !found) 6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return String(); 6151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) String result = getItem(name, exceptionState); 6251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException()) 6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return String(); 6493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return result; 6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 6693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)bool Storage::anonymousNamedSetter(const AtomicString& name, const AtomicString& value, ExceptionState& exceptionState) 6893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) setItem(name, value, exceptionState); 7093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return true; 7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)bool Storage::anonymousIndexedSetter(unsigned index, const AtomicString& value, ExceptionState& exceptionState) 745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles){ 7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return anonymousNamedSetter(AtomicString::number(index), value, exceptionState); 765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)} 775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)DeleteResult Storage::anonymousNamedDeleter(const AtomicString& name, ExceptionState& exceptionState) 7993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 8051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool found = contains(name, exceptionState); 8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!found) 8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return DeleteUnknownProperty; 8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (exceptionState.hadException()) 8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return DeleteReject; 8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) removeItem(name, exceptionState); 8651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException()) 8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return DeleteReject; 8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return DeleteSuccess; 8993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 9093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)DeleteResult Storage::anonymousIndexedDeleter(unsigned index, ExceptionState& exceptionState) 9293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 9309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) DeleteResult result = anonymousNamedDeleter(AtomicString::number(index), exceptionState); 9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return result == DeleteUnknownProperty ? DeleteSuccess : result; 9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 9693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 9751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void Storage::namedPropertyEnumerator(Vector<String>& names, ExceptionState& exceptionState) 985267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles){ 9951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) unsigned length = this->length(exceptionState); 10051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException()) 1015267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) return; 1025267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) names.resize(length); 1035267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) for (unsigned i = 0; i < length; ++i) { 10451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) String key = this->key(i, exceptionState); 10551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException()) 1065267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) return; 1075267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) ASSERT(!key.isNull()); 10851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) String val = getItem(key, exceptionState); 10951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException()) 1105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) return; 1115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) names[i] = key; 1125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) } 1135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)} 11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 11551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)bool Storage::namedPropertyQuery(const AtomicString& name, ExceptionState& exceptionState) 116521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles){ 117521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) if (name == "length") 118521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) return false; 11951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool found = contains(name, exceptionState); 12051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (exceptionState.hadException() || !found) 121521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) return false; 122521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) return true; 123521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)} 124521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 12509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void Storage::trace(Visitor* visitor) 12609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 12709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) visitor->trace(m_storageArea); 1287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci DOMWindowProperty::trace(visitor); 12909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 13009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 132