1/*
2 * Copyright (C) 2013 University of Washington. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1.  Redistributions of source code must retain the above copyright
10 *     notice, this list of conditions and the following disclaimer.
11 * 2.  Redistributions in binary form must reproduce the above copyright
12 *     notice, this list of conditions and the following disclaimer in the
13 *     documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef SerializationMethods_h
29#define SerializationMethods_h
30
31#if ENABLE(WEB_REPLAY)
32
33#include <replay/EncodedValue.h>
34#include <replay/NondeterministicInput.h>
35#include <wtf/Vector.h>
36
37namespace WebCore {
38
39class Document;
40class Frame;
41class Page;
42class PlatformKeyboardEvent;
43class PlatformMouseEvent;
44class PlatformWheelEvent;
45class PluginData;
46class SecurityOrigin;
47class URL;
48
49#if USE(APPKIT)
50struct KeypressCommand;
51#endif
52
53unsigned long frameIndexFromDocument(const Document*);
54unsigned long frameIndexFromFrame(const Frame*);
55Document* documentFromFrameIndex(Page*, unsigned long frameIndex);
56Frame* frameFromFrameIndex(Page*, unsigned long frameIndex);
57
58} // namespace WebCore
59
60// Template specializations must be defined in the same namespace as the template declaration.
61namespace JSC {
62
63#if USE(APPKIT)
64template<> struct EncodingTraits<WebCore::KeypressCommand> {
65    typedef WebCore::KeypressCommand DecodedType;
66
67    static EncodedValue encodeValue(const WebCore::KeypressCommand& value);
68    static bool decodeValue(EncodedValue&, WebCore::KeypressCommand& value);
69};
70#endif // USE(APPKIT)
71
72template<> struct EncodingTraits<NondeterministicInputBase> {
73    typedef NondeterministicInputBase DecodedType;
74
75    static EncodedValue encodeValue(const NondeterministicInputBase& value);
76    static bool decodeValue(EncodedValue&, std::unique_ptr<NondeterministicInputBase>& value);
77};
78
79template<> struct EncodingTraits<WebCore::PlatformKeyboardEvent> {
80    typedef WebCore::PlatformKeyboardEvent DecodedType;
81
82    static EncodedValue encodeValue(const WebCore::PlatformKeyboardEvent& value);
83    static bool decodeValue(EncodedValue&, std::unique_ptr<WebCore::PlatformKeyboardEvent>& value);
84};
85
86template<> struct EncodingTraits<WebCore::PlatformMouseEvent> {
87    typedef WebCore::PlatformMouseEvent DecodedType;
88
89    static EncodedValue encodeValue(const WebCore::PlatformMouseEvent& value);
90    static bool decodeValue(EncodedValue&, std::unique_ptr<WebCore::PlatformMouseEvent>& value);
91};
92
93template<> struct EncodingTraits<WebCore::PlatformWheelEvent> {
94    typedef WebCore::PlatformWheelEvent DecodedType;
95
96    static EncodedValue encodeValue(const WebCore::PlatformWheelEvent& value);
97    static bool decodeValue(EncodedValue&, std::unique_ptr<WebCore::PlatformWheelEvent>& value);
98};
99
100template<> struct EncodingTraits<WebCore::PluginData> {
101    typedef RefPtr<WebCore::PluginData> DecodedType;
102
103    static EncodedValue encodeValue(RefPtr<WebCore::PluginData> value);
104    static bool decodeValue(EncodedValue&, RefPtr<WebCore::PluginData>& value);
105};
106
107template<> struct EncodingTraits<WebCore::URL> {
108    typedef WebCore::URL DecodedType;
109
110    static EncodedValue encodeValue(const WebCore::URL& value);
111    static bool decodeValue(EncodedValue&, WebCore::URL& value);
112};
113
114template<> struct EncodingTraits<WebCore::SecurityOrigin> {
115    typedef RefPtr<WebCore::SecurityOrigin> DecodedType;
116
117    static EncodedValue encodeValue(RefPtr<WebCore::SecurityOrigin> value);
118    static bool decodeValue(EncodedValue&, RefPtr<WebCore::SecurityOrigin>& value);
119};
120
121} // namespace JSC
122
123#endif // ENABLE(WEB_REPLAY)
124
125#endif // SerializationMethods_h
126