1/*
2 * Copyright (C) 2013 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 "PluginInformation.h"
28
29#if ENABLE(NETSCAPE_PLUGIN_API)
30
31#include "APINumber.h"
32#include "APIString.h"
33#include "APIURL.h"
34#include "PluginInfoStore.h"
35#include "PluginModuleInfo.h"
36#include "WKAPICast.h"
37#include <wtf/text/WTFString.h>
38
39namespace WebKit {
40
41String pluginInformationBundleIdentifierKey()
42{
43 return "PluginInformationBundleIdentifier"_s;
44}
45
46String pluginInformationBundleVersionKey()
47{
48 return "PluginInformationBundleVersion"_s;
49}
50
51String pluginInformationBundleShortVersionKey()
52{
53 return "PluginInformationBundleShortVersion"_s;
54}
55
56String pluginInformationPathKey()
57{
58 return "PluginInformationPath"_s;
59}
60
61String pluginInformationDisplayNameKey()
62{
63 return "PluginInformationDisplayName"_s;
64}
65
66String pluginInformationDefaultLoadPolicyKey()
67{
68 return "PluginInformationDefaultLoadPolicy"_s;
69}
70
71String pluginInformationUpdatePastLastBlockedVersionIsKnownAvailableKey()
72{
73 return "PluginInformationUpdatePastLastBlockedVersionIsKnownAvailable"_s;
74}
75
76String pluginInformationHasSandboxProfileKey()
77{
78 return "PluginInformationHasSandboxProfile"_s;
79}
80
81String pluginInformationFrameURLKey()
82{
83 return "PluginInformationFrameURL"_s;
84}
85
86String pluginInformationMIMETypeKey()
87{
88 return "PluginInformationMIMEType"_s;
89}
90
91String pluginInformationPageURLKey()
92{
93 return "PluginInformationPageURL"_s;
94}
95
96String pluginInformationPluginspageAttributeURLKey()
97{
98 return "PluginInformationPluginspageAttributeURL"_s;
99}
100
101String pluginInformationPluginURLKey()
102{
103 return "PluginInformationPluginURL"_s;
104}
105
106String plugInInformationReplacementObscuredKey()
107{
108 return "PlugInInformationReplacementObscured"_s;
109}
110
111void getPluginModuleInformation(const PluginModuleInfo& plugin, API::Dictionary::MapType& map)
112{
113#if ENABLE(NETSCAPE_PLUGIN_API)
114 map.set(pluginInformationPathKey(), API::String::create(plugin.path));
115 map.set(pluginInformationDisplayNameKey(), API::String::create(plugin.info.name));
116 map.set(pluginInformationDefaultLoadPolicyKey(), API::UInt64::create(toWKPluginLoadPolicy(PluginInfoStore::defaultLoadPolicyForPlugin(plugin))));
117
118 getPlatformPluginModuleInformation(plugin, map);
119#else
120 UNUSED_PARAM(plugin);
121 UNUSED_PARAM(map);
122#endif
123}
124
125Ref<API::Dictionary> createPluginInformationDictionary(const PluginModuleInfo& plugin)
126{
127 API::Dictionary::MapType map;
128 getPluginModuleInformation(plugin, map);
129
130 return API::Dictionary::create(WTFMove(map));
131}
132
133Ref<API::Dictionary> createPluginInformationDictionary(const PluginModuleInfo& plugin, const String& frameURLString, const String& mimeType, const String& pageURLString, const String& pluginspageAttributeURLString, const String& pluginURLString, bool replacementObscured)
134{
135 API::Dictionary::MapType map;
136 getPluginModuleInformation(plugin, map);
137
138 if (!frameURLString.isEmpty())
139 map.set(pluginInformationFrameURLKey(), API::URL::create(frameURLString));
140 if (!mimeType.isEmpty())
141 map.set(pluginInformationMIMETypeKey(), API::String::create(mimeType));
142 if (!pageURLString.isEmpty())
143 map.set(pluginInformationPageURLKey(), API::URL::create(pageURLString));
144 if (!pluginspageAttributeURLString.isEmpty())
145 map.set(pluginInformationPluginspageAttributeURLKey(), API::URL::create(pluginspageAttributeURLString));
146 if (!pluginURLString.isEmpty())
147 map.set(pluginInformationPluginURLKey(), API::URL::create(pluginURLString));
148 map.set(plugInInformationReplacementObscuredKey(), API::Boolean::create(replacementObscured));
149
150 return API::Dictionary::create(WTFMove(map));
151}
152
153Ref<API::Dictionary> createPluginInformationDictionary(const String& mimeType, const String& frameURLString, const String& pageURLString)
154{
155 API::Dictionary::MapType map;
156
157 if (!frameURLString.isEmpty())
158 map.set(pluginInformationFrameURLKey(), API::URL::create(frameURLString));
159 if (!mimeType.isEmpty())
160 map.set(pluginInformationMIMETypeKey(), API::String::create(mimeType));
161 if (!pageURLString.isEmpty())
162 map.set(pluginInformationPageURLKey(), API::URL::create(pageURLString));
163
164 return API::Dictionary::create(WTFMove(map));
165}
166
167#if !PLATFORM(COCOA)
168void getPlatformPluginModuleInformation(const PluginModuleInfo&, API::Dictionary::MapType&)
169{
170}
171#endif
172
173} // namespace WebKit
174
175#endif // ENABLE(NETSCAPE_PLUGIN_API)
176