OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #include "web/WebDataSourceImpl.h" | 72 #include "web/WebDataSourceImpl.h" |
73 #include "web/WebLocalFrameImpl.h" | 73 #include "web/WebLocalFrameImpl.h" |
74 #include "web/WorkerContentSettingsClient.h" | 74 #include "web/WorkerContentSettingsClient.h" |
75 #include "wtf/Functional.h" | 75 #include "wtf/Functional.h" |
76 #include "wtf/MainThread.h" | 76 #include "wtf/MainThread.h" |
77 | 77 |
78 namespace blink { | 78 namespace blink { |
79 | 79 |
80 // TODO(toyoshim): Share implementation with WebEmbeddedWorkerImpl as much as | 80 // TODO(toyoshim): Share implementation with WebEmbeddedWorkerImpl as much as |
81 // possible. | 81 // possible. |
82 // A thin wrapper for one-off script loading. | |
83 class WebSharedWorkerImpl::Loader : public WorkerScriptLoaderClient { | |
84 public: | |
85 static PassOwnPtr<Loader> create() | |
86 { | |
87 return adoptPtr(new Loader()); | |
88 } | |
89 | |
90 virtual ~Loader() | |
91 { | |
92 m_scriptLoader->setClient(0); | |
93 } | |
94 | |
95 void load(ExecutionContext* loadingContext, const KURL& scriptURL, PassOwnPt
r<Closure> receiveResponseCallback, PassOwnPtr<Closure> finishCallback) | |
96 { | |
97 ASSERT(loadingContext); | |
98 m_receiveResponseCallback = receiveResponseCallback; | |
99 m_finishCallback = finishCallback; | |
100 m_scriptLoader->setRequestContext(WebURLRequest::RequestContextSharedWor
ker); | |
101 m_scriptLoader->loadAsynchronously( | |
102 *loadingContext, scriptURL, DenyCrossOriginRequests, this); | |
103 } | |
104 | |
105 void didReceiveResponse(unsigned long identifier, const ResourceResponse& re
sponse) override | |
106 { | |
107 m_identifier = identifier; | |
108 m_appCacheID = response.appCacheID(); | |
109 (*m_receiveResponseCallback)(); | |
110 } | |
111 | |
112 virtual void notifyFinished() override | |
113 { | |
114 (*m_finishCallback)(); | |
115 } | |
116 | |
117 void cancel() | |
118 { | |
119 m_scriptLoader->cancel(); | |
120 } | |
121 | |
122 bool failed() const { return m_scriptLoader->failed(); } | |
123 const KURL& url() const { return m_scriptLoader->responseURL(); } | |
124 String script() const { return m_scriptLoader->script(); } | |
125 unsigned long identifier() const { return m_identifier; } | |
126 long long appCacheID() const { return m_appCacheID; } | |
127 PassRefPtr<ContentSecurityPolicy> contentSecurityPolicy() { return m_scriptL
oader->contentSecurityPolicy(); } | |
128 | |
129 private: | |
130 Loader() | |
131 : m_scriptLoader(WorkerScriptLoader::create()) | |
132 , m_identifier(0) | |
133 , m_appCacheID(0) | |
134 { | |
135 m_scriptLoader->setContentSecurityPolicy(ContentSecurityPolicy::create()
); | |
136 } | |
137 | |
138 RefPtr<WorkerScriptLoader> m_scriptLoader; | |
139 unsigned long m_identifier; | |
140 long long m_appCacheID; | |
141 OwnPtr<Closure> m_receiveResponseCallback; | |
142 OwnPtr<Closure> m_finishCallback; | |
143 }; | |
144 | 82 |
145 // This function is called on the main thread to force to initialize some static | 83 // This function is called on the main thread to force to initialize some static |
146 // values used in WebKit before any worker thread is started. This is because in | 84 // values used in WebKit before any worker thread is started. This is because in |
147 // our worker processs, we do not run any WebKit code in main thread and thus | 85 // our worker processs, we do not run any WebKit code in main thread and thus |
148 // when multiple workers try to start at the same time, we might hit crash due | 86 // when multiple workers try to start at the same time, we might hit crash due |
149 // to contention for initializing static values. | 87 // to contention for initializing static values. |
150 static void initializeWebKitStaticValues() | 88 static void initializeWebKitStaticValues() |
151 { | 89 { |
152 static bool initialized = false; | 90 static bool initialized = false; |
153 if (!initialized) { | 91 if (!initialized) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 { | 184 { |
247 if (m_networkProvider) | 185 if (m_networkProvider) |
248 m_networkProvider->willSendRequest(frame->dataSource(), request); | 186 m_networkProvider->willSendRequest(frame->dataSource(), request); |
249 } | 187 } |
250 | 188 |
251 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) | 189 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) |
252 { | 190 { |
253 ASSERT(!m_loadingDocument); | 191 ASSERT(!m_loadingDocument); |
254 ASSERT(!m_mainScriptLoader); | 192 ASSERT(!m_mainScriptLoader); |
255 m_networkProvider = adoptPtr(m_client->createServiceWorkerNetworkProvider(fr
ame->dataSource())); | 193 m_networkProvider = adoptPtr(m_client->createServiceWorkerNetworkProvider(fr
ame->dataSource())); |
256 m_mainScriptLoader = Loader::create(); | 194 m_mainScriptLoader = adoptPtr(new WorkerScriptLoader()); |
| 195 m_mainScriptLoader->setRequestContext(WebURLRequest::RequestContextSharedWor
ker); |
257 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); | 196 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); |
258 m_mainScriptLoader->load( | 197 m_mainScriptLoader->loadAsynchronously( |
259 m_loadingDocument.get(), | 198 *m_loadingDocument.get(), |
260 m_url, | 199 m_url, |
| 200 DenyCrossOriginRequests, |
261 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, this), | 201 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, this), |
262 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, this)); | 202 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, this)); |
263 } | 203 } |
264 | 204 |
265 bool WebSharedWorkerImpl::isControlledByServiceWorker(WebDataSource& dataSource) | 205 bool WebSharedWorkerImpl::isControlledByServiceWorker(WebDataSource& dataSource) |
266 { | 206 { |
267 return m_networkProvider && m_networkProvider->isControlledByServiceWorker(d
ataSource); | 207 return m_networkProvider && m_networkProvider->isControlledByServiceWorker(d
ataSource); |
268 } | 208 } |
269 | 209 |
270 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) | 210 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) | 344 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) |
405 startMode = PauseWorkerGlobalScopeOnStart; | 345 startMode = PauseWorkerGlobalScopeOnStart; |
406 | 346 |
407 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) | 347 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) |
408 SecurityOrigin* starterOrigin = document->securityOrigin(); | 348 SecurityOrigin* starterOrigin = document->securityOrigin(); |
409 | 349 |
410 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); | 350 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); |
411 provideLocalFileSystemToWorker(workerClients.get(), LocalFileSystemClient::c
reate()); | 351 provideLocalFileSystemToWorker(workerClients.get(), LocalFileSystemClient::c
reate()); |
412 WebSecurityOrigin webSecurityOrigin(m_loadingDocument->securityOrigin()); | 352 WebSecurityOrigin webSecurityOrigin(m_loadingDocument->securityOrigin()); |
413 provideContentSettingsClientToWorker(workerClients.get(), adoptPtr(m_client-
>createWorkerContentSettingsClientProxy(webSecurityOrigin))); | 353 provideContentSettingsClientToWorker(workerClients.get(), adoptPtr(m_client-
>createWorkerContentSettingsClientProxy(webSecurityOrigin))); |
| 354 RefPtr<ContentSecurityPolicy> contentSecurityPolicy = m_mainScriptLoader->re
leaseContentSecurityPolicy(); |
414 OwnPtr<WorkerThreadStartupData> startupData = WorkerThreadStartupData::creat
e( | 355 OwnPtr<WorkerThreadStartupData> startupData = WorkerThreadStartupData::creat
e( |
415 m_url, | 356 m_url, |
416 m_loadingDocument->userAgent(m_url), | 357 m_loadingDocument->userAgent(m_url), |
417 m_mainScriptLoader->script(), | 358 m_mainScriptLoader->script(), |
418 nullptr, | 359 nullptr, |
419 startMode, | 360 startMode, |
420 m_mainScriptLoader->contentSecurityPolicy()->headers(), | 361 contentSecurityPolicy ? contentSecurityPolicy->headers() : nullptr, |
421 starterOrigin, | 362 starterOrigin, |
422 workerClients.release()); | 363 workerClients.release()); |
423 m_loaderProxy = WorkerLoaderProxy::create(this); | 364 m_loaderProxy = WorkerLoaderProxy::create(this); |
424 setWorkerThread(SharedWorkerThread::create(m_name, m_loaderProxy, *this)); | 365 setWorkerThread(SharedWorkerThread::create(m_name, m_loaderProxy, *this)); |
425 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), m_mainScri
ptLoader->identifier(), m_mainScriptLoader->script()); | 366 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), m_mainScri
ptLoader->identifier(), m_mainScriptLoader->script()); |
426 m_mainScriptLoader.clear(); | 367 m_mainScriptLoader.clear(); |
427 | 368 |
428 workerThread()->start(startupData.release()); | 369 workerThread()->start(startupData.release()); |
429 m_workerInspectorProxy->workerThreadCreated(m_loadingDocument.get(), workerT
hread(), m_url); | 370 m_workerInspectorProxy->workerThreadCreated(m_loadingDocument.get(), workerT
hread(), m_url); |
430 m_client->workerScriptLoaded(); | 371 m_client->workerScriptLoaded(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 if (devtoolsAgent) | 411 if (devtoolsAgent) |
471 devtoolsAgent->dispatchOnInspectorBackend(message); | 412 devtoolsAgent->dispatchOnInspectorBackend(message); |
472 } | 413 } |
473 | 414 |
474 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) | 415 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) |
475 { | 416 { |
476 return new WebSharedWorkerImpl(client); | 417 return new WebSharedWorkerImpl(client); |
477 } | 418 } |
478 | 419 |
479 } // namespace blink | 420 } // namespace blink |
OLD | NEW |