1/*
2 * Copyright (C) 2010-2017 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 "APIError.h"
28
29#include "WebCoreArgumentCoders.h"
30#include <wtf/NeverDestroyed.h>
31#include <wtf/text/WTFString.h>
32
33namespace API {
34
35const WTF::String& Error::webKitErrorDomain()
36{
37 static NeverDestroyed<WTF::String> webKitErrorDomainString(MAKE_STATIC_STRING_IMPL("WebKitErrorDomain"));
38 return webKitErrorDomainString;
39}
40
41const WTF::String& Error::webKitNetworkErrorDomain()
42{
43#if USE(GLIB)
44 static NeverDestroyed<WTF::String> webKitErrorDomainString(MAKE_STATIC_STRING_IMPL("WebKitNetworkError"));
45 return webKitErrorDomainString;
46#else
47 return webKitErrorDomain();
48#endif
49}
50
51const WTF::String& Error::webKitPolicyErrorDomain()
52{
53#if USE(GLIB)
54 static NeverDestroyed<WTF::String> webKitErrorDomainString(MAKE_STATIC_STRING_IMPL("WebKitPolicyError"));
55 return webKitErrorDomainString;
56#else
57 return webKitErrorDomain();
58#endif
59}
60
61const WTF::String& Error::webKitPluginErrorDomain()
62{
63#if USE(GLIB)
64 static NeverDestroyed<WTF::String> webKitErrorDomainString(MAKE_STATIC_STRING_IMPL("WebKitPluginError"));
65 return webKitErrorDomainString;
66#else
67 return webKitErrorDomain();
68#endif
69}
70
71#if USE(SOUP)
72const WTF::String& Error::webKitDownloadErrorDomain()
73{
74 static NeverDestroyed<WTF::String> webKitErrorDomainString(MAKE_STATIC_STRING_IMPL("WebKitDownloadError"));
75 return webKitErrorDomainString;
76}
77#endif
78
79#if PLATFORM(GTK)
80const WTF::String& Error::webKitPrintErrorDomain()
81{
82 static NeverDestroyed<WTF::String> webKitErrorDomainString(MAKE_STATIC_STRING_IMPL("WebKitPrintError"));
83 return webKitErrorDomainString;
84}
85#endif
86
87void Error::encode(IPC::Encoder& encoder) const
88{
89 encoder << platformError();
90}
91
92bool Error::decode(IPC::Decoder& decoder, RefPtr<Object>& result)
93{
94 WebCore::ResourceError error;
95 if (!decoder.decode(error))
96 return false;
97
98 result = create(error);
99 return true;
100}
101
102} // namespace WebKit
103