|
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: Interface to Browser for handling embedded Gps requests. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <npupp.h> |
|
22 #include <E32HAL.H> |
|
23 #include "GpsPlugin.h" |
|
24 #include "GpsObserver.h" |
|
25 #include <CSatelliteInfoUI.h> |
|
26 |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 enum TIdentifiersNames { |
|
31 EIdLatitude, |
|
32 EIdLongitude, |
|
33 EIdAlt, |
|
34 EIdHorizontalAccuracy, |
|
35 EIdVerticalAccuracy, |
|
36 EIdOnGps, |
|
37 EIdSatelliteStatus, |
|
38 EIdTickCount, |
|
39 EIdLast |
|
40 }; |
|
41 |
|
42 const NPUTF8 *GpsPluginIdentifierNames[EIdLast] |
|
43 = { "latitude", // 0 |
|
44 "longitude", // 1 |
|
45 "altitude", // 2 |
|
46 "horizontalaccuracy", // 3 |
|
47 "verticalaccuracy", // 4 |
|
48 "ongps", // 5 |
|
49 "showsatellitestatus", // 6 |
|
50 "tickcount", // 7 |
|
51 }; |
|
52 |
|
53 const TBool IsMethod[] = { |
|
54 EFalse, // latitude, |
|
55 EFalse, // longitude, |
|
56 EFalse, // altitude |
|
57 EFalse, // horizontalaccuracy |
|
58 EFalse, // verticalaccuracy |
|
59 EFalse, // ongps |
|
60 ETrue, // showSatelliteStatus |
|
61 EFalse, // tickcount |
|
62 }; |
|
63 |
|
64 |
|
65 // ============================ MEMBER FUNCTIONS =============================== |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CGpsPlugin::CGpsPlugin |
|
69 // C++ default constructor can NOT contain any code, that |
|
70 // might leave. |
|
71 // ---------------------------------------------------------------------------- |
|
72 CGpsPlugin::CGpsPlugin() |
|
73 { |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CGpsPlugin::NewL |
|
78 // Two-phased constructor. |
|
79 // ---------------------------------------------------------------------------- |
|
80 CGpsPlugin* CGpsPlugin::NewL() |
|
81 { |
|
82 CGpsPlugin* self = new (ELeave) CGpsPlugin; |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CGpsPlugin::ConstructL |
|
91 // Symbian 2nd phase constructor can leave. |
|
92 // ---------------------------------------------------------------------------- |
|
93 void CGpsPlugin::ConstructL() |
|
94 { |
|
95 iGpsPluginIdentifiers = new (ELeave) NPIdentifier[EIdLast]; |
|
96 NPN_GetStringIdentifiers( GpsPluginIdentifierNames, EIdLast, |
|
97 iGpsPluginIdentifiers ); |
|
98 |
|
99 iGpsObserver = CGpsObserver::NewL( this ); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CGpsPlugin::Destructor |
|
104 // ---------------------------------------------------------------------------- |
|
105 CGpsPlugin::~CGpsPlugin() |
|
106 { |
|
107 delete [] iGpsPluginIdentifiers; |
|
108 delete iGpsObserver; |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // CGpsPlugin::Deallocate |
|
113 // ---------------------------------------------------------------------------- |
|
114 void CGpsPlugin::Deallocate () |
|
115 { |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // CGpsPlugin::InvokeCallback |
|
120 // ---------------------------------------------------------------------------- |
|
121 bool CGpsPlugin::InvokeCallback( TDesC8& name, |
|
122 const NPVariant *args, uint32_t argCount ) |
|
123 { |
|
124 CGpsPluginEcomMain* lGpsPPluginEcomMain = (CGpsPluginEcomMain*) Dll::Tls(); |
|
125 NPNetscapeFuncs* lNetscapeFuncs = lGpsPPluginEcomMain->Funcs(); |
|
126 if (lNetscapeFuncs && iInstanceHandle) |
|
127 { |
|
128 void* value = 0; |
|
129 NPError npErr |
|
130 = lNetscapeFuncs->getvalue( iInstanceHandle, NPNVWindowNPObject, |
|
131 (void*)&value ); |
|
132 if (npErr == NPERR_NO_ERROR) |
|
133 { |
|
134 NPVariant resultVariant; |
|
135 VOID_TO_NPVARIANT( resultVariant ); |
|
136 NPIdentifier ident |
|
137 = NPN_GetStringIdentifier( (const NPUTF8 *)(name.Ptr()) ); |
|
138 return NPN_Invoke( iInstanceHandle, (NPObject*)value, |
|
139 ident, args, argCount, &resultVariant ); |
|
140 } |
|
141 } |
|
142 return false; |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // CWidgetManagerPlugin::HasMethod |
|
147 // ---------------------------------------------------------------------------- |
|
148 |
|
149 bool CGpsPlugin::HasMethod( NPIdentifier name ) |
|
150 { |
|
151 for ( TInt i= 0; i < EIdLast; i++ ) |
|
152 { |
|
153 if ( name == iGpsPluginIdentifiers[i] ) |
|
154 { |
|
155 return IsMethod[i]; |
|
156 } |
|
157 } |
|
158 return false; |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CGpsPlugin::HasProperty |
|
163 // ---------------------------------------------------------------------------- |
|
164 bool CGpsPlugin::HasProperty( NPIdentifier name ) |
|
165 { |
|
166 for ( TInt i= 0; i < EIdLast; i++ ) |
|
167 { |
|
168 if ( name == iGpsPluginIdentifiers[i] ) |
|
169 { |
|
170 return !IsMethod[i]; |
|
171 } |
|
172 } |
|
173 return false; |
|
174 } |
|
175 |
|
176 // ---------------------------------------------------------------------------- |
|
177 // CGpsPlugin::GetProperty |
|
178 // ---------------------------------------------------------------------------- |
|
179 bool CGpsPlugin::GetProperty( NPIdentifier name, NPVariant *variant ) |
|
180 { |
|
181 // default variant value maps to javascript undefined |
|
182 VOID_TO_NPVARIANT( *variant ); |
|
183 if ( name == iGpsPluginIdentifiers[EIdLatitude] ) |
|
184 { |
|
185 DOUBLE_TO_NPVARIANT( iGpsObserver->Latitude(), *variant ); |
|
186 } |
|
187 else if ( name == iGpsPluginIdentifiers[EIdLongitude] ) |
|
188 { |
|
189 DOUBLE_TO_NPVARIANT( iGpsObserver->Longitude(), *variant ); |
|
190 } |
|
191 else if ( name == iGpsPluginIdentifiers[EIdAlt] ) |
|
192 { |
|
193 DOUBLE_TO_NPVARIANT( iGpsObserver->Altitude(), *variant ); |
|
194 } |
|
195 else if ( name == iGpsPluginIdentifiers[EIdHorizontalAccuracy] ) |
|
196 { |
|
197 DOUBLE_TO_NPVARIANT( iGpsObserver->HorizontalAccuracy(), *variant ); |
|
198 } |
|
199 else if ( name == iGpsPluginIdentifiers[EIdVerticalAccuracy] ) |
|
200 { |
|
201 DOUBLE_TO_NPVARIANT( iGpsObserver->VerticalAccuracy(), *variant ); |
|
202 } |
|
203 else if ( name == iGpsPluginIdentifiers[EIdTickCount] ) |
|
204 { |
|
205 INT32_TO_NPVARIANT( iGpsObserver->TickCount(), *variant ); |
|
206 } |
|
207 else |
|
208 { |
|
209 return EFalse; |
|
210 } |
|
211 return ETrue; |
|
212 } |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // CGpsPlugin::Invoke |
|
216 // ---------------------------------------------------------------------------- |
|
217 bool CGpsPlugin::Invoke( NPIdentifier name, |
|
218 NPVariant* /*args*/, |
|
219 uint32_t /*argCount*/, |
|
220 NPVariant *result ) |
|
221 { |
|
222 VOID_TO_NPVARIANT( *result ); |
|
223 if ( name == iGpsPluginIdentifiers[EIdSatelliteStatus] ) |
|
224 { |
|
225 TRAP_IGNORE( |
|
226 CSatelliteInfoUI* satelliteUI = CSatelliteInfoUI::NewL(); |
|
227 (void) satelliteUI->ExecuteLD( _L("BrowserGpsPlugin") ) ); |
|
228 } |
|
229 return true; |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // CGpsPlugin::SetPropertyL |
|
234 // ---------------------------------------------------------------------------- |
|
235 bool CGpsPlugin::SetPropertyL( NPIdentifier name, NPVariant *variant ) |
|
236 { |
|
237 if ( name == iGpsPluginIdentifiers[EIdOnGps] ) |
|
238 { |
|
239 NPString str = NPVARIANT_TO_STRING( *variant ); |
|
240 iGpsObserver->RequestNotificationL(str); |
|
241 } |
|
242 else |
|
243 { |
|
244 return EFalse; |
|
245 } |
|
246 return ETrue; |
|
247 } |
|
248 |
|
249 // ---------------------------------------------------------------------------- |
|
250 // CBAPPlugin::SetWindowL |
|
251 // Called by Browser for window creation. |
|
252 // (other items were commented in a header). |
|
253 // ---------------------------------------------------------------------------- |
|
254 void CGpsPlugin::SetWindowL( |
|
255 MPluginAdapter* /*aPluginAdapter*/, // Allows callback to Browser |
|
256 const TRect& /*aRect*/) // Window information |
|
257 { |
|
258 } |
|
259 // End of File |