Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "webkit/glue/idb_bindings.h"
      6 
      7 #include "base/basictypes.h"
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/string16.h"
     10 #include "base/utf_string_conversions.h"
     11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKey.h"
     12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyPath.h"
     13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h"
     14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
     15 
     16 namespace webkit_glue {
     17 
     18 using WebKit::WebIDBKey;
     19 using WebKit::WebIDBKeyPath;
     20 using WebKit::WebSerializedScriptValue;
     21 
     22 bool IDBKeysFromValuesAndKeyPath(
     23     const std::vector<WebSerializedScriptValue>& serialized_script_values,
     24     const string16& idb_key_path,
     25     std::vector<WebIDBKey>* values) {
     26   WebIDBKeyPath web_idb_key_path = WebIDBKeyPath::create(idb_key_path);
     27   bool error = web_idb_key_path.parseError() != 0;
     28   // TODO(bulach): what to do when we have a parse error? For now, setting
     29   // all values back as invalid and returning a boolean.
     30   for (std::vector<WebSerializedScriptValue>::const_iterator i =
     31            serialized_script_values.begin();
     32        i != serialized_script_values.end(); ++i) {
     33     if (error) {
     34       values->push_back(WebIDBKey::createInvalid());
     35     } else {
     36       values->push_back(
     37           WebIDBKey::createFromValueAndKeyPath(*i, web_idb_key_path));
     38     }
     39   }
     40   return error;
     41 }
     42 
     43 WebSerializedScriptValue InjectIDBKey(
     44     const WebIDBKey& key,
     45     const WebSerializedScriptValue& value,
     46     const string16& idb_key_path) {
     47   return WebIDBKey::injectIDBKeyIntoSerializedValue(
     48       key, value, WebIDBKeyPath::create(idb_key_path));
     49 }
     50 
     51 }  // namespace webkit_glue
     52