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#pragma once
27
28#if ENABLE(CONTENT_EXTENSIONS)
29
30#include "CachedResource.h"
31#include <wtf/OptionSet.h>
32#include <wtf/URL.h>
33
34namespace WebCore {
35namespace ContentExtensions {
36
37enum class ResourceType : uint16_t {
38 Invalid = 0x0000,
39 Document = 0x0001,
40 Image = 0x0002,
41 StyleSheet = 0x0004,
42 Script = 0x0008,
43 Font = 0x0010,
44 Raw = 0x0020,
45 SVGDocument = 0x0040,
46 Media = 0x0080,
47 PlugInStream = 0x0100,
48 Popup = 0x0200,
49 // 0x0400 and 0x0800 are used by LoadType.
50 Ping = 0x1000,
51};
52const uint16_t ResourceTypeMask = 0x13FF;
53
54enum class LoadType : uint16_t {
55 Invalid = 0x0000,
56 FirstParty = 0x0400,
57 ThirdParty = 0x0800,
58};
59const uint16_t LoadTypeMask = 0x0C00;
60
61static_assert(!(ResourceTypeMask & LoadTypeMask), "ResourceTypeMask and LoadTypeMask should be mutually exclusive because they are stored in the same uint16_t");
62
63typedef uint16_t ResourceFlags;
64
65// The first 32 bits of a uint64_t action are used for the action location.
66// The next 16 bits are used for the flags (ResourceType and LoadType).
67// The next bit is used to mark actions that are from a rule with an if-domain.
68// Actions from rules with unless-domain conditions are distinguished from
69// rules with if-domain conditions by not having this bit set.
70// Actions from rules with no conditions are put in the DFA without conditions.
71// The values -1 and -2 are used for removed and empty values in HashTables.
72const uint64_t ActionFlagMask = 0x0000FFFF00000000;
73const uint64_t IfConditionFlag = 0x0001000000000000;
74
75ResourceType toResourceType(CachedResource::Type);
76uint16_t readResourceType(const String&);
77uint16_t readLoadType(const String&);
78
79struct ResourceLoadInfo {
80 URL resourceURL;
81 URL mainDocumentURL;
82 OptionSet<ResourceType> type;
83
84 bool isThirdParty() const;
85 ResourceFlags getResourceFlags() const;
86};
87
88} // namespace ContentExtensions
89} // namespace WebCore
90
91#endif
92