1643ca7872b450ea4efacab6188849e5aac2ba161Steve Block/*
2643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * Copyright (C) 2009 Google Inc. All rights reserved.
3643ca7872b450ea4efacab6188849e5aac2ba161Steve Block *
4643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * Redistribution and use in source and binary forms, with or without
5643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * modification, are permitted provided that the following conditions are
6643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * met:
7643ca7872b450ea4efacab6188849e5aac2ba161Steve Block *
8643ca7872b450ea4efacab6188849e5aac2ba161Steve Block *     * Redistributions of source code must retain the above copyright
9643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * notice, this list of conditions and the following disclaimer.
10643ca7872b450ea4efacab6188849e5aac2ba161Steve Block *     * Redistributions in binary form must reproduce the above
11643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * copyright notice, this list of conditions and the following disclaimer
12643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * in the documentation and/or other materials provided with the
13643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * distribution.
14643ca7872b450ea4efacab6188849e5aac2ba161Steve Block *     * Neither the name of Google Inc. nor the names of its
15643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * contributors may be used to endorse or promote products derived from
16643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * this software without specific prior written permission.
17643ca7872b450ea4efacab6188849e5aac2ba161Steve Block *
18643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28643ca7872b450ea4efacab6188849e5aac2ba161Steve Block * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29643ca7872b450ea4efacab6188849e5aac2ba161Steve Block */
30643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
31643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#ifndef WebStorageArea_h
32643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#define WebStorageArea_h
33643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
34643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#include "WebCommon.h"
35d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "WebString.h"
36643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
37643ca7872b450ea4efacab6188849e5aac2ba161Steve Blocknamespace WebKit {
38643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
39dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockclass WebFrame;
40643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockclass WebURL;
41643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
42643ca7872b450ea4efacab6188849e5aac2ba161Steve Block// In WebCore, there's one distinct StorageArea per origin per StorageNamespace. This
43643ca7872b450ea4efacab6188849e5aac2ba161Steve Block// class wraps a StorageArea.  All the methods have obvious connections to the spec:
44643ca7872b450ea4efacab6188849e5aac2ba161Steve Block// http://dev.w3.org/html5/webstorage/
45643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockclass WebStorageArea {
46643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockpublic:
47643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    virtual ~WebStorageArea() { }
48643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
498a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    enum Result {
508a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        ResultOK = 0,
518a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        ResultBlockedByQuota,
528a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        ResultBlockedByPolicy
538a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    };
548a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block
55643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // The number of key/value pairs in the storage area.
56643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    virtual unsigned length() = 0;
57643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
58643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // Get a value for a specific key. Valid key indices are 0 through length() - 1.
59643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // Indexes may change on any set/removeItem call. Will return null if the index
60643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // provided is out of range.
61643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    virtual WebString key(unsigned index) = 0;
62643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
63643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // Get the value that corresponds to a specific key. This returns null if there is
64643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // no entry for that key.
65643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    virtual WebString getItem(const WebString& key) = 0;
66643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
678a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    // Set the value that corresponds to a specific key. Result will either be ResultOK
688a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    // or some particular error. The value is NOT set when there's an error.  url is the
698a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    // url that should be used if a storage event fires.
70dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    virtual void setItem(const WebString& key, const WebString& newValue, const WebURL& url, Result& result, WebString& oldValue, WebFrame*)
718a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    {
72dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        setItem(key, newValue, url, result, oldValue);
738a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    }
748a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    // FIXME: Remove soon (once Chrome has rolled past this revision).
75dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    virtual void setItem(const WebString& key, const WebString& newValue, const WebURL& url, Result& result, WebString& oldValue)
768a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    {
77dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        setItem(key, newValue, url, result, oldValue, 0);
788a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block    }
79643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
80643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // Remove the value associated with a particular key.  url is the url that should be used
81643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // if a storage event fires.
825e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    virtual void removeItem(const WebString& key, const WebURL& url, WebString& oldValue) = 0;
83643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
84643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    // Clear all key/value pairs.  url is the url that should be used if a storage event fires.
855e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    virtual void clear(const WebURL& url, bool& somethingCleared) = 0;
86643ca7872b450ea4efacab6188849e5aac2ba161Steve Block};
87643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
88643ca7872b450ea4efacab6188849e5aac2ba161Steve Block} // namespace WebKit
89643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
90643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#endif // WebStorageArea_h
91