|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Browser's Netscape API |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "config.h" |
|
19 #include "../../bidi.h" |
|
20 #include "HttpDefs.h" |
|
21 #include "NpnImplementation.h" |
|
22 #include "PluginWin.h" |
|
23 #include "PluginSkin.h" |
|
24 #include <CUserAgent.h> |
|
25 #include <Element.h> |
|
26 #include <HTMLPlugInElement.h> |
|
27 #include <HTMLNames.h> |
|
28 |
|
29 using namespace WebCore::HTMLNames; |
|
30 |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // NpnUrlLoader |
|
35 // |
|
36 // Requests the associated pluginInst to load the given url. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 NPError NpnUrlLoader(NPP aInstance, const TDesC& aUrl, TUint8 aMethod, |
|
40 const TDesC* aWindowType, const TDesC& aBuf, |
|
41 TBool aFromFile, TBool aNotify, void* aNotifyData) |
|
42 { |
|
43 |
|
44 PluginWin* pluginWin = (PluginWin* )aInstance->ndata; |
|
45 if ( !pluginWin ) { |
|
46 return NPERR_INVALID_INSTANCE_ERROR; |
|
47 } |
|
48 |
|
49 TInt status = KErrNone; |
|
50 |
|
51 // Make the load request |
|
52 // convert to 8 bit |
|
53 HBufC8* url = HBufC8::NewLC(aUrl.Length()); |
|
54 url->Des().Copy(aUrl); |
|
55 if (aMethod==EUrlGet) { |
|
56 TRAP_IGNORE(status = pluginWin->pluginSkin()->getRequestL(*url, aNotify, aNotifyData, aWindowType)); |
|
57 } |
|
58 else if (aMethod==EUrlPost) { |
|
59 TRAP_IGNORE(status = pluginWin->pluginSkin()->postRequestL(*url, aBuf, aFromFile, aNotify, aNotifyData, aWindowType)); |
|
60 } |
|
61 |
|
62 CleanupStack::PopAndDestroy(url); |
|
63 |
|
64 // Convert to NPError |
|
65 switch (status) { |
|
66 case KErrNone: |
|
67 return NPERR_NO_ERROR; |
|
68 |
|
69 case KErrNoMemory: |
|
70 return NPERR_OUT_OF_MEMORY_ERROR; |
|
71 |
|
72 default: |
|
73 return NPERR_GENERIC_ERROR; |
|
74 } |
|
75 |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // NpnGetUrl |
|
80 // |
|
81 // Requests the associated pluginInst to load the given url. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 NPError NpnGetUrl(NPP aInstance, const TDesC& aUrl, const TDesC* aWindowType) |
|
85 { |
|
86 TPtrC nullPtr(NULL, 0); |
|
87 return NpnUrlLoader(aInstance, aUrl, EUrlGet, aWindowType, nullPtr, |
|
88 EFalse, EFalse, NULL); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // NpnPostUrl |
|
93 // |
|
94 // Requests the associated pluginInst to POST to the given url. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 NPError NpnPostUrl(NPP aInstance, const TDesC& aUrl, const TDesC* aWindowType, |
|
98 const TDesC& aBuf, NPBool aFile) |
|
99 { |
|
100 return NpnUrlLoader(aInstance, aUrl, EUrlPost, aWindowType, aBuf, |
|
101 aFile, EFalse, NULL); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // NpnRequestRead |
|
106 // |
|
107 // Unsupported. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 NPError NpnRequestRead(NPStream* /*aStream*/, NPByteRange* /*aRangeList*/) |
|
111 { |
|
112 // This function is not supported |
|
113 return NPERR_GENERIC_ERROR; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // NpnNewStream |
|
118 // |
|
119 // Unsupported. |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 NPError NpnNewStream(NPP /*aInstance*/, NPMIMEType /*aType*/, |
|
123 const TDesC* /*aWindowType*/, NPStream** /*aStream*/) |
|
124 { |
|
125 // This function is not supported. |
|
126 // It is specifically intended to create a new Browser window |
|
127 return NPERR_GENERIC_ERROR; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // NpnWrite |
|
132 // |
|
133 // Unsupported. |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 TInt32 NpnWrite(NPP /*aInstance*/, NPStream* /*aStream*/, |
|
137 TInt32 /*aLen*/, void* /*aBuffer*/) |
|
138 { |
|
139 // This function is not supported. |
|
140 return NPERR_GENERIC_ERROR; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // NpnDestroyStream |
|
145 // |
|
146 // Unsupported. |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 NPError NpnDestroyStream(NPP /*aInstance*/, NPStream* /*aStream*/, |
|
150 NPReason /*aReason*/) |
|
151 { |
|
152 // This function is not supported. |
|
153 return NPERR_GENERIC_ERROR; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // NpnStatus |
|
158 // |
|
159 // Allows a plugin to report its current status to the associated PluginInst. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void NpnStatus(NPP aInstance, const TDesC& aMessage) |
|
163 { |
|
164 // This function is not supported. |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // NpnUAgent |
|
169 // |
|
170 // Returns the user agent of the Series 60 Browser. |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 const TDesC* NpnUAgent(NPP /*aInstance*/) |
|
174 { |
|
175 // Get User Agent String |
|
176 CUserAgent* usrAgnt = CUserAgent::NewL(); |
|
177 CleanupStack::PushL( usrAgnt ); |
|
178 |
|
179 HBufC8* userAgent8 = usrAgnt->UserAgentL(); |
|
180 CleanupStack::PushL( userAgent8 ); |
|
181 |
|
182 HBufC* userAgent = HBufC::NewL(userAgent8->Length()); |
|
183 userAgent->Des().Copy(userAgent8->Des()); |
|
184 |
|
185 |
|
186 CleanupStack::PopAndDestroy(2); |
|
187 |
|
188 return userAgent; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // NpnMemAlloc |
|
193 // |
|
194 // Allocates a chunk of memory on the behalf of the plugin. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void* NpnMemAlloc(uint32 aSize) |
|
198 { |
|
199 if (aSize) { |
|
200 return User::Alloc(aSize); |
|
201 } |
|
202 |
|
203 return NULL; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // NpnMemFree |
|
208 // |
|
209 // Deallocates a chunk of memory on the behalf of the plugin. |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void NpnMemFree(void* aPtr) |
|
213 { |
|
214 User::Free(aPtr); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // NpnMemFlush |
|
219 // |
|
220 // Unsupported. |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 uint32 NpnMemFlush(uint32 /*aSize*/) |
|
224 { |
|
225 // This function is not supported |
|
226 return NPERR_GENERIC_ERROR; |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // NpnReloadPlugins |
|
231 // |
|
232 // Causes the PluginHandler to scan for new plugins and reloads the current |
|
233 // page if aReloadPages is true. |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void NpnReloadPlugins(NPBool /*aReloadPages*/) |
|
237 { |
|
238 //This is currently not supported since CPluginHandler is non static |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // NpnGetJavaEnv |
|
243 // |
|
244 // Unsupported. |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 JRIEnv* NpnGetJavaEnv() |
|
248 { |
|
249 // This function is not supported |
|
250 return NULL; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // NpnGetJavaPeer |
|
255 // |
|
256 // Unsupported. |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 jref NpnGetJavaPeer(NPP /*aInstance*/) |
|
260 { |
|
261 // This function is not supported |
|
262 return NULL; |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // NpnGetUrlNotify |
|
267 // |
|
268 // Requests the associated PluginInst to load the given url. The plugin is |
|
269 // notified when the request completes. |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 NPError NpnGetUrlNotify(NPP aInstance, const TDesC& aUrl, |
|
273 const TDesC* aWindowType, void* aNotifyData) |
|
274 { |
|
275 TPtrC nullPtr(NULL, 0); |
|
276 return NpnUrlLoader(aInstance, aUrl, EUrlGet, aWindowType, nullPtr, |
|
277 EFalse, ETrue, aNotifyData); |
|
278 |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // NpnPostUrlNotify |
|
283 // |
|
284 // Requests the associated PluginInst to POST to the given url. The plugin is |
|
285 // notified when the request completes. |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 NPError NpnPostUrlNotify(NPP aInstance, const TDesC& aUrl, |
|
289 const TDesC* aWindowType, const TDesC& aBuf, |
|
290 NPBool aFile, void* aNotifyData) |
|
291 { |
|
292 return NpnUrlLoader(aInstance, aUrl, EUrlPost, aWindowType, aBuf, |
|
293 aFile, ETrue, aNotifyData); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // NpnGetValue |
|
298 // |
|
299 // Query the associated PluginInst for information. |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 NPError NpnGetValue(NPP aInstance, NPNVariable aVariable, void *aRetValue) |
|
303 { |
|
304 |
|
305 switch (aVariable) { |
|
306 |
|
307 case NPNVjavascriptEnabledBool: // Tells whether JavaScript is enabled; true=JavaScript enabled, false=not enabled |
|
308 // NEEDS IMPLEMENTATION |
|
309 // *((TBool*) aRetValue) = NW_Settings_GetEcmaScriptEnabled(); |
|
310 break; |
|
311 |
|
312 case NPNVnetscapeWindow: { |
|
313 |
|
314 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
315 if (pluginWin) { |
|
316 NPWindow* npWindow = (NPWindow*)aRetValue; |
|
317 TRect rect = pluginWin->Rect(); |
|
318 |
|
319 npWindow->x = rect.iTl.iX; |
|
320 npWindow->y = rect.iTl.iY; |
|
321 npWindow->width = rect.Width(); |
|
322 npWindow->height = rect.Height(); |
|
323 npWindow->type = NPWindowTypeWindow; |
|
324 npWindow->window = NULL; |
|
325 |
|
326 NPRect clipRect = {0,0,0,0}; |
|
327 npWindow->clipRect = clipRect; |
|
328 } |
|
329 } |
|
330 break; |
|
331 |
|
332 case NPNVPluginElementNPObject: { |
|
333 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
334 WebCore::Element* pluginElement; |
|
335 if (pluginWin) { |
|
336 pluginElement = pluginWin->pluginSkin()->getElement(); |
|
337 } |
|
338 |
|
339 NPObject* pluginScriptObject = 0; |
|
340 if (pluginElement->hasTagName(appletTag) || pluginElement->hasTagName(embedTag) || pluginElement->hasTagName(objectTag)) |
|
341 pluginScriptObject = static_cast<WebCore::HTMLPlugInElement*>(pluginElement)->getNPObject(); |
|
342 |
|
343 if (pluginScriptObject) |
|
344 _NPN_RetainObject(pluginScriptObject); |
|
345 |
|
346 void** v = (void**)aRetValue; |
|
347 *v = pluginScriptObject; |
|
348 } |
|
349 break; |
|
350 |
|
351 case NPNVWindowNPObject: { |
|
352 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
353 NPObject* windowObject = pluginWin->windowScriptNPObject(); |
|
354 if (windowObject) { |
|
355 void **v = (void **)aRetValue; |
|
356 *v = windowObject; |
|
357 return NPERR_NO_ERROR; |
|
358 } |
|
359 return NPERR_GENERIC_ERROR; |
|
360 } |
|
361 case NPNVDOMWindow: |
|
362 case NPNVxDisplay: // Unix only: Returns the current Display |
|
363 case NPNVxtAppContext: // Unix only: Returns the application's XtAppContext |
|
364 case NPNVasdEnabledBool: // Tells whether SmartUpdate (former name: ASD) is enabled; |
|
365 // true=SmartUpdate enabled, false=not enabled |
|
366 case NPNVisOfflineBool: // Tells whether offline mode is enabled; |
|
367 // true=offline mode enabled, false=not enabled |
|
368 |
|
369 case NPNNetworkAccess: |
|
370 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
371 TInt apId = -1; |
|
372 if (pluginWin) { |
|
373 apId = pluginWin->pluginSkin()->handleNetworkAccess(); |
|
374 } |
|
375 *((TInt*) aRetValue) = apId; |
|
376 break; |
|
377 |
|
378 |
|
379 default: |
|
380 *((TBool*) aRetValue) = EFalse; |
|
381 break; |
|
382 } // end of switch |
|
383 |
|
384 return NPERR_NO_ERROR; |
|
385 |
|
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // NpnSetValue |
|
390 // |
|
391 // Set a value on the associated PluginInst |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 NPError NpnSetValue(NPP aInstance, NPPVariable aVariable, void* aSetValue) |
|
395 { |
|
396 switch (aVariable) { |
|
397 // Set a new plugin window size. This will resize the plugin rect, |
|
398 // which requires a re-layout of the dom (render) tree. |
|
399 case NPPVpluginWindowSize: { |
|
400 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
401 if (pluginWin) { |
|
402 NPWindow* npWindow = (NPWindow*)aSetValue; |
|
403 if (npWindow) { |
|
404 TRect newRect(npWindow->x, npWindow->y, npWindow->width, npWindow->height); |
|
405 pluginWin->resizePluginRect(newRect); |
|
406 } |
|
407 } |
|
408 } |
|
409 break; |
|
410 case NPPVpluginWindowBool: |
|
411 { |
|
412 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
413 if (pluginWin) { |
|
414 NPBool* isWindowed = (NPBool*)aSetValue; |
|
415 if (isWindowed) |
|
416 pluginWin->setWindowedPlugin(*isWindowed); |
|
417 } |
|
418 |
|
419 } |
|
420 break; |
|
421 case NPPVpluginTransparentBool: |
|
422 { |
|
423 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
424 if (pluginWin) { |
|
425 NPBool* isTransparent = (NPBool*)aSetValue; |
|
426 if (isTransparent) |
|
427 pluginWin->setTransparentPlugin(*isTransparent); |
|
428 } |
|
429 } |
|
430 break; |
|
431 case NPPVPluginFocusPosition: |
|
432 { |
|
433 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
434 if (pluginWin) { |
|
435 TPoint* focusPoint = (TPoint*) aSetValue; |
|
436 if (focusPoint) { |
|
437 pluginWin->moveWindow(*focusPoint); |
|
438 } |
|
439 } |
|
440 } |
|
441 break; |
|
442 case NPPVPluginDeactivate: |
|
443 { |
|
444 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
445 if (pluginWin) { |
|
446 pluginWin->pluginDeactivate(); |
|
447 } |
|
448 } |
|
449 break; |
|
450 case NPPVpluginFullScreenBool: |
|
451 { |
|
452 NPBool* isFullScreen = (NPBool*)aSetValue; |
|
453 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
454 pluginWin->TogleScreenMode(*isFullScreen); |
|
455 break; |
|
456 } |
|
457 default: |
|
458 break; |
|
459 |
|
460 } // end of switch |
|
461 |
|
462 return NPERR_NO_ERROR; |
|
463 } |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // NpnInvalidateRect |
|
467 // |
|
468 // Unsupported. |
|
469 // ----------------------------------------------------------------------------- |
|
470 // |
|
471 void NpnInvalidateRect(NPP aInstance, NPRect * /*aRect*/) |
|
472 { |
|
473 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
474 if( pluginWin ) |
|
475 pluginWin->forceRedraw(false); |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // NpnInvalidateRegion |
|
480 // |
|
481 // Unsupported. |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 void NpnInvalidateRegion(NPP /*aInstance*/, NPRegion /*aRegion*/) |
|
485 { |
|
486 // This function is not supported |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // NpnForceRedraw |
|
491 // |
|
492 // Unsupported. |
|
493 // ----------------------------------------------------------------------------- |
|
494 // |
|
495 void NpnForceRedraw(NPP aInstance) |
|
496 { |
|
497 PluginWin* pluginWin = (PluginWin*)aInstance->ndata; |
|
498 if( pluginWin ) |
|
499 pluginWin->forceRedraw(true); |
|
500 } |
|
501 |
|
502 |
|
503 |