Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "WebEmbeddedWorkerImpl.h" | |
| 33 | |
| 34 #include "WebDataSourceImpl.h" | |
| 35 #include "WebFrameImpl.h" | |
| 36 #include "WebServiceWorkerContextClient.h" | |
| 37 #include "WebView.h" | |
| 38 #include "WebWorkerPermissionClientProxy.h" | |
| 39 #include "WorkerPermissionClient.h" | |
| 40 #include "core/dom/Document.h" | |
| 41 #include "core/loader/FrameLoadRequest.h" | |
| 42 #include "core/loader/SubstituteData.h" | |
| 43 #include "core/workers/WorkerClients.h" | |
| 44 #include "core/workers/WorkerScriptLoader.h" | |
| 45 #include "core/workers/WorkerThreadStartupData.h" | |
| 46 #include "platform/NotImplemented.h" | |
| 47 #include "platform/SharedBuffer.h" | |
| 48 | |
| 49 using namespace WebCore; | |
| 50 | |
| 51 namespace blink { | |
| 52 | |
| 53 WebEmbeddedWorker* WebEmbeddedWorker::create( | |
| 54 WebServiceWorkerContextClient* client, | |
| 55 WebWorkerPermissionClientProxy* permissionClient) | |
| 56 { | |
| 57 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient )); | |
| 58 } | |
| 59 | |
| 60 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl( | |
| 61 PassOwnPtr<WebServiceWorkerContextClient> client, | |
| 62 PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) | |
| 63 : m_workerContextClient(client) | |
| 64 , m_permissionClient(permissionClient) | |
| 65 , m_scriptLoader(WorkerScriptLoader::create()) | |
| 66 , m_askedToTerminate(false) | |
| 67 { | |
| 68 m_scriptLoader->setTargetType(ResourceRequest::TargetIsServiceWorker); | |
| 69 } | |
| 70 | |
| 71 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() | |
| 72 { | |
| 73 ASSERT(m_webView); | |
| 74 // Detach the client before closing the view to avoid getting called back. | |
| 75 toWebFrameImpl(m_mainFrame)->setClient(0); | |
| 76 | |
| 77 m_webView->close(); | |
| 78 m_mainFrame->close(); | |
| 79 } | |
| 80 | |
| 81 void WebEmbeddedWorkerImpl::startWorkerContext( | |
| 82 const WebEmbeddedWorkerStartData& data) | |
| 83 { | |
| 84 ASSERT(!m_askedToTerminate); | |
| 85 ASSERT(!m_loading); | |
| 86 m_workerStartData = data; | |
| 87 | |
| 88 prepareShadowPageForLoader(); | |
| 89 | |
| 90 m_loading = true; | |
| 91 m_scriptLoader->loadAsynchronously(m_loadingDocument.get(), data.scriptURL, DenyCrossOriginRequests, this); | |
| 92 } | |
| 93 | |
| 94 void WebEmbeddedWorkerImpl::notifyFinished() | |
| 95 { | |
| 96 ASSERT(m_loading); | |
| 97 m_loading = false; | |
|
michaeln
2013/11/21 02:00:40
Once we've retrieved the results of the main scrip
kinuko
2013/11/21 06:36:05
Done.
| |
| 98 | |
| 99 if (m_scriptLoader->failed()) { | |
| 100 // How could this fail in our case? | |
| 101 m_workerContextClient->workerContextLoadFailed(); | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 if (m_askedToTerminate) { | |
| 106 m_workerContextClient->workerContextDestroyed(); | |
| 107 return; | |
| 108 } | |
| 109 | |
|
michaeln
2013/11/21 02:00:40
What if the main script load involves a series of
kinuko
2013/11/21 06:36:05
Currently we do deny cross-origin request, even vi
michaeln
2013/11/21 22:14:38
That sgtm2, same-origin redirects only.
| |
| 110 WorkerThreadStartMode startMode = m_workerStartData.startMode == WebEmbedded WorkerStartModePauseOnStart ? PauseWorkerGlobalScopeOnStart : DontPauseWorkerGlo balScopeOnStart; | |
| 111 OwnPtr<WorkerClients> workerClients = WorkerClients::create(); | |
| 112 providePermissionClientToWorker(workerClients.get(), m_permissionClient.rele ase()); | |
| 113 | |
| 114 OwnPtr<WorkerThreadStartupData> startupData = | |
| 115 WorkerThreadStartupData::create( | |
| 116 m_workerStartData.scriptURL, | |
| 117 m_workerStartData.userAgent, | |
| 118 m_scriptLoader->script(), | |
| 119 startMode, | |
| 120 m_workerStartData.contentSecurityPolicy, | |
|
michaeln
2013/11/21 02:00:40
ok... so this CSP header value... i think we shoul
kinuko
2013/11/21 06:36:05
Yup. Today I had time to investigate this a bit, a
| |
| 121 static_cast<WebCore::ContentSecurityPolicy::HeaderType>(m_workerStar tData.contentSecurityPolicyType), | |
| 122 workerClients.release()); | |
| 123 | |
| 124 // FIXME: Create WorkerReportingProxy, create ServiceWorkerThread and | |
| 125 // start it with m_scripLoader->script(). | |
| 126 notImplemented(); | |
| 127 } | |
| 128 | |
| 129 void WebEmbeddedWorkerImpl::terminateWorkerContext() | |
| 130 { | |
| 131 if (m_askedToTerminate) | |
| 132 return; | |
|
michaeln
2013/11/21 02:00:40
How do we abort/cancel the main script load if it'
kinuko
2013/11/21 06:36:05
Added cancel().
| |
| 133 m_askedToTerminate = true; | |
| 134 if (m_workerThread) | |
| 135 m_workerThread->stop(); | |
| 136 } | |
| 137 | |
| 138 void WebEmbeddedWorkerImpl::postTaskToLoader(PassOwnPtr<WebCore::ExecutionContex tTask> task) | |
| 139 { | |
| 140 m_loadingDocument->postTask(task); | |
| 141 } | |
| 142 | |
| 143 bool WebEmbeddedWorkerImpl::postTaskForModeToWorkerGlobalScope(PassOwnPtr<WebCor e::ExecutionContextTask> task, const String& mode) | |
| 144 { | |
| 145 m_workerThread->runLoop().postTaskForMode(task, mode); | |
| 146 return true; | |
| 147 } | |
| 148 | |
| 149 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() | |
| 150 { | |
| 151 // Create 'shadow page', which is never displayed and is used mainly to | |
| 152 // provide a context for loading on the main thread. | |
| 153 ASSERT(!m_webView); | |
| 154 m_webView = WebView::create(0); | |
| 155 m_mainFrame = WebFrame::create(this); | |
| 156 m_webView->setMainFrame(m_mainFrame); | |
| 157 | |
| 158 WebFrameImpl* webFrame = toWebFrameImpl(m_webView->mainFrame()); | |
| 159 | |
| 160 // Construct substitute data source for the 'shadow page'. We only need it | |
| 161 // to have same origin as the worker so the loading checks work correctly. | |
| 162 CString content(""); | |
| 163 int length = static_cast<int>(content.length()); | |
| 164 RefPtr<SharedBuffer> buffer(SharedBuffer::create(content.data(), length)); | |
| 165 webFrame->frame()->loader().load(FrameLoadRequest(0, ResourceRequest(m_worke rStartData.scriptURL), SubstituteData(buffer, "text/html", "UTF-8", KURL()))); | |
| 166 | |
| 167 // This document will be used as 'loading context' for the worker. | |
| 168 m_loadingDocument = webFrame->frame()->document(); | |
| 169 } | |
| 170 | |
| 171 void WebEmbeddedWorkerImpl::didCreateDataSource(WebFrame*, WebDataSource* ds) | |
| 172 { | |
| 173 // Tell the loader to load the data into the 'shadow page' synchronously, | |
| 174 // so we can grab the resulting Document right after load. | |
| 175 static_cast<WebDataSourceImpl*>(ds)->setDeferMainResourceDataLoad(false); | |
| 176 } | |
| 177 | |
| 178 } // namespace blink | |
| OLD | NEW |