1/*
2 * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
3 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
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 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28#include "PluginDebug.h"
29
30#include <wtf/text/WTFString.h>
31
32#if !LOG_DISABLED
33
34namespace WebCore {
35
36static const char* const errorStrings[] = {
37    "No errors occurred.", /* NPERR_NO_ERROR */
38    "Error with no specific error code occurred.", /* NPERR_GENERIC_ERROR */
39    "Invalid instance passed to the plug-in.", /* NPERR_INVALID_INSTANCE_ERROR */
40    "Function table invalid.", /* NPERR_INVALID_FUNCTABLE_ERROR */
41    "Loading of plug-in failed.", /* NPERR_MODULE_LOAD_FAILED_ERROR */
42    "Memory allocation failed.", /* NPERR_OUT_OF_MEMORY_ERROR */
43    "Plug-in missing or invalid.", /* NPERR_INVALID_PLUGIN_ERROR */
44    "Plug-in directory missing or invalid.", /* NPERR_INVALID_PLUGIN_DIR_ERROR */
45    "Versions of plug-in and Communicator do not match.", /* NPERR_INCOMPATIBLE_VERSION_ERROR */
46    "Parameter missing or invalid.", /* NPERR_INVALID_PARAM */
47    "URL missing or invalid.", /* NPERR_INVALID_URL */
48    "File missing or invalid.", /* NPERR_FILE_NOT_FOUND */
49    "Stream contains no data.", /* NPERR_NO_DATA */
50    "Seekable stream expected.", /* NPERR_STREAM_NOT_SEEKABLE */
51    "Unknown error code"
52};
53
54#ifdef XP_MACOSX
55static const char* const drawingModels[] = {
56    "NPDrawingModelQuickDraw",
57    "NPDrawingModelCoreGraphics",
58    "NPDrawingModelOpenGL",
59    "NPDrawingModelCoreAnimation"
60};
61
62static const char* const eventModels[] = {
63    "NPEventModelCarbon",
64    "NPEventModelCocoa"
65};
66#endif //XP_MACOSX
67
68const char* prettyNameForNPError(NPError error)
69{
70    return errorStrings[error];
71}
72
73#ifdef XP_MACOSX
74const char* prettyNameForDrawingModel(NPDrawingModel drawingModel)
75{
76    return drawingModels[drawingModel];
77}
78
79const char* prettyNameForEventModel(NPEventModel eventModel)
80{
81    return eventModels[eventModel];
82}
83#endif //XP_MACOSX
84
85CString prettyNameForNPNVariable(NPNVariable variable)
86{
87    switch (variable) {
88    case NPNVxDisplay: return "NPNVxDisplay";
89    case NPNVxtAppContext: return "NPNVxtAppContext";
90    case NPNVnetscapeWindow: return "NPNVnetscapeWindow";
91    case NPNVjavascriptEnabledBool: return "NPNVjavascriptEnabledBool";
92    case NPNVasdEnabledBool: return "NPNVasdEnabledBool";
93    case NPNVisOfflineBool: return "NPNVisOfflineBool";
94
95    case NPNVserviceManager: return "NPNVserviceManager (not supported)";
96    case NPNVDOMElement: return "NPNVDOMElement (not supported)";
97    case NPNVDOMWindow: return "NPNVDOMWindow (not supported)";
98    case NPNVToolkit: return "NPNVToolkit (not supported)";
99    case NPNVSupportsXEmbedBool: return "NPNVSupportsXEmbedBool (not supported)";
100
101    case NPNVWindowNPObject: return "NPNVWindowNPObject";
102    case NPNVPluginElementNPObject: return "NPNVPluginElementNPObject";
103    case NPNVSupportsWindowless: return "NPNVSupportsWindowless";
104    case NPNVprivateModeBool: return "NPNVprivateModeBool";
105
106#ifdef XP_MACOSX
107    case NPNVpluginDrawingModel: return "NPNVpluginDrawingModel";
108#ifndef NP_NO_QUICKDRAW
109    case NPNVsupportsQuickDrawBool: return "NPNVsupportsQuickDrawBool";
110#endif
111    case NPNVsupportsCoreGraphicsBool: return "NPNVsupportsCoreGraphicsBool";
112    case NPNVsupportsOpenGLBool: return "NPNVsupportsOpenGLBool";
113    case NPNVsupportsCoreAnimationBool: return "NPNVsupportsCoreAnimationBool";
114#ifndef NP_NO_CARBON
115    case NPNVsupportsCarbonBool: return "NPNVsupportsCarbonBool";
116#endif
117    case NPNVsupportsCocoaBool: return "NPNVsupportsCocoaBool";
118#endif
119
120    default: return "Unknown variable";
121    }
122}
123
124CString prettyNameForNPPVariable(NPPVariable variable, void* value)
125{
126    switch (variable) {
127    case NPPVpluginNameString: return "NPPVpluginNameString";
128    case NPPVpluginDescriptionString: return "NPPVpluginDescriptionString";
129    case NPPVpluginWindowBool: return "NPPVpluginWindowBool";
130    case NPPVpluginTransparentBool: return "NPPVpluginTransparentBool";
131
132    case NPPVjavaClass: return "NPPVjavaClass (not supported)";
133    case NPPVpluginWindowSize: return "NPPVpluginWindowSize (not supported)";
134    case NPPVpluginTimerInterval: return "NPPVpluginTimerInterval (not supported)";
135    case NPPVpluginScriptableInstance: return "NPPVpluginScriptableInstance (not supported)";
136    case NPPVpluginScriptableIID: return "NPPVpluginScriptableIID (not supported)";
137    case NPPVjavascriptPushCallerBool: return "NPPVjavascriptPushCallerBool (not supported)";
138    case NPPVpluginKeepLibraryInMemory: return "NPPVpluginKeepLibraryInMemory (not supported)";
139    case NPPVpluginNeedsXEmbed: return "NPPVpluginNeedsXEmbed (not supported)";
140
141    case NPPVpluginScriptableNPObject: return "NPPVpluginScriptableNPObject";
142
143    case NPPVformValue: return "NPPVformValue (not supported)";
144    case NPPVpluginUrlRequestsDisplayedBool: return "NPPVpluginUrlRequestsDisplayedBool (not supported)";
145
146    case NPPVpluginWantsAllNetworkStreams: return "NPPVpluginWantsAllNetworkStreams";
147    case NPPVpluginCancelSrcStream: return "NPPVpluginCancelSrcStream";
148
149#ifdef XP_MACOSX
150    case NPPVpluginDrawingModel: {
151        String result("NPPVpluginDrawingModel, ");
152        result.append(prettyNameForDrawingModel(NPDrawingModel(uintptr_t(value))));
153        return result.latin1();
154    }
155    case NPPVpluginEventModel: {
156        String result("NPPVpluginEventModel, ");
157        result.append(prettyNameForEventModel(NPEventModel(uintptr_t(value))));
158        return result.latin1();
159    }
160    case NPPVpluginCoreAnimationLayer: return "NPPVpluginCoreAnimationLayer";
161#else
162    UNUSED_PARAM(value);
163#endif
164
165    default: return "Unknown variable";
166    }
167}
168
169CString prettyNameForNPNURLVariable(NPNURLVariable variable)
170{
171    switch (variable) {
172    case NPNURLVCookie: return "NPNURLVCookie";
173    case NPNURLVProxy: return "NPNURLVProxy";
174    default: return "Unknown variable";
175    }
176}
177} // namespace WebCore
178
179#endif // !LOG_DISABLED
180