1/*
2 * Copyright (C) 2010 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(NETSCAPE_PLUGIN_API)
29
30#include <wtf/text/CString.h>
31
32namespace IPC {
33class Decoder;
34class Encoder;
35}
36
37namespace WebKit {
38
39class NPVariantData {
40public:
41 enum Type {
42 Void,
43 Null,
44 Bool,
45 Int32,
46 Double,
47 String,
48 LocalNPObjectID,
49 RemoteNPObjectID,
50 };
51 NPVariantData();
52
53 static NPVariantData makeVoid();
54 static NPVariantData makeNull();
55 static NPVariantData makeBool(bool value);
56 static NPVariantData makeInt32(int32_t value);
57 static NPVariantData makeDouble(double value);
58 static NPVariantData makeString(const char* string, unsigned length);
59 static NPVariantData makeLocalNPObjectID(uint64_t value);
60 static NPVariantData makeRemoteNPObjectID(uint64_t value);
61
62 Type type() const { return static_cast<Type>(m_type); }
63
64 bool boolValue() const
65 {
66 ASSERT(type() == NPVariantData::Bool);
67 return m_boolValue;
68 }
69
70 int32_t int32Value() const
71 {
72 ASSERT(type() == NPVariantData::Int32);
73 return m_int32Value;
74 }
75
76 double doubleValue() const
77 {
78 ASSERT(type() == NPVariantData::Double);
79 return m_doubleValue;
80 }
81
82 const CString& stringValue() const
83 {
84 ASSERT(type() == NPVariantData::String);
85 return m_stringValue;
86 }
87
88 uint64_t localNPObjectIDValue() const
89 {
90 ASSERT(type() == NPVariantData::LocalNPObjectID);
91 return m_localNPObjectIDValue;
92 }
93
94 uint64_t remoteNPObjectIDValue() const
95 {
96 ASSERT(type() == NPVariantData::RemoteNPObjectID);
97 return m_remoteNPObjectIDValue;
98 }
99
100 void encode(IPC::Encoder&) const;
101 static Optional<NPVariantData> decode(IPC::Decoder&);
102
103private:
104 uint32_t m_type;
105 bool m_boolValue;
106 int32_t m_int32Value;
107 double m_doubleValue;
108 CString m_stringValue;
109 uint64_t m_localNPObjectIDValue;
110 uint64_t m_remoteNPObjectIDValue;
111};
112
113} // namespace WebKit
114
115#endif // ENABLE(NETSCAPE_PLUGIN_API)
116