OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "core/loader/WorkerThreadableLoader.h" | 33 #include "core/loader/WorkerThreadableLoader.h" |
34 | 34 |
35 #include "core/dom/CrossThreadTask.h" | 35 #include "core/dom/CrossThreadTask.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
37 #include "core/loader/DocumentThreadableLoader.h" | 37 #include "core/loader/DocumentThreadableLoader.h" |
38 #include "core/loader/ThreadableLoader.h" | 38 #include "core/loader/ThreadableLoader.h" |
39 #include "core/platform/network/ResourceError.h" | 39 #include "core/platform/network/ResourceError.h" |
40 #include "core/platform/network/ResourceRequest.h" | 40 #include "core/platform/network/ResourceRequest.h" |
41 #include "core/platform/network/ResourceResponse.h" | 41 #include "core/platform/network/ResourceResponse.h" |
42 #include "core/workers/WorkerContext.h" | 42 #include "core/workers/WorkerGlobalScope.h" |
43 #include "core/workers/WorkerLoaderProxy.h" | 43 #include "core/workers/WorkerLoaderProxy.h" |
44 #include "core/workers/WorkerThread.h" | 44 #include "core/workers/WorkerThread.h" |
45 #include <wtf/MainThread.h> | 45 #include <wtf/MainThread.h> |
46 #include <wtf/OwnPtr.h> | 46 #include <wtf/OwnPtr.h> |
47 #include <wtf/Vector.h> | 47 #include <wtf/Vector.h> |
48 | 48 |
49 using namespace std; | 49 using namespace std; |
50 | 50 |
51 namespace WebCore { | 51 namespace WebCore { |
52 | 52 |
53 static const char loadResourceSynchronouslyMode[] = "loadResourceSynchronouslyMo
de"; | 53 static const char loadResourceSynchronouslyMode[] = "loadResourceSynchronouslyMo
de"; |
54 | 54 |
55 WorkerThreadableLoader::WorkerThreadableLoader(WorkerContext* workerContext, Thr
eadableLoaderClient* client, const String& taskMode, const ResourceRequest& requ
est, const ThreadableLoaderOptions& options) | 55 WorkerThreadableLoader::WorkerThreadableLoader(WorkerGlobalScope* workerGlobalSc
ope, ThreadableLoaderClient* client, const String& taskMode, const ResourceReque
st& request, const ThreadableLoaderOptions& options) |
56 : m_workerContext(workerContext) | 56 : m_workerGlobalScope(workerGlobalScope) |
57 , m_workerClientWrapper(ThreadableLoaderClientWrapper::create(client)) | 57 , m_workerClientWrapper(ThreadableLoaderClientWrapper::create(client)) |
58 , m_bridge(*(new MainThreadBridge(m_workerClientWrapper, m_workerContext->th
read()->workerLoaderProxy(), taskMode, request, options, workerContext->url().st
rippedForUseAsReferrer()))) | 58 , m_bridge(*(new MainThreadBridge(m_workerClientWrapper, m_workerGlobalScope
->thread()->workerLoaderProxy(), taskMode, request, options, workerGlobalScope->
url().strippedForUseAsReferrer()))) |
59 { | 59 { |
60 } | 60 } |
61 | 61 |
62 WorkerThreadableLoader::~WorkerThreadableLoader() | 62 WorkerThreadableLoader::~WorkerThreadableLoader() |
63 { | 63 { |
64 m_bridge.destroy(); | 64 m_bridge.destroy(); |
65 } | 65 } |
66 | 66 |
67 void WorkerThreadableLoader::loadResourceSynchronously(WorkerContext* workerCont
ext, const ResourceRequest& request, ThreadableLoaderClient& client, const Threa
dableLoaderOptions& options) | 67 void WorkerThreadableLoader::loadResourceSynchronously(WorkerGlobalScope* worker
GlobalScope, const ResourceRequest& request, ThreadableLoaderClient& client, con
st ThreadableLoaderOptions& options) |
68 { | 68 { |
69 WorkerRunLoop& runLoop = workerContext->thread()->runLoop(); | 69 WorkerRunLoop& runLoop = workerGlobalScope->thread()->runLoop(); |
70 | 70 |
71 // Create a unique mode just for this synchronous resource load. | 71 // Create a unique mode just for this synchronous resource load. |
72 String mode = loadResourceSynchronouslyMode; | 72 String mode = loadResourceSynchronouslyMode; |
73 mode.append(String::number(runLoop.createUniqueId())); | 73 mode.append(String::number(runLoop.createUniqueId())); |
74 | 74 |
75 RefPtr<WorkerThreadableLoader> loader = WorkerThreadableLoader::create(worke
rContext, &client, mode, request, options); | 75 RefPtr<WorkerThreadableLoader> loader = WorkerThreadableLoader::create(worke
rGlobalScope, &client, mode, request, options); |
76 MessageQueueWaitResult result = MessageQueueMessageReceived; | 76 MessageQueueWaitResult result = MessageQueueMessageReceived; |
77 while (!loader->done() && result != MessageQueueTerminated) | 77 while (!loader->done() && result != MessageQueueTerminated) |
78 result = runLoop.runInMode(workerContext, mode); | 78 result = runLoop.runInMode(workerGlobalScope, mode); |
79 | 79 |
80 if (!loader->done() && result == MessageQueueTerminated) | 80 if (!loader->done() && result == MessageQueueTerminated) |
81 loader->cancel(); | 81 loader->cancel(); |
82 } | 82 } |
83 | 83 |
84 void WorkerThreadableLoader::cancel() | 84 void WorkerThreadableLoader::cancel() |
85 { | 85 { |
86 m_bridge.cancel(); | 86 m_bridge.cancel(); |
87 } | 87 } |
88 | 88 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 clientWrapper->didFail(error); | 157 clientWrapper->didFail(error); |
158 } | 158 } |
159 clearClientWrapper(); | 159 clearClientWrapper(); |
160 } | 160 } |
161 | 161 |
162 void WorkerThreadableLoader::MainThreadBridge::clearClientWrapper() | 162 void WorkerThreadableLoader::MainThreadBridge::clearClientWrapper() |
163 { | 163 { |
164 m_workerClientWrapper->clearClient(); | 164 m_workerClientWrapper->clearClient(); |
165 } | 165 } |
166 | 166 |
167 static void workerContextDidSendData(ScriptExecutionContext* context, RefPtr<Thr
eadableLoaderClientWrapper> workerClientWrapper, unsigned long long bytesSent, u
nsigned long long totalBytesToBeSent) | 167 static void workerGlobalScopeDidSendData(ScriptExecutionContext* context, RefPtr
<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long long bytesSen
t, unsigned long long totalBytesToBeSent) |
168 { | 168 { |
169 ASSERT_UNUSED(context, context->isWorkerContext()); | 169 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
170 workerClientWrapper->didSendData(bytesSent, totalBytesToBeSent); | 170 workerClientWrapper->didSendData(bytesSent, totalBytesToBeSent); |
171 } | 171 } |
172 | 172 |
173 void WorkerThreadableLoader::MainThreadBridge::didSendData(unsigned long long by
tesSent, unsigned long long totalBytesToBeSent) | 173 void WorkerThreadableLoader::MainThreadBridge::didSendData(unsigned long long by
tesSent, unsigned long long totalBytesToBeSent) |
174 { | 174 { |
175 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidSendData, m_workerClientWrapper, bytesSent, totalBytesToBeSent), m_taskMode
); | 175 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidSendData, m_workerClientWrapper, bytesSent, totalBytesToBeSent), m_
taskMode); |
176 } | 176 } |
177 | 177 |
178 static void workerContextDidReceiveResponse(ScriptExecutionContext* context, Ref
Ptr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifier
, PassOwnPtr<CrossThreadResourceResponseData> responseData) | 178 static void workerGlobalScopeDidReceiveResponse(ScriptExecutionContext* context,
RefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identi
fier, PassOwnPtr<CrossThreadResourceResponseData> responseData) |
179 { | 179 { |
180 ASSERT_UNUSED(context, context->isWorkerContext()); | 180 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
181 OwnPtr<ResourceResponse> response(ResourceResponse::adopt(responseData)); | 181 OwnPtr<ResourceResponse> response(ResourceResponse::adopt(responseData)); |
182 workerClientWrapper->didReceiveResponse(identifier, *response); | 182 workerClientWrapper->didReceiveResponse(identifier, *response); |
183 } | 183 } |
184 | 184 |
185 void WorkerThreadableLoader::MainThreadBridge::didReceiveResponse(unsigned long
identifier, const ResourceResponse& response) | 185 void WorkerThreadableLoader::MainThreadBridge::didReceiveResponse(unsigned long
identifier, const ResourceResponse& response) |
186 { | 186 { |
187 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidReceiveResponse, m_workerClientWrapper, identifier, response), m_taskMode); | 187 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidReceiveResponse, m_workerClientWrapper, identifier, response), m_ta
skMode); |
188 } | 188 } |
189 | 189 |
190 static void workerContextDidReceiveData(ScriptExecutionContext* context, RefPtr<
ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vector<char> > ve
ctorData) | 190 static void workerGlobalScopeDidReceiveData(ScriptExecutionContext* context, Ref
Ptr<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vector<char>
> vectorData) |
191 { | 191 { |
192 ASSERT_UNUSED(context, context->isWorkerContext()); | 192 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
193 workerClientWrapper->didReceiveData(vectorData->data(), vectorData->size()); | 193 workerClientWrapper->didReceiveData(vectorData->data(), vectorData->size()); |
194 } | 194 } |
195 | 195 |
196 void WorkerThreadableLoader::MainThreadBridge::didReceiveData(const char* data,
int dataLength) | 196 void WorkerThreadableLoader::MainThreadBridge::didReceiveData(const char* data,
int dataLength) |
197 { | 197 { |
198 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCallbackTask. | 198 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCallbackTask. |
199 memcpy(vector->data(), data, dataLength); | 199 memcpy(vector->data(), data, dataLength); |
200 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidReceiveData, m_workerClientWrapper, vector.release()), m_taskMode); | 200 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidReceiveData, m_workerClientWrapper, vector.release()), m_taskMode); |
201 } | 201 } |
202 | 202 |
203 static void workerContextDidReceiveCachedMetadata(ScriptExecutionContext* contex
t, RefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vector<
char> > vectorData) | 203 static void workerGlobalScopeDidReceiveCachedMetadata(ScriptExecutionContext* co
ntext, RefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vec
tor<char> > vectorData) |
204 { | 204 { |
205 ASSERT_UNUSED(context, context->isWorkerContext()); | 205 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
206 workerClientWrapper->didReceiveCachedMetadata(vectorData->data(), vectorData
->size()); | 206 workerClientWrapper->didReceiveCachedMetadata(vectorData->data(), vectorData
->size()); |
207 } | 207 } |
208 | 208 |
209 void WorkerThreadableLoader::MainThreadBridge::didReceiveCachedMetadata(const ch
ar* data, int dataLength) | 209 void WorkerThreadableLoader::MainThreadBridge::didReceiveCachedMetadata(const ch
ar* data, int dataLength) |
210 { | 210 { |
211 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCallbackTask. | 211 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCallbackTask. |
212 memcpy(vector->data(), data, dataLength); | 212 memcpy(vector->data(), data, dataLength); |
213 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidReceiveCachedMetadata, m_workerClientWrapper, vector.release()), m_taskMode
); | 213 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidReceiveCachedMetadata, m_workerClientWrapper, vector.release()), m_
taskMode); |
214 } | 214 } |
215 | 215 |
216 static void workerContextDidFinishLoading(ScriptExecutionContext* context, RefPt
r<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifier,
double finishTime) | 216 static void workerGlobalScopeDidFinishLoading(ScriptExecutionContext* context, R
efPtr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifi
er, double finishTime) |
217 { | 217 { |
218 ASSERT_UNUSED(context, context->isWorkerContext()); | 218 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
219 workerClientWrapper->didFinishLoading(identifier, finishTime); | 219 workerClientWrapper->didFinishLoading(identifier, finishTime); |
220 } | 220 } |
221 | 221 |
222 void WorkerThreadableLoader::MainThreadBridge::didFinishLoading(unsigned long id
entifier, double finishTime) | 222 void WorkerThreadableLoader::MainThreadBridge::didFinishLoading(unsigned long id
entifier, double finishTime) |
223 { | 223 { |
224 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidFinishLoading, m_workerClientWrapper, identifier, finishTime), m_taskMode); | 224 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidFinishLoading, m_workerClientWrapper, identifier, finishTime), m_ta
skMode); |
225 } | 225 } |
226 | 226 |
227 static void workerContextDidFail(ScriptExecutionContext* context, RefPtr<Threada
bleLoaderClientWrapper> workerClientWrapper, const ResourceError& error) | 227 static void workerGlobalScopeDidFail(ScriptExecutionContext* context, RefPtr<Thr
eadableLoaderClientWrapper> workerClientWrapper, const ResourceError& error) |
228 { | 228 { |
229 ASSERT_UNUSED(context, context->isWorkerContext()); | 229 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
230 workerClientWrapper->didFail(error); | 230 workerClientWrapper->didFail(error); |
231 } | 231 } |
232 | 232 |
233 void WorkerThreadableLoader::MainThreadBridge::didFail(const ResourceError& erro
r) | 233 void WorkerThreadableLoader::MainThreadBridge::didFail(const ResourceError& erro
r) |
234 { | 234 { |
235 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidFail, m_workerClientWrapper, error), m_taskMode); | 235 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidFail, m_workerClientWrapper, error), m_taskMode); |
236 } | 236 } |
237 | 237 |
238 static void workerContextDidFailAccessControlCheck(ScriptExecutionContext* conte
xt, PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, const Resourc
eError& error) | 238 static void workerGlobalScopeDidFailAccessControlCheck(ScriptExecutionContext* c
ontext, PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, const Res
ourceError& error) |
239 { | 239 { |
240 ASSERT_UNUSED(context, context->isWorkerContext()); | 240 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
241 workerClientWrapper->didFailAccessControlCheck(error); | 241 workerClientWrapper->didFailAccessControlCheck(error); |
242 } | 242 } |
243 | 243 |
244 void WorkerThreadableLoader::MainThreadBridge::didFailAccessControlCheck(const R
esourceError& error) | 244 void WorkerThreadableLoader::MainThreadBridge::didFailAccessControlCheck(const R
esourceError& error) |
245 { | 245 { |
246 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidFailAccessControlCheck, m_workerClientWrapper, error), m_taskMode); | 246 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidFailAccessControlCheck, m_workerClientWrapper, error), m_taskMode); |
247 } | 247 } |
248 | 248 |
249 static void workerContextDidFailRedirectCheck(ScriptExecutionContext* context, R
efPtr<ThreadableLoaderClientWrapper> workerClientWrapper) | 249 static void workerGlobalScopeDidFailRedirectCheck(ScriptExecutionContext* contex
t, RefPtr<ThreadableLoaderClientWrapper> workerClientWrapper) |
250 { | 250 { |
251 ASSERT_UNUSED(context, context->isWorkerContext()); | 251 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
252 workerClientWrapper->didFailRedirectCheck(); | 252 workerClientWrapper->didFailRedirectCheck(); |
253 } | 253 } |
254 | 254 |
255 void WorkerThreadableLoader::MainThreadBridge::didFailRedirectCheck() | 255 void WorkerThreadableLoader::MainThreadBridge::didFailRedirectCheck() |
256 { | 256 { |
257 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte
xtDidFailRedirectCheck, m_workerClientWrapper), m_taskMode); | 257 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG
lobalScopeDidFailRedirectCheck, m_workerClientWrapper), m_taskMode); |
258 } | 258 } |
259 | 259 |
260 } // namespace WebCore | 260 } // namespace WebCore |
OLD | NEW |