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 "WebCompiledContentRuleListData.h"
28
29#if ENABLE(CONTENT_EXTENSIONS)
30
31#include "ArgumentCoders.h"
32#include "DataReference.h"
33#include "SharedBufferDataReference.h"
34
35namespace WebKit {
36
37void WebCompiledContentRuleListData::encode(IPC::Encoder& encoder) const
38{
39 SharedMemory::Handle handle;
40 data->createHandle(handle, SharedMemory::Protection::ReadOnly);
41 encoder << handle;
42
43 encoder << conditionsApplyOnlyToDomainOffset;
44 encoder << actionsOffset;
45 encoder << actionsSize;
46 encoder << filtersWithoutConditionsBytecodeOffset;
47 encoder << filtersWithoutConditionsBytecodeSize;
48 encoder << filtersWithConditionsBytecodeOffset;
49 encoder << filtersWithConditionsBytecodeSize;
50 encoder << topURLFiltersBytecodeOffset;
51 encoder << topURLFiltersBytecodeSize;
52}
53
54Optional<WebCompiledContentRuleListData> WebCompiledContentRuleListData::decode(IPC::Decoder& decoder)
55{
56 SharedMemory::Handle handle;
57 if (!decoder.decode(handle))
58 return WTF::nullopt;
59 RefPtr<SharedMemory> data = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
60
61 Optional<unsigned> conditionsApplyOnlyToDomainOffset;
62 decoder >> conditionsApplyOnlyToDomainOffset;
63 if (!conditionsApplyOnlyToDomainOffset)
64 return WTF::nullopt;
65
66 Optional<unsigned> actionsOffset;
67 decoder >> actionsOffset;
68 if (!actionsOffset)
69 return WTF::nullopt;
70
71 Optional<unsigned> actionsSize;
72 decoder >> actionsSize;
73 if (!actionsSize)
74 return WTF::nullopt;
75
76 Optional<unsigned> filtersWithoutConditionsBytecodeOffset;
77 decoder >> filtersWithoutConditionsBytecodeOffset;
78 if (!filtersWithoutConditionsBytecodeOffset)
79 return WTF::nullopt;
80
81 Optional<unsigned> filtersWithoutConditionsBytecodeSize;
82 decoder >> filtersWithoutConditionsBytecodeSize;
83 if (!filtersWithoutConditionsBytecodeSize)
84 return WTF::nullopt;
85
86 Optional<unsigned> filtersWithConditionsBytecodeOffset;
87 decoder >> filtersWithConditionsBytecodeOffset;
88 if (!filtersWithConditionsBytecodeOffset)
89 return WTF::nullopt;
90
91 Optional<unsigned> filtersWithConditionsBytecodeSize;
92 decoder >> filtersWithConditionsBytecodeSize;
93 if (!filtersWithConditionsBytecodeSize)
94 return WTF::nullopt;
95
96 Optional<unsigned> topURLFiltersBytecodeOffset;
97 decoder >> topURLFiltersBytecodeOffset;
98 if (!topURLFiltersBytecodeOffset)
99 return WTF::nullopt;
100
101 Optional<unsigned> topURLFiltersBytecodeSize;
102 decoder >> topURLFiltersBytecodeSize;
103 if (!topURLFiltersBytecodeSize)
104 return WTF::nullopt;
105
106 return {{
107 WTFMove(data),
108 WTFMove(*conditionsApplyOnlyToDomainOffset),
109 WTFMove(*actionsOffset),
110 WTFMove(*actionsSize),
111 WTFMove(*filtersWithoutConditionsBytecodeOffset),
112 WTFMove(*filtersWithoutConditionsBytecodeSize),
113 WTFMove(*filtersWithConditionsBytecodeOffset),
114 WTFMove(*filtersWithConditionsBytecodeSize),
115 WTFMove(*topURLFiltersBytecodeOffset),
116 WTFMove(*topURLFiltersBytecodeSize)
117 }};
118}
119
120} // namespace WebKit
121
122#endif // ENABLE(CONTENT_EXTENSIONS)
123