1/* 2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 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 13 * distribution. 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. 17 * 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. 29 */ 30 31#include "config.h" 32#include "core/fileapi/FileError.h" 33 34#include "bindings/v8/ExceptionState.h" 35#include "core/dom/ExceptionCode.h" 36 37namespace WebCore { 38 39const char FileError::abortErrorMessage[] = "An ongoing operation was aborted, typically with a call to abort()."; 40const 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."; 41const 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."; 42const 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."; 43const char FileError::notFoundErrorMessage[] = "A requested file or directory could not be found at the time an operation was processed."; 44const 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."; 45const char FileError::pathExistsErrorMessage[] = "An attempt was made to create a file or directory where an element already exists."; 46const char FileError::quotaExceededErrorMessage[] = "The operation failed because it would cause the application to exceed its storage quota."; 47const 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."; 48const char FileError::syntaxErrorMessage[] = "An invalid or unsupported argument was given, like an invalid line ending specifier."; 49const char FileError::typeMismatchErrorMessage[] = "The path supplied exists, but was not an entry of requested type."; 50 51void FileError::throwDOMException(ExceptionState& es, ErrorCode code) 52{ 53 if (code == FileError::OK) 54 return; 55 56 ExceptionCode ec; 57 const char* message = 0; 58 59 // Note that some of these do not set message. If message is 0 then the default message is used. 60 switch (code) { 61 case FileError::NOT_FOUND_ERR: 62 ec = NotFoundError; 63 message = FileError::notFoundErrorMessage; 64 break; 65 case FileError::SECURITY_ERR: 66 ec = SecurityError; 67 message = FileError::securityErrorMessage; 68 break; 69 case FileError::ABORT_ERR: 70 ec = AbortError; 71 message = FileError::abortErrorMessage; 72 break; 73 case FileError::NOT_READABLE_ERR: 74 ec = NotReadableError; 75 message = FileError::notReadableErrorMessage; 76 break; 77 case FileError::ENCODING_ERR: 78 ec = EncodingError; 79 message = FileError::encodingErrorMessage; 80 break; 81 case FileError::NO_MODIFICATION_ALLOWED_ERR: 82 ec = NoModificationAllowedError; 83 message = FileError::noModificationAllowedErrorMessage; 84 break; 85 case FileError::INVALID_STATE_ERR: 86 ec = InvalidStateError; 87 message = FileError::invalidStateErrorMessage; 88 break; 89 case FileError::SYNTAX_ERR: 90 ec = SyntaxError; 91 message = FileError::syntaxErrorMessage; 92 break; 93 case FileError::INVALID_MODIFICATION_ERR: 94 ec = InvalidModificationError; 95 break; 96 case FileError::QUOTA_EXCEEDED_ERR: 97 ec = QuotaExceededError; 98 message = FileError::quotaExceededErrorMessage; 99 break; 100 case FileError::TYPE_MISMATCH_ERR: 101 ec = TypeMismatchError; 102 break; 103 case FileError::PATH_EXISTS_ERR: 104 ec = PathExistsError; 105 message = FileError::pathExistsErrorMessage; 106 break; 107 default: 108 ASSERT_NOT_REACHED(); 109 return; 110 } 111 112 es.throwDOMException(ec, message); 113} 114 115} // namespace WebCore 116