|
1 /* |
|
2 * Copyright (c) 2004 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "Wrt.h" |
|
23 #include "WrtPlatform.h" |
|
24 #include <CUserAgent.h> |
|
25 //#include "WrtFuncs.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // MACROS |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 _LIT(KWrtVersion, "1.1"); |
|
37 _LIT(KNotAvailable, "N/A"); |
|
38 |
|
39 // MODULE DATA STRUCTURES |
|
40 |
|
41 // LOCAL FUNCTION PROTOTYPES |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 using namespace KJS; |
|
45 const ClassInfo JSWrt::info = { "JSWrt", 0, &WrtTable, 0 }; |
|
46 |
|
47 // ============================= LOCAL FUNCTIONS =============================== |
|
48 /* |
|
49 @begin WrtTable 1 |
|
50 version JSWrt::version DontDelete|ReadOnly |
|
51 platform JSWrt::platform DontDelete|ReadOnly |
|
52 @end |
|
53 */ |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // JSWrt::JSWrt |
|
59 // C++ constructor |
|
60 // |
|
61 // |
|
62 // ---------------------------------------------------------------------------- |
|
63 JSWrt::JSWrt( ExecState* exec ) |
|
64 : JSObject( exec->lexicalInterpreter()->builtinObjectPrototype() ), |
|
65 wrtPriv(new WrtPrivate()) |
|
66 { |
|
67 m_wrtVersion = NULL; |
|
68 TRAP_IGNORE( |
|
69 CUserAgent* usrAgnt = CUserAgent::NewL(); |
|
70 // Get User Agent String |
|
71 if (usrAgnt) |
|
72 m_wrtVersion = usrAgnt->BrowserNameAndVersionL()->AllocL(); |
|
73 delete usrAgnt; |
|
74 ) |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // JSWrt::~JSWrt |
|
79 // Destructor |
|
80 // |
|
81 // |
|
82 // ---------------------------------------------------------------------------- |
|
83 JSWrt::~JSWrt() |
|
84 { |
|
85 delete wrtPriv; |
|
86 delete m_wrtVersion; |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // JSWrt::mark |
|
91 // mark |
|
92 // |
|
93 // |
|
94 // ---------------------------------------------------------------------------- |
|
95 void JSWrt::mark() |
|
96 { |
|
97 JSObject::mark(); |
|
98 if(wrtPriv->m_platform) |
|
99 wrtPriv->m_platform->mark(); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // JSWrt::type |
|
104 // |
|
105 // |
|
106 // |
|
107 // ---------------------------------------------------------------------------- |
|
108 JSType JSWrt::type() const |
|
109 { |
|
110 return ObjectType; |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // JSWrt::toString |
|
115 // Returns string representation of the object |
|
116 // |
|
117 // |
|
118 // ---------------------------------------------------------------------------- |
|
119 UString JSWrt::toString(ExecState *exec) const |
|
120 { |
|
121 return "[object JSWrt]"; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // JSWrt::getValueProperty |
|
126 // |
|
127 // |
|
128 // ---------------------------------------------------------------------------- |
|
129 JSValue* JSWrt::getValueProperty(ExecState *exec, int token) const |
|
130 { |
|
131 switch (token) { |
|
132 case version: { |
|
133 TPtrC wrtVersionPtr; |
|
134 if (m_wrtVersion) |
|
135 { |
|
136 wrtVersionPtr.Set( *m_wrtVersion ); |
|
137 } |
|
138 else |
|
139 { |
|
140 wrtVersionPtr.Set( KNotAvailable ); |
|
141 } |
|
142 |
|
143 return jsString( UString((UChar*) wrtVersionPtr.Ptr(), wrtVersionPtr.Length()) ); |
|
144 } |
|
145 case platform: { |
|
146 return wrtPriv->m_platform ? wrtPriv->m_platform : wrtPriv->m_platform = new JSWrtPlatform(exec); |
|
147 } |
|
148 default: |
|
149 return throwError(exec, GeneralError); |
|
150 } |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // JSWrt::getOwnPropertySlot |
|
155 // |
|
156 // |
|
157 // |
|
158 // ---------------------------------------------------------------------------- |
|
159 bool JSWrt::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
160 { |
|
161 const HashEntry* entry = Lookup::findEntry(&WrtTable, propertyName); |
|
162 if (entry) |
|
163 { |
|
164 slot.setStaticEntry(this, entry, staticValueGetter<JSWrt>); |
|
165 return true; |
|
166 } |
|
167 |
|
168 return JSObject::getOwnPropertySlot(exec, propertyName, slot); |
|
169 } |
|
170 |
|
171 |
|
172 //END OF FILE |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |