|
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 <e32std.h> |
|
21 #include <npapi.h> |
|
22 #include <npscript.h> |
|
23 #include "SystemInfoPlugin.h" |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // ============================= LOCAL FUNCTIONS =============================== |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // SystemInfoNewp |
|
31 // Create a new instance of a plugin. This is non-leaving method. |
|
32 // Returns: NPError: Error codes recognized by Browser |
|
33 // ---------------------------------------------------------------------------- |
|
34 NPError SystemInfoNewp( NPMIMEType /*pluginType*/, // Not used locally |
|
35 NPP aInstance, // Stores pointer to SystemInfo |
|
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 SystemInfoPlugin, call this leaving method to wrap leaving methods |
|
42 TRAPD( err, SystemInfoConstructL( 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 // SystemInfoConstructL |
|
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 SystemInfoConstructL( NPP aInstance, // Stores pointer to SystemInfo |
|
63 CDesCArray* /*argn*/, // The number of arguments passed |
|
64 CDesCArray* /*argv*/ ) // The values of arguments in the array |
|
65 { |
|
66 aInstance->pdata = CSystemInfoPlugin::NewL(); |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // SystemInfoDestroy(NPP aInstance, NPSavedData**) |
|
71 // Called by Browser to destroy the plugin |
|
72 // Returns: NPError: Error Code |
|
73 // ---------------------------------------------------------------------------- |
|
74 NPError SystemInfoDestroy( NPP aInstance, // Link to Browser |
|
75 NPSavedData** /*save*/ ) // Not used locally |
|
76 { |
|
77 CSystemInfoPlugin *pluginInstance = STATIC_CAST( CSystemInfoPlugin*, aInstance->pdata ); |
|
78 delete pluginInstance; |
|
79 |
|
80 return NPERR_NO_ERROR; |
|
81 } |
|
82 |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // SystemInfoGetvalue |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 NPError SystemInfoGetvalue( |
|
89 NPP instance, |
|
90 NPPVariable variable, |
|
91 void* ret_value) |
|
92 { |
|
93 if (variable==NPPVpluginScriptableNPObject) |
|
94 { |
|
95 CSystemInfoPlugin *siplugin = (CSystemInfoPlugin*)instance->pdata; |
|
96 SystemInfoPluginObject *pluginObject = (SystemInfoPluginObject *)NPN_CreateObject (instance, systemInfoPluginClass); |
|
97 pluginObject->plugin = siplugin; |
|
98 siplugin->SetInstance(instance); |
|
99 void** ret = (void**)ret_value; |
|
100 *ret = (void*)pluginObject; |
|
101 } |
|
102 return NPERR_NO_ERROR; |
|
103 } |
|
104 |
|
105 |
|
106 // ============================ LOCAL FUNCTIONS =============================== |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // systemInfoPluginAllocate |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 NPObject* systemInfoPluginAllocate( NPP /*npp*/, NPClass* /*aClass*/ ) |
|
113 { |
|
114 SystemInfoPluginObject *newInstance = |
|
115 (SystemInfoPluginObject*)User::Alloc( sizeof(SystemInfoPluginObject) ); |
|
116 return (NPObject*)newInstance; |
|
117 } |
|
118 |
|
119 // ---------------------------------------------------------------------------- |
|
120 // systemInfoPluginDeallocate |
|
121 // ---------------------------------------------------------------------------- |
|
122 // |
|
123 void systemInfoPluginDeallocate( SystemInfoPluginObject* obj) |
|
124 { |
|
125 obj->plugin->Deallocate(); |
|
126 User::Free( (void*)obj ); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // systemInfoPluginInvalidate |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 void systemInfoPluginInvalidate( NPObject* /*obj*/ ) |
|
134 { |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // systemInfoPluginHasMethod |
|
139 // ---------------------------------------------------------------------------- |
|
140 // |
|
141 bool systemInfoPluginHasMethod( SystemInfoPluginObject* obj, |
|
142 NPIdentifier name ) |
|
143 { |
|
144 return obj->plugin->HasMethod( name ); |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // systemInfoPluginInvokeFunction |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 bool systemInfoPluginInvokeFunction( SystemInfoPluginObject* obj, |
|
152 NPIdentifier name, |
|
153 NPVariant* args, |
|
154 uint32_t argCount, |
|
155 NPVariant* result) |
|
156 { |
|
157 return obj->plugin->Invoke( name, args, argCount, result ); |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // systemInfoPluginHasProperty |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 bool systemInfoPluginHasProperty( SystemInfoPluginObject* obj, |
|
165 NPIdentifier name ) |
|
166 { |
|
167 return obj->plugin->HasProperty( name ); |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // systemInfoPluginGetProperty |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 bool systemInfoPluginGetProperty( SystemInfoPluginObject* obj, |
|
175 NPIdentifier name, |
|
176 NPVariant *variant ) |
|
177 { |
|
178 return obj->plugin->GetProperty( name, variant ); |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // systemInfoPluginSetProperty |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 bool systemInfoPluginSetProperty( SystemInfoPluginObject* obj, |
|
186 NPIdentifier name, |
|
187 NPVariant *variant ) |
|
188 { |
|
189 TBool r = EFalse; |
|
190 TRAPD( error, r = obj->plugin->SetPropertyL( name, variant ) ); |
|
191 return (error || !r)? false : true; |
|
192 } |
|
193 |
|
194 // End of File |