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 wasBlockedByRestrictionsError(const ResourceRequest& request) |
56 | { |
57 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::FrameLoadBlockedByRestrictions, request.url(), WEB_UI_STRING("The URL was blocked by device restrictions" , "WebKitErrorFrameLoadBlockedByRestrictions description" )); |
58 | } |
59 | |
60 | ResourceError interruptedForPolicyChangeError(const ResourceRequest& request) |
61 | { |
62 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::FrameLoadInterruptedByPolicyChange, request.url(), WEB_UI_STRING("Frame load interrupted" , "WebKitErrorFrameLoadInterruptedByPolicyChange description" )); |
63 | } |
64 | |
65 | ResourceError failedCustomProtocolSyncLoad(const ResourceRequest& request) |
66 | { |
67 | return ResourceError(errorDomainWebKitInternal, 0, request.url(), WEB_UI_STRING("Error handling synchronous load with custom protocol" , "Custom protocol synchronous load failure description" )); |
68 | } |
69 | |
70 | #if ENABLE(CONTENT_FILTERING) |
71 | ResourceError blockedByContentFilterError(const ResourceRequest& request) |
72 | { |
73 | return ResourceError(API::Error::webKitPolicyErrorDomain(), API::Error::Policy::FrameLoadBlockedByContentFilter, request.url(), WEB_UI_STRING("The URL was blocked by a content filter" , "WebKitErrorFrameLoadBlockedByContentFilter description" )); |
74 | } |
75 | #endif |
76 | |
77 | ResourceError cannotShowMIMETypeError(const ResourceResponse& response) |
78 | { |
79 | 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" )); |
80 | } |
81 | |
82 | ResourceError pluginWillHandleLoadError(const ResourceResponse& response) |
83 | { |
84 | return ResourceError(API::Error::webKitPluginErrorDomain(), API::Error::Plugin::PlugInWillHandleLoad, response.url(), WEB_UI_STRING("Plug-in handled load" , "WebKitErrorPlugInWillHandleLoad description" )); |
85 | } |
86 | |
87 | ResourceError internalError(const URL& url) |
88 | { |
89 | RELEASE_LOG_ERROR(Loading, "Internal error called" ); |
90 | RELEASE_LOG_STACKTRACE(Loading); |
91 | |
92 | return ResourceError(API::Error::webKitErrorDomain(), API::Error::General::Internal, url, WEB_UI_STRING("WebKit encountered an internal error" , "WebKitErrorInternal description" )); |
93 | } |
94 | |
95 | #if !PLATFORM(COCOA) |
96 | ResourceError cancelledError(const ResourceRequest& request) |
97 | { |
98 | return ResourceError(API::Error::webKitNetworkErrorDomain(), API::Error::Network::Cancelled, request.url(), WEB_UI_STRING("Load request cancelled" , "Load request cancelled" )); |
99 | } |
100 | |
101 | ResourceError fileDoesNotExistError(const ResourceResponse& response) |
102 | { |
103 | return ResourceError(API::Error::webKitNetworkErrorDomain(), API::Error::Network::FileDoesNotExist, response.url(), WEB_UI_STRING("File does not exist" , "The requested file doesn't exist" )); |
104 | } |
105 | #endif |
106 | |
107 | } // namespace WebKit |
108 | |