OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/scoped_ptr.h" |
| 9 #include "base/string16.h" |
| 10 #include "base/utf_string_conversions.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebIDBKey.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebIDBKeyPath.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebSerializedScriptValue.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 15 #include "v8/include/v8.h" |
| 16 |
| 17 namespace webkit_glue { |
| 18 |
| 19 using WebKit::WebIDBKey; |
| 20 using WebKit::WebIDBKeyPath; |
| 21 using WebKit::WebSerializedScriptValue; |
| 22 |
| 23 namespace { |
| 24 |
| 25 class LocalContext { |
| 26 public: |
| 27 LocalContext() |
| 28 : context_(v8::Context::New()) { |
| 29 context_->Enter(); |
| 30 } |
| 31 |
| 32 virtual ~LocalContext() { |
| 33 context_->Exit(); |
| 34 context_.Dispose(); |
| 35 } |
| 36 |
| 37 private: |
| 38 v8::Locker lock_; |
| 39 v8::HandleScope scope_; |
| 40 v8::Persistent<v8::Context> context_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(LocalContext); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 bool IDBKeysFromValuesAndKeyPath( |
| 48 const std::vector<WebSerializedScriptValue>& serialized_script_values, |
| 49 const string16& idb_key_path, |
| 50 std::vector<WebIDBKey>* values) { |
| 51 LocalContext env; |
| 52 WebIDBKeyPath web_idb_key_path = WebIDBKeyPath::create(idb_key_path); |
| 53 bool error = web_idb_key_path.parseError() != 0; |
| 54 // TODO(bulach): what to do when we have a parse error? For now, setting |
| 55 // all values back as invalid and returning a boolean. |
| 56 for (std::vector<WebSerializedScriptValue>::const_iterator i = |
| 57 serialized_script_values.begin(); |
| 58 i != serialized_script_values.end(); ++i) { |
| 59 if (error) { |
| 60 values->push_back(WebIDBKey::createInvalid()); |
| 61 } else { |
| 62 values->push_back( |
| 63 WebIDBKey::createFromValueAndKeyPath(*i, web_idb_key_path)); |
| 64 } |
| 65 } |
| 66 return error; |
| 67 } |
| 68 |
| 69 } // namespace webkit_glue |
OLD | NEW |