|
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: API functions that were loaded into TLS for the Browser to use. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <Uri16.h> |
|
21 #include <mmf/common/MmfControllerFrameworkBase.h> |
|
22 #include "stdlib.h" |
|
23 |
|
24 #include "BavpLogger.h" |
|
25 #include "BavpPlugin.h" |
|
26 #include "BavpVolumeHandler.h" |
|
27 |
|
28 #include <npscript.h> |
|
29 #include "BavpNPObject.h" |
|
30 // CONSTANTS |
|
31 _LIT(KAccessPtId, "accesspointid"); |
|
32 _LIT(KLoop,"loop"); |
|
33 _LIT(KSrc,"src"); |
|
34 _LIT(KData,"data"); |
|
35 _LIT(KRtsp,"rtsp"); |
|
36 _LIT(KInfinite,"infinite"); |
|
37 _LIT(KVolume, "volume"); |
|
38 _LIT(KHigh, "high"); |
|
39 _LIT(KMiddle, "middle"); |
|
40 _LIT(KLow, "low"); |
|
41 |
|
42 const TInt KOneLoopValue = 1; |
|
43 const TInt KMaxLoopValue = 50; |
|
44 |
|
45 // ============================= LOCAL FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // BavpNewp |
|
49 // Create a new instance of a plugin. This is non-leaving method. |
|
50 // Returns: NPError: Error codes recognized by Browser |
|
51 // ----------------------------------------------------------------------------- |
|
52 NPError BavpNewp( NPMIMEType /* pluginType*/, // Not used locally |
|
53 NPP aInstance, // Stores pointer to Bavp |
|
54 uint16 /* mode */, // |
|
55 CDesCArray* argn, // The number of arguments passed |
|
56 CDesCArray* argv, // The values of arguments in the array |
|
57 NPSavedData* /*saved*/ ) // |
|
58 { |
|
59 |
|
60 // Fix for TSW error ID: SLON-74588K, as ControlPanel is unsupported so for the time being |
|
61 // controlPanel plugin window shown as emplty non supported window. |
|
62 |
|
63 _LIT(KControls, "controls"); |
|
64 _LIT(KControlPanel, "controlpanel"); |
|
65 |
|
66 for ( TInt i=0; i < argn->Count(); i++ ) |
|
67 { |
|
68 if(((*argn)[i].Compare( KControls) == 0)&&((*argv)[i].Compare(KControlPanel ) == 0)) |
|
69 { |
|
70 return NPERR_INVALID_PLUGIN_ERROR; |
|
71 } |
|
72 } |
|
73 // Create BrowserAudioVideoPlugin, call this leaving method to wrap leaving methods |
|
74 TRAPD( err, BavpConstructL( aInstance, argn, argv ) ); |
|
75 if ( err == KErrNoMemory ) |
|
76 { |
|
77 Log( EFalse, _L("FUNCTION BavpNewp ERROR! Out of Memory Error") ); |
|
78 |
|
79 return NPERR_OUT_OF_MEMORY_ERROR; |
|
80 } |
|
81 |
|
82 if ( err != KErrNone ) |
|
83 { |
|
84 Log( EFalse, _L("FUNCTION BavpNewp ERROR! Module Load Failure") ); |
|
85 return NPERR_MODULE_LOAD_FAILED_ERROR; |
|
86 } |
|
87 |
|
88 return NPERR_NO_ERROR; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // BavpConstructL |
|
93 // This is the leaving method to create the plugin. We have leaving setters |
|
94 // that need to be wrapped. |
|
95 // Returns: void |
|
96 // ----------------------------------------------------------------------------- |
|
97 void BavpConstructL( NPP aInstance, // Stores pointer to Bavp |
|
98 CDesCArray* argn, // The number of arguments passed |
|
99 CDesCArray* argv ) // The values of arguments in the array |
|
100 { |
|
101 Log( EFalse, _L("Calling FUNCTION BavpConstructL") ); |
|
102 |
|
103 CBavpPlugin *pluginInstance( NULL ); |
|
104 |
|
105 // Create BrowserVideoPlugin |
|
106 pluginInstance = CBavpPlugin::NewL(); |
|
107 |
|
108 // Bavp functions can now be called |
|
109 aInstance->pdata = pluginInstance; |
|
110 |
|
111 // Retrieve the various attributes from the HTTP file and the |
|
112 // object/embed/bgsound/soundstart tags on that page |
|
113 // |
|
114 // Retrieve the access point attribute |
|
115 TInt accessPtIndex; |
|
116 TInt accessPtId( KUseDefaultIap ); |
|
117 if ( !argn->Find( KAccessPtId, accessPtIndex, ECmpFolded ) ) |
|
118 { |
|
119 // If the string is found get the access pt id and convert to TInt |
|
120 TPtrC16 accessPtValue( (*argv)[accessPtIndex] ); |
|
121 TLex lex( accessPtValue ); |
|
122 TInt intVal( 0 ); |
|
123 if ( lex.Val( intVal ) == KErrNone) |
|
124 { |
|
125 accessPtId = intVal; |
|
126 } |
|
127 } |
|
128 pluginInstance->SetAccessPtId( accessPtId ); |
|
129 |
|
130 // Retrieve the "loop" attribute value, default value is "1", |
|
131 // with infiniteFlag off. This handles the loop attribute missing |
|
132 // and loop="0" cases. |
|
133 TInt loopIndex( 0 ); |
|
134 TPtrC16 loopValue; |
|
135 TBool infiniteFlag( EFalse ); // Always false, use loop="50" instead "infinite" |
|
136 TInt loop( KOneLoopValue ); // Our default loop value is "1" |
|
137 |
|
138 TInt positionLoop = argn->Find( KLoop, loopIndex, ECmpFolded ); |
|
139 if ( positionLoop == 0 ) |
|
140 { |
|
141 // Found a loop attribute value |
|
142 TPtrC16 pointerLoopCount( (*argv)[loopIndex] ); |
|
143 loopValue.Set( pointerLoopCount ); |
|
144 |
|
145 // Is the loop value equal to string "infinite" |
|
146 if ( loopValue.Compare( KInfinite ) == 0 ) |
|
147 { |
|
148 // We never play true infinite, we loop max 50 times |
|
149 loop = KMaxLoopValue; |
|
150 } |
|
151 else |
|
152 { |
|
153 // Ensure that only a valid loop value is used (1 to 50) |
|
154 HBufC8* convertPointerLoopCount = HBufC8::New( pointerLoopCount.Length() ); |
|
155 TPtr8 convertToByteLoop = convertPointerLoopCount->Des(); |
|
156 convertToByteLoop.Copy( pointerLoopCount ); |
|
157 |
|
158 loop = atoi( (char*)(convertToByteLoop.Ptr()) ); |
|
159 if ( loop < KOneLoopValue ) |
|
160 { |
|
161 loop = KOneLoopValue; |
|
162 } |
|
163 else if ( loop > KMaxLoopValue ) |
|
164 { |
|
165 loop = KMaxLoopValue; |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 // Retrieve the "volume" attribute value, default is max, so that if the |
|
171 // "volume" attribute isn't present, the user preferences will not get |
|
172 // overwritten. There is a check in controller->SetVolumeByAttribute that |
|
173 // checks current and attribute volume and choses lower volume. |
|
174 TInt positionVolumeValue( 0 ); |
|
175 TInt CRVolume( KCRVolumeMax ); |
|
176 TPtrC16 volumeValue; |
|
177 TInt positionVol = argn->Find( KVolume, positionVolumeValue, ECmpFolded ); |
|
178 if ( positionVol == 0 ) |
|
179 { |
|
180 TPtrC16 pointerVolumeValue( (*argv)[positionVolumeValue] ); |
|
181 volumeValue.Set( pointerVolumeValue ); |
|
182 if ( !(volumeValue.Compare( KHigh )) ) |
|
183 { |
|
184 CRVolume = KCRVolume10; |
|
185 } |
|
186 else if ( !(volumeValue.Compare( KMiddle )) ) |
|
187 { |
|
188 CRVolume = KCRVolume5; |
|
189 } |
|
190 else if ( !(volumeValue.Compare( KLow )) ) |
|
191 { |
|
192 CRVolume = KCRVolume2; |
|
193 } |
|
194 else |
|
195 { |
|
196 // Convert volume numeric string (i.e. volume="6") to CR volume |
|
197 HBufC8* convertPointerVolumeValue = HBufC8::New( pointerVolumeValue.Length() ); |
|
198 TPtr8 convertToByteVolume = convertPointerVolumeValue->Des(); |
|
199 convertToByteVolume.Append( pointerVolumeValue ); |
|
200 CRVolume = atoi( (char*)(convertToByteVolume.Ptr()) ); |
|
201 if ( CRVolume < KCRVolumeMute ) |
|
202 { |
|
203 CRVolume = KCRVolumeMute; |
|
204 } |
|
205 else if ( CRVolume > KCRVolumeMax ) |
|
206 { |
|
207 CRVolume = KCRVolumeMax; |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 // Set the Volume and Loop for plugin |
|
213 pluginInstance->SetVolumeAndLoop( CRVolume, loop, infiniteFlag ); |
|
214 |
|
215 // Retrieve the "src" or "data" attribute value, if it is rtsp scheme lets |
|
216 // save it, so we can start a controller, since rtsp content is not passed |
|
217 // by WebKit. It is our (Bavp) responsibilty to load rtsp content. |
|
218 TInt srcIndex( 0 ); |
|
219 TInt ret = argn->Find( KSrc, srcIndex, ECmpFolded ); |
|
220 if ( ret != 0 ) |
|
221 { |
|
222 // If the src attribute NOT found, try to find data attribute |
|
223 ret = argn->Find( KData, srcIndex, ECmpFolded ); |
|
224 } |
|
225 |
|
226 if ( ret == 0 ) |
|
227 { |
|
228 // We found either data or src attribute |
|
229 TPtrC16 srcValue( (*argv)[ srcIndex ] ); |
|
230 TUriParser uriParser; |
|
231 uriParser.Parse( srcValue ); |
|
232 if ( !uriParser.Extract( EUriScheme ).Compare( KRtsp ) ) |
|
233 { |
|
234 // We found a RTSP scheme. Lets save it up, so when the BavpView |
|
235 // is create we can start the BavpController and load rtsp. This |
|
236 // is because rtsp will not be started by a call to BavpAsFile(). |
|
237 // NOTE: Files (http) are downloaded first and then BavpAsFile() |
|
238 // is called, which starts the BavpController. |
|
239 pluginInstance->SetRtspUriL( uriParser.UriDes() ); |
|
240 |
|
241 // We may have to move this to a different place if eg: the url of |
|
242 // the object is changed later (say from javascript) |
|
243 CBavpPluginEcomMain* lBavpPluginEcomMain = (CBavpPluginEcomMain*) Dll::Tls(); |
|
244 NPNetscapeFuncs* funcPtr = lBavpPluginEcomMain->Funcs(); |
|
245 if ( funcPtr && funcPtr->getvalue ) |
|
246 { |
|
247 funcPtr->getvalue( aInstance, NPNNetworkAccess, (void *)&accessPtId); |
|
248 pluginInstance->SetAccessPtId( accessPtId ); |
|
249 } |
|
250 |
|
251 } |
|
252 } |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // BavpDestroy(NPP aInstance, NPSavedData**) |
|
257 // Called by Browser to destroy the plugin |
|
258 // Returns: NPError: Error Code |
|
259 // ----------------------------------------------------------------------------- |
|
260 NPError BavpDestroy( NPP aInstance, // Link to Browser |
|
261 NPSavedData** /*save*/ ) // Not used locally |
|
262 { |
|
263 Log( EFalse, _L("Calling FUNCTION BavpDestroy") ); |
|
264 |
|
265 CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, aInstance->pdata ); |
|
266 delete pluginInstance; |
|
267 |
|
268 return NPERR_NO_ERROR; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // BavpSetwindow |
|
273 // This is the parent window of plugin |
|
274 // Returns: NPError: Error Code |
|
275 // ----------------------------------------------------------------------------- |
|
276 NPError BavpSetwindow( NPP aInstance, // Link to Browser |
|
277 NPWindow* aWindow ) // Browser's window passed to Bavp |
|
278 { |
|
279 Log( EFalse, _L("Calling FUNCTION BavpSetwindow") ); |
|
280 |
|
281 CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, aInstance->pdata ); |
|
282 MPluginAdapter *pluginAdapter = STATIC_CAST( MPluginAdapter*, aWindow->window); |
|
283 |
|
284 TRAPD( err, pluginInstance->SetWindowL(pluginAdapter, aWindow, aInstance) ); |
|
285 if ( err == KErrNoMemory ) |
|
286 { |
|
287 Log( EFalse, _L("FUNCTION BavpSetWindow ERROR! Out of Memory Error") ); |
|
288 |
|
289 // Set the error to plugin if err occurs, it's for the next create plugin check |
|
290 pluginInstance->iError = ETrue; |
|
291 return NPERR_OUT_OF_MEMORY_ERROR; |
|
292 } |
|
293 |
|
294 if ( err != KErrNone ) |
|
295 { |
|
296 Log( EFalse, _L("FUNCTION BavpSetWindow ERROR: %d"), err ); |
|
297 |
|
298 // Set the error to plugin if err occurs, it's for the next create plugin check |
|
299 pluginInstance->iError = ETrue; |
|
300 return NPERR_GENERIC_ERROR; |
|
301 } |
|
302 |
|
303 return NPERR_NO_ERROR; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // BavpNewstream |
|
308 // Indicates start of downloading of an video file from the internet |
|
309 // Returns: NPError: Error Code |
|
310 // ----------------------------------------------------------------------------- |
|
311 NPError BavpNewstream( NPP instance, |
|
312 NPMIMEType type, |
|
313 NPStream* /*stream*/, // |
|
314 NPBool /*seekable*/, // |
|
315 uint16* stype ) // Will set to NP_ASFILEONLY to notify Browser how to send data |
|
316 { |
|
317 Log( EFalse, _L("Calling FUNCTION BavpNewstream") ); |
|
318 |
|
319 // Bavp needs to set stype to alert Browser to send data via Bavp_asfile |
|
320 *stype = NP_ASFILEONLY; |
|
321 |
|
322 CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, instance->pdata ); |
|
323 |
|
324 pluginInstance->SetMimeType( type ); |
|
325 |
|
326 return NPERR_NO_ERROR; |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // BavpDestroystream NOT USED |
|
331 // Indicates completion of downloading an video file from the internet |
|
332 // Returns: NPError: Error Code |
|
333 // ----------------------------------------------------------------------------- |
|
334 NPError BavpDestroystream( NPP /*instance*/, // Not used locally |
|
335 NPStream* /*stream*/, // |
|
336 NPReason /*aReason*/ ) // |
|
337 { |
|
338 Log( EFalse, _L("Calling FUNCTION BavpDestroyStream") ); |
|
339 |
|
340 return NPERR_NO_ERROR; |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // BavpAsfile |
|
345 // Called by Browser when data is copied to a file. |
|
346 // Returns: void |
|
347 // ----------------------------------------------------------------------------- |
|
348 void BavpAsfile( NPP aInstance, // Link to Browser |
|
349 NPStream* stream, |
|
350 const TDesC& aFileName ) // file name and path |
|
351 { |
|
352 Log( EFalse, _L("Calling FUNCTION BavpAsfile") ); |
|
353 Log( EFalse, _L("Filename:") ); |
|
354 Log( EFalse, aFileName ); |
|
355 |
|
356 CBavpPlugin *pluginInstance = STATIC_CAST( CBavpPlugin*, aInstance->pdata ); |
|
357 |
|
358 // Get the error, and set this error to iError in plugin |
|
359 TRAPD( err, pluginInstance->OpenAndPlayFileL( aFileName, stream->url ) ); |
|
360 if ( err != KErrNone ) |
|
361 { |
|
362 Log( EFalse, _L("FUNCTION BavpAsfile ERROR!") ); |
|
363 |
|
364 // If error, set for plugin, it's for the next create plugin check |
|
365 pluginInstance->iError = ETrue; |
|
366 } |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // BavpWriteready NOT SUPPORTED |
|
371 // ----------------------------------------------------------------------------- |
|
372 int32 BavpWriteready( NPP /*instance*/, |
|
373 NPStream* /*stream*/ ) |
|
374 { |
|
375 // Not implemented |
|
376 return NPERR_NO_ERROR; |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // BavpWrite NOT SUPPORTED |
|
381 // ----------------------------------------------------------------------------- |
|
382 int32 BavpWrite( NPP /*instance*/, |
|
383 NPStream* /*stream*/, |
|
384 int32 /*offset*/, |
|
385 int32 /*len*/, |
|
386 void* /*buffer*/ ) |
|
387 { |
|
388 // Not implemented |
|
389 return NPERR_NO_ERROR; |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // BavpPrint NOT SUPPORTED |
|
394 // ----------------------------------------------------------------------------- |
|
395 void BavpPrint( NPP /*instance*/, |
|
396 NPPrint* /*platformPrint*/ ) |
|
397 { |
|
398 // Not implemented |
|
399 } |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // BavpEvent NOT SUPPORTED |
|
403 // ----------------------------------------------------------------------------- |
|
404 int16 BavpEvent( NPP /*instance*/, |
|
405 void* /*event*/ ) |
|
406 { |
|
407 // Not implemented |
|
408 return NPERR_NO_ERROR; |
|
409 } |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // BavpUrlnotify NOT SUPPORTED |
|
413 // ----------------------------------------------------------------------------- |
|
414 void BavpUrlnotify( NPP /*instance*/, |
|
415 const TDesC8& /*url*/, |
|
416 NPReason /*reason*/, |
|
417 void* /*notifyData*/ ) |
|
418 { |
|
419 // Not implemented |
|
420 } |
|
421 |
|
422 // ----------------------------------------------------------------------------- |
|
423 // BavpSetvalue NOT SUPPORTED |
|
424 // ----------------------------------------------------------------------------- |
|
425 NPError BavpSetvalue( NPP /*instance*/, |
|
426 NPNVariable /*variable*/, |
|
427 void* /*ret_value*/ ) |
|
428 { |
|
429 // Not implemented |
|
430 return NPERR_NO_ERROR; |
|
431 } |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // BavpGetvalue NOT SUPPORTED |
|
435 // ----------------------------------------------------------------------------- |
|
436 NPError BavpGetvalue( NPP aInstance, |
|
437 NPPVariable aVariable, |
|
438 void* ret_value ) |
|
439 { |
|
440 NPError err( NPERR_NO_ERROR ); |
|
441 |
|
442 switch( aVariable ) |
|
443 { |
|
444 case NPPVpluginInteractiveBool: |
|
445 // Interactive=0, Not Interactive=1 |
|
446 *(TBool *)ret_value = EFalse; |
|
447 break; |
|
448 case NPPVpluginScriptableNPObject: |
|
449 { |
|
450 // return instance of scripting object to the browser |
|
451 BavpNPObject *pluginNPObject = BavpNPObject_new( aInstance ); |
|
452 |
|
453 CBavpPlugin *bavpplugin = (CBavpPlugin*)aInstance->pdata; |
|
454 bavpplugin->SetNPObject(pluginNPObject); |
|
455 |
|
456 pluginNPObject->plugin = bavpplugin; |
|
457 pluginNPObject->nppInstance = aInstance; |
|
458 void** ret = (void**)ret_value; |
|
459 *ret = (void*)pluginNPObject; |
|
460 } |
|
461 break; |
|
462 default: |
|
463 break; |
|
464 } //end switch |
|
465 |
|
466 return err; |
|
467 } |
|
468 |
|
469 // End of File |