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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 m_threadableLoader->cancel(); | 189 m_threadableLoader->cancel(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 String WorkerScriptLoader::script() | 192 String WorkerScriptLoader::script() |
| 191 { | 193 { |
| 192 return m_script.toString(); | 194 return m_script.toString(); |
| 193 } | 195 } |
| 194 | 196 |
| 195 void WorkerScriptLoader::notifyFinished() | 197 void WorkerScriptLoader::notifyFinished() |
| 196 { | 198 { |
| 197 if (!m_finishedCallback || m_finishing) | 199 ASSERT(m_failed); |
| 200 if (!m_finishedCallback) | |
| 198 return; | 201 return; |
| 199 | 202 |
| 200 m_finishing = true; | 203 // notifyError() would be called before ThreadableLoader::create() returns |
|
kinuko
2015/07/01 08:11:15
nit: would be -> could be ?
Takashi Toyoshima
2015/07/02 05:55:03
Done.
| |
| 201 if (m_finishedCallback) | 204 // e.g., from didFail(). Since m_finishedCallback potentially delete this |
|
kinuko
2015/07/01 08:11:15
could we also clearly note that null m_threadableL
Takashi Toyoshima
2015/07/02 05:55:03
Done.
| |
| 202 (*m_finishedCallback)(); | 205 // object, the callback invocation should be postponed until the create() |
| 206 // call returns. | |
| 207 if (!m_threadableLoader) | |
| 208 return; | |
| 209 | |
| 210 OwnPtr<Closure> callback = m_finishedCallback.release(); | |
| 211 (*callback)(); | |
| 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 |