| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 void FileWriter::stop() | 81 void FileWriter::stop() |
| 82 { | 82 { |
| 83 // Make sure we've actually got something to stop, and haven't already calle
d abort(). | 83 // Make sure we've actually got something to stop, and haven't already calle
d abort(). |
| 84 if (!writer() || m_readyState != WRITING) | 84 if (!writer() || m_readyState != WRITING) |
| 85 return; | 85 return; |
| 86 doOperation(OperationAbort); | 86 doOperation(OperationAbort); |
| 87 m_readyState = DONE; | 87 m_readyState = DONE; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void FileWriter::write(Blob* data, ExceptionState& es) | 90 void FileWriter::write(Blob* data, ExceptionState& exceptionState) |
| 91 { | 91 { |
| 92 ASSERT(writer()); | 92 ASSERT(writer()); |
| 93 ASSERT(data); | 93 ASSERT(data); |
| 94 ASSERT(m_truncateLength == -1); | 94 ASSERT(m_truncateLength == -1); |
| 95 if (m_readyState == WRITING) { | 95 if (m_readyState == WRITING) { |
| 96 setError(FileError::INVALID_STATE_ERR, es); | 96 setError(FileError::INVALID_STATE_ERR, exceptionState); |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 if (!data) { | 99 if (!data) { |
| 100 setError(FileError::TYPE_MISMATCH_ERR, es); | 100 setError(FileError::TYPE_MISMATCH_ERR, exceptionState); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 if (m_recursionDepth > kMaxRecursionDepth) { | 103 if (m_recursionDepth > kMaxRecursionDepth) { |
| 104 setError(FileError::SECURITY_ERR, es); | 104 setError(FileError::SECURITY_ERR, exceptionState); |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 m_blobBeingWritten = data; | 108 m_blobBeingWritten = data; |
| 109 m_readyState = WRITING; | 109 m_readyState = WRITING; |
| 110 m_bytesWritten = 0; | 110 m_bytesWritten = 0; |
| 111 m_bytesToWrite = data->size(); | 111 m_bytesToWrite = data->size(); |
| 112 ASSERT(m_queuedOperation == OperationNone); | 112 ASSERT(m_queuedOperation == OperationNone); |
| 113 if (m_operationInProgress != OperationNone) { | 113 if (m_operationInProgress != OperationNone) { |
| 114 // We must be waiting for an abort to complete, since m_readyState wasn'
t WRITING. | 114 // We must be waiting for an abort to complete, since m_readyState wasn'
t WRITING. |
| 115 ASSERT(m_operationInProgress == OperationAbort); | 115 ASSERT(m_operationInProgress == OperationAbort); |
| 116 m_queuedOperation = OperationWrite; | 116 m_queuedOperation = OperationWrite; |
| 117 } else | 117 } else |
| 118 doOperation(OperationWrite); | 118 doOperation(OperationWrite); |
| 119 | 119 |
| 120 fireEvent(EventTypeNames::writestart); | 120 fireEvent(EventTypeNames::writestart); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void FileWriter::seek(long long position, ExceptionState& es) | 123 void FileWriter::seek(long long position, ExceptionState& exceptionState) |
| 124 { | 124 { |
| 125 ASSERT(writer()); | 125 ASSERT(writer()); |
| 126 if (m_readyState == WRITING) { | 126 if (m_readyState == WRITING) { |
| 127 setError(FileError::INVALID_STATE_ERR, es); | 127 setError(FileError::INVALID_STATE_ERR, exceptionState); |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 | 130 |
| 131 ASSERT(m_truncateLength == -1); | 131 ASSERT(m_truncateLength == -1); |
| 132 ASSERT(m_queuedOperation == OperationNone); | 132 ASSERT(m_queuedOperation == OperationNone); |
| 133 seekInternal(position); | 133 seekInternal(position); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void FileWriter::truncate(long long position, ExceptionState& es) | 136 void FileWriter::truncate(long long position, ExceptionState& exceptionState) |
| 137 { | 137 { |
| 138 ASSERT(writer()); | 138 ASSERT(writer()); |
| 139 ASSERT(m_truncateLength == -1); | 139 ASSERT(m_truncateLength == -1); |
| 140 if (m_readyState == WRITING || position < 0) { | 140 if (m_readyState == WRITING || position < 0) { |
| 141 setError(FileError::INVALID_STATE_ERR, es); | 141 setError(FileError::INVALID_STATE_ERR, exceptionState); |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 if (m_recursionDepth > kMaxRecursionDepth) { | 144 if (m_recursionDepth > kMaxRecursionDepth) { |
| 145 setError(FileError::SECURITY_ERR, es); | 145 setError(FileError::SECURITY_ERR, exceptionState); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 m_readyState = WRITING; | 149 m_readyState = WRITING; |
| 150 m_bytesWritten = 0; | 150 m_bytesWritten = 0; |
| 151 m_bytesToWrite = 0; | 151 m_bytesToWrite = 0; |
| 152 m_truncateLength = position; | 152 m_truncateLength = position; |
| 153 ASSERT(m_queuedOperation == OperationNone); | 153 ASSERT(m_queuedOperation == OperationNone); |
| 154 if (m_operationInProgress != OperationNone) { | 154 if (m_operationInProgress != OperationNone) { |
| 155 // We must be waiting for an abort to complete, since m_readyState wasn'
t WRITING. | 155 // We must be waiting for an abort to complete, since m_readyState wasn'
t WRITING. |
| 156 ASSERT(m_operationInProgress == OperationAbort); | 156 ASSERT(m_operationInProgress == OperationAbort); |
| 157 m_queuedOperation = OperationTruncate; | 157 m_queuedOperation = OperationTruncate; |
| 158 } else | 158 } else |
| 159 doOperation(OperationTruncate); | 159 doOperation(OperationTruncate); |
| 160 fireEvent(EventTypeNames::writestart); | 160 fireEvent(EventTypeNames::writestart); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void FileWriter::abort(ExceptionState& es) | 163 void FileWriter::abort(ExceptionState& exceptionState) |
| 164 { | 164 { |
| 165 ASSERT(writer()); | 165 ASSERT(writer()); |
| 166 if (m_readyState != WRITING) | 166 if (m_readyState != WRITING) |
| 167 return; | 167 return; |
| 168 ++m_numAborts; | 168 ++m_numAborts; |
| 169 | 169 |
| 170 doOperation(OperationAbort); | 170 doOperation(OperationAbort); |
| 171 signalCompletion(FileError::ABORT_ERR); | 171 signalCompletion(FileError::ABORT_ERR); |
| 172 } | 172 } |
| 173 | 173 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 305 } |
| 306 | 306 |
| 307 void FileWriter::fireEvent(const AtomicString& type) | 307 void FileWriter::fireEvent(const AtomicString& type) |
| 308 { | 308 { |
| 309 ++m_recursionDepth; | 309 ++m_recursionDepth; |
| 310 dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWri
te)); | 310 dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWri
te)); |
| 311 --m_recursionDepth; | 311 --m_recursionDepth; |
| 312 ASSERT(m_recursionDepth >= 0); | 312 ASSERT(m_recursionDepth >= 0); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionState& es) | 315 void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionState& except
ionState) |
| 316 { | 316 { |
| 317 ASSERT(errorCode); | 317 ASSERT(errorCode); |
| 318 FileError::throwDOMException(es, errorCode); | 318 FileError::throwDOMException(exceptionState, errorCode); |
| 319 m_error = FileError::create(errorCode); | 319 m_error = FileError::create(errorCode); |
| 320 } | 320 } |
| 321 | 321 |
| 322 } // namespace WebCore | 322 } // namespace WebCore |
| OLD | NEW |