1 | /* |
2 | * Copyright (C) 2015 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 "ContentExtensionError.h" |
28 | |
29 | #if ENABLE(CONTENT_EXTENSIONS) |
30 | |
31 | #include <string> |
32 | #include <wtf/NeverDestroyed.h> |
33 | |
34 | namespace WebCore { |
35 | namespace ContentExtensions { |
36 | |
37 | const char* WebKitContentBlockerDomain = "WebKitContentBlockerDomain" ; |
38 | |
39 | const std::error_category& contentExtensionErrorCategory() |
40 | { |
41 | class ContentExtensionErrorCategory : public std::error_category { |
42 | const char* name() const noexcept override |
43 | { |
44 | return "content extension" ; |
45 | } |
46 | |
47 | std::string message(int errorCode) const override |
48 | { |
49 | switch (static_cast<ContentExtensionError>(errorCode)) { |
50 | case ContentExtensionError::JSONInvalid: |
51 | return "Failed to parse the JSON String." ; |
52 | case ContentExtensionError::JSONTopLevelStructureNotAnObject: |
53 | return "Invalid input, the top level structure is not an object." ; |
54 | case ContentExtensionError::JSONTopLevelStructureNotAnArray: |
55 | return "Invalid input, the top level structure is not an array." ; |
56 | case ContentExtensionError::JSONInvalidObjectInTopLevelArray: |
57 | return "Invalid object in the top level array." ; |
58 | case ContentExtensionError::JSONInvalidRule: |
59 | return "Invalid rule." ; |
60 | case ContentExtensionError::JSONContainsNoRules: |
61 | return "Empty extension." ; |
62 | case ContentExtensionError::JSONInvalidTrigger: |
63 | return "Invalid trigger object." ; |
64 | case ContentExtensionError::JSONInvalidURLFilterInTrigger: |
65 | return "Invalid url-filter object." ; |
66 | case ContentExtensionError::JSONInvalidTriggerFlagsArray: |
67 | return "Invalid trigger flags array." ; |
68 | case ContentExtensionError::JSONInvalidObjectInTriggerFlagsArray: |
69 | return "Invalid object in the trigger flags array." ; |
70 | case ContentExtensionError::JSONInvalidStringInTriggerFlagsArray: |
71 | return "Invalid string in the trigger flags array." ; |
72 | case ContentExtensionError::JSONInvalidAction: |
73 | return "Invalid action object." ; |
74 | case ContentExtensionError::JSONInvalidActionType: |
75 | return "Invalid action type." ; |
76 | case ContentExtensionError::JSONInvalidCSSDisplayNoneActionType: |
77 | return "Invalid css-display-none action type. Requires a selector." ; |
78 | case ContentExtensionError::JSONInvalidRegex: |
79 | return "Invalid or unsupported regular expression." ; |
80 | case ContentExtensionError::JSONInvalidConditionList: |
81 | return "Invalid list of if-domain, unless-domain, if-top-url, or unless-top-url conditions." ; |
82 | case ContentExtensionError::JSONTooManyRules: |
83 | return "Too many rules in JSON array." ; |
84 | case ContentExtensionError::JSONDomainNotLowerCaseASCII: |
85 | return "Domains must be lower case ASCII. Use punycode to encode non-ASCII characters." ; |
86 | case ContentExtensionError::JSONMultipleConditions: |
87 | return "A trigger cannot have more than one condition (if-domain, unless-domain, if-top-url, or unless-top-url)" ; |
88 | case ContentExtensionError::JSONTopURLAndDomainConditions: |
89 | return "A list cannot have if-domain and unless-domain mixed with if-top-url and unless-top-url" ; |
90 | case ContentExtensionError::JSONInvalidNotification: |
91 | return "A notify action must have a string notification" ; |
92 | } |
93 | |
94 | return std::string(); |
95 | } |
96 | }; |
97 | |
98 | static NeverDestroyed<ContentExtensionErrorCategory> contentExtensionErrorCategory; |
99 | return contentExtensionErrorCategory; |
100 | } |
101 | |
102 | } // namespace ContentExtensions |
103 | } // namespace WebCore |
104 | |
105 | #endif // ENABLE(CONTENT_EXTENSIONS) |
106 | |