|
1 /* |
|
2 * Copyright (c) 2007 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 <e32std.h> |
|
21 #include <npupp.h> |
|
22 #include <npscript.h> |
|
23 #include "GpsPlugin.h" |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // ============================= LOCAL FUNCTIONS =============================== |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // GpsNewp |
|
31 // Create a new instance of a plugin. This is non-leaving method. |
|
32 // Returns: NPError: Error codes recognized by Browser |
|
33 // ---------------------------------------------------------------------------- |
|
34 NPError GpsNewp( NPMIMEType /*pluginType*/, // Not used locally |
|
35 NPP aInstance, // Stores pointer to Gps |
|
36 uint16 /*mode*/, // |
|
37 CDesCArray* argn, // The number of arguments passed |
|
38 CDesCArray* argv, // The values of arguments in the array |
|
39 NPSavedData* /*saved*/ ) // |
|
40 { |
|
41 // Create GpsPlugin, call this leaving method to wrap leaving methods |
|
42 TRAPD( err, GpsConstructL( aInstance, argn, argv ) ); |
|
43 if ( err == KErrNoMemory ) |
|
44 { |
|
45 return NPERR_OUT_OF_MEMORY_ERROR; |
|
46 } |
|
47 |
|
48 if ( err != KErrNone ) |
|
49 { |
|
50 return NPERR_MODULE_LOAD_FAILED_ERROR; |
|
51 } |
|
52 |
|
53 return NPERR_NO_ERROR; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // GpsConstructL |
|
58 // This is the leaving method to create the plugin. We have leaving setters |
|
59 // that need to be wrapped. |
|
60 // Returns: void |
|
61 // ---------------------------------------------------------------------------- |
|
62 void GpsConstructL( NPP aInstance, // Stores pointer to Gps |
|
63 CDesCArray* /*argn*/, // The number of arguments passed |
|
64 CDesCArray* /*argv*/ ) // The values of arguments in the array |
|
65 { |
|
66 aInstance->pdata = CGpsPlugin::NewL(); |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // GpsDestroy(NPP aInstance, NPSavedData**) |
|
71 // Called by Browser to destroy the plugin |
|
72 // Returns: NPError: Error Code |
|
73 // ---------------------------------------------------------------------------- |
|
74 NPError GpsDestroy( NPP aInstance, // Link to Browser |
|
75 NPSavedData** /*save*/ ) // Not used locally |
|
76 { |
|
77 CGpsPlugin *pluginInstance = STATIC_CAST( CGpsPlugin*, aInstance->pdata ); |
|
78 delete pluginInstance; |
|
79 return NPERR_NO_ERROR; |
|
80 } |
|
81 |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // GpsGetvalue |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 NPError GpsGetvalue( NPP instance, |
|
88 NPPVariable variable, |
|
89 void* ret_value) |
|
90 { |
|
91 if (variable==NPPVpluginScriptableNPObject) |
|
92 { |
|
93 CGpsPlugin *siplugin = (CGpsPlugin*)instance->pdata; |
|
94 GpsPluginObject *pluginObject |
|
95 = (GpsPluginObject *)NPN_CreateObject (instance, GpsPluginClass); |
|
96 pluginObject->plugin = siplugin; |
|
97 siplugin->SetInstance(instance); |
|
98 void** ret = (void**)ret_value; |
|
99 *ret = (void*)pluginObject; |
|
100 } |
|
101 return NPERR_NO_ERROR; |
|
102 } |
|
103 |
|
104 |
|
105 // ============================= LOCAL FUNCTIONS =============================== |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // GpsPluginAllocate |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 NPObject* GpsPluginAllocate( NPP /*npp*/, NPClass* /*aClass*/ ) |
|
112 { |
|
113 GpsPluginObject* newInstance |
|
114 = (GpsPluginObject*)User::Alloc( sizeof(GpsPluginObject) ); |
|
115 return (NPObject*)newInstance; |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // GpsPluginDeallocate |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 void GpsPluginDeallocate( GpsPluginObject* obj ) |
|
123 { |
|
124 obj->plugin->Deallocate(); |
|
125 User::Free( (void*)obj ); |
|
126 } |
|
127 |
|
128 // ---------------------------------------------------------------------------- |
|
129 // GpsPluginInvalidate |
|
130 // ---------------------------------------------------------------------------- |
|
131 // |
|
132 void GpsPluginInvalidate( NPObject* /*obj*/ ) |
|
133 { |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------------------------- |
|
137 // GpsPluginHasMethod |
|
138 // ---------------------------------------------------------------------------- |
|
139 // |
|
140 bool GpsPluginHasMethod( GpsPluginObject* obj, |
|
141 NPIdentifier name ) |
|
142 { |
|
143 return obj->plugin->HasMethod( name ); |
|
144 } |
|
145 |
|
146 //----------------------------------------------------------------------------- |
|
147 // GpsPluginInvoke |
|
148 //----------------------------------------------------------------------------- |
|
149 // |
|
150 bool GpsPluginInvoke( GpsPluginObject* obj, |
|
151 NPIdentifier name, |
|
152 NPVariant* args, |
|
153 uint32_t argCount, |
|
154 NPVariant *result ) |
|
155 { |
|
156 return obj->plugin->Invoke( name, args, argCount, result ); |
|
157 } |
|
158 |
|
159 // ---------------------------------------------------------------------------- |
|
160 // GpsPluginHasProperty |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 bool GpsPluginHasProperty( GpsPluginObject* obj, |
|
164 NPIdentifier name ) |
|
165 { |
|
166 return obj->plugin->HasProperty( name ); |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // GpsPluginGetProperty |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 bool GpsPluginGetProperty( GpsPluginObject* obj, |
|
174 NPIdentifier name, |
|
175 NPVariant *variant ) |
|
176 { |
|
177 return obj->plugin->GetProperty( name, variant ); |
|
178 } |
|
179 |
|
180 // ---------------------------------------------------------------------------- |
|
181 // GpsPluginSetProperty |
|
182 // ---------------------------------------------------------------------------- |
|
183 // |
|
184 bool GpsPluginSetProperty( GpsPluginObject* obj, |
|
185 NPIdentifier name, |
|
186 NPVariant *variant ) |
|
187 { |
|
188 TBool r = EFalse; |
|
189 TRAPD( error, r = obj->plugin->SetPropertyL( name, variant ) ); |
|
190 return (r || error)? true : false; |
|
191 } |
|
192 |
|
193 // ---------------------------------------------------------------------------- |
|
194 // BapSetwindow |
|
195 // This is the parent window of plugin |
|
196 // Returns: NPError: Error Code |
|
197 // ---------------------------------------------------------------------------- |
|
198 // |
|
199 NPError GpsSetwindow( |
|
200 NPP /*aInstance*/, // Link to Browser |
|
201 NPWindow* /*aWindow*/ ) // Browser's window passed to BAP |
|
202 { |
|
203 return NPERR_NO_ERROR; |
|
204 } |
|
205 |
|
206 // End of File |