tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / storage / Storage.cpp
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "Storage.h"
28
29 #include "Frame.h"
30 #include "Page.h"
31 #include "Settings.h"
32 #include "StorageArea.h"
33 #include "PlatformString.h"
34 #include <wtf/PassRefPtr.h>
35
36 namespace WebCore {
37
38 PassRefPtr<Storage> Storage::create(Frame* frame, PassRefPtr<StorageArea> storageArea)
39 {
40     return adoptRef(new Storage(frame, storageArea));
41 }
42
43 Storage::Storage(Frame* frame, PassRefPtr<StorageArea> storageArea)
44     : m_frame(frame)
45     , m_storageArea(storageArea)
46 {
47     ASSERT(m_frame);
48     ASSERT(m_storageArea);
49 }
50
51 Storage::~Storage()
52 {
53 }
54
55 unsigned Storage::length() const
56 {
57     if (!m_frame || !m_frame->page() || m_storageArea->disabledByPrivateBrowsingInFrame(m_frame))
58         return 0;
59
60     return m_storageArea->length(m_frame);
61 }
62
63 String Storage::key(unsigned index) const
64 {
65     if (!m_frame || !m_frame->page() || m_storageArea->disabledByPrivateBrowsingInFrame(m_frame))
66         return String();
67
68     return m_storageArea->key(index, m_frame);
69 }
70
71 String Storage::getItem(const String& key) const
72 {
73     if (!m_frame || !m_frame->page() || m_storageArea->disabledByPrivateBrowsingInFrame(m_frame))
74         return String();
75
76 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
77     return m_storageArea->getItem(key).first;
78 #else
79     return m_storageArea->getItem(key, m_frame);
80 #endif
81 }
82
83 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
84 void Storage::setItem(const String& key, const String& value, ExceptionCode& ec, bool readOnly)
85 #else
86 void Storage::setItem(const String& key, const String& value, ExceptionCode& ec)
87 #endif
88 {
89     ec = 0;
90     if (!m_frame)
91         return;
92
93 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
94     m_storageArea->setItem(key, value, ec, m_frame, readOnly);
95 #else
96     m_storageArea->setItem(key, value, ec, m_frame);
97 #endif
98 }
99
100 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
101 void Storage::removeItem(const String& key, ExceptionCode* ec)
102 #else
103 void Storage::removeItem(const String& key)
104 #endif
105 {
106     if (!m_frame)
107         return;
108
109 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
110     m_storageArea->removeItem(key, m_frame, ec);
111 #else
112     m_storageArea->removeItem(key, m_frame);
113 #endif
114 }
115
116 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
117 void Storage::clear(bool removeReadOnly)
118 #else
119 void Storage::clear()
120 #endif
121 {
122     if (!m_frame)
123         return;
124
125 #if ENABLE(TIZEN_LOCAL_STORAGE_READ_ONLY_EXTENSION)
126     m_storageArea->clear(m_frame, removeReadOnly);
127 #else
128     m_storageArea->clear(m_frame);
129 #endif
130 }
131
132 bool Storage::contains(const String& key) const
133 {
134     if (!m_frame || !m_frame->page() || m_storageArea->disabledByPrivateBrowsingInFrame(m_frame))
135         return false;
136
137     return m_storageArea->contains(key, m_frame);
138 }
139
140 }