summaryrefslogtreecommitdiffstats
path: root/webkit/glue/idb_bindings.cc
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 13:54:59 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 13:54:59 +0000
commit67a7851692243892bb2d7253d2f1974833e57432 (patch)
tree98bdc05f9af985cbcc8b9cc6ea0ccf472a85b588 /webkit/glue/idb_bindings.cc
parente40cc399bd7e438579d6fcfa208103c12caf9052 (diff)
downloadchromium_src-67a7851692243892bb2d7253d2f1974833e57432.zip
chromium_src-67a7851692243892bb2d7253d2f1974833e57432.tar.gz
chromium_src-67a7851692243892bb2d7253d2f1974833e57432.tar.bz2
Adds IDBKeyPath parser / extractor, and provides a mechanism to call it sandboxed.
TEST=idbkeypathextractor_browsertests.cc Review URL: http://codereview.chromium.org/3043037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/idb_bindings.cc')
-rw-r--r--webkit/glue/idb_bindings.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/webkit/glue/idb_bindings.cc b/webkit/glue/idb_bindings.cc
new file mode 100644
index 0000000..fd26130
--- /dev/null
+++ b/webkit/glue/idb_bindings.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/glue/idb_bindings.h"
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBKey.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBKeyPath.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSerializedScriptValue.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+#include "v8/include/v8.h"
+
+namespace webkit_glue {
+
+using WebKit::WebIDBKey;
+using WebKit::WebIDBKeyPath;
+using WebKit::WebSerializedScriptValue;
+
+namespace {
+
+class LocalContext {
+ public:
+ LocalContext()
+ : context_(v8::Context::New()) {
+ context_->Enter();
+ }
+
+ virtual ~LocalContext() {
+ context_->Exit();
+ context_.Dispose();
+ }
+
+ private:
+ v8::Locker lock_;
+ v8::HandleScope scope_;
+ v8::Persistent<v8::Context> context_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalContext);
+};
+
+} // namespace
+
+bool IDBKeysFromValuesAndKeyPath(
+ const std::vector<WebSerializedScriptValue>& serialized_script_values,
+ const string16& idb_key_path,
+ std::vector<WebIDBKey>* values) {
+ LocalContext env;
+ WebIDBKeyPath web_idb_key_path = WebIDBKeyPath::create(idb_key_path);
+ bool error = web_idb_key_path.parseError() != 0;
+ // TODO(bulach): what to do when we have a parse error? For now, setting
+ // all values back as invalid and returning a boolean.
+ for (std::vector<WebSerializedScriptValue>::const_iterator i =
+ serialized_script_values.begin();
+ i != serialized_script_values.end(); ++i) {
+ if (error) {
+ values->push_back(WebIDBKey::createInvalid());
+ } else {
+ values->push_back(
+ WebIDBKey::createFromValueAndKeyPath(*i, web_idb_key_path));
+ }
+ }
+ return error;
+}
+
+} // namespace webkit_glue