1
// System.cpp: ActionScript "System" class, for Gnash.
3
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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.
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.
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
22
#include "movie_root.h" // interface callback
24
#include "System_as.h"
26
#include "builtin_function.h"
27
#include "VM.h" // for getPlayerVersion()
28
#include "Object.h" // for getObjectInterface
38
static const std::string& systemLanguage(as_object& proto);
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);
48
void registerSystemNative(as_object& global)
50
VM& vm = global.getVM();
52
vm.registerNative(system_security_allowdomain, 12, 0);
53
vm.registerNative(system_showsettings, 2107, 0);
55
// From http://osflash.org/flashcoders/undocumented/asnative
57
// Run once in startup script then deleted...
58
// System.Capabilities.Query 11, 0
60
// System.Product.isRunning 2201, 0
61
// System.Product.isInstalled 2201, 1
62
// System.Product.launch 2201, 2
63
// System.Product.download 2201, 3
67
getSystemSecurityInterface(as_object& o)
71
static boost::intrusive_ptr<as_object> proto;
74
proto = new as_object(getObjectInterface());
75
proto->init_member("allowDomain", vm.getNative(12, 0));
77
// TODO: only available when SWF >= 7
78
proto->init_member("allowInsecureDomain", new builtin_function(system_security_allowinsecuredomain));
80
proto->init_member("loadPolicyFile", new builtin_function(system_security_loadpolicyfile));
86
getSystemCapabilitiesInterface(as_object& o)
88
RcInitFile& rcfile = RcInitFile::getDefaultInstance();
91
// Filesystem, access, miscellaneous hardware information
94
// "Windows XP", "Windows 2000", "Windows NT", "Windows 98/ME",
95
// "Windows 95", "Windows CE", "Linux", "MacOS"
96
// Override in gnashrc
99
const std::string os = vm.getOSName();
101
const std::string language = systemLanguage(o);
103
// FIXME: these need to be implemented properly
104
// Does the NetStream object natively support SSL?
105
const bool hasTLS = false;
107
// Microphone and camera access disabled
108
const bool avHardwareDisable = false;
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;
114
const bool hasPrinting = true;
115
const bool hasAccessibility = true;
116
const bool isDebugger = false;
117
const bool localFileReadDisable = false;
120
// Display information (needs active GUI)
123
// Documented to be a number, but is in fact a string.
124
std::string pixelAspectRatio;
126
// "StandAlone", "External", "PlugIn", "ActiveX" (get from GUI)
127
std::string playerType;
129
std::string screenColor;
133
int screenResolutionX = 0;
134
int screenResolutionY = 0;
136
std::istringstream ss;
138
const movie_root& m = vm.getRoot();
140
ss.str(m.callInterface("System.capabilities.screenResolutionX", ""));
141
ss >> screenResolutionX;
144
ss.str(m.callInterface("System.capabilities.screenResolutionY", ""));
145
ss >> screenResolutionY;
148
ss.str(m.callInterface("System.capabilities.screenDPI", ""));
151
pixelAspectRatio = m.callInterface("System.capabilities.pixelAspectRatio", "");
152
playerType = m.callInterface("System.capabilities.playerType", "");
153
screenColor = m.callInterface("System.capabilities.screenColor", "");
159
// Is audio available?
160
const bool hasAudio = (get_sound_handler() != NULL);
162
// FIXME: these need to be implemented properly. They are mostly
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;
178
// "LNX 9,0,22,0", "MAC 8,0,99,0"
179
// Override in gnashrc
180
const std::string version = vm.getPlayerVersion();
182
// "Macromedia Windows", "Macromedia Linux", "Macromedia MacOS"
183
// Override in gnashrc
184
const std::string manufacturer = rcfile.getFlashSystemManufacturer();
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
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
199
// TLS and hasTLS are documented for AS3, player version 9.
201
// WD is included in the server string for player version 9,
202
// but not documented. It corresponds to the equally undocumented
203
// windowlessDisable.
205
// This should be the standard order of parameters in the server
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)
228
<< "&PT=" << playerType
229
<< "&AVD=" << trueFalse(avHardwareDisable)
230
<< "&LFD=" << trueFalse(localFileReadDisable)
231
<< "&WD=" << trueFalse(windowlessDisable)
232
<< "&TLS=" << trueFalse(hasTLS);
234
static boost::intrusive_ptr<as_object> proto;
237
const int flags = as_prop_flags::dontDelete
238
| as_prop_flags::dontEnum
239
| as_prop_flags::readOnly;
241
proto = new as_object(getObjectInterface());
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);
276
attachSystemInterface(as_object& proto)
278
VM& vm = proto.getVM();
279
const int version = vm.getSWFVersion();
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));
286
proto.init_property("useCodepage", &system_usecodepage, &system_usecodepage);
288
if (version < 6) return;
290
proto.init_property("exactSettings", &system_exactsettings, &system_exactsettings);
296
system_security_allowdomain(const fn_call& /*fn*/)
298
LOG_ONCE(log_unimpl ("System.security.allowDomain") );
304
system_security_allowinsecuredomain(const fn_call& /*fn*/)
306
LOG_ONCE(log_unimpl ("System.security.allowInsecureDomain") );
312
system_security_loadpolicyfile(const fn_call& /*fn*/)
314
LOG_ONCE(log_unimpl ("System.security.loadPolicyFile") );
320
system_setclipboard(const fn_call& /*fn*/)
322
LOG_ONCE(log_unimpl ("System.setClipboard") );
328
system_showsettings(const fn_call& /*fn*/)
330
LOG_ONCE(log_unimpl ("System.showSettings") );
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.
340
system_exactsettings(const fn_call& fn)
342
static boost::intrusive_ptr<as_object> obj = ensureType<as_object>(fn.this_ptr);
347
// Is always true until we implement it.
348
return as_value(true);
354
LOG_ONCE(log_unimpl ("System.exactSettings") );
360
// FIXME: if true, SWF6+ should treat characters as Latin
361
// charset variants. If false (default), as UtrueFalse-8.
364
system_usecodepage(const fn_call& fn)
366
static boost::intrusive_ptr<as_object> obj = ensureType<as_object>(fn.this_ptr);
371
// Is always false until we implement it.
372
return as_value(false);
378
LOG_ONCE(log_unimpl ("System.useCodepage") );
385
system_class_init(as_object& global)
387
// _global.System is NOT a class, but a simple object, see System.as
389
static boost::intrusive_ptr<as_object> obj = new as_object(getObjectInterface());
390
attachSystemInterface(*obj);
391
global.init_member("System", obj.get());
396
systemLanguage(as_object& proto)
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.
407
static std::string lang = proto.getVM().getSystemLanguage();
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"};
414
const unsigned int size = sizeof (languages) / sizeof (*languages);
416
if (std::find(languages, languages + size, lang.substr(0,2)) != languages + size)
418
if (lang.substr(0,2) == "zh")
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";
428
// All other matching cases: retain just the first
435
// Unknown language. We also return this if
436
// getSystemLanguage() returns something unexpected.
444
} // end of gnash namespace