| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 if (devtoolsAgent) | 410 if (devtoolsAgent) |
| 471 devtoolsAgent->dispatchOnInspectorBackend(message); | 411 devtoolsAgent->dispatchOnInspectorBackend(message); |
| 472 } | 412 } |
| 473 | 413 |
| 474 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) | 414 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) |
| 475 { | 415 { |
| 476 return new WebSharedWorkerImpl(client); | 416 return new WebSharedWorkerImpl(client); |
| 477 } | 417 } |
| 478 | 418 |
| 479 } // namespace blink | 419 } // namespace blink |
| OLD | NEW |