summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-13 04:10:40 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-13 04:10:40 +0000
commit10e5cf1c02a7f30b7cd0b3ef3fef4ecb8faa75a0 (patch)
tree0bd741bb4d609f04bb8947ff5cd237a0098e01f8 /content
parent831de724f3aed4700bb20750e2434b4159f485da (diff)
downloadchromium_src-10e5cf1c02a7f30b7cd0b3ef3fef4ecb8faa75a0.zip
chromium_src-10e5cf1c02a7f30b7cd0b3ef3fef4ecb8faa75a0.tar.gz
chromium_src-10e5cf1c02a7f30b7cd0b3ef3fef4ecb8faa75a0.tar.bz2
Add IPC plumbing code for Quota API
BUG=61676 TEST=No new tests; just IPC plumbing (manually tested) Review URL: http://codereview.chromium.org/6811022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81364 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/quota_dispatcher_host.cc46
-rw-r--r--content/browser/renderer_host/quota_dispatcher_host.h31
-rw-r--r--content/common/child_thread.cc4
-rw-r--r--content/common/child_thread.h7
-rw-r--r--content/common/content_message_generator.h1
-rw-r--r--content/common/quota_dispatcher.cc90
-rw-r--r--content/common/quota_dispatcher.h61
-rw-r--r--content/common/quota_dispatcher_dummy.cc21
-rw-r--r--content/common/quota_messages.h43
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/content_common.gypi3
-rw-r--r--content/renderer/render_view.cc36
-rw-r--r--content/renderer/render_view.h11
13 files changed, 356 insertions, 0 deletions
diff --git a/content/browser/renderer_host/quota_dispatcher_host.cc b/content/browser/renderer_host/quota_dispatcher_host.cc
new file mode 100644
index 0000000..aef300c
--- /dev/null
+++ b/content/browser/renderer_host/quota_dispatcher_host.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2011 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 "content/browser/renderer_host/quota_dispatcher_host.h"
+
+#include "content/common/quota_messages.h"
+#include "googleurl/src/gurl.h"
+
+QuotaDispatcherHost::~QuotaDispatcherHost() {
+}
+
+bool QuotaDispatcherHost::OnMessageReceived(
+ const IPC::Message& message, bool* message_was_ok) {
+ *message_was_ok = true;
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(QuotaDispatcherHost, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(QuotaHostMsg_QueryStorageUsageAndQuota,
+ OnQueryStorageUsageAndQuota)
+ IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota,
+ OnRequestStorageQuota)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ return handled;
+}
+
+void QuotaDispatcherHost::OnQueryStorageUsageAndQuota(
+ int request_id,
+ const GURL& origin,
+ WebKit::WebStorageQuotaType type) {
+ // TODO(kinuko): not implemented yet.
+ Send(new QuotaMsg_DidFail(
+ request_id,
+ WebKit::WebStorageQuotaErrorNotSupported));
+}
+
+void QuotaDispatcherHost::OnRequestStorageQuota(
+ int request_id,
+ const GURL& origin,
+ WebKit::WebStorageQuotaType type,
+ int64 requested_size) {
+ // TODO(kinuko): not implemented yet.
+ Send(new QuotaMsg_DidFail(
+ request_id,
+ WebKit::WebStorageQuotaErrorNotSupported));
+}
diff --git a/content/browser/renderer_host/quota_dispatcher_host.h b/content/browser/renderer_host/quota_dispatcher_host.h
new file mode 100644
index 0000000..ac75278
--- /dev/null
+++ b/content/browser/renderer_host/quota_dispatcher_host.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 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 CONTENT_BROWSER_RENDERER_HOST_QUOTA_DISPATCHER_HOST_H_
+#define CONTENT_BROWSER_RENDERER_HOST_QUOTA_DISPATCHER_HOST_H_
+
+#include "base/basictypes.h"
+#include "content/browser/browser_message_filter.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"
+
+class GURL;
+
+class QuotaDispatcherHost : public BrowserMessageFilter {
+ public:
+ ~QuotaDispatcherHost();
+ bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok);
+
+ private:
+ void OnQueryStorageUsageAndQuota(
+ int request_id,
+ const GURL& origin_url,
+ WebKit::WebStorageQuotaType type);
+ void OnRequestStorageQuota(
+ int request_id,
+ const GURL& origin_url,
+ WebKit::WebStorageQuotaType type,
+ int64 requested_size);
+};
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_QUOTA_DISPATCHER_HOST_H_
diff --git a/content/common/child_thread.cc b/content/common/child_thread.cc
index 574b43b..92d2cca 100644
--- a/content/common/child_thread.cc
+++ b/content/common/child_thread.cc
@@ -13,6 +13,7 @@
#include "content/common/content_switches.h"
#include "content/common/file_system/file_system_dispatcher.h"
#include "content/common/notification_service.h"
+#include "content/common/quota_dispatcher.h"
#include "content/common/resource_dispatcher.h"
#include "content/common/socket_stream_dispatcher.h"
#include "ipc/ipc_logging.h"
@@ -53,6 +54,7 @@ void ChildThread::Init() {
resource_dispatcher_.reset(new ResourceDispatcher(this));
socket_stream_dispatcher_.reset(new SocketStreamDispatcher());
file_system_dispatcher_.reset(new FileSystemDispatcher());
+ quota_dispatcher_.reset(new QuotaDispatcher());
sync_message_filter_ =
new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent());
@@ -150,6 +152,8 @@ bool ChildThread::OnMessageReceived(const IPC::Message& msg) {
return true;
if (file_system_dispatcher_->OnMessageReceived(msg))
return true;
+ if (quota_dispatcher_->OnMessageReceived(msg))
+ return true;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChildThread, msg)
diff --git a/content/common/child_thread.h b/content/common/child_thread.h
index 4b27ab7..f2ac864 100644
--- a/content/common/child_thread.h
+++ b/content/common/child_thread.h
@@ -14,6 +14,7 @@
class FileSystemDispatcher;
class MessageLoop;
class NotificationService;
+class QuotaDispatcher;
class ResourceDispatcher;
class SocketStreamDispatcher;
@@ -56,6 +57,10 @@ class ChildThread : public IPC::Channel::Listener,
return file_system_dispatcher_.get();
}
+ QuotaDispatcher* quota_dispatcher() const {
+ return quota_dispatcher_.get();
+ }
+
// Safe to call on any thread, as long as it's guaranteed that the thread's
// lifetime is less than the main thread.
IPC::SyncMessageFilter* sync_message_filter();
@@ -122,6 +127,8 @@ class ChildThread : public IPC::Channel::Listener,
scoped_ptr<FileSystemDispatcher> file_system_dispatcher_;
+ scoped_ptr<QuotaDispatcher> quota_dispatcher_;
+
DISALLOW_COPY_AND_ASSIGN(ChildThread);
};
diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h
index eab0100..10c9fd8 100644
--- a/content/common/content_message_generator.h
+++ b/content/common/content_message_generator.h
@@ -26,6 +26,7 @@
#include "content/common/p2p_messages.h"
#include "content/common/pepper_file_messages.h"
#include "content/common/plugin_messages.h"
+#include "content/common/quota_messages.h"
#include "content/common/resource_messages.h"
#include "content/common/speech_input_messages.h"
#include "content/common/socket_stream_messages.h"
diff --git a/content/common/quota_dispatcher.cc b/content/common/quota_dispatcher.cc
new file mode 100644
index 0000000..0ecf1c4
--- /dev/null
+++ b/content/common/quota_dispatcher.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2011 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 "content/common/quota_dispatcher.h"
+
+#include "content/common/child_thread.h"
+#include "content/common/quota_messages.h"
+#include "googleurl/src/gurl.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
+
+using WebKit::WebStorageQuotaCallbacks;
+using WebKit::WebStorageQuotaError;
+using WebKit::WebStorageQuotaType;
+
+QuotaDispatcher::QuotaDispatcher() {
+}
+
+QuotaDispatcher::~QuotaDispatcher() {
+ IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_);
+ while (!iter.IsAtEnd()) {
+ iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort);
+ iter.Advance();
+ }
+}
+
+bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg)
+ IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota,
+ DidGrantStorageQuota)
+ IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota,
+ DidQueryStorageUsageAndQuota);
+ IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail);
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void QuotaDispatcher::QueryStorageUsageAndQuota(
+ const GURL& origin_url,
+ WebStorageQuotaType type,
+ WebStorageQuotaCallbacks* callbacks) {
+ DCHECK(callbacks);
+ int request_id = pending_quota_callbacks_.Add(callbacks);
+ ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota(
+ request_id, origin_url, type));
+}
+
+void QuotaDispatcher::RequestStorageQuota(
+ const GURL& origin_url,
+ WebStorageQuotaType type,
+ unsigned long long requested_size,
+ WebStorageQuotaCallbacks* callbacks) {
+ DCHECK(callbacks);
+ int request_id = pending_quota_callbacks_.Add(callbacks);
+ ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota(
+ request_id, origin_url, type, requested_size));
+}
+
+void QuotaDispatcher::DidGrantStorageQuota(
+ int request_id,
+ int64 granted_quota) {
+ WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup(
+ request_id);
+ DCHECK(callbacks);
+ callbacks->didGrantStorageQuota(granted_quota);
+ pending_quota_callbacks_.Remove(request_id);
+}
+
+void QuotaDispatcher::DidQueryStorageUsageAndQuota(
+ int request_id,
+ int64 current_usage,
+ int64 current_quota) {
+ WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup(
+ request_id);
+ DCHECK(callbacks);
+ callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota);
+ pending_quota_callbacks_.Remove(request_id);
+}
+
+void QuotaDispatcher::DidFail(
+ int request_id,
+ WebStorageQuotaError error) {
+ WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup(
+ request_id);
+ DCHECK(callbacks);
+ callbacks->didFail(error);
+ pending_quota_callbacks_.Remove(request_id);
+}
diff --git a/content/common/quota_dispatcher.h b/content/common/quota_dispatcher.h
new file mode 100644
index 0000000..d283b28
--- /dev/null
+++ b/content/common/quota_dispatcher.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2011 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 CONTENT_COMMON_QUOTA_DISPATCHER_H_
+#define CONTENT_COMMON_QUOTA_DISPATCHER_H_
+
+#include <map>
+#include <set>
+
+#include "base/basictypes.h"
+#include "base/id_map.h"
+#include "ipc/ipc_channel.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"
+
+class GURL;
+
+namespace IPC {
+class Message;
+}
+
+namespace WebKit {
+class WebStorageQuotaCallbacks;
+}
+
+// Dispatches and sends quota related messages sent to/from a child
+// process from/to the main browser process. There is one instance
+// per child process. Messages are dispatched on the main child thread.
+class QuotaDispatcher : public IPC::Channel::Listener {
+ public:
+ QuotaDispatcher();
+ ~QuotaDispatcher();
+
+ // IPC::Channel::Listener implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ void QueryStorageUsageAndQuota(const GURL& gurl,
+ WebKit::WebStorageQuotaType type,
+ WebKit::WebStorageQuotaCallbacks* callbacks);
+ void RequestStorageQuota(const GURL& gurl,
+ WebKit::WebStorageQuotaType type,
+ unsigned long long requested_size,
+ WebKit::WebStorageQuotaCallbacks* callbacks);
+
+ private:
+ // Message handlers.
+ void DidQueryStorageUsageAndQuota(int request_id,
+ int64 current_usage,
+ int64 current_quota);
+ void DidGrantStorageQuota(int request_id,
+ int64 granted_quota);
+ void DidFail(int request_id,
+ WebKit::WebStorageQuotaError error);
+
+ IDMap<WebKit::WebStorageQuotaCallbacks> pending_quota_callbacks_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuotaDispatcher);
+};
+
+#endif // CONTENT_COMMON_QUOTA_DISPATCHER_H_
diff --git a/content/common/quota_dispatcher_dummy.cc b/content/common/quota_dispatcher_dummy.cc
new file mode 100644
index 0000000..7eec28b
--- /dev/null
+++ b/content/common/quota_dispatcher_dummy.cc
@@ -0,0 +1,21 @@
+// Copyright (c) 2011 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 "content/common/quota_dispatcher.h"
+
+#include "base/compiler_specific.h"
+
+// QuotaDispatcher -------------------------------------------------------------
+
+QuotaDispatcher::QuotaDispatcher() {
+}
+
+QuotaDispatcher::~QuotaDispatcher() {
+}
+
+// QuotaDispatcher implementation ----------------------------------------------
+
+bool QuotaDispatcher::OnMessageReceived(const IPC::Message& message) {
+ return false;
+}
diff --git a/content/common/quota_messages.h b/content/common/quota_messages.h
new file mode 100644
index 0000000..205c4a8
--- /dev/null
+++ b/content/common/quota_messages.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2011 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.
+
+// Multiply-included message file, hence no include guard.
+
+#include "base/basictypes.h"
+#include "ipc/ipc_message_macros.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"
+
+#define IPC_MESSAGE_START QuotaMsgStart
+
+IPC_ENUM_TRAITS(WebKit::WebStorageQuotaType)
+IPC_ENUM_TRAITS(WebKit::WebStorageQuotaError)
+
+// Quota messages sent from the browser to the child process.
+
+IPC_MESSAGE_CONTROL2(QuotaMsg_DidGrantStorageQuota,
+ int /* request_id */,
+ int64 /* granted_quota */)
+
+IPC_MESSAGE_CONTROL3(QuotaMsg_DidQueryStorageUsageAndQuota,
+ int /* request_id */,
+ int64 /* current_usage */,
+ int64 /* current_quota */)
+
+IPC_MESSAGE_CONTROL2(QuotaMsg_DidFail,
+ int /* request_id */,
+ WebKit::WebStorageQuotaError /* error */)
+
+// Quota messages sent from the child process to the browser.
+
+IPC_MESSAGE_CONTROL3(QuotaHostMsg_QueryStorageUsageAndQuota,
+ int /* request_id */,
+ GURL /* origin_url */,
+ WebKit::WebStorageQuotaType /* type */)
+
+IPC_MESSAGE_CONTROL4(QuotaHostMsg_RequestStorageQuota,
+ int /* request_id */,
+ GURL /* origin_url */,
+ WebKit::WebStorageQuotaType /* type */,
+ int64 /* requested_size */)
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 7a90b4e..923362c 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -223,6 +223,8 @@
'browser/renderer_host/p2p/socket_host_udp.h',
'browser/renderer_host/p2p/socket_dispatcher_host.cc',
'browser/renderer_host/p2p/socket_dispatcher_host.h',
+ 'browser/renderer_host/quota_dispatcher_host.cc',
+ 'browser/renderer_host/quota_dispatcher_host.h',
'browser/renderer_host/redirect_to_file_resource_handler.cc',
'browser/renderer_host/redirect_to_file_resource_handler.h',
'browser/renderer_host/render_message_filter.cc',
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 22ca40e..f0e16a1 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -170,6 +170,9 @@
'common/process_watcher_win.cc',
'common/property_bag.cc',
'common/property_bag.h',
+ 'common/quota_messages.h',
+ 'common/quota_dispatcher.cc',
+ 'common/quota_dispatcher.h',
'common/renderer_preferences.cc',
'common/renderer_preferences.h',
'common/resource_dispatcher.cc',
diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc
index 83d6756..08cd94c 100644
--- a/content/renderer/render_view.cc
+++ b/content/renderer/render_view.cc
@@ -54,6 +54,7 @@
#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
#include "content/common/notification_service.h"
#include "content/common/pepper_messages.h"
+#include "content/common/quota_dispatcher.h"
#include "content/common/renderer_preferences.h"
#include "content/common/view_messages.h"
#include "content/renderer/audio_message_filter.h"
@@ -121,6 +122,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
@@ -229,6 +231,9 @@ using WebKit::WebSettings;
using WebKit::WebSharedWorker;
using WebKit::WebSize;
using WebKit::WebStorageNamespace;
+using WebKit::WebStorageQuotaCallbacks;
+using WebKit::WebStorageQuotaError;
+using WebKit::WebStorageQuotaType;
using WebKit::WebString;
using WebKit::WebTextAffinity;
using WebKit::WebTextDirection;
@@ -3265,6 +3270,37 @@ void RenderView::openFileSystem(
size, create, new WebFileSystemCallbackDispatcher(callbacks));
}
+void RenderView::queryStorageUsageAndQuota(
+ WebFrame* frame,
+ WebStorageQuotaType type,
+ WebStorageQuotaCallbacks* callbacks) {
+ DCHECK(frame);
+ WebSecurityOrigin origin = frame->securityOrigin();
+ if (origin.isEmpty()) {
+ // Uninitialized document?
+ callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
+ return;
+ }
+ ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
+ GURL(origin.toString()), type, callbacks);
+}
+
+void RenderView::requestStorageQuota(
+ WebFrame* frame,
+ WebStorageQuotaType type,
+ unsigned long long requested_size,
+ WebStorageQuotaCallbacks* callbacks) {
+ DCHECK(frame);
+ WebSecurityOrigin origin = frame->securityOrigin();
+ if (origin.isEmpty()) {
+ // Uninitialized document?
+ callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
+ return;
+ }
+ ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
+ GURL(origin.toString()), type, requested_size, callbacks);
+}
+
// webkit_glue::WebPluginPageDelegate -----------------------------------------
webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
diff --git a/content/renderer/render_view.h b/content/renderer/render_view.h
index 747ac35..25cb05a 100644
--- a/content/renderer/render_view.h
+++ b/content/renderer/render_view.h
@@ -577,6 +577,17 @@ class RenderView : public RenderWidget,
bool create,
WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void queryStorageUsageAndQuota(
+ WebKit::WebFrame* frame,
+ WebKit::WebStorageQuotaType type,
+ WebKit::WebStorageQuotaCallbacks* callbacks);
+
+ virtual void requestStorageQuota(
+ WebKit::WebFrame* frame,
+ WebKit::WebStorageQuotaType type,
+ unsigned long long requested_size,
+ WebKit::WebStorageQuotaCallbacks* callbacks);
+
// WebKit::WebPageSerializerClient implementation ----------------------------
virtual void didSerializeDataForFrame(const WebKit::WebURL& frame_url,