193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/* 293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * modification, are permitted provided that the following conditions are 693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * met: 793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * in the documentation and/or other materials provided with the 1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * distribution. 1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * this software without specific prior written permission. 1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) */ 3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "config.h" 32591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "core/fileapi/FileError.h" 3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 340019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch#include "bindings/v8/ExceptionState.h" 350019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch#include "core/dom/ExceptionCode.h" 360019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace WebCore { 3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 390019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::abortErrorMessage[] = "An ongoing operation was aborted, typically with a call to abort()."; 400019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::encodingErrorMessage[] = "A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs."; 410019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::invalidStateErrorMessage[] = "An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk."; 420019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::noModificationAllowedErrorMessage[] = "An attempt was made to write to a file or directory which could not be modified due to the state of the underlying filesystem."; 430019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::notFoundErrorMessage[] = "A requested file or directory could not be found at the time an operation was processed."; 440019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::notReadableErrorMessage[] = "The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired."; 450019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::pathExistsErrorMessage[] = "An attempt was made to create a file or directory where an element already exists."; 460019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::quotaExceededErrorMessage[] = "The operation failed because it would cause the application to exceed its storage quota."; 470019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::securityErrorMessage[] = "It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources."; 480019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::syntaxErrorMessage[] = "An invalid or unsupported argument was given, like an invalid line ending specifier."; 490019e4eead4d990e4304c54a9028aca9122fb256Ben Murdochconst char FileError::typeMismatchErrorMessage[] = "The path supplied exists, but was not an entry of requested type."; 500019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 51e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)namespace { 520019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 53e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)ExceptionCode errorCodeToExceptionCode(FileError::ErrorCode code) 54e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){ 55e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) switch (code) { 56e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::OK: 57e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return 0; 58e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::NOT_FOUND_ERR: 59e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return NotFoundError; 60e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::SECURITY_ERR: 61e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return SecurityError; 62e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::ABORT_ERR: 63e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return AbortError; 64e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::NOT_READABLE_ERR: 65e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return NotReadableError; 66e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::ENCODING_ERR: 67e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return EncodingError; 68e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::NO_MODIFICATION_ALLOWED_ERR: 69e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return NoModificationAllowedError; 70e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::INVALID_STATE_ERR: 71e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return InvalidStateError; 72e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::SYNTAX_ERR: 73e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return SyntaxError; 74e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::INVALID_MODIFICATION_ERR: 75e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return InvalidModificationError; 76e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::QUOTA_EXCEEDED_ERR: 77e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return QuotaExceededError; 78e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::TYPE_MISMATCH_ERR: 79e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return TypeMismatchError; 80e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::PATH_EXISTS_ERR: 81e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return PathExistsError; 82e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) default: 83e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) ASSERT_NOT_REACHED(); 84e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return code; 85e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) } 86e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)} 870019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 88e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)const char* errorCodeToMessage(FileError::ErrorCode code) 89e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){ 900019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch // Note that some of these do not set message. If message is 0 then the default message is used. 91591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch switch (code) { 92e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::OK: 93e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return 0; 940019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::SECURITY_ERR: 95e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::securityErrorMessage; 96e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) case FileError::NOT_FOUND_ERR: 97e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::notFoundErrorMessage; 980019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::ABORT_ERR: 99e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::abortErrorMessage; 1000019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::NOT_READABLE_ERR: 101e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::notReadableErrorMessage; 1020019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::ENCODING_ERR: 103e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::encodingErrorMessage; 1040019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::NO_MODIFICATION_ALLOWED_ERR: 105e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::noModificationAllowedErrorMessage; 1060019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::INVALID_STATE_ERR: 107e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::invalidStateErrorMessage; 1080019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::SYNTAX_ERR: 109e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::syntaxErrorMessage; 1100019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::INVALID_MODIFICATION_ERR: 111e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return 0; 1120019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::QUOTA_EXCEEDED_ERR: 113e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::quotaExceededErrorMessage; 1140019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::TYPE_MISMATCH_ERR: 115e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return 0; 1160019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch case FileError::PATH_EXISTS_ERR: 117e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return FileError::pathExistsErrorMessage; 118591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch default: 119591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch ASSERT_NOT_REACHED(); 120e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return 0; 121e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) } 122e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)} 123e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 124e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)} // namespace 125e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 12651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void FileError::throwDOMException(ExceptionState& exceptionState, ErrorCode code) 127e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){ 128e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) if (code == FileError::OK) 129e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) return; 130e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 131e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) // SecurityError is special-cased, as we want to route those exceptions through ExceptionState::throwSecurityError. 132e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) if (code == FileError::SECURITY_ERR) { 13351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) exceptionState.throwSecurityError(FileError::securityErrorMessage); 1340019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch return; 135591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch } 1360019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 13751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) exceptionState.throwDOMException(errorCodeToExceptionCode(code), errorCodeToMessage(code)); 138e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)} 139e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 140e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)FileError::FileError(ErrorCode code) 141e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) : DOMError(DOMException::getErrorName(errorCodeToExceptionCode(code)), errorCodeToMessage(code)) 142e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) , m_code(code) 143e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){ 144e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) ScriptWrappable::init(this); 145591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch} 146591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 14793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} // namespace WebCore 148