diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 02:25:16 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 02:25:16 +0000 |
commit | 21737472cbcee12ee98460a455a1a398e76df6cf (patch) | |
tree | a83f7d566c4a77161fc1e0d955797d7384fafa48 /webkit/tools | |
parent | 4b59a4240d02d872cb94b529cc38cee34360a5dd (diff) | |
download | chromium_src-21737472cbcee12ee98460a455a1a398e76df6cf.zip chromium_src-21737472cbcee12ee98460a455a1a398e76df6cf.tar.gz chromium_src-21737472cbcee12ee98460a455a1a398e76df6cf.tar.bz2 |
Integrate the new dom_storage backend into chromium DRT and test_shell.
- test_shell_webkit_init is used in test_shell
- test_webview_delegate is used test_shell
- test_webkit_platform_support is used in crDRT
- webkit_support is used in crDRT (by way of WebViewHost.cpp upstream)
(I'll have to land a seperate patch to alter WebViewHost.cpp)
This is behind a compile time enable flag defined in dom_storage_types,
the flag is undefined in this CL. It will be enabled in a future CL
when chromium is also ready to switch over to the new backend across
the board.
BUG=106763
Review URL: https://chromiumcodereview.appspot.com/9429029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124337 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools')
-rw-r--r-- | webkit/tools/test_shell/simple_dom_storage_system.cc | 213 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_dom_storage_system.h | 56 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.cc | 10 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 5 |
5 files changed, 285 insertions, 1 deletions
diff --git a/webkit/tools/test_shell/simple_dom_storage_system.cc b/webkit/tools/test_shell/simple_dom_storage_system.cc new file mode 100644 index 0000000..942f1e7 --- /dev/null +++ b/webkit/tools/test_shell/simple_dom_storage_system.cc @@ -0,0 +1,213 @@ +// Copyright (c) 2012 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/tools/test_shell/simple_dom_storage_system.h" + +#include "googleurl/src/gurl.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" +#include "webkit/database/database_util.h" +#include "webkit/dom_storage/dom_storage_context.h" +#include "webkit/dom_storage/dom_storage_host.h" +#include "webkit/dom_storage/dom_storage_session.h" + +using dom_storage::DomStorageContext; +using dom_storage::DomStorageHost; +using dom_storage::DomStorageSession; +using webkit_database::DatabaseUtil; +using WebKit::WebStorageNamespace; +using WebKit::WebStorageArea; +using WebKit::WebString; +using WebKit::WebURL; + +namespace { +const int kInvalidNamespaceId = -1; +} + +class SimpleDomStorageSystem::NamespaceImpl : public WebStorageNamespace { + public: + explicit NamespaceImpl(const base::WeakPtr<SimpleDomStorageSystem>& parent); + NamespaceImpl(const base::WeakPtr<SimpleDomStorageSystem>& parent, + int session_namespace_id); + virtual ~NamespaceImpl(); + virtual WebStorageArea* createStorageArea(const WebString& origin) OVERRIDE; + virtual WebStorageNamespace* copy() OVERRIDE; + virtual void close() OVERRIDE; + + private: + DomStorageContext* Context() { + if (!parent_.get()) + return NULL; + return parent_->context_.get(); + } + + base::WeakPtr<SimpleDomStorageSystem> parent_; + int namespace_id_; +}; + +class SimpleDomStorageSystem::AreaImpl : public WebStorageArea { + public: + AreaImpl(const base::WeakPtr<SimpleDomStorageSystem>& parent, + int namespace_id, const GURL& origin); + virtual ~AreaImpl(); + virtual unsigned length() OVERRIDE; + virtual WebString key(unsigned index) OVERRIDE; + virtual WebString getItem(const WebString& key) OVERRIDE; + virtual void setItem(const WebString& key, const WebString& newValue, + const WebURL&, Result&, WebString& oldValue) OVERRIDE; + virtual void removeItem(const WebString& key, const WebURL& url, + WebString& oldValue) OVERRIDE; + virtual void clear(const WebURL& url, bool& somethingCleared) OVERRIDE; + + private: + DomStorageHost* Host() { + if (!parent_.get()) + return NULL; + return parent_->host_.get(); + } + + base::WeakPtr<SimpleDomStorageSystem> parent_; + int connection_id_; +}; + +// NamespaceImpl ----------------------------- + +SimpleDomStorageSystem::NamespaceImpl::NamespaceImpl( + const base::WeakPtr<SimpleDomStorageSystem>& parent) + : parent_(parent), + namespace_id_(dom_storage::kLocalStorageNamespaceId) { +} + +SimpleDomStorageSystem::NamespaceImpl::NamespaceImpl( + const base::WeakPtr<SimpleDomStorageSystem>& parent, + int session_namespace_id) + : parent_(parent), + namespace_id_(session_namespace_id) { +} + +SimpleDomStorageSystem::NamespaceImpl::~NamespaceImpl() { + if (namespace_id_ == dom_storage::kLocalStorageNamespaceId || + namespace_id_ == kInvalidNamespaceId || !Context()) { + return; + } + Context()->DeleteSessionNamespace(namespace_id_); +} + +WebStorageArea* SimpleDomStorageSystem::NamespaceImpl::createStorageArea( + const WebString& origin) { + return new AreaImpl(parent_, namespace_id_, GURL(origin)); +} + +WebStorageNamespace* SimpleDomStorageSystem::NamespaceImpl::copy() { + DCHECK_NE(dom_storage::kLocalStorageNamespaceId, namespace_id_); + int new_id = kInvalidNamespaceId; + if (Context()) { + new_id = Context()->AllocateSessionId(); + Context()->CloneSessionNamespace(namespace_id_, new_id); + } + return new NamespaceImpl(parent_, new_id); +} + +void SimpleDomStorageSystem::NamespaceImpl::close() { +} + +// AreaImpl ----------------------------- + +SimpleDomStorageSystem::AreaImpl::AreaImpl( + const base::WeakPtr<SimpleDomStorageSystem>& parent, + int namespace_id, const GURL& origin) + : parent_(parent), + connection_id_(0) { + if (Host()) + connection_id_ = Host()->OpenStorageArea(namespace_id, origin); +} + +SimpleDomStorageSystem::AreaImpl::~AreaImpl() { + if (Host()) + Host()->CloseStorageArea(connection_id_); +} + +unsigned SimpleDomStorageSystem::AreaImpl::length() { + if (Host()) + return Host()->GetAreaLength(connection_id_); + return 0; +} + +WebString SimpleDomStorageSystem::AreaImpl::key(unsigned index) { + if (Host()) + return Host()->GetAreaKey(connection_id_, index); + return NullableString16(true); +} + +WebString SimpleDomStorageSystem::AreaImpl::getItem(const WebString& key) { + if (Host()) + return Host()->GetAreaItem(connection_id_, key); + return NullableString16(true); +} + +void SimpleDomStorageSystem::AreaImpl::setItem( + const WebString& key, const WebString& newValue, + const WebURL& pageUrl, Result& result, WebString& oldValue) { + result = ResultBlockedByQuota; + oldValue = NullableString16(true); + if (!Host()) + return; + + NullableString16 old_value; + if (!Host()->SetAreaItem(connection_id_, key, newValue, pageUrl, + &old_value)) + return; + + result = ResultOK; + oldValue = old_value; +} + +void SimpleDomStorageSystem::AreaImpl::removeItem( + const WebString& key, const WebURL& pageUrl, WebString& oldValue) { + oldValue = NullableString16(true); + if (!Host()) + return; + + string16 old_value; + if (!Host()->RemoveAreaItem(connection_id_, key, pageUrl, &old_value)) + return; + + oldValue = old_value; +} + +void SimpleDomStorageSystem::AreaImpl::clear( + const WebURL& pageUrl, bool& somethingCleared) { + if (Host()) + somethingCleared = Host()->ClearArea(connection_id_, pageUrl); + else + somethingCleared = false; +} + +// SimpleDomStorageSystem ----------------------------- + +SimpleDomStorageSystem* SimpleDomStorageSystem::g_instance_; + +SimpleDomStorageSystem::SimpleDomStorageSystem() + : weak_factory_(this), + context_(new DomStorageContext(FilePath(), NULL, NULL)), + host_(new DomStorageHost(context_)) { + DCHECK(!g_instance_); + g_instance_ = this; +} + +SimpleDomStorageSystem::~SimpleDomStorageSystem() { + g_instance_ = NULL; + host_.reset(); +} + +WebStorageNamespace* SimpleDomStorageSystem::CreateLocalStorageNamespace() { + return new NamespaceImpl(weak_factory_.GetWeakPtr()); +} + +WebStorageNamespace* SimpleDomStorageSystem::CreateSessionStorageNamespace() { + int id = context_->AllocateSessionId(); + context_->CreateSessionNamespace(id); + return new NamespaceImpl(weak_factory_.GetWeakPtr(), id); +} diff --git a/webkit/tools/test_shell/simple_dom_storage_system.h b/webkit/tools/test_shell/simple_dom_storage_system.h new file mode 100644 index 0000000..96c78c4 --- /dev/null +++ b/webkit/tools/test_shell/simple_dom_storage_system.h @@ -0,0 +1,56 @@ +// Copyright (c) 2012 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 WEBKIT_TOOLS_TEST_SHELL_SIMPLE_DOM_STORAGE_SYSTEM_H_ +#define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_DOM_STORAGE_SYSTEM_H_ +#pragma once + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "webkit/dom_storage/dom_storage_context.h" +#include "webkit/dom_storage/dom_storage_host.h" +#include "webkit/dom_storage/dom_storage_types.h" // For the ENABLE flag. + +namespace dom_storage { +class DomStorageContext; +class DomStorageHost; +} +namespace WebKit { +class WebStorageNamespace; +} + +// Class that composes dom_storage classes together for use +// in simple single process environments like test_shell and DRT. +class SimpleDomStorageSystem { + public: + static SimpleDomStorageSystem& instance() { return *g_instance_; } + + SimpleDomStorageSystem(); + ~SimpleDomStorageSystem(); + + // The Create<<>> calls are bound to WebKit api that the embedder + // is responsible for implementing. These factories are called strictly + // on the 'main' webkit thread. Ditto the methods on the returned + // objects. SimplDomStorageSystem manufactures implementations of the + // WebStorageNamespace and WebStorageArea interfaces that ultimately + // plumb Get, Set, Remove, and Clear javascript calls to the dom_storage + // classes. The caller (webkit/webcore) takes ownership of the returned + // instances and will delete them when done. + WebKit::WebStorageNamespace* CreateLocalStorageNamespace(); + WebKit::WebStorageNamespace* CreateSessionStorageNamespace(); + + private: + // Inner classes that implement the WebKit WebStorageNamespace and + // WebStorageArea interfaces in terms of dom_storage classes. + class NamespaceImpl; + class AreaImpl; + + base::WeakPtrFactory<SimpleDomStorageSystem> weak_factory_; + scoped_refptr<dom_storage::DomStorageContext> context_; + scoped_ptr<dom_storage::DomStorageHost> host_; + + static SimpleDomStorageSystem* g_instance_; +}; + +#endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_DOM_STORAGE_SYSTEM_H_ diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc index 5ae9083..2f243e3 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.cc +++ b/webkit/tools/test_shell/test_shell_webkit_init.cc @@ -257,10 +257,14 @@ WebKit::WebString TestShellWebKitInit::defaultLocale() { WebKit::WebStorageNamespace* TestShellWebKitInit::createLocalStorageNamespace( const WebKit::WebString& path, unsigned quota) { +#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND + return dom_storage_system_.CreateLocalStorageNamespace(); +#else // Enforce quota here, ignoring the value from the renderer as in Chrome. return WebKit::WebStorageNamespace::createLocalStorageNamespace( path, WebKit::WebStorageNamespace::m_localStorageQuota); +#endif } void TestShellWebKitInit::dispatchStorageEvent( @@ -268,7 +272,11 @@ void TestShellWebKitInit::dispatchStorageEvent( const WebKit::WebString& old_value, const WebKit::WebString& new_value, const WebKit::WebString& origin, const WebKit::WebURL& url, bool is_local_storage) { - // The event is dispatched by the proxy. + // All events are dispatched by the WebCore::StorageAreaProxy in the + // simple single process case. +#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND + NOTREACHED(); +#endif } WebKit::WebIDBFactory* TestShellWebKitInit::idbFactory() { diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index b94f5c4..b334cb4 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -21,6 +21,7 @@ #include "webkit/tools/test_shell/mock_webclipboard_impl.h" #include "webkit/tools/test_shell/simple_appcache_system.h" #include "webkit/tools/test_shell/simple_clipboard_impl.h" +#include "webkit/tools/test_shell/simple_dom_storage_system.h" #include "webkit/tools/test_shell/simple_file_system.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/simple_webcookiejar_impl.h" @@ -129,6 +130,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitPlatformSupportImpl { ScopedTempDir appcache_dir_; SimpleAppCacheSystem appcache_system_; SimpleDatabaseSystem database_system_; + SimpleDomStorageSystem dom_storage_system_; SimpleWebCookieJarImpl cookie_jar_; scoped_refptr<TestShellWebBlobRegistryImpl> blob_registry_; SimpleFileSystem file_system_; diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 1bafbae..573dba5 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -70,6 +70,7 @@ #include "webkit/tools/test_shell/mock_spellcheck.h" #include "webkit/tools/test_shell/notification_presenter.h" #include "webkit/tools/test_shell/simple_appcache_system.h" +#include "webkit/tools/test_shell/simple_dom_storage_system.h" #include "webkit/tools/test_shell/simple_file_system.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell.h" @@ -333,9 +334,13 @@ WebWidget* TestWebViewDelegate::createPopupMenu(WebPopupType popup_type) { WebStorageNamespace* TestWebViewDelegate::createSessionStorageNamespace( unsigned quota) { +#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND + return SimpleDomStorageSystem::instance().CreateSessionStorageNamespace(); +#else // Enforce quota, ignoring the parameter from WebCore as in Chrome. return WebKit::WebStorageNamespace::createSessionStorageNamespace( WebStorageNamespace::m_sessionStorageQuota); +#endif } WebGraphicsContext3D* TestWebViewDelegate::createGraphicsContext3D( |