Commit 93caf451 authored by horo@chromium.org's avatar horo@chromium.org

Move the worker script loading code to the worker process (phase:2/5)

- Add content_security_policy and security_policy_type to ViewHostMsg_CreateWorker_Params and WorkerProcessMsg_CreateWorker_Params.
 It is needed because WorkerMsg_StartWorkerContext will be removed.
- Implement workerScriptLoaded, workerScriptLoadFailed and selectAppChacheID.
- Queue WebMessagePortChannel in WebSharedWorkerStub::OnConnect
  When we will add the script loading code in WebSharedWorkerImpl, the worker process can't respond to the connection request which is sent soon after the SharedWorker is created.
  So we have to create WebMessagePortChannelImpl in WebSharedWorkerStub::OnConnect.

This is step 2 of moving the worker script loading code from the renderer process to the worker process.
See: http://crbug.com/329786

BUG=329786

Review URL: https://codereview.chromium.org/115713004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243864 0039d316-1c4b-4281-b951-d872f2087c98
parent 11798005
......@@ -45,6 +45,7 @@ include_rules = [
"+third_party/WebKit/public/web/WebAXEnums.h",
"+third_party/WebKit/public/web/WebCompositionUnderline.h",
"+third_party/WebKit/public/web/WebConsoleMessage.h",
"+third_party/WebKit/public/web/WebContentSecurityPolicy.h",
"+third_party/WebKit/public/web/WebDragOperation.h",
"+third_party/WebKit/public/web/WebDragStatus.h",
"+third_party/WebKit/public/web/WebFindOptions.h",
......
......@@ -282,6 +282,8 @@ void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) {
WorkerProcessMsg_CreateWorker_Params params;
params.url = instance.url();
params.name = instance.name();
params.content_security_policy = instance.content_security_policy();
params.security_policy_type = instance.security_policy_type();
params.route_id = instance.worker_route_id();
params.creator_process_id = instance.parent_process_id();
params.shared_worker_appcache_id = instance.main_resource_appcache_id();
......@@ -577,6 +579,8 @@ net::URLRequestContext* WorkerProcessHost::GetRequestContext(
WorkerProcessHost::WorkerInstance::WorkerInstance(
const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
int worker_route_id,
int parent_process_id,
int64 main_resource_appcache_id,
......@@ -585,6 +589,8 @@ WorkerProcessHost::WorkerInstance::WorkerInstance(
: url_(url),
closed_(false),
name_(name),
content_security_policy_(content_security_policy),
security_policy_type_(security_policy_type),
worker_route_id_(worker_route_id),
parent_process_id_(parent_process_id),
main_resource_appcache_id_(main_resource_appcache_id),
......
......@@ -19,6 +19,7 @@
#include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/common/process_type.h"
#include "ipc/ipc_sender.h"
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "url/gurl.h"
#include "webkit/common/resource_type.h"
......@@ -58,6 +59,8 @@ class WorkerProcessHost : public BrowserChildProcessHostDelegate,
public:
WorkerInstance(const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
int worker_route_id,
int parent_process_id,
int64 main_resource_appcache_id,
......@@ -108,6 +111,12 @@ class WorkerProcessHost : public BrowserChildProcessHostDelegate,
void set_closed(bool closed) { closed_ = closed; }
const GURL& url() const { return url_; }
const base::string16 name() const { return name_; }
const base::string16 content_security_policy() const {
return content_security_policy_;
}
blink::WebContentSecurityPolicyType security_policy_type() const {
return security_policy_type_;
}
int worker_route_id() const { return worker_route_id_; }
int parent_process_id() const { return parent_process_id_; }
int64 main_resource_appcache_id() const {
......@@ -128,6 +137,8 @@ class WorkerProcessHost : public BrowserChildProcessHostDelegate,
GURL url_;
bool closed_;
base::string16 name_;
base::string16 content_security_policy_;
blink::WebContentSecurityPolicyType security_policy_type_;
int worker_route_id_;
int parent_process_id_;
int64 main_resource_appcache_id_;
......
......@@ -312,6 +312,8 @@ void WorkerServiceImpl::CreateWorker(
WorkerProcessHost::WorkerInstance instance(
params.url,
params.name,
params.content_security_policy,
params.security_policy_type,
next_worker_route_id(),
0,
params.script_resource_appcache_id,
......
......@@ -10,6 +10,7 @@
#include "content/common/content_export.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/latency_info.h"
#include "webkit/common/resource_type.h"
......@@ -18,6 +19,7 @@
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
IPC_ENUM_TRAITS(ResourceType::Type)
IPC_ENUM_TRAITS(blink::WebContentSecurityPolicyType)
IPC_ENUM_TRAITS(blink::WebInputEvent::Type)
IPC_ENUM_TRAITS(ui::LatencyComponentType)
......
......@@ -388,6 +388,12 @@ IPC_STRUCT_BEGIN(ViewHostMsg_CreateWorker_Params)
// Name for a SharedWorker, otherwise empty string.
IPC_STRUCT_MEMBER(base::string16, name)
// Security policy used in the worker.
IPC_STRUCT_MEMBER(base::string16, content_security_policy)
// Security policy type used in the worker.
IPC_STRUCT_MEMBER(blink::WebContentSecurityPolicyType, security_policy_type)
// The ID of the parent document (unique within parent renderer).
IPC_STRUCT_MEMBER(unsigned long long, document_id)
......
......@@ -14,9 +14,9 @@
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "content/common/content_export.h"
#include "content/common/content_param_traits.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_utils.h"
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "url/gurl.h"
#undef IPC_MESSAGE_EXPORT
......@@ -40,13 +40,13 @@ IPC_STRUCT_END()
IPC_STRUCT_BEGIN(WorkerProcessMsg_CreateWorker_Params)
IPC_STRUCT_MEMBER(GURL, url)
IPC_STRUCT_MEMBER(base::string16, name)
IPC_STRUCT_MEMBER(base::string16, content_security_policy)
IPC_STRUCT_MEMBER(blink::WebContentSecurityPolicyType, security_policy_type)
IPC_STRUCT_MEMBER(int, route_id)
IPC_STRUCT_MEMBER(int, creator_process_id)
IPC_STRUCT_MEMBER(int64, shared_worker_appcache_id)
IPC_STRUCT_END()
IPC_ENUM_TRAITS(blink::WebContentSecurityPolicyType)
//-----------------------------------------------------------------------------
// WorkerProcess messages
// These are messages sent from the browser to the worker process.
......
......@@ -26,13 +26,17 @@ blink::WebSharedWorkerConnector*
SharedWorkerRepository::createSharedWorkerConnector(
const blink::WebURL& url,
const blink::WebString& name,
DocumentID document_id) {
DocumentID document_id,
const blink::WebString& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type) {
int route_id = MSG_ROUTING_NONE;
bool exists = false;
bool url_mismatch = false;
ViewHostMsg_CreateWorker_Params params;
params.url = url;
params.name = name;
params.content_security_policy = content_security_policy;
params.security_policy_type = security_policy_type;
params.document_id = document_id;
params.render_frame_route_id = render_frame()->GetRoutingID();
params.route_id = MSG_ROUTING_NONE;
......
......@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "content/public/renderer/render_frame_observer.h"
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebSharedWorkerRepositoryClient.h"
namespace content {
......@@ -28,7 +29,9 @@ class SharedWorkerRepository : public RenderFrameObserver,
virtual blink::WebSharedWorkerConnector* createSharedWorkerConnector(
const blink::WebURL& url,
const blink::WebString& name,
DocumentID document_id) OVERRIDE;
DocumentID document_id,
const blink::WebString& content_security_policy,
blink::WebContentSecurityPolicyType) OVERRIDE;
virtual void documentDetached(DocumentID document_id) OVERRIDE;
private:
......
......@@ -62,6 +62,8 @@ void WebSharedWorkerProxy::CreateWorkerContext(
ViewHostMsg_CreateWorker_Params params;
params.url = script_url;
params.name = name;
params.content_security_policy = content_security_policy;
params.security_policy_type = policy_type;
params.document_id = document_id_;
params.render_frame_route_id = render_frame_route_id_;
params.route_id = pending_route_id;
......
......@@ -19,14 +19,18 @@
namespace content {
WebSharedWorkerStub::WebSharedWorkerStub(
const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
int route_id,
const WorkerAppCacheInitInfo& appcache_init_info)
: route_id_(route_id),
appcache_init_info_(appcache_init_info),
client_(route_id, this),
name_(name),
started_(false) {
started_(false),
worker_script_loaded_(false) {
WorkerThread* worker_thread = WorkerThread::current();
DCHECK(worker_thread);
......@@ -94,30 +98,21 @@ void WebSharedWorkerStub::OnStartWorkerContext(
content_security_policy, policy_type, 0);
started_ = true;
url_ = url;
// Process any pending connections.
for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin();
iter != pending_connects_.end();
++iter) {
OnConnect(iter->first, iter->second);
}
pending_connects_.clear();
}
void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) {
if (started_) {
blink::WebMessagePortChannel* channel =
new WebMessagePortChannelImpl(routing_id,
sent_message_port_id,
base::MessageLoopProxy::current().get());
blink::WebMessagePortChannel* channel =
new WebMessagePortChannelImpl(routing_id,
sent_message_port_id,
base::MessageLoopProxy::current().get());
if (started_ && worker_script_loaded_) {
impl_->connect(channel);
} else {
// If two documents try to load a SharedWorker at the same time, the
// WorkerMsg_Connect for one of the documents can come in before the
// worker is started. Just queue up the connect and deliver it once the
// worker starts.
PendingConnectInfo pending_connect(sent_message_port_id, routing_id);
pending_connects_.push_back(pending_connect);
pending_channels_.push_back(channel);
}
}
......@@ -129,4 +124,19 @@ void WebSharedWorkerStub::OnTerminateWorkerContext() {
started_ = false;
}
void WebSharedWorkerStub::WorkerScriptLoaded() {
worker_script_loaded_ = true;
// Process any pending connections.
for (PendingChannelList::const_iterator iter = pending_channels_.begin();
iter != pending_channels_.end();
++iter) {
impl_->connect(*iter);
}
pending_channels_.clear();
}
void WebSharedWorkerStub::WorkerScriptLoadFailed() {
// FIXME(horo): Implement this.
}
} // namespace content
......@@ -14,18 +14,24 @@
#include "url/gurl.h"
namespace blink {
class WebMessagePortChannel;
class WebSharedWorker;
}
namespace content {
class SharedWorkerDevToolsAgent;
class WebMessagePortChannelImpl;
// This class creates a WebSharedWorker, and translates incoming IPCs to the
// appropriate WebSharedWorker APIs.
class WebSharedWorkerStub : public IPC::Listener {
public:
WebSharedWorkerStub(const base::string16& name, int route_id,
WebSharedWorkerStub(const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
int route_id,
const WorkerAppCacheInitInfo& appcache_init_info);
// IPC::Listener implementation.
......@@ -35,6 +41,9 @@ class WebSharedWorkerStub : public IPC::Listener {
// Invoked when the WebSharedWorkerClientProxy is shutting down.
void Shutdown();
void WorkerScriptLoaded();
void WorkerScriptLoadFailed();
// Called after terminating the worker context to make sure that the worker
// actually terminates (is not stuck in an infinite loop).
void EnsureWorkerContextTerminates();
......@@ -74,11 +83,11 @@ class WebSharedWorkerStub : public IPC::Listener {
base::string16 name_;
bool started_;
GURL url_;
bool worker_script_loaded_;
scoped_ptr<SharedWorkerDevToolsAgent> worker_devtools_agent_;
typedef std::pair<int, int> PendingConnectInfo;
typedef std::vector<PendingConnectInfo> PendingConnectInfoList;
PendingConnectInfoList pending_connects_;
typedef std::vector<blink::WebMessagePortChannel*> PendingChannelList;
PendingChannelList pending_channels_;
DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerStub);
};
......
......@@ -42,7 +42,8 @@ WebSharedWorkerClientProxy::WebSharedWorkerClientProxy(
appcache_host_id_(0),
stub_(stub),
weak_factory_(this),
devtools_agent_(NULL) {
devtools_agent_(NULL),
app_cache_host_(NULL) {
}
WebSharedWorkerClientProxy::~WebSharedWorkerClientProxy() {
......@@ -59,6 +60,26 @@ void WebSharedWorkerClientProxy::workerContextDestroyed() {
stub_->Shutdown();
}
void WebSharedWorkerClientProxy::workerScriptLoaded() {
if (stub_)
stub_->WorkerScriptLoaded();
}
void WebSharedWorkerClientProxy::workerScriptLoadFailed() {
if (stub_)
stub_->WorkerScriptLoadFailed();
}
void WebSharedWorkerClientProxy::selectAppCacheID(long long app_cache_id) {
if (app_cache_host_) {
// app_cache_host_ could become stale as it's owned by blink's
// DocumentLoader. This method is assumed to be called while it's valid.
app_cache_host_->backend()->SelectCacheForSharedWorker(
app_cache_host_->host_id(),
app_cache_id);
}
}
blink::WebNotificationPresenter*
WebSharedWorkerClientProxy::notificationPresenter() {
// TODO(johnnyg): Notifications are not yet hooked up to workers.
......@@ -69,13 +90,14 @@ WebSharedWorkerClientProxy::notificationPresenter() {
WebApplicationCacheHost* WebSharedWorkerClientProxy::createApplicationCacheHost(
blink::WebApplicationCacheHostClient* client) {
WorkerWebApplicationCacheHostImpl* host =
DCHECK(!app_cache_host_);
app_cache_host_ =
new WorkerWebApplicationCacheHostImpl(stub_->appcache_init_info(),
client);
// Remember the id of the instance we create so we have access to that
// value when creating nested dedicated workers in createWorker.
appcache_host_id_ = host->host_id();
return host;
appcache_host_id_ = app_cache_host_->host_id();
return app_cache_host_;
}
blink::WebWorkerPermissionClientProxy*
......
......@@ -21,6 +21,7 @@ namespace content {
class SharedWorkerDevToolsAgent;
class WebSharedWorkerStub;
class WorkerWebApplicationCacheHostImpl;
// This class receives IPCs from the renderer and calls the WebCore::Worker
// implementation (after the data types have been converted by glue code). It
......@@ -35,6 +36,9 @@ class WebSharedWorkerClientProxy : public blink::WebSharedWorkerClient {
// WebSharedWorkerClient implementation.
virtual void workerContextClosed();
virtual void workerContextDestroyed();
virtual void workerScriptLoaded();
virtual void workerScriptLoadFailed();
virtual void selectAppCacheID(long long app_cache_id);
virtual blink::WebNotificationPresenter* notificationPresenter();
......@@ -61,6 +65,7 @@ class WebSharedWorkerClientProxy : public blink::WebSharedWorkerClient {
WebSharedWorkerStub* stub_;
base::WeakPtrFactory<WebSharedWorkerClientProxy> weak_factory_;
SharedWorkerDevToolsAgent* devtools_agent_;
WorkerWebApplicationCacheHostImpl* app_cache_host_;
DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerClientProxy);
};
......
......@@ -121,7 +121,13 @@ void WorkerThread::OnCreateWorker(
params.shared_worker_appcache_id);
// WebSharedWorkerStub own themselves.
new WebSharedWorkerStub(params.name, params.route_id, appcache_init_info);
new WebSharedWorkerStub(
params.url,
params.name,
params.content_security_policy,
params.security_policy_type,
params.route_id,
appcache_init_info);
}
// The browser process is likely dead. Terminate all workers.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment