blob: 1bad2376afa8bcf2328919bd8f802bc9fa501166 [file] [log] [blame]
[email protected]5196b0cd2010-08-11 09:03:521// 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
[email protected]acb94722011-03-18 01:33:345#include "content/renderer/renderer_webidbcursor_impl.h"
[email protected]5196b0cd2010-08-11 09:03:526
[email protected]5196b0cd2010-08-11 09:03:527#include "chrome/renderer/render_thread.h"
[email protected]127dd582011-03-16 21:32:108#include "content/common/indexed_db_messages.h"
[email protected]230b7ef2011-03-16 22:30:199#include "content/renderer/indexed_db_dispatcher.h"
[email protected]5196b0cd2010-08-11 09:03:5210
[email protected]fb033cdc2010-10-13 07:19:4211using WebKit::WebExceptionCode;
[email protected]5196b0cd2010-08-11 09:03:5212using WebKit::WebIDBCallbacks;
13using WebKit::WebIDBKey;
14using WebKit::WebSerializedScriptValue;
15
16RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id)
17 : idb_cursor_id_(idb_cursor_id) {
18}
19
20RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() {
[email protected]21f69942011-01-12 10:40:2121 // It's not possible for there to be pending callbacks that address this
22 // object since inside WebKit, they hold a reference to the object wich owns
23 // this object. But, if that ever changed, then we'd need to invalidate
24 // any such pointers.
[email protected]2ba871b2010-12-13 21:11:0025 RenderThread::current()->Send(new IndexedDBHostMsg_CursorDestroyed(
[email protected]5196b0cd2010-08-11 09:03:5226 idb_cursor_id_));
27}
28
29unsigned short RendererWebIDBCursorImpl::direction() const {
30 int direction;
31 RenderThread::current()->Send(
[email protected]2ba871b2010-12-13 21:11:0032 new IndexedDBHostMsg_CursorDirection(idb_cursor_id_, &direction));
[email protected]5196b0cd2010-08-11 09:03:5233 return direction;
34}
35
36WebIDBKey RendererWebIDBCursorImpl::key() const {
37 IndexedDBKey key;
38 RenderThread::current()->Send(
[email protected]2ba871b2010-12-13 21:11:0039 new IndexedDBHostMsg_CursorKey(idb_cursor_id_, &key));
[email protected]5196b0cd2010-08-11 09:03:5240 return key;
41}
42
[email protected]849991d2011-03-02 22:18:4543WebIDBKey RendererWebIDBCursorImpl::primaryKey() const {
44 IndexedDBKey primaryKey;
45 RenderThread::current()->Send(
46 new IndexedDBHostMsg_CursorPrimaryKey(idb_cursor_id_, &primaryKey));
47 return primaryKey;
48}
49
[email protected]e7fd19802010-09-17 11:27:2650void RendererWebIDBCursorImpl::value(
51 WebSerializedScriptValue& webScriptValue,
52 WebIDBKey& webKey) const {
53 SerializedScriptValue scriptValue;
54 IndexedDBKey key;
[email protected]5196b0cd2010-08-11 09:03:5255 RenderThread::current()->Send(
[email protected]2ba871b2010-12-13 21:11:0056 new IndexedDBHostMsg_CursorValue(idb_cursor_id_, &scriptValue,
57 &key));
[email protected]b7d57442010-09-17 13:56:4758 // Only one or the other type should have been "returned" to us.
59 DCHECK(scriptValue.is_null() != (key.type() == WebIDBKey::InvalidType));
[email protected]e7fd19802010-09-17 11:27:2660 webScriptValue = scriptValue;
[email protected]e7fd19802010-09-17 11:27:2661 webKey = key;
[email protected]5196b0cd2010-08-11 09:03:5262}
63
64void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value,
[email protected]fb033cdc2010-10-13 07:19:4265 WebIDBCallbacks* callbacks,
66 WebExceptionCode& ec) {
[email protected]1e2de552010-09-03 12:15:1567 IndexedDBDispatcher* dispatcher =
68 RenderThread::current()->indexed_db_dispatcher();
[email protected]fb033cdc2010-10-13 07:19:4269 dispatcher->RequestIDBCursorUpdate(SerializedScriptValue(value), callbacks,
70 idb_cursor_id_, &ec);
[email protected]5196b0cd2010-08-11 09:03:5271}
72
73void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key,
[email protected]fb033cdc2010-10-13 07:19:4274 WebIDBCallbacks* callbacks,
75 WebExceptionCode& ec) {
[email protected]1e2de552010-09-03 12:15:1576 IndexedDBDispatcher* dispatcher =
77 RenderThread::current()->indexed_db_dispatcher();
[email protected]fb033cdc2010-10-13 07:19:4278 dispatcher->RequestIDBCursorContinue(IndexedDBKey(key), callbacks,
79 idb_cursor_id_, &ec);
[email protected]5196b0cd2010-08-11 09:03:5280}
81
[email protected]fb033cdc2010-10-13 07:19:4282void RendererWebIDBCursorImpl::remove(WebIDBCallbacks* callbacks,
83 WebExceptionCode& ec) {
[email protected]1e2de552010-09-03 12:15:1584 IndexedDBDispatcher* dispatcher =
85 RenderThread::current()->indexed_db_dispatcher();
[email protected]6454c0b2010-12-03 15:22:5086 dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec);
[email protected]5196b0cd2010-08-11 09:03:5287}