1 | /* |
2 | * Copyright (C) 2010 Apple 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 |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "WKErrorRef.h" |
28 | |
29 | #include "APIError.h" |
30 | #include "WKAPICast.h" |
31 | |
32 | WKTypeID WKErrorGetTypeID() |
33 | { |
34 | return WebKit::toAPI(API::Error::APIType); |
35 | } |
36 | |
37 | WKStringRef WKErrorCopyWKErrorDomain() |
38 | { |
39 | return WebKit::toCopiedAPI(API::Error::webKitErrorDomain()); |
40 | } |
41 | |
42 | WKStringRef WKErrorCopyDomain(WKErrorRef errorRef) |
43 | { |
44 | return WebKit::toCopiedAPI(WebKit::toImpl(errorRef)->domain()); |
45 | } |
46 | |
47 | int WKErrorGetErrorCode(WKErrorRef errorRef) |
48 | { |
49 | auto errorCode = WebKit::toImpl(errorRef)->errorCode(); |
50 | switch (errorCode) { |
51 | case API::Error::Policy::CannotShowMIMEType: |
52 | return kWKErrorCodeCannotShowMIMEType; |
53 | case API::Error::Policy::CannotShowURL: |
54 | return kWKErrorCodeCannotShowURL; |
55 | case API::Error::Policy::FrameLoadInterruptedByPolicyChange: |
56 | return kWKErrorCodeFrameLoadInterruptedByPolicyChange; |
57 | case API::Error::Policy::CannotUseRestrictedPort: |
58 | return kWKErrorCodeCannotUseRestrictedPort; |
59 | case API::Error::Policy::FrameLoadBlockedByContentBlocker: |
60 | return kWKErrorCodeFrameLoadBlockedByContentBlocker; |
61 | case API::Error::Policy::FrameLoadBlockedByRestrictions: |
62 | return kWKErrorCodeFrameLoadBlockedByRestrictions; |
63 | case API::Error::Policy::FrameLoadBlockedByContentFilter: |
64 | return kWKErrorCodeFrameLoadBlockedByContentFilter; |
65 | case API::Error::Plugin::CannotFindPlugIn: |
66 | return kWKErrorCodeCannotFindPlugIn; |
67 | case API::Error::Plugin::CannotLoadPlugIn: |
68 | return kWKErrorCodeCannotLoadPlugIn; |
69 | case API::Error::Plugin::JavaUnavailable: |
70 | return kWKErrorCodeJavaUnavailable; |
71 | case API::Error::Plugin::PlugInCancelledConnection: |
72 | return kWKErrorCodePlugInCancelledConnection; |
73 | case API::Error::Plugin::PlugInWillHandleLoad: |
74 | return kWKErrorCodePlugInWillHandleLoad; |
75 | case API::Error::Plugin::InsecurePlugInVersion: |
76 | return kWKErrorCodeInsecurePlugInVersion; |
77 | case API::Error::General::Internal: |
78 | return kWKErrorInternal; |
79 | } |
80 | |
81 | return errorCode; |
82 | } |
83 | |
84 | WKURLRef WKErrorCopyFailingURL(WKErrorRef errorRef) |
85 | { |
86 | return WebKit::toCopiedURLAPI(WebKit::toImpl(errorRef)->failingURL()); |
87 | } |
88 | |
89 | WKStringRef WKErrorCopyLocalizedDescription(WKErrorRef errorRef) |
90 | { |
91 | return WebKit::toCopiedAPI(WebKit::toImpl(errorRef)->localizedDescription()); |
92 | } |
93 | |