1 /* 2 * Copyright (C) 2011 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include "config.h" 29 #include "WebIDBKey.h" 30 31 #if ENABLE(INDEXED_DATABASE) 32 33 #include "IDBBindingUtilities.h" 34 #include "IDBKey.h" 35 #include "IDBKeyPath.h" 36 #include "SerializedScriptValue.h" 37 #include "WebIDBKeyPath.h" 38 #include "WebSerializedScriptValue.h" 39 40 using namespace WebCore; 41 42 namespace WebKit { 43 44 WebIDBKey WebIDBKey::createNull() 45 { 46 WebIDBKey key; 47 key.assignNull(); 48 return key; 49 } 50 51 WebIDBKey WebIDBKey::createString(const WebString& string) 52 { 53 WebIDBKey key; 54 key.assignString(string); 55 return key; 56 } 57 58 WebIDBKey WebIDBKey::createDate(double date) 59 { 60 WebIDBKey key; 61 key.assignDate(date); 62 return key; 63 } 64 65 WebIDBKey WebIDBKey::createNumber(double number) 66 { 67 WebIDBKey key; 68 key.assignNumber(number); 69 return key; 70 } 71 72 WebIDBKey WebIDBKey::createInvalid() 73 { 74 WebIDBKey key; 75 key.assignInvalid(); 76 return key; 77 } 78 79 WebIDBKey WebIDBKey::createFromValueAndKeyPath(const WebSerializedScriptValue& serializedScriptValue, const WebIDBKeyPath& idbKeyPath) 80 { 81 if (serializedScriptValue.isNull()) 82 return WebIDBKey::createInvalid(); 83 return createIDBKeyFromSerializedValueAndKeyPath(serializedScriptValue, idbKeyPath); 84 } 85 86 WebSerializedScriptValue WebIDBKey::injectIDBKeyIntoSerializedValue(const WebIDBKey& key, const WebSerializedScriptValue& value, const WebIDBKeyPath& path) 87 { 88 return WebCore::injectIDBKeyIntoSerializedValue(key, value, path); 89 } 90 91 void WebIDBKey::assign(const WebIDBKey& value) 92 { 93 m_private = value.m_private; 94 } 95 96 void WebIDBKey::assignNull() 97 { 98 m_private = IDBKey::createNull(); 99 } 100 101 void WebIDBKey::assignString(const WebString& string) 102 { 103 m_private = IDBKey::createString(string); 104 } 105 106 void WebIDBKey::assignDate(double date) 107 { 108 m_private = IDBKey::createDate(date); 109 } 110 111 void WebIDBKey::assignNumber(double number) 112 { 113 m_private = IDBKey::createNumber(number); 114 } 115 116 void WebIDBKey::assignInvalid() 117 { 118 m_private = 0; 119 } 120 121 void WebIDBKey::reset() 122 { 123 m_private.reset(); 124 } 125 126 WebIDBKey::Type WebIDBKey::type() const 127 { 128 if (!m_private.get()) 129 return InvalidType; 130 return Type(m_private->type()); 131 } 132 133 WebString WebIDBKey::string() const 134 { 135 return m_private->string(); 136 } 137 138 double WebIDBKey::date() const 139 { 140 return m_private->date(); 141 } 142 143 double WebIDBKey::number() const 144 { 145 return m_private->number(); 146 } 147 148 WebIDBKey::WebIDBKey(const PassRefPtr<IDBKey>& value) 149 : m_private(value) 150 { 151 } 152 153 WebIDBKey& WebIDBKey::operator=(const PassRefPtr<IDBKey>& value) 154 { 155 m_private = value; 156 return *this; 157 } 158 159 WebIDBKey::operator PassRefPtr<IDBKey>() const 160 { 161 return m_private.get(); 162 } 163 164 } // namespace WebKit 165 166 #endif // ENABLE(INDEXED_DATABASE) 167