summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 01:30:08 +0000
committerericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 01:30:08 +0000
commit2b437e23748d7444f1698ae9242fabf0bc0730a7 (patch)
tree40a740c3f0a8032e30299d8724e54d9a269291af /chrome/browser
parente0976a77dcc9be00485086b5b0e112fe6d159ff2 (diff)
downloadchromium_src-2b437e23748d7444f1698ae9242fabf0bc0730a7.zip
chromium_src-2b437e23748d7444f1698ae9242fabf0bc0730a7.tar.gz
chromium_src-2b437e23748d7444f1698ae9242fabf0bc0730a7.tar.bz2
Changes to the Browser to support Database access from Workers.
This changelist should have no visible effect until the V8 bindings for the Database get added to the Worker context in WebKit. BUG=none TEST=webkit layout tests Review URL: http://codereview.chromium.org/1387001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/renderer_host/database_dispatcher_host.cc28
-rw-r--r--chrome/browser/renderer_host/database_dispatcher_host.h14
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc9
-rw-r--r--chrome/browser/worker_host/worker_process_host.cc36
-rw-r--r--chrome/browser/worker_host/worker_process_host.h29
-rw-r--r--chrome/browser/worker_host/worker_service.cc35
-rw-r--r--chrome/browser/worker_host/worker_service.h15
7 files changed, 123 insertions, 43 deletions
diff --git a/chrome/browser/renderer_host/database_dispatcher_host.cc b/chrome/browser/renderer_host/database_dispatcher_host.cc
index c4ad80d..f649dfb 100644
--- a/chrome/browser/renderer_host/database_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/database_dispatcher_host.cc
@@ -18,10 +18,10 @@
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/host_content_settings_map.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/database_permission_request.h"
-#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/render_messages.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
@@ -38,14 +38,16 @@ const int kDelayDeleteRetryMs = 100;
DatabaseDispatcherHost::DatabaseDispatcherHost(
DatabaseTracker* db_tracker,
- ResourceMessageFilter* resource_message_filter)
+ IPC::Message::Sender* sender,
+ HostContentSettingsMap *host_content_settings_map)
: db_tracker_(db_tracker),
- resource_message_filter_(resource_message_filter),
+ message_sender_(sender),
process_handle_(0),
observer_added_(false),
- shutdown_(false) {
+ shutdown_(false),
+ host_content_settings_map_(host_content_settings_map) {
DCHECK(db_tracker_);
- DCHECK(resource_message_filter_);
+ DCHECK(message_sender_);
}
void DatabaseDispatcherHost::Init(base::ProcessHandle process_handle) {
@@ -58,7 +60,7 @@ void DatabaseDispatcherHost::Init(base::ProcessHandle process_handle) {
void DatabaseDispatcherHost::Shutdown() {
shutdown_ = true;
- resource_message_filter_ = NULL;
+ message_sender_ = NULL;
if (observer_added_) {
ChromeThread::PostTask(
ChromeThread::FILE, FROM_HERE,
@@ -119,8 +121,8 @@ void DatabaseDispatcherHost::Send(IPC::Message* message) {
return;
}
- if (!shutdown_ && resource_message_filter_)
- resource_message_filter_->Send(message);
+ if (!shutdown_ && message_sender_)
+ message_sender_->Send(message);
else
delete message;
}
@@ -356,11 +358,9 @@ void DatabaseDispatcherHost::OnAllowDatabase(const std::string& origin_url,
unsigned long estimated_size,
IPC::Message* reply_msg) {
GURL url = GURL(origin_url);
- HostContentSettingsMap* host_content_settings_map = resource_message_filter_->
- GetRequestContextForURL(url)->host_content_settings_map();
- ContentSetting content_setting = host_content_settings_map->GetContentSetting(
- url, CONTENT_SETTINGS_TYPE_COOKIES);
-
+ ContentSetting content_setting =
+ host_content_settings_map_->GetContentSetting(
+ url, CONTENT_SETTINGS_TYPE_COOKIES);
if (content_setting == CONTENT_SETTING_ASK) {
// Create a task for each possible outcome.
scoped_ptr<Task> on_allow(NewRunnableMethod(
@@ -373,7 +373,7 @@ void DatabaseDispatcherHost::OnAllowDatabase(const std::string& origin_url,
scoped_refptr<DatabasePermissionRequest> request(
new DatabasePermissionRequest(url, name, display_name, estimated_size,
on_allow.release(), on_block.release(),
- host_content_settings_map));
+ host_content_settings_map_));
request->RequestPermission();
// Tell the renderer that it needs to run a nested message loop.
diff --git a/chrome/browser/renderer_host/database_dispatcher_host.h b/chrome/browser/renderer_host/database_dispatcher_host.h
index 251bc5b..748e538 100644
--- a/chrome/browser/renderer_host/database_dispatcher_host.h
+++ b/chrome/browser/renderer_host/database_dispatcher_host.h
@@ -24,7 +24,8 @@ class DatabaseDispatcherHost
public webkit_database::DatabaseTracker::Observer {
public:
DatabaseDispatcherHost(webkit_database::DatabaseTracker* db_tracker,
- ResourceMessageFilter* resource_message_filter);
+ IPC::Message::Sender* sender,
+ HostContentSettingsMap *host_content_settings_map);
void Init(base::ProcessHandle process_handle);
void Shutdown();
@@ -65,6 +66,10 @@ class DatabaseDispatcherHost
virtual void OnDatabaseScheduledForDeletion(const string16& origin_identifier,
const string16& database_name);
+ webkit_database::DatabaseTracker* database_tracker() const {
+ return db_tracker_.get();
+ }
+
void Send(IPC::Message* message);
private:
@@ -105,8 +110,8 @@ class DatabaseDispatcherHost
// The database tracker for the current profile.
scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
- // The resource message filter that owns us.
- ResourceMessageFilter* resource_message_filter_;
+ // The sender to be used for sending out IPC messages.
+ IPC::Message::Sender* message_sender_;
// The handle of this process.
base::ProcessHandle process_handle_;
@@ -122,6 +127,9 @@ class DatabaseDispatcherHost
// Keeps track of all DB connections opened by this renderer
webkit_database::DatabaseConnections database_connections_;
+
+ // Used to look up permissions at database creation time.
+ scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
};
#endif // CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index a095e3d..23733f8 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -302,12 +302,13 @@ ResourceMessageFilter::ResourceMessageFilter(
render_widget_helper_(render_widget_helper),
audio_renderer_host_(audio_renderer_host),
appcache_dispatcher_host_(
- new AppCacheDispatcherHost(profile->GetRequestContext())),
+ new AppCacheDispatcherHost(profile->GetRequestContext())),
ALLOW_THIS_IN_INITIALIZER_LIST(dom_storage_dispatcher_host_(
new DOMStorageDispatcherHost(this, profile->GetWebKitContext(),
resource_dispatcher_host->webkit_thread()))),
ALLOW_THIS_IN_INITIALIZER_LIST(db_dispatcher_host_(
- new DatabaseDispatcherHost(profile->GetDatabaseTracker(), this))),
+ new DatabaseDispatcherHost(profile->GetDatabaseTracker(), this,
+ profile->GetHostContentSettingsMap()))),
notification_prefs_(
profile->GetDesktopNotificationService()->prefs_cache()),
host_zoom_map_(profile->GetHostZoomMap()),
@@ -800,7 +801,9 @@ void ResourceMessageFilter::OnCreateWorker(
params.route_id : render_widget_helper_->GetNextRoutingID();
WorkerService::GetInstance()->CreateWorker(
params.url, params.is_shared, off_the_record(), params.name,
- params.document_id, id(), params.render_view_route_id, this, *route_id);
+ params.document_id, id(), params.render_view_route_id, this, *route_id,
+ db_dispatcher_host_->database_tracker(),
+ GetRequestContextForURL(params.url)->host_content_settings_map());
}
void ResourceMessageFilter::OnLookupSharedWorker(
diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc
index ba01a2d..38dd8e3 100644
--- a/chrome/browser/worker_host/worker_process_host.cc
+++ b/chrome/browser/worker_host/worker_process_host.cc
@@ -14,6 +14,7 @@
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/child_process_security_policy.h"
+#include "chrome/browser/renderer_host/database_dispatcher_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
@@ -53,13 +54,21 @@ class WorkerCrashTask : public Task {
WorkerProcessHost::WorkerProcessHost(
- ResourceDispatcherHost* resource_dispatcher_host)
- : ChildProcessHost(WORKER_PROCESS, resource_dispatcher_host) {
+ ResourceDispatcherHost* resource_dispatcher_host,
+ webkit_database::DatabaseTracker *db_tracker,
+ HostContentSettingsMap *host_content_settings_map)
+ : ChildProcessHost(WORKER_PROCESS, resource_dispatcher_host),
+ host_content_settings_map_(host_content_settings_map) {
next_route_id_callback_.reset(NewCallbackWithReturnValue(
WorkerService::GetInstance(), &WorkerService::next_worker_route_id));
+ db_dispatcher_host_ =
+ new DatabaseDispatcherHost(db_tracker, this, host_content_settings_map);
}
WorkerProcessHost::~WorkerProcessHost() {
+ // Shut down the database dispatcher host.
+ db_dispatcher_host_->Shutdown();
+
// Let interested observers know we are being deleted.
NotificationService::current()->Notify(
NotificationType::WORKER_PROCESS_HOST_SHUTDOWN,
@@ -108,6 +117,11 @@ bool WorkerProcessHost::Init() {
}
if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableDatabases)) {
+ cmd_line->AppendSwitch(switches::kDisableDatabases);
+ }
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLogging)) {
cmd_line->AppendSwitch(switches::kEnableLogging);
}
@@ -124,6 +138,7 @@ bool WorkerProcessHost::Init() {
switches::kDisableWebSockets)) {
cmd_line->AppendSwitch(switches::kDisableWebSockets);
}
+
#if defined(OS_WIN)
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableDesktopNotifications)) {
@@ -233,8 +248,9 @@ void WorkerProcessHost::OnWorkerContextClosed(int worker_route_id) {
void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) {
bool msg_is_ok = true;
- bool handled = MessagePortDispatcher::GetInstance()->OnMessageReceived(
- message, this, next_route_id_callback_.get(), &msg_is_ok);
+ bool handled = db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ MessagePortDispatcher::GetInstance()->OnMessageReceived(
+ message, this, next_route_id_callback_.get(), &msg_is_ok);
if (!handled) {
handled = true;
@@ -279,6 +295,10 @@ void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) {
}
}
+void WorkerProcessHost::OnProcessLaunched() {
+ db_dispatcher_host_->Init(handle());
+}
+
CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback(
IPC::Message::Sender* sender) {
// We don't keep callbacks for senders associated with workers, so figure out
@@ -435,7 +455,8 @@ void WorkerProcessHost::OnCreateWorker(
WorkerService::GetInstance()->CreateWorker(
params.url, params.is_shared, instances_.front().off_the_record(),
params.name, params.document_id, first_parent->renderer_id(),
- first_parent->render_view_route_id(), this, *route_id);
+ first_parent->render_view_route_id(), this, *route_id,
+ database_tracker(), host_content_settings_map_);
}
void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) {
@@ -466,6 +487,11 @@ void WorkerProcessHost::DocumentDetached(IPC::Message::Sender* parent,
}
}
+webkit_database::DatabaseTracker*
+ WorkerProcessHost::database_tracker() const {
+ return db_dispatcher_host_->database_tracker();
+}
+
WorkerProcessHost::WorkerInstance::WorkerInstance(const GURL& url,
bool shared,
bool off_the_record,
diff --git a/chrome/browser/worker_host/worker_process_host.h b/chrome/browser/worker_host/worker_process_host.h
index ea585dd..36d4312 100644
--- a/chrome/browser/worker_host/worker_process_host.h
+++ b/chrome/browser/worker_host/worker_process_host.h
@@ -9,13 +9,25 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/ref_counted.h"
#include "chrome/browser/child_process_host.h"
+#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/worker_host/worker_document_set.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
+class DatabaseDispatcherHost;
+namespace webkit_database {
+class DatabaseTracker;
+} // namespace webkit_database
+
struct ViewHostMsg_CreateWorker_Params;
+// The WorkerProcessHost is the interface that represents the browser side of
+// the browser <-> worker communication channel. There will be one
+// WorkerProcessHost per worker process. Currently each worker runs in its own
+// process, but that may change. However, we do assume [by storing a
+// HostContentSettingsMap] that a WorkerProcessHost serves a single Profile.
class WorkerProcessHost : public ChildProcessHost {
public:
@@ -82,7 +94,9 @@ class WorkerProcessHost : public ChildProcessHost {
scoped_refptr<WorkerDocumentSet> worker_document_set_;
};
- explicit WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host);
+ WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host,
+ webkit_database::DatabaseTracker *db_tracker,
+ HostContentSettingsMap *host_content_settings_map);
~WorkerProcessHost();
// Starts the process. Returns true iff it succeeded.
@@ -102,6 +116,12 @@ class WorkerProcessHost : public ChildProcessHost {
void DocumentDetached(IPC::Message::Sender* sender,
unsigned long long document_id);
+ webkit_database::DatabaseTracker* database_tracker() const;
+
+ HostContentSettingsMap *GetHostContentSettingsMap() const {
+ return host_content_settings_map_;
+ }
+
protected:
friend class WorkerService;
@@ -118,6 +138,9 @@ class WorkerProcessHost : public ChildProcessHost {
// Called when a message arrives from the worker process.
void OnMessageReceived(const IPC::Message& message);
+ // Called when the process has been launched successfully.
+ virtual void OnProcessLaunched();
+
// Called when the app invokes close() from within worker context.
void OnWorkerContextClosed(int worker_route_id);
@@ -150,6 +173,10 @@ class WorkerProcessHost : public ChildProcessHost {
Instances instances_;
+ scoped_refptr<DatabaseDispatcherHost> db_dispatcher_host_;
+
+ scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
+
// A callback to create a routing id for the associated worker process.
scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_;
diff --git a/chrome/browser/worker_host/worker_service.cc b/chrome/browser/worker_host/worker_service.cc
index f021e24..6946427 100644
--- a/chrome/browser/worker_host/worker_service.cc
+++ b/chrome/browser/worker_host/worker_service.cc
@@ -9,6 +9,7 @@
#include "base/sys_info.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
@@ -45,15 +46,18 @@ void WorkerService::Initialize(ResourceDispatcherHost* rdh) {
WorkerService::~WorkerService() {
}
-bool WorkerService::CreateWorker(const GURL &url,
- bool is_shared,
- bool off_the_record,
- const string16& name,
- unsigned long long document_id,
- int renderer_id,
- int render_view_route_id,
- IPC::Message::Sender* sender,
- int sender_route_id) {
+bool WorkerService::CreateWorker(
+ const GURL &url,
+ bool is_shared,
+ bool off_the_record,
+ const string16& name,
+ unsigned long long document_id,
+ int renderer_id,
+ int render_view_route_id,
+ IPC::Message::Sender* sender,
+ int sender_route_id,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map) {
// Generate a unique route id for the browser-worker communication that's
// unique among all worker processes. That way when the worker process sends
// a wrapped IPC message through us, we know which WorkerProcessHost to give
@@ -67,11 +71,14 @@ bool WorkerService::CreateWorker(const GURL &url,
instance.worker_document_set()->Add(
sender, document_id, renderer_id, render_view_route_id);
- return CreateWorkerFromInstance(instance);
+ return CreateWorkerFromInstance(instance, db_tracker,
+ host_content_settings_map);
}
bool WorkerService::CreateWorkerFromInstance(
- WorkerProcessHost::WorkerInstance instance) {
+ WorkerProcessHost::WorkerInstance instance,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map) {
WorkerProcessHost* worker = NULL;
if (CommandLine::ForCurrentProcess()->HasSwitch(
@@ -152,7 +159,8 @@ bool WorkerService::CreateWorkerFromInstance(
}
if (!worker) {
- worker = new WorkerProcessHost(resource_dispatcher_host_);
+ worker = new WorkerProcessHost(resource_dispatcher_host_, db_tracker,
+ host_content_settings_map);
if (!worker->Init()) {
delete worker;
return false;
@@ -440,7 +448,8 @@ void WorkerService::WorkerProcessDestroyed(WorkerProcessHost* process) {
if (CanCreateWorkerProcess(*i)) {
WorkerProcessHost::WorkerInstance instance = *i;
queued_workers_.erase(i);
- CreateWorkerFromInstance(instance);
+ CreateWorkerFromInstance(instance, process->database_tracker(),
+ process->GetHostContentSettingsMap());
// CreateWorkerFromInstance can modify the queued_workers_ list when it
// coalesces queued instances after starting a shared worker, so we
diff --git a/chrome/browser/worker_host/worker_service.h b/chrome/browser/worker_host/worker_service.h
index 97891b5..c08d139 100644
--- a/chrome/browser/worker_host/worker_service.h
+++ b/chrome/browser/worker_host/worker_service.h
@@ -14,8 +14,10 @@
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message.h"
-class WorkerProcessHost;
+class DatabaseTracker;
+class HostContentSettingsMap;
class ResourceDispatcherHost;
+class WorkerProcessHost;
class WorkerService : public NotificationObserver {
public:
@@ -25,7 +27,7 @@ class WorkerService : public NotificationObserver {
// Initialize the WorkerService. OK to be called multiple times.
void Initialize(ResourceDispatcherHost* rdh);
- // Creates a dedicated worker. Returns true on success.
+ // Creates a worker. Returns true on success.
bool CreateWorker(const GURL &url,
bool is_shared,
bool is_off_the_record,
@@ -34,7 +36,9 @@ class WorkerService : public NotificationObserver {
int renderer_pid,
int render_view_route_id,
IPC::Message::Sender* sender,
- int sender_route_id);
+ int sender_route_id,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map);
// Validates the passed URL and checks for the existence of matching shared
// worker. Returns true if the url was found, and sets the url_mismatch out
@@ -88,7 +92,10 @@ class WorkerService : public NotificationObserver {
~WorkerService();
// Given a WorkerInstance, create an associated worker process.
- bool CreateWorkerFromInstance(WorkerProcessHost::WorkerInstance instance);
+ bool CreateWorkerFromInstance(
+ WorkerProcessHost::WorkerInstance instance,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map);
// Returns a WorkerProcessHost object if one exists for the given domain, or
// NULL if there are no such workers yet.