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#include "PlatformString.h"
30
31#if !LOG_DISABLED
32
33namespace WebCore {
34
35static const char* const errorStrings[] = {
36    "No errors occurred.", /* NPERR_NO_ERROR */
37    "Error with no specific error code occurred.", /* NPERR_GENERIC_ERROR */
38    "Invalid instance passed to the plug-in.", /* NPERR_INVALID_INSTANCE_ERROR */
39    "Function table invalid.", /* NPERR_INVALID_FUNCTABLE_ERROR */
40    "Loading of plug-in failed.", /* NPERR_MODULE_LOAD_FAILED_ERROR */
41    "Memory allocation failed.", /* NPERR_OUT_OF_MEMORY_ERROR */
42    "Plug-in missing or invalid.", /* NPERR_INVALID_PLUGIN_ERROR */
43    "Plug-in directory missing or invalid.", /* NPERR_INVALID_PLUGIN_DIR_ERROR */
44    "Versions of plug-in and Communicator do not match.", /* NPERR_INCOMPATIBLE_VERSION_ERROR */
45    "Parameter missing or invalid.", /* NPERR_INVALID_PARAM */
46    "URL missing or invalid.", /* NPERR_INVALID_URL */
47    "File missing or invalid.", /* NPERR_FILE_NOT_FOUND */
48    "Stream contains no data.", /* NPERR_NO_DATA */
49    "Seekable stream expected.", /* NPERR_STREAM_NOT_SEEKABLE */
50    "Unknown error code"
51};
52
53#ifdef XP_MACOSX
54static const char* const drawingModels[] = {
55    "NPDrawingModelQuickDraw",
56    "NPDrawingModelCoreGraphics",
57    "NPDrawingModelOpenGL",
58    "NPDrawingModelCoreAnimation"
59};
60
61static const char* const eventModels[] = {
62    "NPEventModelCarbon",
63    "NPEventModelCocoa"
64};
65#endif //XP_MACOSX
66
67const char* prettyNameForNPError(NPError error)
68{
69    return errorStrings[error];
70}
71
72#ifdef XP_MACOSX
73const char* prettyNameForDrawingModel(NPDrawingModel drawingModel)
74{
75    return drawingModels[drawingModel];
76}
77
78const char* prettyNameForEventModel(NPEventModel eventModel)
79{
80    return eventModels[eventModel];
81}
82#endif //XP_MACOSX
83
84CString prettyNameForNPNVariable(NPNVariable variable)
85{
86    switch (variable) {
87    case NPNVxDisplay: return "NPNVxDisplay";
88    case NPNVxtAppContext: return "NPNVxtAppContext";
89    case NPNVnetscapeWindow: return "NPNVnetscapeWindow";
90    case NPNVjavascriptEnabledBool: return "NPNVjavascriptEnabledBool";
91    case NPNVasdEnabledBool: return "NPNVasdEnabledBool";
92    case NPNVisOfflineBool: return "NPNVisOfflineBool";
93
94    case NPNVserviceManager: return "NPNVserviceManager (not supported)";
95    case NPNVDOMElement: return "NPNVDOMElement (not supported)";
96    case NPNVDOMWindow: return "NPNVDOMWindow (not supported)";
97    case NPNVToolkit: return "NPNVToolkit (not supported)";
98    case NPNVSupportsXEmbedBool: return "NPNVSupportsXEmbedBool (not supported)";
99
100    case NPNVWindowNPObject: return "NPNVWindowNPObject";
101    case NPNVPluginElementNPObject: return "NPNVPluginElementNPObject";
102    case NPNVSupportsWindowless: return "NPNVSupportsWindowless";
103    case NPNVprivateModeBool: return "NPNVprivateModeBool";
104
105#ifdef XP_MACOSX
106    case NPNVpluginDrawingModel: return "NPNVpluginDrawingModel";
107#ifndef NP_NO_QUICKDRAW
108    case NPNVsupportsQuickDrawBool: return "NPNVsupportsQuickDrawBool";
109#endif
110    case NPNVsupportsCoreGraphicsBool: return "NPNVsupportsCoreGraphicsBool";
111    case NPNVsupportsOpenGLBool: return "NPNVsupportsOpenGLBool";
112    case NPNVsupportsCoreAnimationBool: return "NPNVsupportsCoreAnimationBool";
113#ifndef NP_NO_CARBON
114    case NPNVsupportsCarbonBool: return "NPNVsupportsCarbonBool";
115#endif
116    case NPNVsupportsCocoaBool: return "NPNVsupportsCocoaBool";
117#endif
118
119    default: return "Unknown variable";
120    }
121}
122
123CString prettyNameForNPPVariable(NPPVariable variable, void* value)
124{
125    switch (variable) {
126    case NPPVpluginNameString: return "NPPVpluginNameString";
127    case NPPVpluginDescriptionString: return "NPPVpluginDescriptionString";
128    case NPPVpluginWindowBool: return "NPPVpluginWindowBool";
129    case NPPVpluginTransparentBool: return "NPPVpluginTransparentBool";
130
131    case NPPVjavaClass: return "NPPVjavaClass (not supported)";
132    case NPPVpluginWindowSize: return "NPPVpluginWindowSize (not supported)";
133    case NPPVpluginTimerInterval: return "NPPVpluginTimerInterval (not supported)";
134    case NPPVpluginScriptableInstance: return "NPPVpluginScriptableInstance (not supported)";
135    case NPPVpluginScriptableIID: return "NPPVpluginScriptableIID (not supported)";
136    case NPPVjavascriptPushCallerBool: return "NPPVjavascriptPushCallerBool (not supported)";
137    case NPPVpluginKeepLibraryInMemory: return "NPPVpluginKeepLibraryInMemory (not supported)";
138    case NPPVpluginNeedsXEmbed: return "NPPVpluginNeedsXEmbed (not supported)";
139
140    case NPPVpluginScriptableNPObject: return "NPPVpluginScriptableNPObject";
141
142    case NPPVformValue: return "NPPVformValue (not supported)";
143    case NPPVpluginUrlRequestsDisplayedBool: return "NPPVpluginUrlRequestsDisplayedBool (not supported)";
144
145    case NPPVpluginWantsAllNetworkStreams: return "NPPVpluginWantsAllNetworkStreams";
146    case NPPVpluginCancelSrcStream: return "NPPVpluginCancelSrcStream";
147
148#ifdef XP_MACOSX
149    case NPPVpluginDrawingModel: {
150        String result("NPPVpluginDrawingModel, ");
151        result.append(prettyNameForDrawingModel(NPDrawingModel(uintptr_t(value))));
152        return result.latin1();
153    }
154    case NPPVpluginEventModel: {
155        String result("NPPVpluginEventModel, ");
156        result.append(prettyNameForEventModel(NPEventModel(uintptr_t(value))));
157        return result.latin1();
158    }
159    case NPPVpluginCoreAnimationLayer: return "NPPVpluginCoreAnimationLayer";
160#endif
161
162    default: return "Unknown variable";
163    }
164}
165
166CString prettyNameForNPNURLVariable(NPNURLVariable variable)
167{
168    switch (variable) {
169    case NPNURLVCookie: return "NPNURLVCookie";
170    case NPNURLVProxy: return "NPNURLVProxy";
171    default: return "Unknown variable";
172    }
173}
174} // namespace WebCore
175
176#endif // !LOG_DISABLED
177