| 1 | /* |
| 2 | * Copyright (C) 2010-2016 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2017 Igalia S.L. |
| 4 | * Copyright (C) 2018 Sony Interactive Entertainment Inc. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 17 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 19 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 25 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "WebErrors.h" |
| 30 | |
| 31 | #include "APIError.h" |
| 32 | #include "Logging.h" |
| 33 | #include <WebCore/LocalizedStrings.h> |
| 34 | #include <WebCore/ResourceRequest.h> |
| 35 | #include <WebCore/ResourceResponse.h> |
| 36 | |
| 37 | namespace WebKit { |
| 38 | using namespace WebCore; |
| 39 | |
| 40 | ResourceError blockedError(const ResourceRequest& request) |
| 41 | { |
| 42 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::CannotUseRestrictedPort, request.url(), WEB_UI_STRING("Not allowed to use restricted network port" , "WebKitErrorCannotUseRestrictedPort description" )); |
| 43 | } |
| 44 | |
| 45 | ResourceError blockedByContentBlockerError(const ResourceRequest& request) |
| 46 | { |
| 47 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::FrameLoadBlockedByContentBlocker, request.url(), WEB_UI_STRING("The URL was blocked by a content blocker" , "WebKitErrorBlockedByContentBlocker description" )); |
| 48 | } |
| 49 | |
| 50 | ResourceError cannotShowURLError(const ResourceRequest& request) |
| 51 | { |
| 52 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::CannotShowURL, request.url(), WEB_UI_STRING("The URL can’t be shown" , "WebKitErrorCannotShowURL description" )); |
| 53 | } |
| 54 | |
| 55 | ResourceError interruptedForPolicyChangeError(const ResourceRequest& request) |
| 56 | { |
| 57 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::FrameLoadInterruptedByPolicyChange, request.url(), WEB_UI_STRING("Frame load interrupted" , "WebKitErrorFrameLoadInterruptedByPolicyChange description" )); |
| 58 | } |
| 59 | |
| 60 | ResourceError failedCustomProtocolSyncLoad(const ResourceRequest& request) |
| 61 | { |
| 62 | return ResourceError(errorDomainWebKitInternal, 0, request.url(), WEB_UI_STRING("Error handling synchronous load with custom protocol" , "Custom protocol synchronous load failure description" )); |
| 63 | } |
| 64 | |
| 65 | #if ENABLE(CONTENT_FILTERING) |
| 66 | ResourceError blockedByContentFilterError(const ResourceRequest& request) |
| 67 | { |
| 68 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::FrameLoadBlockedByContentFilter, request.url(), WEB_UI_STRING("The URL was blocked by a content filter" , "WebKitErrorFrameLoadBlockedByContentFilter description" )); |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | ResourceError cannotShowMIMETypeError(const ResourceResponse& response) |
| 73 | { |
| 74 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::CannotShowMIMEType, response.url(), WEB_UI_STRING("Content with specified MIME type can’t be shown" , "WebKitErrorCannotShowMIMEType description" )); |
| 75 | } |
| 76 | |
| 77 | ResourceError pluginWillHandleLoadError(const ResourceResponse& response) |
| 78 | { |
| 79 | return ResourceError(API::Error::webKitPluginErrorDomain(), API::Error::Plugin::PlugInWillHandleLoad, response.url(), WEB_UI_STRING("Plug-in handled load" , "WebKitErrorPlugInWillHandleLoad description" )); |
| 80 | } |
| 81 | |
| 82 | ResourceError internalError(const URL& url) |
| 83 | { |
| 84 | RELEASE_LOG_ERROR(Loading, "Internal error called" ); |
| 85 | RELEASE_LOG_STACKTRACE(Loading); |
| 86 | |
| 87 | return ResourceError(API::Error::webKitErrorDomain(), API::Error::General::Internal, url, WEB_UI_STRING("WebKit encountered an internal error" , "WebKitErrorInternal description" )); |
| 88 | } |
| 89 | |
| 90 | #if !PLATFORM(COCOA) |
| 91 | ResourceError cancelledError(const ResourceRequest& request) |
| 92 | { |
| 93 | return ResourceError(API::Error::webKitNetworkErrorDomain(), API::Error::Network::Cancelled, request.url(), WEB_UI_STRING("Load request cancelled" , "Load request cancelled" )); |
| 94 | } |
| 95 | |
| 96 | ResourceError fileDoesNotExistError(const ResourceResponse& response) |
| 97 | { |
| 98 | return ResourceError(API::Error::webKitNetworkErrorDomain(), API::Error::Network::FileDoesNotExist, response.url(), WEB_UI_STRING("File does not exist" , "The requested file doesn't exist" )); |
| 99 | } |
| 100 | #endif |
| 101 | |
| 102 | } // namespace WebKit |
| 103 | |