[email protected] | 9b8aa5b | 2011-08-22 18:15:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 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] | acb9472 | 2011-03-18 01:33:34 | [diff] [blame] | 5 | #include "content/renderer/renderer_webidbcursor_impl.h" |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 6 | |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 7 | #include "content/common/indexed_db_messages.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 8 | #include "content/renderer/indexed_db_dispatcher.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 9 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 10 | |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 11 | using WebKit::WebExceptionCode; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 12 | using WebKit::WebIDBCallbacks; |
| 13 | using WebKit::WebIDBKey; |
| 14 | using WebKit::WebSerializedScriptValue; |
| 15 | |
[email protected] | c97dd2f | 2011-10-12 05:23:40 | [diff] [blame] | 16 | RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id, |
| 17 | const IndexedDBKey& key, const IndexedDBKey& primary_key, |
| 18 | const SerializedScriptValue& value) |
| 19 | : idb_cursor_id_(idb_cursor_id), |
| 20 | key_(key), |
| 21 | primary_key_(primary_key), |
| 22 | value_(value) { |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { |
[email protected] | 21f6994 | 2011-01-12 10:40:21 | [diff] [blame] | 26 | // It's not possible for there to be pending callbacks that address this |
| 27 | // object since inside WebKit, they hold a reference to the object wich owns |
| 28 | // this object. But, if that ever changed, then we'd need to invalidate |
| 29 | // any such pointers. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 30 | RenderThreadImpl::current()->Send(new IndexedDBHostMsg_CursorDestroyed( |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 31 | idb_cursor_id_)); |
| 32 | } |
| 33 | |
| 34 | unsigned short RendererWebIDBCursorImpl::direction() const { |
| 35 | int direction; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 36 | RenderThreadImpl::current()->Send( |
[email protected] | 2ba871b | 2010-12-13 21:11:00 | [diff] [blame] | 37 | new IndexedDBHostMsg_CursorDirection(idb_cursor_id_, &direction)); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 38 | return direction; |
| 39 | } |
| 40 | |
| 41 | WebIDBKey RendererWebIDBCursorImpl::key() const { |
[email protected] | c97dd2f | 2011-10-12 05:23:40 | [diff] [blame] | 42 | return key_; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 43 | } |
| 44 | |
[email protected] | 849991d | 2011-03-02 22:18:45 | [diff] [blame] | 45 | WebIDBKey RendererWebIDBCursorImpl::primaryKey() const { |
[email protected] | c97dd2f | 2011-10-12 05:23:40 | [diff] [blame] | 46 | return primary_key_; |
[email protected] | 849991d | 2011-03-02 22:18:45 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | 9b8aa5b | 2011-08-22 18:15:15 | [diff] [blame] | 49 | WebSerializedScriptValue RendererWebIDBCursorImpl::value() const { |
[email protected] | c97dd2f | 2011-10-12 05:23:40 | [diff] [blame] | 50 | return value_; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value, |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 54 | WebIDBCallbacks* callbacks, |
| 55 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 56 | IndexedDBDispatcher* dispatcher = |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 57 | RenderThreadImpl::current()->indexed_db_dispatcher(); |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 58 | dispatcher->RequestIDBCursorUpdate(SerializedScriptValue(value), callbacks, |
| 59 | idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key, |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 63 | WebIDBCallbacks* callbacks, |
| 64 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 65 | IndexedDBDispatcher* dispatcher = |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 66 | RenderThreadImpl::current()->indexed_db_dispatcher(); |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 67 | dispatcher->RequestIDBCursorContinue(IndexedDBKey(key), callbacks, |
| 68 | idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | 9b8aa5b | 2011-08-22 18:15:15 | [diff] [blame] | 71 | void RendererWebIDBCursorImpl::deleteFunction(WebIDBCallbacks* callbacks, |
| 72 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 73 | IndexedDBDispatcher* dispatcher = |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 74 | RenderThreadImpl::current()->indexed_db_dispatcher(); |
[email protected] | 6454c0b | 2010-12-03 15:22:50 | [diff] [blame] | 75 | dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 76 | } |