OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/shared_worker/shared_worker_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
6 | 6 |
7 #include "content/browser/frame_host/render_frame_host_delegate.h" | 7 #include "content/browser/frame_host/render_frame_host_delegate.h" |
8 #include "content/browser/frame_host/render_frame_host_impl.h" | 8 #include "content/browser/frame_host/render_frame_host_impl.h" |
9 #include "content/browser/message_port_service.h" | 9 #include "content/browser/message_port_service.h" |
10 #include "content/browser/shared_worker/shared_worker_instance.h" | 10 #include "content/browser/shared_worker/shared_worker_instance.h" |
11 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 11 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
12 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
13 #include "content/common/worker_messages.h" | 13 #include "content/common/worker_messages.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/common/content_client.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 namespace { | 19 namespace { |
18 | 20 |
19 // Notifies RenderViewHost that one or more worker objects crashed. | 21 // Notifies RenderViewHost that one or more worker objects crashed. |
20 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { | 22 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { |
21 RenderFrameHostImpl* host = | 23 RenderFrameHostImpl* host = |
22 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); | 24 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); |
23 if (host) | 25 if (host) |
24 host->delegate()->WorkerCrashed(host); | 26 host->delegate()->WorkerCrashed(host); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 i->filter()->Send(new ViewMsg_WorkerConnected(i->route_id())); | 162 i->filter()->Send(new ViewMsg_WorkerConnected(i->route_id())); |
161 return; | 163 return; |
162 } | 164 } |
163 } | 165 } |
164 | 166 |
165 void SharedWorkerHost::AllowDatabase(const GURL& url, | 167 void SharedWorkerHost::AllowDatabase(const GURL& url, |
166 const base::string16& name, | 168 const base::string16& name, |
167 const base::string16& display_name, | 169 const base::string16& display_name, |
168 unsigned long estimated_size, | 170 unsigned long estimated_size, |
169 bool* result) { | 171 bool* result) { |
170 // TODO(horo): implement this. | 172 if (!instance_) |
171 NOTIMPLEMENTED(); | 173 return; |
| 174 *result = GetContentClient()->browser()->AllowWorkerDatabase( |
| 175 url, |
| 176 name, |
| 177 display_name, |
| 178 estimated_size, |
| 179 instance_->resource_context(), |
| 180 GetRenderFrameIDsForWorker()); |
172 } | 181 } |
173 | 182 |
174 void SharedWorkerHost::AllowFileSystem(const GURL& url, | 183 void SharedWorkerHost::AllowFileSystem(const GURL& url, |
175 bool* result) { | 184 bool* result) { |
176 // TODO(horo): implement this. | 185 if (!instance_) |
177 NOTIMPLEMENTED(); | 186 return; |
| 187 *result = GetContentClient()->browser()->AllowWorkerFileSystem( |
| 188 url, instance_->resource_context(), GetRenderFrameIDsForWorker()); |
178 } | 189 } |
179 | 190 |
180 void SharedWorkerHost::AllowIndexedDB(const GURL& url, | 191 void SharedWorkerHost::AllowIndexedDB(const GURL& url, |
181 const base::string16& name, | 192 const base::string16& name, |
182 bool* result) { | 193 bool* result) { |
183 // TODO(horo): implement this. | 194 if (!instance_) |
184 NOTIMPLEMENTED(); | 195 return; |
| 196 *result = GetContentClient()->browser()->AllowWorkerIndexedDB( |
| 197 url, name, instance_->resource_context(), GetRenderFrameIDsForWorker()); |
185 } | 198 } |
186 | 199 |
187 void SharedWorkerHost::RelayMessage( | 200 void SharedWorkerHost::RelayMessage( |
188 const IPC::Message& message, | 201 const IPC::Message& message, |
189 SharedWorkerMessageFilter* incoming_filter) { | 202 SharedWorkerMessageFilter* incoming_filter) { |
190 if (!instance_) | 203 if (!instance_) |
191 return; | 204 return; |
192 if (message.type() == WorkerMsg_Connect::ID) { | 205 if (message.type() == WorkerMsg_Connect::ID) { |
193 // Crack the SharedWorker Connect message to setup routing for the port. | 206 // Crack the SharedWorker Connect message to setup routing for the port. |
194 int sent_message_port_id; | 207 int sent_message_port_id; |
(...skipping 23 matching lines...) Expand all Loading... |
218 new_message->set_routing_id(worker_route_id_); | 231 new_message->set_routing_id(worker_route_id_); |
219 Send(new_message); | 232 Send(new_message); |
220 return; | 233 return; |
221 } | 234 } |
222 } | 235 } |
223 | 236 |
224 void SharedWorkerHost::TerminateWorker() { | 237 void SharedWorkerHost::TerminateWorker() { |
225 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); | 238 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); |
226 } | 239 } |
227 | 240 |
| 241 std::vector<std::pair<int, int> > |
| 242 SharedWorkerHost::GetRenderFrameIDsForWorker() { |
| 243 std::vector<std::pair<int, int> > result; |
| 244 if (!instance_) |
| 245 return result; |
| 246 const WorkerDocumentSet::DocumentInfoSet& documents = |
| 247 instance_->worker_document_set()->documents(); |
| 248 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = |
| 249 documents.begin(); |
| 250 doc != documents.end(); |
| 251 ++doc) { |
| 252 result.push_back( |
| 253 std::make_pair(doc->render_process_id(), doc->render_frame_id())); |
| 254 } |
| 255 return result; |
| 256 } |
| 257 |
228 } // namespace content | 258 } // namespace content |
OLD | NEW |