~ubuntu-branches/ubuntu/karmic/gnash/karmic

« back to all changes in this revision

Viewing changes to libcore/asobj/System_as.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// System.cpp:  ActionScript "System" class, for Gnash.
 
2
// 
 
3
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
4
// 
 
5
// This program is free software; you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation; either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
// 
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program; if not, write to the Free Software
 
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
//
 
19
 
 
20
#include <sstream>
 
21
 
 
22
#include "movie_root.h" // interface callback
 
23
#include "log.h"
 
24
#include "System_as.h"
 
25
#include "fn_call.h"
 
26
#include "builtin_function.h"
 
27
#include "VM.h" // for getPlayerVersion() 
 
28
#include "Object.h" // for getObjectInterface
 
29
 
 
30
inline std::string
 
31
trueFalse(bool x)
 
32
{
 
33
    return x ? "t" : "f";
 
34
}
 
35
 
 
36
namespace gnash {
 
37
 
 
38
static const std::string& systemLanguage(as_object& proto);
 
39
 
 
40
static as_value system_security_allowdomain(const fn_call& fn);
 
41
static as_value system_security_allowinsecuredomain(const fn_call& fn);
 
42
static as_value system_security_loadpolicyfile(const fn_call& fn);
 
43
static as_value system_setclipboard(const fn_call& fn);
 
44
static as_value system_showsettings(const fn_call& fn);
 
45
static as_value system_exactsettings(const fn_call& fn);
 
46
static as_value system_usecodepage(const fn_call& fn);
 
47
 
 
48
void registerSystemNative(as_object& global)
 
49
{
 
50
    VM& vm = global.getVM();
 
51
    
 
52
    vm.registerNative(system_security_allowdomain, 12, 0);
 
53
    vm.registerNative(system_showsettings, 2107, 0);
 
54
    
 
55
    // From http://osflash.org/flashcoders/undocumented/asnative
 
56
    
 
57
    // Run once in startup script then deleted...
 
58
    // System.Capabilities.Query 11, 0    
 
59
    
 
60
    // System.Product.isRunning 2201, 0
 
61
    // System.Product.isInstalled 2201, 1
 
62
    // System.Product.launch 2201, 2
 
63
    // System.Product.download 2201, 3    
 
64
}
 
65
 
 
66
static as_object*
 
67
getSystemSecurityInterface(as_object& o)
 
68
{
 
69
    VM& vm = o.getVM();
 
70
 
 
71
        static boost::intrusive_ptr<as_object> proto;
 
72
        if ( proto == NULL )
 
73
        {
 
74
                proto = new as_object(getObjectInterface());
 
75
                proto->init_member("allowDomain", vm.getNative(12, 0));
 
76
 
 
77
                // TODO: only available when SWF >= 7 
 
78
                proto->init_member("allowInsecureDomain", new builtin_function(system_security_allowinsecuredomain));
 
79
 
 
80
                proto->init_member("loadPolicyFile", new builtin_function(system_security_loadpolicyfile));
 
81
        }
 
82
        return proto.get();
 
83
}
 
84
 
 
85
static as_object*
 
86
getSystemCapabilitiesInterface(as_object& o)
 
87
{
 
88
        RcInitFile& rcfile = RcInitFile::getDefaultInstance();
 
89
 
 
90
    //
 
91
    // Filesystem, access, miscellaneous hardware information
 
92
    //
 
93
 
 
94
    // "Windows XP", "Windows 2000", "Windows NT", "Windows 98/ME",
 
95
    // "Windows 95", "Windows CE", "Linux", "MacOS"
 
96
    // Override in gnashrc
 
97
    VM& vm = o.getVM();
 
98
    
 
99
    const std::string os = vm.getOSName();
 
100
 
 
101
    const std::string language = systemLanguage(o);
 
102
 
 
103
    // FIXME: these need to be implemented properly 
 
104
    // Does the NetStream object natively support SSL?
 
105
        const bool hasTLS = false;
 
106
 
 
107
    // Microphone and camera access disabled
 
108
        const bool avHardwareDisable = false;
 
109
        
 
110
        // Not sure: seems to be whether the movie can 'float' above web pages,
 
111
        // and is useful for disabling certain annoying adverts.
 
112
        const bool windowlessDisable = false;
 
113
 
 
114
        const bool hasPrinting = true;
 
115
        const bool hasAccessibility = true;
 
116
        const bool isDebugger = false;
 
117
        const bool localFileReadDisable = false;
 
118
 
 
119
    //
 
120
    // Display information (needs active GUI)
 
121
    //
 
122
 
 
123
    // Documented to be a number, but is in fact a string.
 
124
    std::string pixelAspectRatio;
 
125
 
 
126
    // "StandAlone", "External", "PlugIn", "ActiveX" (get from GUI)
 
127
    std::string playerType;
 
128
    
 
129
    std::string screenColor;
 
130
    
 
131
    int screenDPI = 0;
 
132
 
 
133
    int screenResolutionX = 0;
 
134
    int screenResolutionY = 0;
 
135
 
 
136
    std::istringstream ss;
 
137
 
 
138
    const movie_root& m = vm.getRoot();
 
139
 
 
140
    ss.str(m.callInterface("System.capabilities.screenResolutionX", ""));
 
141
    ss >> screenResolutionX;
 
142
        
 
143
    ss.clear();
 
144
    ss.str(m.callInterface("System.capabilities.screenResolutionY", ""));
 
145
    ss >> screenResolutionY;
 
146
 
 
147
    ss.clear();
 
148
    ss.str(m.callInterface("System.capabilities.screenDPI", ""));
 
149
    ss >> screenDPI;
 
150
        
 
151
    pixelAspectRatio = m.callInterface("System.capabilities.pixelAspectRatio", "");
 
152
    playerType = m.callInterface("System.capabilities.playerType", "");
 
153
    screenColor = m.callInterface("System.capabilities.screenColor", "");
 
154
 
 
155
    //
 
156
        // Media
 
157
        //
 
158
                
 
159
        // Is audio available?
 
160
        const bool hasAudio = (get_sound_handler() != NULL);
 
161
 
 
162
    // FIXME: these need to be implemented properly. They are mostly
 
163
    // self-explanatory.
 
164
    const bool hasAudioEncoder = true;
 
165
    const bool hasEmbeddedVideo = true;
 
166
    const bool hasIME = true;
 
167
    const bool hasMP3 = true;
 
168
    const bool hasScreenBroadcast = true;
 
169
    const bool hasScreenPlayback = true;
 
170
    const bool hasStreamingAudio = true;
 
171
    const bool hasStreamingVideo = true;
 
172
    const bool hasVideoEncoder = true;
 
173
 
 
174
    //
 
175
    // Player version
 
176
    //
 
177
 
 
178
    // "LNX 9,0,22,0", "MAC 8,0,99,0"
 
179
    // Override in gnashrc
 
180
    const std::string version = vm.getPlayerVersion();
 
181
 
 
182
    // "Macromedia Windows", "Macromedia Linux", "Macromedia MacOS"
 
183
    // Override in gnashrc
 
184
    const std::string manufacturer = rcfile.getFlashSystemManufacturer();
 
185
    
 
186
    // serverString
 
187
        // A URL-encoded string to send system info to a server.
 
188
        // Boolean values are represented as t or f.            
 
189
        // Privacy concerns should probably be addressed by     
 
190
        // allowing this string to be sent or not; individual   
 
191
        // values that might affect privacy can be overridden   
 
192
        // in gnashrc.
 
193
        
 
194
        // hasIME seems not to be included in the server string, though
 
195
        // it is documented to have a server string of IME.
 
196
        // Linux player version 9 has no hasIME property (but no need
 
197
        // to emulate that.)
 
198
        
 
199
        // TLS and hasTLS are documented for AS3, player version 9.
 
200
        //
 
201
        // WD is included in the server string for player version 9,
 
202
        // but not documented. It corresponds to the equally undocumented
 
203
        // windowlessDisable.
 
204
        
 
205
        // This should be the standard order of parameters in the server
 
206
        // string.
 
207
        std::ostringstream serverString;
 
208
        serverString << "A="    << trueFalse(hasAudio)
 
209
                        << "&SA="       << trueFalse(hasStreamingAudio)
 
210
                        << "&SV="       << trueFalse(hasStreamingVideo)
 
211
                        << "&EV="       << trueFalse(hasEmbeddedVideo)
 
212
                        << "&MP3="      << trueFalse(hasMP3)                                            
 
213
                        << "&AE="       << trueFalse(hasAudioEncoder)
 
214
                        << "&VE="       << trueFalse(hasVideoEncoder)
 
215
                        << "&ACC="      << trueFalse(hasAccessibility)
 
216
                        << "&PR="       << trueFalse(hasPrinting)
 
217
                        << "&SP="       << trueFalse(hasScreenPlayback) 
 
218
                        << "&SB="       << trueFalse(hasScreenBroadcast) 
 
219
                        << "&DEB="      << trueFalse(isDebugger)
 
220
                        << "&V="    << URL::encode(version)
 
221
                        << "&M="    << URL::encode(manufacturer)
 
222
                        << "&R="    << screenResolutionX << "x" << screenResolutionY
 
223
                        << "&DP="       << screenDPI
 
224
                        << "&COL="      << screenColor                                  
 
225
                        << "&AR="   << pixelAspectRatio
 
226
                        << "&OS="   << URL::encode(os)
 
227
                        << "&L="    << language                 
 
228
                        << "&PT="   << playerType
 
229
                        << "&AVD="      << trueFalse(avHardwareDisable) 
 
230
                        << "&LFD="      << trueFalse(localFileReadDisable)
 
231
                        << "&WD="   << trueFalse(windowlessDisable)
 
232
                        << "&TLS="      << trueFalse(hasTLS);
 
233
        
 
234
        static boost::intrusive_ptr<as_object> proto;
 
235
        if ( proto == NULL )
 
236
        {
 
237
                const int flags = as_prop_flags::dontDelete
 
238
                                | as_prop_flags::dontEnum
 
239
                                | as_prop_flags::readOnly;
 
240
 
 
241
                proto = new as_object(getObjectInterface());
 
242
 
 
243
                proto->init_member("version", version, flags);
 
244
                proto->init_member("playerType", playerType, flags);
 
245
                proto->init_member("os", os, flags);
 
246
                proto->init_member("manufacturer", manufacturer, flags);
 
247
                proto->init_member("language", language, flags);
 
248
                proto->init_member("hasAudio", hasAudio, flags);
 
249
                proto->init_member("screenResolutionX", screenResolutionX, flags);
 
250
                proto->init_member("screenResolutionY", screenResolutionY, flags);
 
251
                proto->init_member("screenColor", screenColor, flags);
 
252
                proto->init_member("screenDPI", screenDPI, flags);
 
253
                proto->init_member("pixelAspectRatio", pixelAspectRatio, flags);
 
254
                proto->init_member("serverString", serverString.str(), flags);
 
255
                proto->init_member("avHardwareDisable", avHardwareDisable, flags);
 
256
                proto->init_member("hasAudioEncoder", hasAudioEncoder, flags);
 
257
                proto->init_member("hasEmbeddedVideo", hasEmbeddedVideo, flags);
 
258
                proto->init_member("hasIME", hasIME, flags);
 
259
                proto->init_member("hasMP3", hasMP3, flags);
 
260
                proto->init_member("hasPrinting", hasPrinting, flags);
 
261
                proto->init_member("hasScreenBroadcast", hasScreenBroadcast, flags);
 
262
                proto->init_member("hasScreenPlayback", hasScreenPlayback, flags);
 
263
                proto->init_member("hasStreamingAudio", hasStreamingAudio, flags);
 
264
                proto->init_member("hasStreamingVideo", hasStreamingVideo, flags);
 
265
                proto->init_member("hasVideoEncoder", hasVideoEncoder, flags);
 
266
                proto->init_member("hasAccessibility", hasAccessibility, flags);
 
267
                proto->init_member("isDebugger", isDebugger, flags);
 
268
                proto->init_member("localFileReadDisable", localFileReadDisable, flags);
 
269
                proto->init_member("hasTLS", hasTLS, flags);
 
270
                proto->init_member("windowlessDisable", windowlessDisable, flags);
 
271
        }
 
272
        return proto.get();
 
273
}
 
274
 
 
275
static void
 
276
attachSystemInterface(as_object& proto)
 
277
{
 
278
        VM& vm = proto.getVM();
 
279
    const int version = vm.getSWFVersion();
 
280
 
 
281
        proto.init_member("security", getSystemSecurityInterface(proto));
 
282
        proto.init_member("capabilities", getSystemCapabilitiesInterface(proto));
 
283
        proto.init_member("setClipboard", new builtin_function(system_setclipboard));
 
284
        proto.init_member("showSettings", vm.getNative(2107, 0));
 
285
 
 
286
        proto.init_property("useCodepage", &system_usecodepage, &system_usecodepage);
 
287
 
 
288
    if (version < 6) return;
 
289
 
 
290
    proto.init_property("exactSettings", &system_exactsettings, &system_exactsettings);
 
291
 
 
292
}
 
293
 
 
294
 
 
295
as_value
 
296
system_security_allowdomain(const fn_call& /*fn*/)
 
297
{
 
298
    LOG_ONCE(log_unimpl ("System.security.allowDomain") );
 
299
    return as_value();
 
300
}
 
301
 
 
302
 
 
303
as_value
 
304
system_security_allowinsecuredomain(const fn_call& /*fn*/)
 
305
{
 
306
    LOG_ONCE(log_unimpl ("System.security.allowInsecureDomain") );
 
307
    return as_value();
 
308
}
 
309
 
 
310
 
 
311
as_value
 
312
system_security_loadpolicyfile(const fn_call& /*fn*/)
 
313
{
 
314
    LOG_ONCE(log_unimpl ("System.security.loadPolicyFile") );
 
315
    return as_value();
 
316
}
 
317
 
 
318
 
 
319
as_value
 
320
system_setclipboard(const fn_call& /*fn*/)
 
321
{
 
322
    LOG_ONCE(log_unimpl ("System.setClipboard") );
 
323
    return as_value();
 
324
}
 
325
 
 
326
 
 
327
as_value
 
328
system_showsettings(const fn_call& /*fn*/)
 
329
{
 
330
    LOG_ONCE(log_unimpl ("System.showSettings") );
 
331
    return as_value();
 
332
}
 
333
 
 
334
 
 
335
// FIXME: should return true if shared object files
 
336
// are stored under an exact domain name (www.gnashdev.org or
 
337
// gnashdev.org); false if both are stored under gnashdev.org.
 
338
// Can be set.
 
339
as_value
 
340
system_exactsettings(const fn_call& fn)
 
341
{
 
342
        static boost::intrusive_ptr<as_object> obj = ensureType<as_object>(fn.this_ptr);
 
343
 
 
344
    // Getter
 
345
    if (fn.nargs == 0)
 
346
    {
 
347
        // Is always true until we implement it.
 
348
        return as_value(true);   
 
349
    }
 
350
    
 
351
    // Setter
 
352
    else 
 
353
    {
 
354
        LOG_ONCE(log_unimpl ("System.exactSettings") );
 
355
        return as_value();
 
356
    }
 
357
}
 
358
 
 
359
 
 
360
// FIXME: if true, SWF6+ should treat characters as Latin
 
361
// charset variants. If false (default), as UtrueFalse-8.
 
362
// Can be set.
 
363
as_value
 
364
system_usecodepage(const fn_call& fn)
 
365
{
 
366
        static boost::intrusive_ptr<as_object> obj = ensureType<as_object>(fn.this_ptr);
 
367
 
 
368
    // Getter
 
369
    if (fn.nargs == 0)
 
370
    {
 
371
        // Is always false until we implement it.
 
372
        return as_value(false);   
 
373
    }
 
374
    
 
375
    // Setter
 
376
    else 
 
377
    {
 
378
        LOG_ONCE(log_unimpl ("System.useCodepage") );
 
379
        return as_value();
 
380
    }
 
381
}
 
382
 
 
383
 
 
384
void
 
385
system_class_init(as_object& global)
 
386
{
 
387
        // _global.System is NOT a class, but a simple object, see System.as
 
388
 
 
389
        static boost::intrusive_ptr<as_object> obj = new as_object(getObjectInterface());
 
390
        attachSystemInterface(*obj);
 
391
        global.init_member("System", obj.get());
 
392
}
 
393
 
 
394
 
 
395
const std::string&
 
396
systemLanguage(as_object& proto)
 
397
{
 
398
        // Two-letter language code ('en', 'de') corresponding to ISO 639-1
 
399
        // Chinese can be either zh-CN or zh-TW. English used to have a 
 
400
        // country (GB, US) qualifier, but that was dropped in version 7 of the player.
 
401
        // This method relies on getting a POSIX-style language code of the form
 
402
        // "zh_TW.utf8", "zh_CN" or "it" from the VM.
 
403
        // It is obviously very easy to extend support to all language codes, but
 
404
        // some scripts rely on there being only 20 possible languages. It could
 
405
        // be a run time option if it's important enough to care.
 
406
 
 
407
        static std::string lang = proto.getVM().getSystemLanguage();
 
408
        
 
409
        const char* languages[] = {"en", "fr", "ko", "ja", "sv",
 
410
                                "de", "es", "it", "zh", "pt",
 
411
                                "pl", "hu", "cs", "tr", "fi",
 
412
                                "da", "nl", "no", "ru"};
 
413
        
 
414
        const unsigned int size = sizeof (languages) / sizeof (*languages);
 
415
        
 
416
        if (std::find(languages, languages + size, lang.substr(0,2)) != languages + size)
 
417
        {
 
418
                if (lang.substr(0,2) == "zh")
 
419
                {
 
420
                        // Chinese is the only language since the pp version 7
 
421
                        // to need an additional qualifier.
 
422
                        if (lang.substr(2, 3) == "_TW") lang = "zh-TW";
 
423
                        else if (lang.substr(2, 3) == "_CN") lang = "zh-CN";
 
424
                        else lang = "xu";
 
425
                }
 
426
                else
 
427
                {
 
428
                        // All other matching cases: retain just the first
 
429
                        // two characters.
 
430
                        lang.erase(2);
 
431
                }
 
432
        }
 
433
        else
 
434
        {
 
435
                // Unknown language. We also return this if
 
436
                // getSystemLanguage() returns something unexpected. 
 
437
                lang = "xu";
 
438
        }
 
439
 
 
440
        return lang;
 
441
 
 
442
}
 
443
 
 
444
} // end of gnash namespace