~ubuntu-branches/ubuntu/trusty/parole/trusty-proposed

« back to all changes in this revision

Viewing changes to browser-plugin/npp_gate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2010-04-28 21:42:11 UTC
  • Revision ID: james.westby@ubuntu.com-20100428214211-i7olyr9ch8tnpnaf
Tags: upstream-0.2.0.2
ImportĀ upstreamĀ versionĀ 0.2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the NPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
////////////////////////////////////////////////////////////
 
39
//
 
40
// Implementation of plugin entry points (NPP_*)
 
41
// most are just empty stubs for this particular plugin 
 
42
//
 
43
#include "plugin.h"
 
44
#include "plugin_types.h"
 
45
#include "plugin_setup.h"
 
46
 
 
47
char *NPP_GetMIMEDescription(void)
 
48
{
 
49
    return GetMIMEDescription();
 
50
}
 
51
 
 
52
 
 
53
NPError NPP_Initialize(void)
 
54
{
 
55
    return NPERR_NO_ERROR;
 
56
}
 
57
 
 
58
void NPP_Shutdown(void)
 
59
{
 
60
}
 
61
 
 
62
// here the plugin creates an instance of our CPlugin object which 
 
63
// will be associated with this newly created plugin instance and 
 
64
// will do all the neccessary job
 
65
NPError NPP_New(NPMIMEType pluginType,
 
66
                NPP instance,
 
67
                uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData * saved)
 
68
{
 
69
    if (instance == NULL)
 
70
        return NPERR_INVALID_INSTANCE_ERROR;
 
71
 
 
72
    NPError rv = NPERR_NO_ERROR;
 
73
 
 
74
    CPlugin *pPlugin = new CPlugin(instance);
 
75
    if (pPlugin == NULL)
 
76
        return NPERR_OUT_OF_MEMORY_ERROR;
 
77
 
 
78
    instance->pdata = (void *) pPlugin;
 
79
    pPlugin->mode = mode;
 
80
    pPlugin->mimetype = g_strdup(pluginType);
 
81
    pPlugin->mInstance = instance;
 
82
    new_instance(pPlugin, argc, argn, argv);
 
83
    
 
84
    g_debug ("NEW INSTANCE mode=%d NP_FULL=%d NP_EMBED=%d", mode, NP_FULL, NP_EMBED);
 
85
    return rv;
 
86
}
 
87
 
 
88
// here is the place to clean up and destroy the CPlugin object
 
89
NPError NPP_Destroy(NPP instance, NPSavedData ** save)
 
90
{
 
91
    if (instance == NULL)
 
92
        return NPERR_INVALID_INSTANCE_ERROR;
 
93
 
 
94
    NPError rv = NPERR_NO_ERROR;
 
95
 
 
96
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
97
    if (pPlugin != NULL) {
 
98
        pPlugin->shut();
 
99
        delete pPlugin;
 
100
    }
 
101
    return rv;
 
102
}
 
103
 
 
104
// during this call we know when the plugin window is ready or
 
105
// is about to be destroyed so we can do some gui specific
 
106
// initialization and shutdown
 
107
NPError NPP_SetWindow(NPP instance, NPWindow * pNPWindow)
 
108
{
 
109
    if (instance == NULL)
 
110
        return NPERR_INVALID_INSTANCE_ERROR;
 
111
 
 
112
    NPError rv = NPERR_NO_ERROR;
 
113
 
 
114
    if (pNPWindow == NULL)
 
115
        return NPERR_GENERIC_ERROR;
 
116
 
 
117
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
118
 
 
119
    if (pPlugin == NULL)
 
120
        return NPERR_GENERIC_ERROR;
 
121
 
 
122
    // window just created
 
123
    if (!pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
 
124
        if (!pPlugin->init(pNPWindow)) {
 
125
            delete pPlugin;
 
126
            pPlugin = NULL;
 
127
            return NPERR_MODULE_LOAD_FAILED_ERROR;
 
128
        }
 
129
    }
 
130
    // window goes away
 
131
    if ((pNPWindow->window == NULL) && pPlugin->isInitialized())
 
132
        return NPERR_NO_ERROR;
 
133
 
 
134
    // window resized
 
135
    if (pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
 
136
        pPlugin->SetWindow(pNPWindow);
 
137
        return NPERR_NO_ERROR;
 
138
    }
 
139
    // this should not happen, nothing to do
 
140
    if ((pNPWindow->window == NULL) && !pPlugin->isInitialized())
 
141
        return NPERR_NO_ERROR;
 
142
 
 
143
    return rv;
 
144
}
 
145
 
 
146
// ==============================
 
147
// ! Scriptability related code !
 
148
// ==============================
 
149
//
 
150
// here the plugin is asked by Mozilla to tell if it is scriptable
 
151
// we should return a valid interface id and a pointer to 
 
152
// nsScriptablePeer interface which we should have implemented
 
153
// and which should be defined in the corressponding *.xpt file
 
154
// in the bin/components folder
 
155
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
 
