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_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
6 | 6 |
| 7 #include "content/browser/shared_worker/shared_worker_host.h" |
| 8 #include "content/browser/shared_worker/shared_worker_instance.h" |
7 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 9 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 10 #include "content/browser/worker_host/worker_document_set.h" |
| 11 #include "content/common/view_messages.h" |
8 #include "content/common/worker_messages.h" | 12 #include "content/common/worker_messages.h" |
9 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/worker_service_observer.h" | 14 #include "content/public/browser/worker_service_observer.h" |
11 | 15 |
12 namespace content { | 16 namespace content { |
13 | 17 |
14 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { | 18 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { |
15 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
16 return Singleton<SharedWorkerServiceImpl>::get(); | 20 return Singleton<SharedWorkerServiceImpl>::get(); |
17 } | 21 } |
(...skipping 25 matching lines...) Expand all Loading... |
43 observers_.RemoveObserver(observer); | 47 observers_.RemoveObserver(observer); |
44 } | 48 } |
45 | 49 |
46 void SharedWorkerServiceImpl::CreateWorker( | 50 void SharedWorkerServiceImpl::CreateWorker( |
47 const ViewHostMsg_CreateWorker_Params& params, | 51 const ViewHostMsg_CreateWorker_Params& params, |
48 int route_id, | 52 int route_id, |
49 SharedWorkerMessageFilter* filter, | 53 SharedWorkerMessageFilter* filter, |
50 ResourceContext* resource_context, | 54 ResourceContext* resource_context, |
51 const WorkerStoragePartition& partition, | 55 const WorkerStoragePartition& partition, |
52 bool* url_mismatch) { | 56 bool* url_mismatch) { |
53 // TODO(horo): implement this. | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
54 NOTIMPLEMENTED(); | 58 *url_mismatch = false; |
| 59 SharedWorkerInstance* existing_instance = |
| 60 FindSharedWorkerInstance( |
| 61 params.url, params.name, partition, resource_context); |
| 62 if (existing_instance) { |
| 63 if (params.url != existing_instance->url()) { |
| 64 *url_mismatch = true; |
| 65 return; |
| 66 } |
| 67 if (existing_instance->load_failed()) { |
| 68 filter->Send(new ViewMsg_WorkerScriptLoadFailed(route_id)); |
| 69 return; |
| 70 } |
| 71 existing_instance->AddFilter(filter, route_id); |
| 72 existing_instance->worker_document_set()->Add( |
| 73 filter, params.document_id, filter->render_process_id(), |
| 74 params.render_frame_route_id); |
| 75 filter->Send(new ViewMsg_WorkerCreated(route_id)); |
| 76 return; |
| 77 } |
| 78 |
| 79 scoped_ptr<SharedWorkerInstance> instance(new SharedWorkerInstance( |
| 80 params.url, |
| 81 params.name, |
| 82 params.content_security_policy, |
| 83 params.security_policy_type, |
| 84 resource_context, |
| 85 partition)); |
| 86 instance->AddFilter(filter, route_id); |
| 87 instance->worker_document_set()->Add( |
| 88 filter, params.document_id, filter->render_process_id(), |
| 89 params.render_frame_route_id); |
| 90 |
| 91 scoped_ptr<SharedWorkerHost> worker(new SharedWorkerHost(instance.release())); |
| 92 worker->Init(filter); |
| 93 const int worker_route_id = worker->worker_route_id(); |
| 94 worker_hosts_.push_back(worker.release()); |
| 95 |
| 96 FOR_EACH_OBSERVER( |
| 97 WorkerServiceObserver, observers_, |
| 98 WorkerCreated(params.url, |
| 99 params.name, |
| 100 filter->render_process_id(), |
| 101 worker_route_id)); |
55 } | 102 } |
56 | 103 |
57 void SharedWorkerServiceImpl::ForwardToWorker( | 104 void SharedWorkerServiceImpl::ForwardToWorker( |
58 const IPC::Message& message, | 105 const IPC::Message& message, |
59 SharedWorkerMessageFilter* filter) { | 106 SharedWorkerMessageFilter* filter) { |
60 // TODO(horo): implement this. | 107 // TODO(horo): implement this. |
61 NOTIMPLEMENTED(); | 108 NOTIMPLEMENTED(); |
62 } | 109 } |
63 | 110 |
64 void SharedWorkerServiceImpl::DocumentDetached( | 111 void SharedWorkerServiceImpl::DocumentDetached( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // TODO(horo): implement this. | 181 // TODO(horo): implement this. |
135 NOTIMPLEMENTED(); | 182 NOTIMPLEMENTED(); |
136 } | 183 } |
137 | 184 |
138 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( | 185 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( |
139 SharedWorkerMessageFilter* filter) { | 186 SharedWorkerMessageFilter* filter) { |
140 // TODO(horo): implement this. | 187 // TODO(horo): implement this. |
141 NOTIMPLEMENTED(); | 188 NOTIMPLEMENTED(); |
142 } | 189 } |
143 | 190 |
| 191 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( |
| 192 const GURL& url, |
| 193 const base::string16& name, |
| 194 const WorkerStoragePartition& partition, |
| 195 ResourceContext* resource_context) { |
| 196 for (ScopedVector<SharedWorkerHost>::const_iterator iter = |
| 197 worker_hosts_.begin(); |
| 198 iter != worker_hosts_.end(); |
| 199 ++iter) { |
| 200 SharedWorkerInstance* instance = (*iter)->instance(); |
| 201 if (instance && |
| 202 instance->Matches(url, name, partition, resource_context)) |
| 203 return instance; |
| 204 } |
| 205 return NULL; |
| 206 } |
| 207 |
144 } // namespace content | 208 } // namespace content |
OLD | NEW |