OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/websharedworker_proxy.h" | 5 #include "content/renderer/websharedworker_proxy.h" |
6 #include "content/common/child_thread.h" | 6 #include "content/common/child_thread.h" |
7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.h" |
8 #include "content/common/webmessageportchannel_impl.h" | 8 #include "content/common/webmessageportchannel_impl.h" |
9 #include "content/common/worker_messages.h" | 9 #include "content/common/worker_messages.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 return; | 38 return; |
39 | 39 |
40 // So the messages from WorkerContext (like WorkerContextDestroyed) do not | 40 // So the messages from WorkerContext (like WorkerContextDestroyed) do not |
41 // come after nobody is listening. Since Worker and WorkerContext can | 41 // come after nobody is listening. Since Worker and WorkerContext can |
42 // terminate independently, already sent messages may still be in the pipe. | 42 // terminate independently, already sent messages may still be in the pipe. |
43 child_thread_->RemoveRoute(route_id_); | 43 child_thread_->RemoveRoute(route_id_); |
44 | 44 |
45 route_id_ = MSG_ROUTING_NONE; | 45 route_id_ = MSG_ROUTING_NONE; |
46 } | 46 } |
47 | 47 |
48 void WebSharedWorkerProxy::CreateWorkerContext(const GURL& script_url, | 48 void WebSharedWorkerProxy::CreateWorkerContext( |
49 bool is_shared, | 49 const GURL& script_url, |
50 const string16& name, | 50 bool is_shared, |
51 const string16& user_agent, | 51 const string16& name, |
52 const string16& source_code, | 52 const string16& user_agent, |
53 int pending_route_id, | 53 const string16& source_code, |
54 int64 script_resource_appcache_id) { | 54 const string16& content_security_policy, |
| 55 WebKit::WebContentSecurityPolicyType policy_type, |
| 56 int pending_route_id, |
| 57 int64 script_resource_appcache_id) { |
55 DCHECK(route_id_ == MSG_ROUTING_NONE); | 58 DCHECK(route_id_ == MSG_ROUTING_NONE); |
56 ViewHostMsg_CreateWorker_Params params; | 59 ViewHostMsg_CreateWorker_Params params; |
57 params.url = script_url; | 60 params.url = script_url; |
58 params.name = name; | 61 params.name = name; |
59 params.document_id = document_id_; | 62 params.document_id = document_id_; |
60 params.render_view_route_id = render_view_route_id_; | 63 params.render_view_route_id = render_view_route_id_; |
61 params.route_id = pending_route_id; | 64 params.route_id = pending_route_id; |
62 params.script_resource_appcache_id = script_resource_appcache_id; | 65 params.script_resource_appcache_id = script_resource_appcache_id; |
63 IPC::Message* create_message = new ViewHostMsg_CreateWorker( | 66 IPC::Message* create_message = new ViewHostMsg_CreateWorker( |
64 params, &route_id_); | 67 params, &route_id_); |
65 child_thread_->Send(create_message); | 68 child_thread_->Send(create_message); |
66 if (route_id_ == MSG_ROUTING_NONE) | 69 if (route_id_ == MSG_ROUTING_NONE) |
67 return; | 70 return; |
68 | 71 |
69 child_thread_->AddRoute(route_id_, this); | 72 child_thread_->AddRoute(route_id_, this); |
70 | 73 |
71 // We make sure that the start message is the first, since postMessage or | 74 // We make sure that the start message is the first, since postMessage or |
72 // connect might have already been called. | 75 // connect might have already been called. |
73 queued_messages_.insert(queued_messages_.begin(), | 76 queued_messages_.insert(queued_messages_.begin(), |
74 new WorkerMsg_StartWorkerContext( | 77 new WorkerMsg_StartWorkerContext( |
75 route_id_, script_url, user_agent, source_code)); | 78 route_id_, script_url, user_agent, source_code, |
| 79 content_security_policy, policy_type)); |
76 } | 80 } |
77 | 81 |
78 bool WebSharedWorkerProxy::IsStarted() { | 82 bool WebSharedWorkerProxy::IsStarted() { |
79 // Worker is started if we have a route ID and there are no queued messages | 83 // Worker is started if we have a route ID and there are no queued messages |
80 // (meaning we've sent the WorkerMsg_StartWorkerContext already). | 84 // (meaning we've sent the WorkerMsg_StartWorkerContext already). |
81 return (route_id_ != MSG_ROUTING_NONE && queued_messages_.empty()); | 85 return (route_id_ != MSG_ROUTING_NONE && queued_messages_.empty()); |
82 } | 86 } |
83 | 87 |
84 bool WebSharedWorkerProxy::Send(IPC::Message* message) { | 88 bool WebSharedWorkerProxy::Send(IPC::Message* message) { |
85 // It's possible that messages will be sent before the worker is created, in | 89 // It's possible that messages will be sent before the worker is created, in |
(...skipping 26 matching lines...) Expand all Loading... |
112 bool WebSharedWorkerProxy::isStarted() { | 116 bool WebSharedWorkerProxy::isStarted() { |
113 return IsStarted(); | 117 return IsStarted(); |
114 } | 118 } |
115 | 119 |
116 void WebSharedWorkerProxy::startWorkerContext( | 120 void WebSharedWorkerProxy::startWorkerContext( |
117 const WebKit::WebURL& script_url, | 121 const WebKit::WebURL& script_url, |
118 const WebKit::WebString& name, | 122 const WebKit::WebString& name, |
119 const WebKit::WebString& user_agent, | 123 const WebKit::WebString& user_agent, |
120 const WebKit::WebString& source_code, | 124 const WebKit::WebString& source_code, |
121 long long script_resource_appcache_id) { | 125 long long script_resource_appcache_id) { |
| 126 CreateWorkerContext( |
| 127 script_url, true, name, user_agent, source_code, string16(), |
| 128 WebKit::WebContentSecurityPolicyTypeReportOnly, pending_route_id_, |
| 129 script_resource_appcache_id); |
| 130 } |
| 131 |
| 132 void WebSharedWorkerProxy::startWorkerContext( |
| 133 const WebKit::WebURL& script_url, |
| 134 const WebKit::WebString& name, |
| 135 const WebKit::WebString& user_agent, |
| 136 const WebKit::WebString& source_code, |
| 137 const WebKit::WebString& content_security_policy, |
| 138 WebKit::WebContentSecurityPolicyType policy_type, |
| 139 long long script_resource_appcache_id) { |
122 DCHECK(!isStarted()); | 140 DCHECK(!isStarted()); |
123 CreateWorkerContext(script_url, true, name, user_agent, source_code, | 141 CreateWorkerContext( |
124 pending_route_id_, script_resource_appcache_id); | 142 script_url, true, name, user_agent, source_code, content_security_policy, |
| 143 policy_type, pending_route_id_, script_resource_appcache_id); |
125 } | 144 } |
126 | 145 |
127 void WebSharedWorkerProxy::terminateWorkerContext() { | 146 void WebSharedWorkerProxy::terminateWorkerContext() { |
128 // This API should only be invoked from worker context. | 147 // This API should only be invoked from worker context. |
129 NOTREACHED(); | 148 NOTREACHED(); |
130 } | 149 } |
131 | 150 |
132 void WebSharedWorkerProxy::clientDestroyed() { | 151 void WebSharedWorkerProxy::clientDestroyed() { |
133 // This API should only be invoked from worker context. | 152 // This API should only be invoked from worker context. |
134 NOTREACHED(); | 153 NOTREACHED(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // The worker is created - now send off the CreateWorkerContext message and | 185 // The worker is created - now send off the CreateWorkerContext message and |
167 // any other queued messages | 186 // any other queued messages |
168 SendQueuedMessages(); | 187 SendQueuedMessages(); |
169 | 188 |
170 // Inform any listener that the pending connect event has been sent | 189 // Inform any listener that the pending connect event has been sent |
171 // (this can result in this object being freed). | 190 // (this can result in this object being freed). |
172 if (connect_listener_) { | 191 if (connect_listener_) { |
173 connect_listener_->connected(); | 192 connect_listener_->connected(); |
174 } | 193 } |
175 } | 194 } |
OLD | NEW |