1e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke/*
2e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * Copyright (C) 2010 Google Inc. All rights reserved.
3e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke *
4e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * Redistribution and use in source and binary forms, with or without
5e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * modification, are permitted provided that the following conditions
6e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * are met:
7e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke *
8e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * 1.  Redistributions of source code must retain the above copyright
9e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke *     notice, this list of conditions and the following disclaimer.
10e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * 2.  Redistributions in binary form must reproduce the above copyright
11e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke *     notice, this list of conditions and the following disclaimer in the
12e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke *     documentation and/or other materials provided with the distribution.
13e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke *
14e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke */
25e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
26e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#ifndef WebIDBKey_h
27e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#define WebIDBKey_h
28e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
29e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebCommon.h"
30e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebPrivatePtr.h"
31e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebString.h"
32e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
33e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkenamespace WebCore { class IDBKey; }
34e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
35e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkenamespace WebKit {
36e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
37f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrickclass WebIDBKeyPath;
38f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrickclass WebSerializedScriptValue;
39f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick
40e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkeclass WebIDBKey {
41e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkepublic:
42e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // Please use one of the factory methods. This is public only to allow WebVector.
43e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    WebIDBKey() { }
44967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch    ~WebIDBKey() { reset(); }
4568513a70bcd92384395513322f1b801e7bf9c729Steve Block
46e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API static WebIDBKey createNull();
47f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API static WebIDBKey createString(const WebString&);
48f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API static WebIDBKey createDate(double);
49f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API static WebIDBKey createNumber(double);
50e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API static WebIDBKey createInvalid();
51f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick    WEBKIT_API static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&);
5281bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch    WEBKIT_API static WebSerializedScriptValue injectIDBKeyIntoSerializedValue(const WebIDBKey&, const WebSerializedScriptValue&, const WebIDBKeyPath&);
53e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
54e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WebIDBKey(const WebIDBKey& e) { assign(e); }
55e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WebIDBKey& operator=(const WebIDBKey& e)
56e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    {
57e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        assign(e);
58e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        return *this;
59e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    }
60e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
61e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API void assign(const WebIDBKey&);
62e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API void assignNull();
63f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API void assignString(const WebString&);
64f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API void assignDate(double);
65f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API void assignNumber(double);
66e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API void assignInvalid();
67967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch    WEBKIT_API void reset();
68e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
69e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    enum Type {
70e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        NullType = 0,
71e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        StringType,
72f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        DateType,
73e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        NumberType,
74e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        // Types not in WebCore::IDBKey:
75e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        InvalidType
76e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    };
77e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
78e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API Type type() const;
79e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WEBKIT_API WebString string() const; // Only valid for StringType.
80f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API double date() const; // Only valid for DateType.
81f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WEBKIT_API double number() const; // Only valid for NumberType.
82e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
83e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#if WEBKIT_IMPLEMENTATION
84e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WebIDBKey(const WTF::PassRefPtr<WebCore::IDBKey>&);
85e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WebIDBKey& operator=(const WTF::PassRefPtr<WebCore::IDBKey>&);
86e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    operator WTF::PassRefPtr<WebCore::IDBKey>() const;
87e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#endif
88e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
89e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkeprivate:
90e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WebPrivatePtr<WebCore::IDBKey> m_private;
91e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke};
92e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
93e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke} // namespace WebKit
94e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
95e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#endif // WebIDBKey_h
96