Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "core/fileapi/FileReaderLoader.h" | 33 #include "core/fileapi/FileReaderLoader.h" |
| 34 | 34 |
| 35 #include "core/dom/ScriptExecutionContext.h" | 35 #include "core/dom/ScriptExecutionContext.h" |
| 36 #include "core/fileapi/Blob.h" | 36 #include "core/fileapi/Blob.h" |
| 37 #include "core/fileapi/BlobRegistry.h" | 37 #include "core/fileapi/BlobRegistry.h" |
| 38 #include "core/fileapi/BlobURL.h" | 38 #include "core/fileapi/BlobURL.h" |
| 39 #include "core/fileapi/FileReaderLoaderClient.h" | 39 #include "core/fileapi/FileReaderLoaderClient.h" |
| 40 #include "core/fileapi/Stream.h" | |
| 40 #include "core/loader/TextResourceDecoder.h" | 41 #include "core/loader/TextResourceDecoder.h" |
| 41 #include "core/loader/ThreadableLoader.h" | 42 #include "core/loader/ThreadableLoader.h" |
| 42 #include "core/platform/network/ResourceRequest.h" | 43 #include "core/platform/network/ResourceRequest.h" |
| 43 #include "core/platform/network/ResourceResponse.h" | 44 #include "core/platform/network/ResourceResponse.h" |
| 44 #include <wtf/ArrayBuffer.h> | 45 #include <wtf/ArrayBuffer.h> |
| 45 #include <wtf/PassRefPtr.h> | 46 #include <wtf/PassRefPtr.h> |
| 46 #include <wtf/RefPtr.h> | 47 #include <wtf/RefPtr.h> |
| 47 #include <wtf/text/Base64.h> | 48 #include <wtf/text/Base64.h> |
| 48 #include <wtf/text/StringBuilder.h> | 49 #include <wtf/text/StringBuilder.h> |
| 49 #include <wtf/Vector.h> | 50 #include <wtf/Vector.h> |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 69 { | 70 { |
| 70 } | 71 } |
| 71 | 72 |
| 72 FileReaderLoader::~FileReaderLoader() | 73 FileReaderLoader::~FileReaderLoader() |
| 73 { | 74 { |
| 74 terminate(); | 75 terminate(); |
| 75 if (!m_urlForReading.isEmpty()) | 76 if (!m_urlForReading.isEmpty()) |
| 76 BlobRegistry::unregisterBlobURL(m_urlForReading); | 77 BlobRegistry::unregisterBlobURL(m_urlForReading); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Blo b* blob) | 80 void FileReaderLoader::startForURL(ScriptExecutionContext* scriptExecutionContex t, const KURL& url) |
| 80 { | 81 { |
| 81 // The blob is read by routing through the request handling layer given a te mporary public url. | 82 // The blob is read by routing through the request handling layer given a te mporary public url. |
| 82 m_urlForReading = BlobURL::createPublicURL(scriptExecutionContext->securityO rigin()); | 83 m_urlForReading = BlobURL::createPublicURL(scriptExecutionContext->securityO rigin()); |
| 83 if (m_urlForReading.isEmpty()) { | 84 if (m_urlForReading.isEmpty()) { |
| 84 failed(FileError::SECURITY_ERR); | 85 failed(FileError::SECURITY_ERR); |
| 85 return; | 86 return; |
| 86 } | 87 } |
| 87 BlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_ur lForReading, blob->url()); | 88 BlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_ur lForReading, url); |
| 88 | 89 |
| 89 // Construct and load the request. | 90 // Construct and load the request. |
| 90 ResourceRequest request(m_urlForReading); | 91 ResourceRequest request(m_urlForReading); |
| 91 request.setHTTPMethod("GET"); | 92 request.setHTTPMethod("GET"); |
| 92 if (m_hasRange) | 93 if (m_hasRange) |
| 93 request.setHTTPHeaderField("Range", String::format("bytes=%d-%d", m_rang eStart, m_rangeEnd)); | 94 request.setHTTPHeaderField("Range", String::format("bytes=%d-%d", m_rang eStart, m_rangeEnd)); |
| 94 | 95 |
| 95 ThreadableLoaderOptions options; | 96 ThreadableLoaderOptions options; |
| 96 options.sendLoadCallbacks = SendCallbacks; | 97 options.sendLoadCallbacks = SendCallbacks; |
| 97 options.sniffContent = DoNotSniffContent; | 98 options.sniffContent = DoNotSniffContent; |
| 98 options.preflightPolicy = ConsiderPreflight; | 99 options.preflightPolicy = ConsiderPreflight; |
| 99 options.allowCredentials = AllowStoredCredentials; | 100 options.allowCredentials = AllowStoredCredentials; |
| 100 options.crossOriginRequestPolicy = DenyCrossOriginRequests; | 101 options.crossOriginRequestPolicy = DenyCrossOriginRequests; |
| 101 // FIXME: Is there a directive to which this load should be subject? | 102 // FIXME: Is there a directive to which this load should be subject? |
| 102 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy ; | 103 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy ; |
| 103 | 104 |
| 104 if (m_client) | 105 if (m_client) |
| 105 m_loader = ThreadableLoader::create(scriptExecutionContext, this, reques t, options); | 106 m_loader = ThreadableLoader::create(scriptExecutionContext, this, reques t, options); |
| 106 else | 107 else |
| 107 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext, requ est, *this, options); | 108 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext, requ est, *this, options); |
| 108 } | 109 } |
| 109 | 110 |
| 111 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Blo b* blob) | |
| 112 { | |
| 113 startForURL(scriptExecutionContext, blob->url()); | |
| 114 } | |
| 115 | |
| 116 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Str eam* stream) | |
|
tkent
2013/07/12 09:03:49
nit: We assume |steram| is non-0. So we had bette
tyoshino (SeeGerritForStatus)
2013/07/12 11:15:17
Done
| |
| 117 { | |
| 118 startForURL(scriptExecutionContext, stream->url()); | |
| 119 } | |
| 120 | |
| 110 void FileReaderLoader::cancel() | 121 void FileReaderLoader::cancel() |
| 111 { | 122 { |
| 112 m_errorCode = FileError::ABORT_ERR; | 123 m_errorCode = FileError::ABORT_ERR; |
| 113 terminate(); | 124 terminate(); |
| 114 } | 125 } |
| 115 | 126 |
| 116 void FileReaderLoader::terminate() | 127 void FileReaderLoader::terminate() |
| 117 { | 128 { |
| 118 if (m_loader) { | 129 if (m_loader) { |
| 119 m_loader->cancel(); | 130 m_loader->cancel(); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 void FileReaderLoader::setRange(unsigned start, unsigned length) | 399 void FileReaderLoader::setRange(unsigned start, unsigned length) |
| 389 { | 400 { |
| 390 ASSERT(length > 0); | 401 ASSERT(length > 0); |
| 391 m_hasRange = true; | 402 m_hasRange = true; |
| 392 m_rangeStart = start; | 403 m_rangeStart = start; |
| 393 m_rangeEnd = start + length - 1; | 404 m_rangeEnd = start + length - 1; |
| 394 } | 405 } |
| 395 #endif // ENABLE(STREAM) | 406 #endif // ENABLE(STREAM) |
| 396 | 407 |
| 397 } // namespace WebCore | 408 } // namespace WebCore |
| OLD | NEW |