| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "platform/heap/Persistent.h" | 52 #include "platform/heap/Persistent.h" |
| 53 #include "platform/network/ContentSecurityPolicyParsers.h" | 53 #include "platform/network/ContentSecurityPolicyParsers.h" |
| 54 #include "platform/network/ResourceResponse.h" | 54 #include "platform/network/ResourceResponse.h" |
| 55 #include "platform/weborigin/KURL.h" | 55 #include "platform/weborigin/KURL.h" |
| 56 #include "platform/weborigin/SecurityOrigin.h" | 56 #include "platform/weborigin/SecurityOrigin.h" |
| 57 #include "public/platform/Platform.h" | 57 #include "public/platform/Platform.h" |
| 58 #include "public/platform/WebMessagePortChannel.h" | 58 #include "public/platform/WebMessagePortChannel.h" |
| 59 #include "public/platform/WebString.h" | 59 #include "public/platform/WebString.h" |
| 60 #include "public/platform/WebURL.h" | 60 #include "public/platform/WebURL.h" |
| 61 #include "public/platform/WebURLRequest.h" | 61 #include "public/platform/WebURLRequest.h" |
| 62 #include "public/platform/modules/serviceworker/WebServiceWorkerNetworkProvider.
h" |
| 62 #include "public/web/WebDevToolsAgent.h" | 63 #include "public/web/WebDevToolsAgent.h" |
| 63 #include "public/web/WebFrame.h" | 64 #include "public/web/WebFrame.h" |
| 64 #include "public/web/WebSettings.h" | 65 #include "public/web/WebSettings.h" |
| 65 #include "public/web/WebView.h" | 66 #include "public/web/WebView.h" |
| 66 #include "public/web/WebWorkerContentSettingsClientProxy.h" | 67 #include "public/web/WebWorkerContentSettingsClientProxy.h" |
| 67 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" | |
| 68 #include "web/IndexedDBClientImpl.h" | 68 #include "web/IndexedDBClientImpl.h" |
| 69 #include "web/LocalFileSystemClient.h" | 69 #include "web/LocalFileSystemClient.h" |
| 70 #include "web/WebDataSourceImpl.h" | 70 #include "web/WebDataSourceImpl.h" |
| 71 #include "web/WebLocalFrameImpl.h" | 71 #include "web/WebLocalFrameImpl.h" |
| 72 #include "web/WorkerContentSettingsClient.h" | 72 #include "web/WorkerContentSettingsClient.h" |
| 73 #include "wtf/Functional.h" | 73 #include "wtf/Functional.h" |
| 74 #include "wtf/PtrUtil.h" | 74 #include "wtf/PtrUtil.h" |
| 75 | 75 |
| 76 namespace blink { | 76 namespace blink { |
| 77 | 77 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 CString content(""); | 163 CString content(""); |
| 164 RefPtr<SharedBuffer> buffer( | 164 RefPtr<SharedBuffer> buffer( |
| 165 SharedBuffer::create(content.data(), content.length())); | 165 SharedBuffer::create(content.data(), content.length())); |
| 166 m_mainFrame->frame()->loader().load( | 166 m_mainFrame->frame()->loader().load( |
| 167 FrameLoadRequest(0, ResourceRequest(m_url), | 167 FrameLoadRequest(0, ResourceRequest(m_url), |
| 168 SubstituteData(buffer, "text/html", "UTF-8", KURL()))); | 168 SubstituteData(buffer, "text/html", "UTF-8", KURL()))); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void WebSharedWorkerImpl::willSendRequest(WebLocalFrame* frame, | 171 void WebSharedWorkerImpl::willSendRequest(WebLocalFrame* frame, |
| 172 WebURLRequest& request) { | 172 WebURLRequest& request) { |
| 173 DCHECK(isMainThread()); | 173 auto* networkProvider = |
| 174 if (m_networkProvider) | 174 frame->dataSource()->getServiceWorkerNetworkProvider(); |
| 175 m_networkProvider->willSendRequest(frame->dataSource(), request); | 175 if (networkProvider) |
| 176 networkProvider->willSendRequest(request); |
| 176 } | 177 } |
| 177 | 178 |
| 178 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) { | 179 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) { |
| 179 DCHECK(isMainThread()); | 180 DCHECK(isMainThread()); |
| 180 DCHECK(!m_loadingDocument); | 181 DCHECK(!m_loadingDocument); |
| 181 DCHECK(!m_mainScriptLoader); | 182 DCHECK(!m_mainScriptLoader); |
| 182 m_networkProvider = WTF::wrapUnique( | 183 frame->dataSource()->setServiceWorkerNetworkProvider( |
| 183 m_client->createServiceWorkerNetworkProvider(frame->dataSource())); | 184 WTF::wrapUnique(m_client->createServiceWorkerNetworkProvider())); |
| 184 m_mainScriptLoader = WorkerScriptLoader::create(); | 185 m_mainScriptLoader = WorkerScriptLoader::create(); |
| 185 m_mainScriptLoader->setRequestContext( | 186 m_mainScriptLoader->setRequestContext( |
| 186 WebURLRequest::RequestContextSharedWorker); | 187 WebURLRequest::RequestContextSharedWorker); |
| 187 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); | 188 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); |
| 188 | 189 |
| 189 CrossOriginRequestPolicy crossOriginRequestPolicy = | 190 CrossOriginRequestPolicy crossOriginRequestPolicy = |
| 190 (static_cast<KURL>(m_url)).protocolIsData() ? AllowCrossOriginRequests | 191 (static_cast<KURL>(m_url)).protocolIsData() ? AllowCrossOriginRequests |
| 191 : DenyCrossOriginRequests; | 192 : DenyCrossOriginRequests; |
| 192 | 193 |
| 193 m_mainScriptLoader->loadAsynchronously( | 194 m_mainScriptLoader->loadAsynchronously( |
| 194 *m_loadingDocument.get(), m_url, crossOriginRequestPolicy, | 195 *m_loadingDocument.get(), m_url, crossOriginRequestPolicy, |
| 195 m_creationAddressSpace, | 196 m_creationAddressSpace, |
| 196 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, | 197 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, |
| 197 WTF::unretained(this)), | 198 WTF::unretained(this)), |
| 198 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, | 199 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, |
| 199 WTF::unretained(this))); | 200 WTF::unretained(this))); |
| 200 // Do nothing here since onScriptLoaderFinished() might have been already | 201 // Do nothing here since onScriptLoaderFinished() might have been already |
| 201 // invoked and |this| might have been deleted at this point. | 202 // invoked and |this| might have been deleted at this point. |
| 202 } | 203 } |
| 203 | 204 |
| 204 bool WebSharedWorkerImpl::isControlledByServiceWorker( | |
| 205 WebDataSource& dataSource) { | |
| 206 DCHECK(isMainThread()); | |
| 207 return m_networkProvider && | |
| 208 m_networkProvider->isControlledByServiceWorker(dataSource); | |
| 209 } | |
| 210 | |
| 211 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) { | |
| 212 DCHECK(isMainThread()); | |
| 213 if (!m_networkProvider) | |
| 214 return -1; | |
| 215 return m_networkProvider->serviceWorkerID(dataSource); | |
| 216 } | |
| 217 | |
| 218 void WebSharedWorkerImpl::sendProtocolMessage(int sessionId, | 205 void WebSharedWorkerImpl::sendProtocolMessage(int sessionId, |
| 219 int callId, | 206 int callId, |
| 220 const WebString& message, | 207 const WebString& message, |
| 221 const WebString& state) { | 208 const WebString& state) { |
| 222 DCHECK(isMainThread()); | 209 DCHECK(isMainThread()); |
| 223 m_client->sendDevToolsMessage(sessionId, callId, message, state); | 210 m_client->sendDevToolsMessage(sessionId, callId, message, state); |
| 224 } | 211 } |
| 225 | 212 |
| 226 void WebSharedWorkerImpl::resumeStartup() { | 213 void WebSharedWorkerImpl::resumeStartup() { |
| 227 DCHECK(isMainThread()); | 214 DCHECK(isMainThread()); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 if (devtoolsAgent) | 426 if (devtoolsAgent) |
| 440 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, | 427 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, |
| 441 message); | 428 message); |
| 442 } | 429 } |
| 443 | 430 |
| 444 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { | 431 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { |
| 445 return new WebSharedWorkerImpl(client); | 432 return new WebSharedWorkerImpl(client); |
| 446 } | 433 } |
| 447 | 434 |
| 448 } // namespace blink | 435 } // namespace blink |
| OLD | NEW |