| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "BlobURL.h" | 34 #include "BlobURL.h" |
| 35 #include "File.h" | 35 #include "File.h" |
| 36 #include "HistogramSupport.h" | 36 #include "HistogramSupport.h" |
| 37 #include "ScriptCallStack.h" | 37 #include "ScriptCallStack.h" |
| 38 #include "ScriptExecutionContext.h" | 38 #include "ScriptExecutionContext.h" |
| 39 #include "ThreadableBlobRegistry.h" | 39 #include "ThreadableBlobRegistry.h" |
| 40 | 40 |
| 41 namespace WebCore { | 41 namespace WebCore { |
| 42 | 42 |
| 43 namespace { | 43 Blob::Blob(PassRefPtr<BlobDataHandle> dataHandle) |
| 44 | 44 : m_blobDataHandle(dataHandle) |
| 45 // Used in histograms to see when we can actually deprecate the prefixed slice. | |
| 46 enum SliceHistogramEnum { | |
| 47 SliceWithoutPrefix, | |
| 48 SliceWithPrefix, | |
| 49 SliceHistogramEnumMax, | |
| 50 }; | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 Blob::Blob() | |
| 55 : m_size(0) | |
| 56 { | 45 { |
| 57 OwnPtr<BlobData> blobData = BlobData::create(); | 46 ASSERT(m_blobDataHandle); |
| 58 | |
| 59 // Create a new internal URL and register it with the provided blob data. | |
| 60 m_internalURL = BlobURL::createInternalURL(); | |
| 61 ThreadableBlobRegistry::registerBlobURL(m_internalURL, blobData.release()); | |
| 62 } | |
| 63 | |
| 64 Blob::Blob(PassOwnPtr<BlobData> blobData, long long size) | |
| 65 : m_type(blobData->contentType()) | |
| 66 , m_size(size) | |
| 67 { | |
| 68 ASSERT(blobData); | |
| 69 | |
| 70 // Create a new internal URL and register it with the provided blob data. | |
| 71 m_internalURL = BlobURL::createInternalURL(); | |
| 72 ThreadableBlobRegistry::registerBlobURL(m_internalURL, blobData); | |
| 73 } | |
| 74 | |
| 75 Blob::Blob(const KURL& srcURL, const String& type, long long size) | |
| 76 : m_type(type) | |
| 77 , m_size(size) | |
| 78 { | |
| 79 // Create a new internal URL and register it with the same blob data as the
source URL. | |
| 80 m_internalURL = BlobURL::createInternalURL(); | |
| 81 ThreadableBlobRegistry::registerBlobURL(0, m_internalURL, srcURL); | |
| 82 } | 47 } |
| 83 | 48 |
| 84 Blob::~Blob() | 49 Blob::~Blob() |
| 85 { | 50 { |
| 86 ThreadableBlobRegistry::unregisterBlobURL(m_internalURL); | |
| 87 } | 51 } |
| 88 | 52 |
| 89 #if ENABLE(BLOB) | 53 #if ENABLE(BLOB) |
| 90 PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte
ntType) const | 54 PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte
ntType) const |
| 91 { | 55 { |
| 92 // When we slice a file for the first time, we obtain a snapshot of the file
by capturing its current size and modification time. | 56 // When we slice a file for the first time, we obtain a snapshot of the file
by capturing its current size and modification time. |
| 93 // The modification time will be used to verify if the file has been changed
or not, when the underlying data are accessed. | 57 // The modification time will be used to verify if the file has been changed
or not, when the underlying data are accessed. |
| 94 long long size; | 58 long long size; |
| 95 double modificationTime; | 59 double modificationTime; |
| 96 if (isFile()) { | 60 if (isFile()) { |
| 97 // FIXME: This involves synchronous file operation. We need to figure ou
t how to make it asynchronous. | 61 // FIXME: This involves synchronous file operation. We need to figure ou
t how to make it asynchronous. |
| 98 toFile(this)->captureSnapshot(size, modificationTime); | 62 toFile(this)->captureSnapshot(size, modificationTime); |
| 99 } else { | 63 } else { |
| 100 ASSERT(m_size != -1); | 64 size = this->size(); |
| 101 size = m_size; | 65 ASSERT(size != -1); |
| 102 } | 66 } |
| 103 | 67 |
| 104 // Convert the negative value that is used to select from the end. | 68 // Convert the negative value that is used to select from the end. |
| 105 if (start < 0) | 69 if (start < 0) |
| 106 start = start + size; | 70 start = start + size; |
| 107 if (end < 0) | 71 if (end < 0) |
| 108 end = end + size; | 72 end = end + size; |
| 109 | 73 |
| 110 // Clamp the range if it exceeds the size limit. | 74 // Clamp the range if it exceeds the size limit. |
| 111 if (start < 0) | 75 if (start < 0) |
| 112 start = 0; | 76 start = 0; |
| 113 if (end < 0) | 77 if (end < 0) |
| 114 end = 0; | 78 end = 0; |
| 115 if (start >= size) { | 79 if (start >= size) { |
| 116 start = 0; | 80 start = 0; |
| 117 end = 0; | 81 end = 0; |
| 118 } else if (end < start) | 82 } else if (end < start) |
| 119 end = start; | 83 end = start; |
| 120 else if (end > size) | 84 else if (end > size) |
| 121 end = size; | 85 end = size; |
| 122 | 86 |
| 123 long long length = end - start; | 87 long long length = end - start; |
| 124 OwnPtr<BlobData> blobData = BlobData::create(); | 88 OwnPtr<BlobData> blobData = BlobData::create(); |
| 125 blobData->setContentType(contentType); | 89 blobData->setContentType(contentType); |
| 126 if (isFile()) { | 90 if (isFile()) { |
| 127 #if ENABLE(FILE_SYSTEM) | 91 #if ENABLE(FILE_SYSTEM) |
| 128 if (!toFile(this)->fileSystemURL().isEmpty()) | 92 if (!toFile(this)->fileSystemURL().isEmpty()) |
| 129 blobData->appendURL(toFile(this)->fileSystemURL(), start, length, mo
dificationTime); | 93 blobData->appendFileSystemURL(toFile(this)->fileSystemURL(), start,
length, modificationTime); |
| 130 else | 94 else |
| 131 #endif | 95 #endif |
| 132 blobData->appendFile(toFile(this)->path(), start, length, modificationTi
me); | 96 blobData->appendFile(toFile(this)->path(), start, length, modificationTi
me); |
| 133 } else | 97 } else |
| 134 blobData->appendBlob(m_internalURL, start, length); | 98 blobData->appendBlob(m_blobDataHandle, start, length); |
| 135 | 99 |
| 136 return Blob::create(blobData.release(), length); | 100 return Blob::create(BlobDataHandle::create(blobData.release(), length)); |
| 137 } | 101 } |
| 138 #endif | 102 #endif |
| 139 | 103 |
| 140 } // namespace WebCore | 104 } // namespace WebCore |
| OLD | NEW |