Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 WorkerScriptLoader::WorkerScriptLoader() | 44 WorkerScriptLoader::WorkerScriptLoader() |
| 45 : m_responseCallback(nullptr) | 45 : m_responseCallback(nullptr) |
| 46 , m_finishedCallback(nullptr) | 46 , m_finishedCallback(nullptr) |
| 47 , m_failed(false) | 47 , m_failed(false) |
| 48 , m_identifier(0) | 48 , m_identifier(0) |
| 49 , m_appCacheID(0) | 49 , m_appCacheID(0) |
| 50 , m_finishing(false) | |
| 51 , m_requestContext(WebURLRequest::RequestContextWorker) | 50 , m_requestContext(WebURLRequest::RequestContextWorker) |
| 52 { | 51 { |
| 53 } | 52 } |
| 54 | 53 |
| 55 WorkerScriptLoader::~WorkerScriptLoader() | 54 WorkerScriptLoader::~WorkerScriptLoader() |
| 56 { | 55 { |
| 57 } | 56 } |
| 58 | 57 |
| 59 void WorkerScriptLoader::loadSynchronously(ExecutionContext& executionContext, c onst KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy) | 58 void WorkerScriptLoader::loadSynchronously(ExecutionContext& executionContext, c onst KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy) |
| 60 { | 59 { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 88 if (!request) | 87 if (!request) |
| 89 return; | 88 return; |
| 90 | 89 |
| 91 ThreadableLoaderOptions options; | 90 ThreadableLoaderOptions options; |
| 92 options.crossOriginRequestPolicy = crossOriginRequestPolicy; | 91 options.crossOriginRequestPolicy = crossOriginRequestPolicy; |
| 93 | 92 |
| 94 ResourceLoaderOptions resourceLoaderOptions; | 93 ResourceLoaderOptions resourceLoaderOptions; |
| 95 resourceLoaderOptions.allowCredentials = AllowStoredCredentials; | 94 resourceLoaderOptions.allowCredentials = AllowStoredCredentials; |
| 96 | 95 |
| 97 m_threadableLoader = ThreadableLoader::create(executionContext, this, *reque st, options, resourceLoaderOptions); | 96 m_threadableLoader = ThreadableLoader::create(executionContext, this, *reque st, options, resourceLoaderOptions); |
| 97 if (m_failed) | |
| 98 notifyFinished(); | |
| 99 // Do nothing here since notifyFinished() could delete |this|. | |
| 98 } | 100 } |
| 99 | 101 |
| 100 const KURL& WorkerScriptLoader::responseURL() const | 102 const KURL& WorkerScriptLoader::responseURL() const |
| 101 { | 103 { |
| 102 ASSERT(!failed()); | 104 ASSERT(!failed()); |
| 103 return m_responseURL; | 105 return m_responseURL; |
| 104 } | 106 } |
| 105 | 107 |
| 106 PassOwnPtr<ResourceRequest> WorkerScriptLoader::createResourceRequest() | 108 PassOwnPtr<ResourceRequest> WorkerScriptLoader::createResourceRequest() |
| 107 { | 109 { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 } | 173 } |
| 172 | 174 |
| 173 void WorkerScriptLoader::didFailRedirectCheck() | 175 void WorkerScriptLoader::didFailRedirectCheck() |
| 174 { | 176 { |
| 175 notifyError(); | 177 notifyError(); |
| 176 } | 178 } |
| 177 | 179 |
| 178 void WorkerScriptLoader::notifyError() | 180 void WorkerScriptLoader::notifyError() |
| 179 { | 181 { |
| 180 m_failed = true; | 182 m_failed = true; |
| 181 notifyFinished(); | 183 // notifyError() could be called before ThreadableLoader::create() returns |
| 184 // e.g. from didFail(), and in that case m_threadableLoader is not yet set | |
| 185 // (i.e. still null). | |
| 186 // Since the callback invocation in notifyFinished() potentially delete | |
|
haraken
2015/07/02 06:18:06
Another way to avoid this would be to make WorkerS
Takashi Toyoshima
2015/07/02 07:33:56
Yep, originally this class was RefCounted, and I c
| |
| 187 // |this| object, the callback invocation should be postponed until the | |
| 188 // create() call returns. See loadAsynchronously() for the postponed call. | |
| 189 if (m_threadableLoader) | |
| 190 notifyFinished(); | |
| 182 } | 191 } |
| 183 | 192 |
| 184 void WorkerScriptLoader::cancel() | 193 void WorkerScriptLoader::cancel() |
| 185 { | 194 { |
| 186 if (m_threadableLoader) | 195 if (m_threadableLoader) |
| 187 m_threadableLoader->cancel(); | 196 m_threadableLoader->cancel(); |
| 188 } | 197 } |
| 189 | 198 |
| 190 String WorkerScriptLoader::script() | 199 String WorkerScriptLoader::script() |
| 191 { | 200 { |
| 192 return m_script.toString(); | 201 return m_script.toString(); |
| 193 } | 202 } |
| 194 | 203 |
| 195 void WorkerScriptLoader::notifyFinished() | 204 void WorkerScriptLoader::notifyFinished() |
|
haraken
2015/07/02 06:18:06
If this method is invoked only in a case where som
Takashi Toyoshima
2015/07/02 07:33:56
Good point.
Maybe we should use notifyFinished() e
| |
| 196 { | 205 { |
| 197 if (!m_finishedCallback || m_finishing) | 206 ASSERT(m_failed); |
| 207 if (!m_finishedCallback) | |
| 198 return; | 208 return; |
| 199 | 209 |
| 200 m_finishing = true; | 210 OwnPtr<Closure> callback = m_finishedCallback.release(); |
| 201 if (m_finishedCallback) | 211 (*callback)(); |
| 202 (*m_finishedCallback)(); | |
| 203 } | 212 } |
| 204 | 213 |
| 205 void WorkerScriptLoader::processContentSecurityPolicy(const ResourceResponse& re sponse) | 214 void WorkerScriptLoader::processContentSecurityPolicy(const ResourceResponse& re sponse) |
| 206 { | 215 { |
| 207 // Per http://www.w3.org/TR/CSP2/#processing-model-workers, if the Worker's | 216 // Per http://www.w3.org/TR/CSP2/#processing-model-workers, if the Worker's |
| 208 // URL is not a GUID, then it grabs its CSP from the response headers | 217 // URL is not a GUID, then it grabs its CSP from the response headers |
| 209 // directly. Otherwise, the Worker inherits the policy from the parent | 218 // directly. Otherwise, the Worker inherits the policy from the parent |
| 210 // document (which is implemented in WorkerMessagingProxy, and | 219 // document (which is implemented in WorkerMessagingProxy, and |
| 211 // m_contentSecurityPolicy should be left as nullptr to inherit the policy). | 220 // m_contentSecurityPolicy should be left as nullptr to inherit the policy). |
| 212 if (!response.url().protocolIs("blob") && !response.url().protocolIs("file") && !response.url().protocolIs("filesystem")) { | 221 if (!response.url().protocolIs("blob") && !response.url().protocolIs("file") && !response.url().protocolIs("filesystem")) { |
| 213 m_contentSecurityPolicy = ContentSecurityPolicy::create(); | 222 m_contentSecurityPolicy = ContentSecurityPolicy::create(); |
| 214 m_contentSecurityPolicy->setOverrideURLForSelf(response.url()); | 223 m_contentSecurityPolicy->setOverrideURLForSelf(response.url()); |
| 215 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponse Headers(response)); | 224 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponse Headers(response)); |
| 216 } | 225 } |
| 217 } | 226 } |
| 218 | 227 |
| 219 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |