blob: 97f4f0648baf7cbd565eca995f39b307f375a8bc [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
5#include "chrome/renderer/renderer_webidbcursor_impl.h"
6
[email protected]1e2de552010-09-03 12:15:157#include "chrome/common/indexed_db_key.h"
[email protected]5196b0cd2010-08-11 09:03:528#include "chrome/common/render_messages.h"
[email protected]1e2de552010-09-03 12:15:159#include "chrome/common/serialized_script_value.h"
10#include "chrome/renderer/indexed_db_dispatcher.h"
[email protected]5196b0cd2010-08-11 09:03:5211#include "chrome/renderer/render_thread.h"
12
[email protected]fb033cdc2010-10-13 07:19:4213using WebKit::WebExceptionCode;
[email protected]5196b0cd2010-08-11 09:03:5214using WebKit::WebIDBCallbacks;
15using WebKit::WebIDBKey;
16using WebKit::WebSerializedScriptValue;
17
18RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id)
19 : idb_cursor_id_(idb_cursor_id) {
20}
21
22RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() {
23 RenderThread::current()->Send(new ViewHostMsg_IDBCursorDestroyed(
24 idb_cursor_id_));
25}
26
27unsigned short RendererWebIDBCursorImpl::direction() const {
28 int direction;
29 RenderThread::current()->Send(
30 new ViewHostMsg_IDBCursorDirection(idb_cursor_id_, &direction));
31 return direction;
32}
33
34WebIDBKey RendererWebIDBCursorImpl::key() const {
35 IndexedDBKey key;
36 RenderThread::current()->Send(
37 new ViewHostMsg_IDBCursorKey(idb_cursor_id_, &key));
38 return key;
39}
40
[email protected]e7fd19802010-09-17 11:27:2641void RendererWebIDBCursorImpl::value(
42 WebSerializedScriptValue& webScriptValue,
43 WebIDBKey& webKey) const {
44 SerializedScriptValue scriptValue;
45 IndexedDBKey key;
[email protected]5196b0cd2010-08-11 09:03:5246 RenderThread::current()->Send(
[email protected]e7fd19802010-09-17 11:27:2647 new ViewHostMsg_IDBCursorValue(idb_cursor_id_, &scriptValue,
48 &key));
[email protected]b7d57442010-09-17 13:56:4749 // Only one or the other type should have been "returned" to us.
50 DCHECK(scriptValue.is_null() != (key.type() == WebIDBKey::InvalidType));
[email protected]e7fd19802010-09-17 11:27:2651 webScriptValue = scriptValue;
[email protected]e7fd19802010-09-17 11:27:2652 webKey = key;
[email protected]5196b0cd2010-08-11 09:03:5253}
54
55void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value,
[email protected]fb033cdc2010-10-13 07:19:4256 WebIDBCallbacks* callbacks,
57 WebExceptionCode& ec) {
[email protected]1e2de552010-09-03 12:15:1558 IndexedDBDispatcher* dispatcher =
59 RenderThread::current()->indexed_db_dispatcher();
[email protected]fb033cdc2010-10-13 07:19:4260 dispatcher->RequestIDBCursorUpdate(SerializedScriptValue(value), callbacks,
61 idb_cursor_id_, &ec);
[email protected]5196b0cd2010-08-11 09:03:5262}
63
64void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key,
[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->RequestIDBCursorContinue(IndexedDBKey(key), callbacks,
70 idb_cursor_id_, &ec);
[email protected]5196b0cd2010-08-11 09:03:5271}
72
[email protected]fb033cdc2010-10-13 07:19:4273void RendererWebIDBCursorImpl::remove(WebIDBCallbacks* callbacks,
74 WebExceptionCode& ec) {
[email protected]1e2de552010-09-03 12:15:1575 IndexedDBDispatcher* dispatcher =
76 RenderThread::current()->indexed_db_dispatcher();
[email protected]6454c0b2010-12-03 15:22:5077 dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec);
[email protected]5196b0cd2010-08-11 09:03:5278}