2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/fileapi/FileError.h"
34 #include "bindings/core/v8/ExceptionState.h"
35 #include "core/dom/ExceptionCode.h"
39 const char FileError::abortErrorMessage[] = "An ongoing operation was aborted, typically with a call to abort().";
40 const 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.";
41 const 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.";
42 const 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.";
43 const char FileError::notFoundErrorMessage[] = "A requested file or directory could not be found at the time an operation was processed.";
44 const 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.";
45 const char FileError::pathExistsErrorMessage[] = "An attempt was made to create a file or directory where an element already exists.";
46 const char FileError::quotaExceededErrorMessage[] = "The operation failed because it would cause the application to exceed its storage quota.";
47 const 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.";
48 const char FileError::syntaxErrorMessage[] = "An invalid or unsupported argument was given, like an invalid line ending specifier.";
49 const char FileError::typeMismatchErrorMessage[] = "The path supplied exists, but was not an entry of requested type.";
53 ExceptionCode errorCodeToExceptionCode(FileError::ErrorCode code)
58 case FileError::NOT_FOUND_ERR:
60 case FileError::SECURITY_ERR:
62 case FileError::ABORT_ERR:
64 case FileError::NOT_READABLE_ERR:
65 return NotReadableError;
66 case FileError::ENCODING_ERR:
68 case FileError::NO_MODIFICATION_ALLOWED_ERR:
69 return NoModificationAllowedError;
70 case FileError::INVALID_STATE_ERR:
71 return InvalidStateError;
72 case FileError::SYNTAX_ERR:
74 case FileError::INVALID_MODIFICATION_ERR:
75 return InvalidModificationError;
76 case FileError::QUOTA_EXCEEDED_ERR:
77 return QuotaExceededError;
78 case FileError::TYPE_MISMATCH_ERR:
79 return TypeMismatchError;
80 case FileError::PATH_EXISTS_ERR:
81 return PathExistsError;
88 const char* errorCodeToMessage(FileError::ErrorCode code)
90 // Note that some of these do not set message. If message is 0 then the default message is used.
94 case FileError::SECURITY_ERR:
95 return FileError::securityErrorMessage;
96 case FileError::NOT_FOUND_ERR:
97 return FileError::notFoundErrorMessage;
98 case FileError::ABORT_ERR:
99 return FileError::abortErrorMessage;
100 case FileError::NOT_READABLE_ERR:
101 return FileError::notReadableErrorMessage;
102 case FileError::ENCODING_ERR:
103 return FileError::encodingErrorMessage;
104 case FileError::NO_MODIFICATION_ALLOWED_ERR:
105 return FileError::noModificationAllowedErrorMessage;
106 case FileError::INVALID_STATE_ERR:
107 return FileError::invalidStateErrorMessage;
108 case FileError::SYNTAX_ERR:
109 return FileError::syntaxErrorMessage;
110 case FileError::INVALID_MODIFICATION_ERR:
112 case FileError::QUOTA_EXCEEDED_ERR:
113 return FileError::quotaExceededErrorMessage;
114 case FileError::TYPE_MISMATCH_ERR:
116 case FileError::PATH_EXISTS_ERR:
117 return FileError::pathExistsErrorMessage;
119 ASSERT_NOT_REACHED();
126 void FileError::throwDOMException(ExceptionState& exceptionState, ErrorCode code)
128 if (code == FileError::OK)
131 // SecurityError is special-cased, as we want to route those exceptions through ExceptionState::throwSecurityError.
132 if (code == FileError::SECURITY_ERR) {
133 exceptionState.throwSecurityError(FileError::securityErrorMessage);
137 exceptionState.throwDOMException(errorCodeToExceptionCode(code), errorCodeToMessage(code));
140 FileError::FileError(ErrorCode code)
141 : DOMError(DOMException::getErrorName(errorCodeToExceptionCode(code)), errorCodeToMessage(code))
144 ScriptWrappable::init(this);