| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 Blob::~Blob() | 75 Blob::~Blob() |
| 76 { | 76 { |
| 77 } | 77 } |
| 78 | 78 |
| 79 PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte
ntType) const | 79 PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte
ntType) const |
| 80 { | 80 { |
| 81 // When we slice a file for the first time, we obtain a snapshot of the file
by capturing its current size and modification time. | 81 // When we slice a file for the first time, we obtain a snapshot of the file
by capturing its current size and modification time. |
| 82 // The modification time will be used to verify if the file has been changed
or not, when the underlying data are accessed. | 82 // The modification time will be used to verify if the file has been changed
or not, when the underlying data are accessed. |
| 83 long long size; | 83 long long size; |
| 84 double modificationTime; | 84 double modificationTime; |
| 85 if (isFile()) { | 85 if (hasBackingFile()) { |
| 86 // FIXME: This involves synchronous file operation. We need to figure ou
t how to make it asynchronous. | 86 // FIXME: This involves synchronous file operation. We need to figure ou
t how to make it asynchronous. |
| 87 toFile(this)->captureSnapshot(size, modificationTime); | 87 toFile(this)->captureSnapshot(size, modificationTime); |
| 88 } else { | 88 } else { |
| 89 size = this->size(); | 89 size = this->size(); |
| 90 ASSERT(size != -1); | 90 ASSERT(size != -1); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Convert the negative value that is used to select from the end. | 93 // Convert the negative value that is used to select from the end. |
| 94 if (start < 0) | 94 if (start < 0) |
| 95 start = start + size; | 95 start = start + size; |
| 96 if (end < 0) | 96 if (end < 0) |
| 97 end = end + size; | 97 end = end + size; |
| 98 | 98 |
| 99 // Clamp the range if it exceeds the size limit. | 99 // Clamp the range if it exceeds the size limit. |
| 100 if (start < 0) | 100 if (start < 0) |
| 101 start = 0; | 101 start = 0; |
| 102 if (end < 0) | 102 if (end < 0) |
| 103 end = 0; | 103 end = 0; |
| 104 if (start >= size) { | 104 if (start >= size) { |
| 105 start = 0; | 105 start = 0; |
| 106 end = 0; | 106 end = 0; |
| 107 } else if (end < start) | 107 } else if (end < start) |
| 108 end = start; | 108 end = start; |
| 109 else if (end > size) | 109 else if (end > size) |
| 110 end = size; | 110 end = size; |
| 111 | 111 |
| 112 long long length = end - start; | 112 long long length = end - start; |
| 113 OwnPtr<BlobData> blobData = BlobData::create(); | 113 OwnPtr<BlobData> blobData = BlobData::create(); |
| 114 blobData->setContentType(contentType); | 114 blobData->setContentType(contentType); |
| 115 if (isFile()) { | 115 if (hasBackingFile()) { |
| 116 if (!toFile(this)->fileSystemURL().isEmpty()) | 116 if (!toFile(this)->fileSystemURL().isEmpty()) |
| 117 blobData->appendFileSystemURL(toFile(this)->fileSystemURL(), start,
length, modificationTime); | 117 blobData->appendFileSystemURL(toFile(this)->fileSystemURL(), start,
length, modificationTime); |
| 118 else | 118 else |
| 119 blobData->appendFile(toFile(this)->path(), start, length, modificati
onTime); | 119 blobData->appendFile(toFile(this)->path(), start, length, modificati
onTime); |
| 120 } else { | 120 } else { |
| 121 blobData->appendBlob(m_blobDataHandle, start, length); | 121 blobData->appendBlob(m_blobDataHandle, start, length); |
| 122 } | 122 } |
| 123 return Blob::create(BlobDataHandle::create(blobData.release(), length)); | 123 return Blob::create(BlobDataHandle::create(blobData.release(), length)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 URLRegistry& Blob::registry() const | 126 URLRegistry& Blob::registry() const |
| 127 { | 127 { |
| 128 return BlobURLRegistry::registry(); | 128 return BlobURLRegistry::registry(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 } // namespace WebCore | 132 } // namespace WebCore |
| OLD | NEW |