156
{
 
157
    NPError rv = NPERR_NO_ERROR;
 
158
 
 
159
    if (variable == NPPVpluginScriptableNPObject) {
 
160
        if (instance == NULL)
 
161
            return NPERR_INVALID_INSTANCE_ERROR;
 
162
        CPlugin *plugin = (CPlugin *) instance->pdata;
 
163
        if (plugin == NULL)
 
164
            return NPERR_GENERIC_ERROR;
 
165
        //*(NPObject **) value = plugin->GetScriptableObject();
 
166
    } else {
 
167
        rv = PluginGetValue(variable, value);
 
168
    }
 
169
 
 
170
    return rv;
 
171
}
 
172
 
 
173
NPError NPP_NewStream(NPP instance,
 
174
                      NPMIMEType type, NPStream * stream, NPBool seekable, uint16_t * stype)
 
175
{
 
176
    if (instance == NULL)
 
177
        return NPERR_INVALID_INSTANCE_ERROR;
 
178
 
 
179
    NPError rv = NPERR_NO_ERROR;
 
180
 
 
181
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
182
 
 
183
    if (pPlugin == NULL)
 
184
        return NPERR_GENERIC_ERROR;
 
185
 
 
186
    pPlugin->NewStream(type, stream, seekable, stype);
 
187
 
 
188
    return rv;
 
189
}
 
190
 
 
191
int32_t NPP_WriteReady(NPP instance, NPStream * stream)
 
192
{
 
193
    if (instance == NULL)
 
194
        return NPERR_INVALID_INSTANCE_ERROR;
 
195
 
 
196
    int32_t rv = 0x0fffffff;
 
197
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
198
 
 
199
    if (pPlugin == NULL)
 
200
        return NPERR_GENERIC_ERROR;
 
201
 
 
202
    rv = pPlugin->WriteReady(stream);
 
203
    // printf("rv = %i\n",rv);
 
204
 
 
205
    return rv;
 
206
}
 
207
 
 
208
int32_t NPP_Write(NPP instance, NPStream * stream, int32_t offset, int32_t len, void *buffer)
 
209
{
 
210
    if (instance == NULL)
 
211
        return NPERR_INVALID_INSTANCE_ERROR;
 
212
 
 
213
    int32_t rv = len;
 
214
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
215
 
 
216
    if (pPlugin == NULL)
 
217
        return NPERR_GENERIC_ERROR;
 
218
 
 
219
    rv = pPlugin->Write(stream, offset, len, buffer);
 
220
    // printf("rv = %i\n", rv);
 
221
    return rv;
 
222
}
 
223
 
 
224
NPError NPP_DestroyStream(NPP instance, NPStream * stream, NPError reason)
 
225
{
 
226
    if (instance == NULL)
 
227
        return NPERR_INVALID_INSTANCE_ERROR;
 
228
 
 
229
    NPError rv = NPERR_NO_ERROR;
 
230
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
231
 
 
232
    if (pPlugin == NULL)
 
233
        return NPERR_GENERIC_ERROR;
 
234
 
 
235
    pPlugin->DestroyStream(stream, reason);
 
236
    return rv;
 
237
}
 
238
 
 
239
void NPP_StreamAsFile(NPP instance, NPStream * stream, const char *fname)
 
240
{
 
241
    if (instance == NULL)
 
242
        return;
 
243
}
 
244
 
 
245
void NPP_Print(NPP instance, NPPrint * printInfo)
 
246
{
 
247
    if (instance == NULL)
 
248
        return;
 
249
}
 
250
 
 
251
void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
 
252
{
 
253
    if (instance == NULL)
 
254
        return;
 
255
 
 
256
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
257
 
 
258
    if (pPlugin == NULL)
 
259
        return;
 
260
 
 
261
    pPlugin->URLNotify(url, reason, notifyData);
 
262
 
 
263
}
 
264
 
 
265
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
 
266
{
 
267
    if (instance == NULL)
 
268
        return NPERR_INVALID_INSTANCE_ERROR;
 
269
 
 
270
    NPError rv = NPERR_NO_ERROR;
 
271
    return rv;
 
272
}
 
273
 
 
274
int16_t NPP_HandleEvent(NPP instance, void *event)
 
275
{
 
276
    if (instance == NULL)
 
277
        return 0;
 
278
/*
 
279
    int16_t rv = 0;
 
280
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
281
    if (pPlugin)
 
282
        rv = pPlugin->handleEvent(event);
 
283
*/
 
284
    return 0;
 
285
}
 
286
 
 
287
/*
 
288
jref NPP_GetJavaClass (void)
 
289
{
 
290
  return NULL;
 
291
}
 
292
*/
 
293
 
 
294
NPObject *NPP_GetScriptableInstance(NPP instance)
 
295
{
 
296
    if (!instance)
 
297
        return 0;
 
298
/*
 
299
    NPObject *npobj = 0;
 
300
    CPlugin *pPlugin = (CPlugin *) instance->pdata;
 
301
    if (!pPlugin)
 
302
        npobj = pPlugin->GetScriptableObject();
 
303
*/
 
304
    return 0;
 
305
}