diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-14 12:59:11 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-14 12:59:11 +0000 |
commit | 70c19a930beddde0e382777cb8799e7c8ebb1625 (patch) | |
tree | 887ab4d3962e19a5d114f205c0871ba2f9cf1e98 /chrome | |
parent | 7d754b0c3f04087aad0931141cdbdfbf1a82ba41 (diff) | |
download | chromium_src-70c19a930beddde0e382777cb8799e7c8ebb1625.zip chromium_src-70c19a930beddde0e382777cb8799e7c8ebb1625.tar.gz chromium_src-70c19a930beddde0e382777cb8799e7c8ebb1625.tar.bz2 |
Implement IndexedDatabase::open up until re-entrance into WebKit. That (and the
rest of IndexedDB) will be done in subsequent patches. Included in this patch
is a lot of other infrastructure for making IndexedDB work. Included is a
conversion from the DOMStorageDispatcherHost into a dispatcher host for all APIs
that have a backend in WebKit.
I named it WebKitAPIDispatcherHost. Since it's in browser/in_process_webkit and
it is for APIs that connect up to the WebKit API and it's used for APIs whose
backend is implemented in WebKit I thought the name was decent and not _too_
confusing, but if you have better ideas, please let me know.
This includes some code that you've already reviewed (darin), but a lot has
changed so please take a look at all of it.
TEST=Not much to test yet + behind a flag.
BUG=none
Review URL: http://codereview.chromium.org/1599009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
29 files changed, 787 insertions, 63 deletions
diff --git a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc index bb28bff..965623e 100644 --- a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc +++ b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc @@ -9,7 +9,6 @@ #include "chrome/browser/in_process_webkit/dom_storage_area.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/in_process_webkit/dom_storage_namespace.h" -#include "chrome/browser/in_process_webkit/webkit_thread.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" #include "chrome/browser/renderer_host/render_view_host_notification_task.h" @@ -45,14 +44,11 @@ ScopedStorageEventContext::~ScopedStorageEventContext() { DOMStorageDispatcherHost::DOMStorageDispatcherHost( ResourceMessageFilter* resource_message_filter, - WebKitContext* webkit_context, - WebKitThread* webkit_thread) + WebKitContext* webkit_context) : webkit_context_(webkit_context), - webkit_thread_(webkit_thread), resource_message_filter_(resource_message_filter), process_handle_(0) { DCHECK(webkit_context_.get()); - DCHECK(webkit_thread_); DCHECK(resource_message_filter_); } @@ -71,24 +67,11 @@ void DOMStorageDispatcherHost::Init(int process_id, } void DOMStorageDispatcherHost::Shutdown() { - if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { - if (process_handle_) // Init() was called - Context()->UnregisterDispatcherHost(this); - resource_message_filter_ = NULL; - - // The task will only execute if the WebKit thread is already running. - ChromeThread::PostTask( - ChromeThread::WEBKIT, FROM_HERE, - NewRunnableMethod(this, &DOMStorageDispatcherHost::Shutdown)); - return; - } - - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); - DCHECK(!resource_message_filter_); - - // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks - // and others will likely need this, so let's not delete this - // code even though it doesn't do anyting yet. + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + // This is not always true during testing. + if (process_handle_) + Context()->UnregisterDispatcherHost(this); + resource_message_filter_ = NULL; } /* static */ @@ -114,7 +97,7 @@ void DOMStorageDispatcherHost::DispatchStorageEvent(const NullableString16& key, } bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, - bool *msg_is_ok) { + bool* msg_is_ok) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(process_handle_); @@ -139,21 +122,25 @@ int64 DOMStorageDispatcherHost::CloneSessionStorage(int64 original_id) { } void DOMStorageDispatcherHost::Send(IPC::Message* message) { - if (!resource_message_filter_) { - delete message; + if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { + // TODO(jorlow): Even if we successfully post, I believe it's possible for + // the task to never run (if the IO thread is already shutting + // down). We may want to handle this case, though + // realistically it probably doesn't matter. + if (!ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod( + this, &DOMStorageDispatcherHost::Send, message))) { + // The IO thread is dead. + delete message; + } return; } - if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (!resource_message_filter_) + delete message; + else resource_message_filter_->Send(message); - return; - } - - // The IO thread can't go away while the WebKit thread is still running. - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message)); } void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, diff --git a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h index fea147a..dad174e 100644 --- a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h +++ b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h @@ -18,7 +18,6 @@ class GURL; class HostContentSettingsMap; class ResourceMessageFilter; class Task; -class WebKitThread; struct ViewMsg_DOMStorageEvent_Params; // This class handles the logistics of DOM Storage within the browser process. @@ -30,7 +29,7 @@ class DOMStorageDispatcherHost // Only call the constructor from the UI thread. DOMStorageDispatcherHost( ResourceMessageFilter* resource_message_filter_, - WebKitContext* webkit_context, WebKitThread* webkit_thread); + WebKitContext* webkit_context); // Only call from ResourceMessageFilter on the IO thread. void Init(int process_id, base::ProcessHandle process_handle); @@ -40,7 +39,7 @@ class DOMStorageDispatcherHost void Shutdown(); // Only call from ResourceMessageFilter on the IO thread. - bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); + bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); // Clones a session storage namespace and returns the cloned namespaces' id. // Only call on the IO thread. @@ -101,9 +100,6 @@ class DOMStorageDispatcherHost // Data shared between renderer processes with the same profile. scoped_refptr<WebKitContext> webkit_context_; - // ResourceDispatcherHost takes care of destruction. Immutable. - WebKitThread* webkit_thread_; - // Only set and use on the IO thread. ResourceMessageFilter* resource_message_filter_; diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.cc b/chrome/browser/in_process_webkit/indexed_db_callbacks.cc new file mode 100644 index 0000000..82a48aa --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.cc @@ -0,0 +1,29 @@ +// 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 "chrome/browser/in_process_webkit/indexed_db_callbacks.h" + +#include "base/logging.h" +#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" + +using WebKit::WebIDBDatabase; +using WebKit::WebSerializedScriptValue; + +IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* parent, + int32 response_id) + : parent_(parent), + response_id_(response_id) { +} + +IndexedDBCallbacks::~IndexedDBCallbacks() { +} + +void IndexedDBCallbacks::onSuccess(WebIDBDatabase* idb_database) { + NOTREACHED(); +} + +void IndexedDBCallbacks::onSuccess(const WebSerializedScriptValue& value) { + NOTREACHED(); +} + diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.h b/chrome/browser/in_process_webkit/indexed_db_callbacks.h new file mode 100644 index 0000000..4b104a7 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.h @@ -0,0 +1,37 @@ +// 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. + +#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ +#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ + +#include "base/basictypes.h" +#include "base/ref_counted.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" + +class IndexedDBDispatcherHost; + +class IndexedDBCallbacks : public WebKit::WebIDBCallbacks { + public: + IndexedDBCallbacks(IndexedDBDispatcherHost* parent, int32 response_id); + virtual ~IndexedDBCallbacks(); + + // We define default versions of these functions which simply DCHECK. + // For each WebIDBCallbacks implementation, there should only be one success + // callback that can possibly be called. + virtual void onSuccess(WebKit::WebIDBDatabase* idb_database); + virtual void onSuccess(const WebKit::WebSerializedScriptValue& value); + + protected: + IndexedDBDispatcherHost* parent() { return parent_.get(); } + int32 response_id() const { return response_id_; } + + private: + scoped_refptr<IndexedDBDispatcherHost> parent_; + int32 response_id_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ + diff --git a/chrome/browser/in_process_webkit/indexed_db_context.cc b/chrome/browser/in_process_webkit/indexed_db_context.cc new file mode 100644 index 0000000..6235833 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_context.cc @@ -0,0 +1,24 @@ +// 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 "chrome/browser/in_process_webkit/indexed_db_context.h" + +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" + +using WebKit::WebIDBDatabase; +using WebKit::WebIndexedDatabase; + +IndexedDBContext::IndexedDBContext() { +} + +IndexedDBContext::~IndexedDBContext() { +} + +WebIndexedDatabase* IndexedDBContext::GetIndexedDatabase() { + if (!indexed_database_.get()) + indexed_database_.reset(WebIndexedDatabase::create()); + DCHECK(indexed_database_.get()); + return indexed_database_.get(); +} diff --git a/chrome/browser/in_process_webkit/indexed_db_context.h b/chrome/browser/in_process_webkit/indexed_db_context.h new file mode 100644 index 0000000..07edd88 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_context.h @@ -0,0 +1,31 @@ +// 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. + +#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CONTEXT_H_ +#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CONTEXT_H_ + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/scoped_ptr.h" + +namespace WebKit { +class WebIndexedDatabase; +} + +class IndexedDBContext { + public: + IndexedDBContext(); + ~IndexedDBContext(); + + // TODO(jorlow): If this is all this class ever does, then we should kill it + // and move this variable to WebKitContext. + WebKit::WebIndexedDatabase* GetIndexedDatabase(); + + private: + scoped_ptr<WebKit::WebIndexedDatabase> indexed_database_; + + DISALLOW_COPY_AND_ASSIGN(IndexedDBContext); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CONTEXT_H_ diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc new file mode 100644 index 0000000..7a114b1 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc @@ -0,0 +1,150 @@ +// 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 "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" + +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/in_process_webkit/indexed_db_callbacks.h" +#include "chrome/browser/renderer_host/resource_message_filter.h" +#include "chrome/common/render_messages.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" + +using WebKit::WebIDBDatabase; +using WebKit::WebIDBDatabaseError; + +IndexedDBDispatcherHost::IndexedDBDispatcherHost( + IPC::Message::Sender* sender, WebKitContext* webkit_context) + : sender_(sender), + webkit_context_(webkit_context), + process_handle_(0) { + DCHECK(sender_); + DCHECK(webkit_context_.get()); +} + +IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { +} + +void IndexedDBDispatcherHost::Init(int process_id, + base::ProcessHandle process_handle) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + DCHECK(sender_); // Ensure Shutdown() has not been called. + DCHECK(!process_handle_); // Make sure Init() has not yet been called. + DCHECK(process_handle); + process_id_ = process_id; + process_handle_ = process_handle; +} + +void IndexedDBDispatcherHost::Shutdown() { + if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + sender_ = NULL; + + bool success = ChromeThread::PostTask( + ChromeThread::WEBKIT, FROM_HERE, + NewRunnableMethod(this, &IndexedDBDispatcherHost::Shutdown)); + DCHECK(success); // The WebKit thread is always shutdown after the IO. + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + DCHECK(!sender_); + + // TODO(jorlow): Do we still need this? +} + +bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message, + bool* msg_is_ok) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + DCHECK(process_handle_); + + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *msg_is_ok) + IPC_MESSAGE_HANDLER(ViewHostMsg_IndexedDatabaseOpen, OnIndexedDatabaseOpen) + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed, + OnIDBDatabaseDestroyed) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void IndexedDBDispatcherHost::Send(IPC::Message* message) { + if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { + // TODO(jorlow): Even if we successfully post, I believe it's possible for + // the task to never run (if the IO thread is already shutting + // down). We may want to handle this case, though + // realistically it probably doesn't matter. + if (!ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod( + this, &IndexedDBDispatcherHost::Send, message))) { + // The IO thread is dead. + delete message; + } + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (!sender_) + delete message; + else + sender_->Send(message); +} + +int32 IndexedDBDispatcherHost::AddIDBDatabase(WebIDBDatabase* idb_database) { + return idb_database_map_.Add(idb_database); +} + +class IndexedDatabaseOpenCallbacks : public IndexedDBCallbacks { + public: + IndexedDatabaseOpenCallbacks(IndexedDBDispatcherHost* parent, + int32 response_id) + : IndexedDBCallbacks(parent, response_id) { + } + + virtual void onError(const WebIDBDatabaseError& error) { + parent()->Send(new ViewMsg_IndexedDatabaseOpenError( + response_id(), error.code(), error.message())); + } + + virtual void onSuccess(WebIDBDatabase* idb_database) { + int32 idb_database_id = parent()->AddIDBDatabase(idb_database); + parent()->Send(new ViewMsg_IndexedDatabaseOpenSuccess(response_id(), + idb_database_id)); + } +}; + +void IndexedDBDispatcherHost::OnIndexedDatabaseOpen( + const ViewHostMsg_IndexedDatabaseOpen_Params& params) { + // TODO(jorlow): Check the content settings map and use params.routing_id_ + // if it's necessary to ask the user for permission. + + if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( + this, &IndexedDBDispatcherHost::OnIndexedDatabaseOpen, params)); + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + int exception_code = 0; + Context()->GetIndexedDatabase()->open( + params.name_, params.description_, params.modify_database_, + new IndexedDatabaseOpenCallbacks(this, params.response_id_), + params.origin_, NULL, exception_code); + // ViewHostMsg_IndexedDatabaseOpen is async because we assume the exception + // code is always 0 in the renderer side. + DCHECK(exception_code == 0); +} + +void IndexedDBDispatcherHost::OnIDBDatabaseDestroyed(int32 idb_database_id) { + if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( + this, &IndexedDBDispatcherHost::OnIDBDatabaseDestroyed, + idb_database_id)); + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + idb_database_map_.Remove(idb_database_id); +} diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h new file mode 100644 index 0000000..2a70748 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h @@ -0,0 +1,85 @@ +// 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. + +#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ +#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ + +#include "base/basictypes.h" +#include "base/id_map.h" +#include "base/process.h" +#include "base/ref_counted.h" +#include "chrome/browser/in_process_webkit/webkit_context.h" +#include "ipc/ipc_message.h" + +struct ViewHostMsg_IndexedDatabaseOpen_Params; + +namespace WebKit { +class WebIDBDatabase; +} + +// Handles all IndexedDB related messages from a particular renderer process. +class IndexedDBDispatcherHost + : public base::RefCountedThreadSafe<IndexedDBDispatcherHost> { + public: + // Only call the constructor from the UI thread. + IndexedDBDispatcherHost(IPC::Message::Sender* sender, + WebKitContext* webkit_context); + + // Only call from ResourceMessageFilter on the IO thread. + void Init(int process_id, base::ProcessHandle process_handle); + + // Only call from ResourceMessageFilter on the IO thread. Calls self on the + // WebKit thread in some cases. + void Shutdown(); + + // Only call from ResourceMessageFilter on the IO thread. + bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); + + // Send a message to the renderer process associated with our sender_ via the + // IO thread. May be called from any thread. + void Send(IPC::Message* message); + + // A shortcut for accessing our context. + IndexedDBContext* Context() { + return webkit_context_->indexed_db_context(); + } + + // The various IndexedDBCallbacks children call these methods to add the + // results into the applicable map. See below for more details. + int32 AddIDBDatabase(WebKit::WebIDBDatabase* idb_database); + // TODO(andreip/jorlow): Add functions for other maps here. + + private: + friend class base::RefCountedThreadSafe<IndexedDBDispatcherHost>; + ~IndexedDBDispatcherHost(); + + // IndexedDB message handlers. + void OnIndexedDatabaseOpen( + const ViewHostMsg_IndexedDatabaseOpen_Params& params); + void OnIDBDatabaseDestroyed(int32 idb_database_id); + + // Only use on the IO thread. + IPC::Message::Sender* sender_; + + // Data shared between renderer processes with the same profile. + scoped_refptr<WebKitContext> webkit_context_; + + // Maps from IDs we pass to the renderer and the actual WebKit objects. + // The map takes ownership and returns an ID. That ID is passed to the + // renderer and used to reference it. + IDMap<WebKit::WebIDBDatabase, IDMapOwnPointer> + idb_database_map_; + // TODO(andreip/jorlow): Add other maps here. + + // If we get a corrupt message from a renderer, we need to kill it using this + // handle. + base::ProcessHandle process_handle_; + + // Used to dispatch messages to the correct view host. + int process_id_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ diff --git a/chrome/browser/in_process_webkit/webkit_context.cc b/chrome/browser/in_process_webkit/webkit_context.cc index be07568..b9cf36f 100644 --- a/chrome/browser/in_process_webkit/webkit_context.cc +++ b/chrome/browser/in_process_webkit/webkit_context.cc @@ -5,12 +5,14 @@ #include "chrome/browser/in_process_webkit/webkit_context.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/profile.h" -WebKitContext::WebKitContext(const FilePath& data_path, bool is_incognito) - : data_path_(data_path), - is_incognito_(is_incognito), +WebKitContext::WebKitContext(Profile* profile) + : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), + is_incognito_(profile->IsOffTheRecord()), ALLOW_THIS_IN_INITIALIZER_LIST( - dom_storage_context_(new DOMStorageContext(this))) { + dom_storage_context_(new DOMStorageContext(this))), + indexed_db_context_(new IndexedDBContext()) { } WebKitContext::~WebKitContext() { diff --git a/chrome/browser/in_process_webkit/webkit_context.h b/chrome/browser/in_process_webkit/webkit_context.h index 82fa12d..7f18f88 100644 --- a/chrome/browser/in_process_webkit/webkit_context.h +++ b/chrome/browser/in_process_webkit/webkit_context.h @@ -10,8 +10,9 @@ #include "base/scoped_ptr.h" #include "base/time.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" +#include "chrome/browser/in_process_webkit/indexed_db_context.h" -class WebKitThread; +class Profile; // There's one WebKitContext per profile. Various DispatcherHost classes // have a pointer to the Context to store shared state. Unfortunately, this @@ -22,14 +23,19 @@ class WebKitThread; // threads. class WebKitContext : public base::RefCountedThreadSafe<WebKitContext> { public: - WebKitContext(const FilePath& data_path, bool is_incognito); + explicit WebKitContext(Profile* profile); const FilePath& data_path() const { return data_path_; } bool is_incognito() const { return is_incognito_; } + DOMStorageContext* dom_storage_context() { return dom_storage_context_.get(); } + IndexedDBContext* indexed_db_context() { + return indexed_db_context_.get(); + } + #ifdef UNIT_TEST // For unit tests, allow specifying a DOMStorageContext directly so it can be // mocked. @@ -60,6 +66,8 @@ class WebKitContext : public base::RefCountedThreadSafe<WebKitContext> { scoped_ptr<DOMStorageContext> dom_storage_context_; + scoped_ptr<IndexedDBContext> indexed_db_context_; + DISALLOW_IMPLICIT_CONSTRUCTORS(WebKitContext); }; diff --git a/chrome/browser/in_process_webkit/webkit_context_unittest.cc b/chrome/browser/in_process_webkit/webkit_context_unittest.cc index 98ccfd0..9158495 100644 --- a/chrome/browser/in_process_webkit/webkit_context_unittest.cc +++ b/chrome/browser/in_process_webkit/webkit_context_unittest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/in_process_webkit/webkit_context.h" +#include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" class MockDOMStorageContext : public DOMStorageContext { @@ -27,14 +28,15 @@ class MockDOMStorageContext : public DOMStorageContext { }; TEST(WebKitContextTest, Basic) { - FilePath file_path; - scoped_refptr<WebKitContext> context1(new WebKitContext(file_path, true)); - EXPECT_TRUE(file_path == context1->data_path()); - EXPECT_TRUE(context1->is_incognito()); - - scoped_refptr<WebKitContext> context2(new WebKitContext(file_path, false)); - EXPECT_TRUE(file_path == context2->data_path()); - EXPECT_FALSE(context2->is_incognito()); + TestingProfile profile; + + scoped_refptr<WebKitContext> context1(new WebKitContext(&profile)); + EXPECT_TRUE(profile.GetPath() == context1->data_path()); + EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito()); + + scoped_refptr<WebKitContext> context2(new WebKitContext(&profile)); + EXPECT_TRUE(context1->data_path() == context2->data_path()); + EXPECT_TRUE(context1->is_incognito() == context2->is_incognito()); } TEST(WebKitContextTest, PurgeMemory) { @@ -44,7 +46,8 @@ TEST(WebKitContextTest, PurgeMemory) { webkit_thread.Start(); // Create the contexts. - scoped_refptr<WebKitContext> context(new WebKitContext(FilePath(), false)); + TestingProfile profile; + scoped_refptr<WebKitContext> context(new WebKitContext(&profile)); MockDOMStorageContext* mock_context = new MockDOMStorageContext(context.get()); context->set_dom_storage_context(mock_context); // Takes ownership. diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 449085f..84f6b44 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -536,7 +536,7 @@ class OffTheRecordProfileImpl : public Profile, virtual WebKitContext* GetWebKitContext() { if (!webkit_context_.get()) - webkit_context_ = new WebKitContext(FilePath(), true); + webkit_context_ = new WebKitContext(this); DCHECK(webkit_context_.get()); return webkit_context_.get(); } @@ -1425,7 +1425,7 @@ void ProfileImpl::SpellCheckHostInitialized() { WebKitContext* ProfileImpl::GetWebKitContext() { if (!webkit_context_.get()) - webkit_context_ = new WebKitContext(path_, false); + webkit_context_ = new WebKitContext(this); DCHECK(webkit_context_.get()); return webkit_context_.get(); } diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 6cb3362..d27ec21 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -26,6 +26,7 @@ #include "chrome/browser/gpu_process_host.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h" +#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" #include "chrome/browser/metrics/histogram_synchronizer.h" #include "chrome/browser/nacl_host/nacl_process_host.h" #include "chrome/browser/net/chrome_url_request_context.h" @@ -308,8 +309,9 @@ ResourceMessageFilter::ResourceMessageFilter( appcache_dispatcher_host_( new AppCacheDispatcherHost(profile->GetRequestContext())), ALLOW_THIS_IN_INITIALIZER_LIST(dom_storage_dispatcher_host_( - new DOMStorageDispatcherHost(this, profile->GetWebKitContext(), - resource_dispatcher_host->webkit_thread()))), + new DOMStorageDispatcherHost(this, profile->GetWebKitContext()))), + ALLOW_THIS_IN_INITIALIZER_LIST(indexed_db_dispatcher_host_( + new IndexedDBDispatcherHost(this, profile->GetWebKitContext()))), ALLOW_THIS_IN_INITIALIZER_LIST(db_dispatcher_host_( new DatabaseDispatcherHost(profile->GetDatabaseTracker(), this, profile->GetHostContentSettingsMap()))), @@ -340,6 +342,9 @@ ResourceMessageFilter::~ResourceMessageFilter() { // Tell the DOM Storage dispatcher host to stop sending messages via us. dom_storage_dispatcher_host_->Shutdown(); + // Tell the Indexed DB dispatcher host to stop sending messages via us. + indexed_db_dispatcher_host_->Shutdown(); + // Shut down the database dispatcher host. db_dispatcher_host_->Shutdown(); @@ -380,6 +385,7 @@ void ResourceMessageFilter::OnChannelConnected(int32 peer_pid) { WorkerService::GetInstance()->Initialize(resource_dispatcher_host_); appcache_dispatcher_host_->Initialize(this, id(), handle()); dom_storage_dispatcher_host_->Init(id(), handle()); + indexed_db_dispatcher_host_->Init(id(), handle()); db_dispatcher_host_->Init(handle()); } @@ -410,6 +416,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { resource_dispatcher_host_->OnMessageReceived(msg, this, &msg_is_ok) || appcache_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || dom_storage_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || + indexed_db_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || audio_renderer_host_->OnMessageReceived(msg, &msg_is_ok) || db_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || mp_dispatcher->OnMessageReceived( diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 88642cd..e3e9ef6 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -41,6 +41,7 @@ class DOMStorageDispatcherHost; class ExtensionMessageService; class GeolocationDispatcherHost; class HostZoomMap; +class IndexedDBDispatcherHost; class NotificationsPrefsCache; class Profile; class RenderWidgetHelper; @@ -403,6 +404,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, // Handles DOM Storage related messages. scoped_refptr<DOMStorageDispatcherHost> dom_storage_dispatcher_host_; + // Handles Indexed Database related messages. + scoped_refptr<IndexedDBDispatcherHost> indexed_db_dispatcher_host_; + // Handles HTML5 DB related messages scoped_refptr<DatabaseDispatcherHost> db_dispatcher_host_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index e4e0702..19e1655 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1541,6 +1541,12 @@ 'browser/in_process_webkit/dom_storage_namespace.h', 'browser/in_process_webkit/dom_storage_permission_request.cc', 'browser/in_process_webkit/dom_storage_permission_request.h', + 'browser/in_process_webkit/indexed_db_callbacks.cc', + 'browser/in_process_webkit/indexed_db_callbacks.h', + 'browser/in_process_webkit/indexed_db_context.cc', + 'browser/in_process_webkit/indexed_db_context.h', + 'browser/in_process_webkit/indexed_db_dispatcher_host.cc', + 'browser/in_process_webkit/indexed_db_dispatcher_host.h', 'browser/in_process_webkit/webkit_context.cc', 'browser/in_process_webkit/webkit_context.h', 'browser/in_process_webkit/webkit_thread.cc', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 5999cdf..d308da9 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -98,6 +98,8 @@ 'renderer/geolocation_dispatcher.cc', 'renderer/geolocation_dispatcher.h', 'renderer/gpu_channel_host.cc', + 'renderer/indexed_db_dispatcher.cc', + 'renderer/indexed_db_dispatcher.h', 'renderer/gpu_channel_host.h', 'renderer/localized_error.cc', 'renderer/localized_error.h', @@ -146,6 +148,10 @@ 'renderer/renderer_webapplicationcachehost_impl.h', 'renderer/renderer_webcookiejar_impl.cc', 'renderer/renderer_webcookiejar_impl.h', + 'renderer/renderer_webidbdatabase_impl.cc', + 'renderer/renderer_webidbdatabase_impl.h', + 'renderer/renderer_webindexeddatabase_impl.cc', + 'renderer/renderer_webindexeddatabase_impl.h', 'renderer/renderer_webkitclient_impl.cc', 'renderer/renderer_webkitclient_impl.h', 'renderer/renderer_webstoragearea_impl.cc', diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index e6dba64..14fc353 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -528,6 +528,27 @@ struct ViewMsg_DOMStorageEvent_Params { DOMStorageType storage_type_; }; +// Used to open an indexed database. +struct ViewHostMsg_IndexedDatabaseOpen_Params { + // The routing ID of the view initiating the open. + int32 routing_id_; + + // The response should have this id. + int32 response_id_; + + // The origin doing the initiating. + string16 origin_; + + // The name of the database. + string16 name_; + + // The description of the database. + string16 description_; + + // Should the database be modified if it doesn't match the above params. + bool modify_database_; +}; + // Allows an extension to execute code in a tab. struct ViewMsg_ExecuteCode_Params { ViewMsg_ExecuteCode_Params() {} @@ -2327,6 +2348,44 @@ struct ParamTraits<ViewMsg_DOMStorageEvent_Params> { } }; +// Traits for ViewHostMsg_IndexedDatabaseOpen_Params. +template <> +struct ParamTraits<ViewHostMsg_IndexedDatabaseOpen_Params> { + typedef ViewHostMsg_IndexedDatabaseOpen_Params param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.routing_id_); + WriteParam(m, p.response_id_); + WriteParam(m, p.origin_); + WriteParam(m, p.name_); + WriteParam(m, p.description_); + WriteParam(m, p.modify_database_); + } + static bool Read(const Message* m, void** iter, param_type* p) { + return + ReadParam(m, iter, &p->routing_id_) && + ReadParam(m, iter, &p->response_id_) && + ReadParam(m, iter, &p->origin_) && + ReadParam(m, iter, &p->name_) && + ReadParam(m, iter, &p->description_) && + ReadParam(m, iter, &p->modify_database_); + } + static void Log(const param_type& p, std::wstring* l) { + l->append(L"("); + LogParam(p.routing_id_, l); + l->append(L", "); + LogParam(p.response_id_, l); + l->append(L", "); + LogParam(p.origin_, l); + l->append(L", "); + LogParam(p.name_, l); + l->append(L", "); + LogParam(p.description_, l); + l->append(L", "); + LogParam(p.modify_database_, l); + l->append(L")"); + } +}; + // Traits for ViewHostMsg_CreateWorker_Params template <> struct ParamTraits<ViewHostMsg_CreateWorker_Params> { diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index a4646ae..db1907d 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -833,6 +833,15 @@ IPC_BEGIN_MESSAGES(View) IPC_MESSAGE_CONTROL1(ViewMsg_DOMStorageEvent, ViewMsg_DOMStorageEvent_Params) + // IndexedDatabase::open message responses. + IPC_MESSAGE_CONTROL2(ViewMsg_IndexedDatabaseOpenSuccess, + int32 /* response_id */, + int32 /* idb_database_id */) + IPC_MESSAGE_CONTROL3(ViewMsg_IndexedDatabaseOpenError, + int32 /* response_id */, + int /* code */, + string16 /* message */) + #if defined(IPC_MESSAGE_LOG_ENABLED) // Tell the renderer process to begin or end IPC message logging. IPC_MESSAGE_CONTROL1(ViewMsg_SetIPCLoggingEnabled, @@ -2133,6 +2142,14 @@ IPC_BEGIN_MESSAGES(ViewHost) GURL /* url */, bool /* something_cleared */) + // IndexedDatabase::open() message. + IPC_MESSAGE_CONTROL1(ViewHostMsg_IndexedDatabaseOpen, + ViewHostMsg_IndexedDatabaseOpen_Params) + + // IDBDatabase::~IDBDatabase() message. + IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBDatabaseDestroyed, + int32 /* idb_database_id */) + // Get file size in bytes. Set result to -1 if failed to get the file size. IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetFileSize, FilePath /* path */, diff --git a/chrome/renderer/indexed_db_dispatcher.cc b/chrome/renderer/indexed_db_dispatcher.cc new file mode 100644 index 0000000..3dbaf0b --- /dev/null +++ b/chrome/renderer/indexed_db_dispatcher.cc @@ -0,0 +1,84 @@ +// Copyright (c) 2009 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 "chrome/renderer/indexed_db_dispatcher.h" + +#include "chrome/common/render_messages.h" +#include "chrome/renderer/render_thread.h" +#include "chrome/renderer/render_view.h" +#include "chrome/renderer/renderer_webidbdatabase_impl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" + +using WebKit::WebFrame; +using WebKit::WebIDBCallbacks; +using WebKit::WebIDBDatabase; +using WebKit::WebIDBDatabaseError; + +IndexedDBDispatcher::IndexedDBDispatcher() { +} + +IndexedDBDispatcher::~IndexedDBDispatcher() { +} + +bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) + IPC_MESSAGE_HANDLER(ViewMsg_IndexedDatabaseOpenSuccess, + OnIndexedDatabaseOpenSuccess) + IPC_MESSAGE_HANDLER(ViewMsg_IndexedDatabaseOpenError, + OnIndexedDatabaseOpenError) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void IndexedDBDispatcher::RequestIndexedDatabaseOpen( + const string16& name, const string16& description, bool modify_database, + WebIDBCallbacks* callbacks_ptr, const string16& origin, WebFrame* web_frame, + int* exception_code) { + scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); + *exception_code = 0; // Redundant, but why not... + + if (!web_frame) + return; // We must be shutting down. + RenderView* render_view = RenderView::FromWebView(web_frame->view()); + if (!render_view) + return; // We must be shutting down. + + ViewHostMsg_IndexedDatabaseOpen_Params params; + params.routing_id_ = render_view->routing_id(); + params.response_id_ = indexed_database_open_callbacks_.Add( + callbacks.release()); + params.origin_ = origin; + params.name_ = name; + params.description_ = description; + params.modify_database_ = modify_database; + RenderThread::current()->Send(new ViewHostMsg_IndexedDatabaseOpen(params)); +} + +void IndexedDBDispatcher::SendIDBDatabaseDestroyed(int32 idb_database_id) { + // TODO(jorlow): Is it possible for this to be destroyed but still have + // pending callbacks? If so, fix! + RenderThread::current()->Send(new ViewHostMsg_IDBDatabaseDestroyed( + idb_database_id)); +} + +void IndexedDBDispatcher::OnIndexedDatabaseOpenSuccess( + int32 response_id, int32 idb_database_id) { + WebKit::WebIDBCallbacks* callbacks = + indexed_database_open_callbacks_.Lookup(response_id); + callbacks->onSuccess(new RendererWebIDBDatabaseImpl(idb_database_id)); + indexed_database_open_callbacks_.Remove(response_id); +} + +void IndexedDBDispatcher::OnIndexedDatabaseOpenError( + int32 response_id, int code, const string16& message) { + WebKit::WebIDBCallbacks* callbacks = + indexed_database_open_callbacks_.Lookup(response_id); + callbacks->onError(WebIDBDatabaseError(code, message)); + indexed_database_open_callbacks_.Remove(response_id); +} diff --git a/chrome/renderer/indexed_db_dispatcher.h b/chrome/renderer/indexed_db_dispatcher.h new file mode 100644 index 0000000..78bb80b --- /dev/null +++ b/chrome/renderer/indexed_db_dispatcher.h @@ -0,0 +1,51 @@ +// 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. + +#ifndef CHROME_RENDERER_INDEXED_DB_DISPATCHER_H_ +#define CHROME_RENDERER_INDEXED_DB_DISPATCHER_H_ + +#include "base/id_map.h" +#include "base/string16.h" +#include "ipc/ipc_message.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" + +namespace WebKit { +class WebFrame; +} + +// Handle the indexed db related communication for this entire renderer. +class IndexedDBDispatcher { + public: + IndexedDBDispatcher(); + ~IndexedDBDispatcher(); + + // Called to possibly handle the incoming IPC message. Returns true if + // handled. + bool OnMessageReceived(const IPC::Message& msg); + + void RequestIndexedDatabaseOpen( + const string16& name, const string16& description, bool modify_database, + WebKit::WebIDBCallbacks* callbacks, const string16& origin, + WebKit::WebFrame* web_frame, int* exception_code); + + void SendIDBDatabaseDestroyed(int32 idb_database_id_); + + private: + // Message handlers. For each message we send, we need to handle both the + // success and the error case. + void OnIndexedDatabaseOpenSuccess(int32 response_id, + int32 idb_database_id); + void OnIndexedDatabaseOpenError(int32 response_id, int code, + const string16& message); + + // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be + // destroyed and used on the same thread it was created on. + IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> + indexed_database_open_callbacks_; + + DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); +}; + +#endif // CHROME_RENDERER_INDEXED_DB_DISPATCHER_H_ diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index bccacf6..92b4b80 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -50,12 +50,14 @@ #include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" #include "chrome/renderer/external_extension.h" +#include "chrome/renderer/indexed_db_dispatcher.h" #include "chrome/renderer/loadtimes_extension_bindings.h" #include "chrome/renderer/net/render_dns_master.h" #include "chrome/renderer/plugin_channel_host.h" #include "chrome/renderer/render_process_impl.h" #include "chrome/renderer/render_view.h" #include "chrome/renderer/render_view_visitor.h" +#include "chrome/renderer/renderer_webindexeddatabase_impl.h" #include "chrome/renderer/renderer_webkitclient_impl.h" #include "chrome/renderer/spellchecker/spellcheck.h" #include "chrome/renderer/user_script_slave.h" @@ -234,6 +236,7 @@ void RenderThread::Init() { dns_master_.reset(new RenderDnsMaster()); histogram_snapshots_.reset(new RendererHistogramSnapshots()); appcache_dispatcher_.reset(new AppCacheDispatcher(this)); + indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); spellchecker_.reset(new SpellCheck()); devtools_agent_filter_ = new DevToolsAgentFilter(); @@ -522,9 +525,11 @@ void RenderThread::OnDOMStorageEvent( } void RenderThread::OnControlMessageReceived(const IPC::Message& msg) { - // App cache messages are handled by a delegate. + // Some messages are handled by delegates. if (appcache_dispatcher_->OnMessageReceived(msg)) return; + if (indexed_db_dispatcher_->OnMessageReceived(msg)) + return; IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index 3578f77..a02a0b9 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -31,6 +31,7 @@ class CookieMessageFilter; class DBMessageFilter; class DevToolsAgentFilter; class FilePath; +class IndexedDBDispatcher; class ListValue; class NullableString16; class RenderDnsMaster; @@ -143,6 +144,10 @@ class RenderThread : public RenderThreadBase, return appcache_dispatcher_.get(); } + IndexedDBDispatcher* indexed_db_dispatcher() const { + return indexed_db_dispatcher_.get(); + } + SpellCheck* spellchecker() const { return spellchecker_.get(); } @@ -283,6 +288,7 @@ class RenderThread : public RenderThreadBase, scoped_ptr<UserScriptSlave> user_script_slave_; scoped_ptr<RenderDnsMaster> dns_master_; scoped_ptr<AppCacheDispatcher> appcache_dispatcher_; + scoped_ptr<IndexedDBDispatcher> indexed_db_dispatcher_; scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_; scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_; scoped_ptr<RendererWebKitClientImpl> webkit_client_; diff --git a/chrome/renderer/renderer_webidbdatabase_impl.cc b/chrome/renderer/renderer_webidbdatabase_impl.cc new file mode 100644 index 0000000..1c8e114 --- /dev/null +++ b/chrome/renderer/renderer_webidbdatabase_impl.cc @@ -0,0 +1,18 @@ +// 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 "chrome/renderer/renderer_webidbdatabase_impl.h" + +#include "chrome/renderer/render_thread.h" +#include "chrome/renderer/indexed_db_dispatcher.h" + +RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl(int32 idb_database_id) + : idb_database_id_(idb_database_id) { +} + +RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() { + IndexedDBDispatcher* dispatcher = + RenderThread::current()->indexed_db_dispatcher(); + dispatcher->SendIDBDatabaseDestroyed(idb_database_id_); +} diff --git a/chrome/renderer/renderer_webidbdatabase_impl.h b/chrome/renderer/renderer_webidbdatabase_impl.h new file mode 100644 index 0000000..f4fe7fc --- /dev/null +++ b/chrome/renderer/renderer_webidbdatabase_impl.h @@ -0,0 +1,21 @@ +// 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. + +#ifndef CHROME_RENDERER_RENDERER_WEBIDBDATABASE_IMPL_H_ +#define CHROME_RENDERER_RENDERER_WEBIDBDATABASE_IMPL_H_ + +#include "base/basictypes.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" + +class RendererWebIDBDatabaseImpl : public WebKit::WebIDBDatabase { + public: + explicit RendererWebIDBDatabaseImpl(int32 idb_database_id); + virtual ~RendererWebIDBDatabaseImpl(); + + private: + int32 idb_database_id_; +}; + +#endif // CHROME_RENDERER_RENDERER_WEBIDBDATABASE_IMPL_H_ diff --git a/chrome/renderer/renderer_webindexeddatabase_impl.cc b/chrome/renderer/renderer_webindexeddatabase_impl.cc new file mode 100644 index 0000000..e472a8b2 --- /dev/null +++ b/chrome/renderer/renderer_webindexeddatabase_impl.cc @@ -0,0 +1,31 @@ +// 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 "chrome/renderer/renderer_webindexeddatabase_impl.h" + +#include "chrome/renderer/render_thread.h" +#include "chrome/renderer/indexed_db_dispatcher.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" + +using WebKit::WebIDBCallbacks; +using WebKit::WebIDBDatabase; +using WebKit::WebString; +using WebKit::WebFrame; + +RendererWebIndexedDatabaseImpl::RendererWebIndexedDatabaseImpl() { +} + +RendererWebIndexedDatabaseImpl::~RendererWebIndexedDatabaseImpl() { +} + +void RendererWebIndexedDatabaseImpl::open( + const WebString& name, const WebString& description, bool modify_database, + WebIDBCallbacks* callbacks, const WebString& origin, WebFrame* web_frame, + int& exception_code) { + IndexedDBDispatcher* dispatcher = + RenderThread::current()->indexed_db_dispatcher(); + dispatcher->RequestIndexedDatabaseOpen(name, description, modify_database, + callbacks, origin, web_frame, + &exception_code); +} diff --git a/chrome/renderer/renderer_webindexeddatabase_impl.h b/chrome/renderer/renderer_webindexeddatabase_impl.h new file mode 100644 index 0000000..6cc73f2d --- /dev/null +++ b/chrome/renderer/renderer_webindexeddatabase_impl.h @@ -0,0 +1,30 @@ +// 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. + +#ifndef CHROME_RENDERER_RENDERER_WEBINDEXEDDATABASE_IMPL_H_ +#define CHROME_RENDERER_RENDERER_WEBINDEXEDDATABASE_IMPL_H_ + +#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" + +namespace WebKit { +class WebFrame; +class WebIDBDatabase; +class WebString; +} + +class RendererWebIndexedDatabaseImpl : public WebKit::WebIndexedDatabase { + public: + RendererWebIndexedDatabaseImpl(); + virtual ~RendererWebIndexedDatabaseImpl(); + + // See WebIndexedDatabase.h for documentation on these functions. + virtual void open( + const WebKit::WebString& name, const WebKit::WebString& description, + bool modify_database, WebKit::WebIDBCallbacks* callbacks, + const WebKit::WebString& origin, WebKit::WebFrame* web_frame, + int& exception_code); +}; + +#endif // CHROME_RENDERER_RENDERER_WEBINDEXEDDATABASE_IMPL_H_ diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc index 0846df1..bc3c0c9 100644 --- a/chrome/renderer/renderer_webkitclient_impl.cc +++ b/chrome/renderer/renderer_webkitclient_impl.cc @@ -21,6 +21,7 @@ #include "chrome/renderer/net/render_dns_master.h" #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" +#include "chrome/renderer/renderer_webindexeddatabase_impl.h" #include "chrome/renderer/renderer_webstoragenamespace_impl.h" #include "chrome/renderer/visitedlink_slave.h" #include "chrome/renderer/webgles2context_impl.h" @@ -29,6 +30,7 @@ #include "ipc/ipc_sync_message_filter.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" #include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" @@ -44,6 +46,7 @@ #endif using WebKit::WebFrame; +using WebKit::WebIndexedDatabase; using WebKit::WebKitClient; using WebKit::WebStorageArea; using WebKit::WebStorageEventDispatcher; @@ -52,6 +55,13 @@ using WebKit::WebString; using WebKit::WebURL; using WebKit::WebVector; +RendererWebKitClientImpl::RendererWebKitClientImpl() + : sudden_termination_disables_(0) { +} + +RendererWebKitClientImpl::~RendererWebKitClientImpl() { +} + //------------------------------------------------------------------------------ WebKit::WebClipboard* RendererWebKitClientImpl::clipboard() { @@ -170,6 +180,18 @@ void RendererWebKitClientImpl::dispatchStorageEvent( //------------------------------------------------------------------------------ +WebIndexedDatabase* RendererWebKitClientImpl::indexedDatabase() { + if (!web_indexed_database_.get()) { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) + web_indexed_database_.reset(WebIndexedDatabase::create()); + else + web_indexed_database_.reset(new RendererWebIndexedDatabaseImpl()); + } + return web_indexed_database_.get(); +} + +//------------------------------------------------------------------------------ + WebString RendererWebKitClientImpl::MimeRegistry::mimeTypeForExtension( const WebString& file_extension) { if (IsPluginProcess()) diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h index adcad69..82c40295 100644 --- a/chrome/renderer/renderer_webkitclient_impl.h +++ b/chrome/renderer/renderer_webkitclient_impl.h @@ -6,6 +6,7 @@ #define CHROME_RENDERER_RENDERER_WEBKITCLIENT_IMPL_H_ #include "base/platform_file.h" +#include "base/scoped_ptr.h" #include "chrome/renderer/websharedworkerrepository_impl.h" #include "webkit/glue/simple_webmimeregistry_impl.h" #include "webkit/glue/webclipboard_impl.h" @@ -27,7 +28,8 @@ class SyncMessage; class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { public: - RendererWebKitClientImpl() : sudden_termination_disables_(0) {} + RendererWebKitClientImpl(); + virtual ~RendererWebKitClientImpl(); // WebKitClient methods: virtual WebKit::WebClipboard* clipboard(); @@ -62,6 +64,8 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { unsigned key_size_index, const WebKit::WebString& challenge, const WebKit::WebURL& url); + virtual WebKit::WebIndexedDatabase* indexedDatabase(); + virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository(); virtual WebKit::WebGraphicsContext3D* createGraphicsContext3D(); virtual WebKit::WebGLES2Context* createGLES2Context(); @@ -129,6 +133,7 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { // to WorkerService on the browser thread. WebSharedWorkerRepositoryImpl shared_worker_repository_; + scoped_ptr<WebKit::WebIndexedDatabase> web_indexed_database_; }; #endif // CHROME_RENDERER_RENDERER_WEBKITCLIENT_IMPL_H_ diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 7ceaec6..12f3496 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -245,7 +245,7 @@ class TestingProfile : public Profile { virtual void ReinitializeSpellCheckHost(bool force) { } virtual WebKitContext* GetWebKitContext() { if (webkit_context_ == NULL) - webkit_context_ = new WebKitContext(GetPath(), false); + webkit_context_ = new WebKitContext(this); return webkit_context_; } virtual WebKitContext* GetOffTheRecordWebKitContext() { return NULL; } |