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
21
#include "gnashconfig.h"
27
#include "builtin_function.h"
28
#include "VM.h" // for getPlayerVersion()
29
#include "Object.h" // for getObjectInterface
30
#include "URL.h" // for encoding serverString
32
#define TF(x) (x ? "t" : "f")
36
const std::string& systemLanguage();
38
static as_value system_security_allowdomain(const fn_call& fn);
39
static as_value system_security_allowinsecuredomain(const fn_call& fn);
40
static as_value system_security_loadpolicyfile(const fn_call& fn);
41
static as_value system_setclipboard(const fn_call& fn);
42
static as_value system_showsettings(const fn_call& fn);
43
static as_value system_showsettings(const fn_call& fn);
46
getSystemSecurityInterface()
48
static boost::intrusive_ptr<as_object> proto;
51
proto = new as_object(getObjectInterface());
52
proto->init_member("allowDomain", new builtin_function(system_security_allowdomain));
54
// TODO: only available when SWF >= 7
55
proto->init_member("allowInsecureDomain", new builtin_function(system_security_allowinsecuredomain));
57
proto->init_member("loadPolicyFile", new builtin_function(system_security_loadpolicyfile));
63
getSystemCapabilitiesInterface()
65
RcInitFile& rcfile = RcInitFile::getDefaultInstance();
67
// "LNX 9,0,22,0", "MAC 8,0,99,0"
68
// Override in gnashrc
69
const std::string version = VM::get().getPlayerVersion();
71
// Flash 7: "StandAlone", "External", "PlugIn", "ActiveX"
72
// TODO: Implement properly
73
const std::string playerType = "StandAlone";
75
// "Windows XP", "Windows 2000", "Windows NT", "Windows 98/ME", "Windows 95", "Windows CE", "Linux", "MacOS"
76
// Override in gnashrc
77
const std::string os = VM::get().getOSName();
79
// "Macromedia Windows", "Macromedia Linux", "Macromedia MacOS"
80
// Override in gnashrc
81
const std::string manufacturer = rcfile.getFlashSystemManufacturer();
84
const std::string language = systemLanguage();
88
// Is audio available?
89
const bool hasAudio = (get_sound_handler() != NULL);
91
/* A URL-encoded string to send system info to a server.*/
92
/* Boolean values are represented as t or f. */
93
/* Privacy concerns should probably be addressed by */
94
/* allowing this string to be sent or not; individual */
95
/* values that might affect privacy can be overridden */
98
std::string serverString =
99
+ "OS=" + URL::encode(os)
100
+ "&A=" + TF(hasAudio)
101
+ "&V=" + URL::encode(version)
102
+ "&PT=" + playerType
104
+ "&AVD=" // avHardwareDisable (bool)
105
+ "&ACC=" // hasAccessibility (bool)
106
+ "&AE=" // hasAudioEncoder (bool)
107
+ "&EV=" // hasEmbeddedVideo (bool)
108
+ "&IME=" // hasIME (bool)
109
+ "&MP3=" // hasMP3 (bool)
110
+ "&PR=" // hasPrinting (bool)
111
+ "&SB=" // hasScreenBroadcast (bool)
112
+ "&SP=" // hasScreenPlayback (bool)
113
+ "&SA=" // hasStreamingAudio (bool)
114
+ "&SV=" // hasStreamingVideo (bool)
115
+ "&VE=" // hasVideoEncoder (bool)
116
+ "&DEB=" // isDebugger (bool)
117
+ "&LFD=" // localFileReadDisable (bool)
118
+ "&M=" + URL::encode(manufacturer)
119
+ "&AR=" // pixelAspectRatio (double)
120
+ "&COL=" // screenColor (?)
121
+ "&DP=" // screenDPI (int?)
122
+ "&R=" // + screenResolutionX + "x" + screenResolutionY
125
static boost::intrusive_ptr<as_object> proto;
128
int flags = as_prop_flags::dontDelete;
129
flags |= as_prop_flags::dontEnum;
130
flags |= as_prop_flags::readOnly;
132
proto = new as_object(getObjectInterface());
134
proto->init_member("version", version, flags);
135
proto->init_member("playerType", playerType, flags);
136
proto->init_member("os", os, flags);
137
proto->init_member("manufacturer", manufacturer, flags);
138
proto->init_member("language", language, flags);
139
proto->init_member("hasAudio", hasAudio, flags);
140
proto->init_member("serverString", serverString, flags);
147
attachSystemInterface(as_object& proto)
149
// Initialize Function prototype
150
proto.init_member("security", getSystemSecurityInterface());
151
proto.init_member("capabilities", getSystemCapabilitiesInterface());
152
proto.init_member("setClipboard", new builtin_function(system_setclipboard));
153
proto.init_member("showSettings", new builtin_function(system_showsettings));
159
static boost::intrusive_ptr<as_object> proto;
162
proto = new as_object(getObjectInterface());
163
attachSystemInterface(*proto);
168
system_as_object::system_as_object()
170
as_object(getSystemInterface()) // pass System inheritence
174
as_value system_security_allowdomain(const fn_call& /*fn*/) {
175
log_unimpl (__PRETTY_FUNCTION__);
179
as_value system_security_allowinsecuredomain(const fn_call& /*fn*/) {
180
log_unimpl (__PRETTY_FUNCTION__);
184
as_value system_security_loadpolicyfile(const fn_call& /*fn*/) {
185
log_unimpl (__PRETTY_FUNCTION__);
189
as_value system_setclipboard(const fn_call& /*fn*/) {
190
log_unimpl (__PRETTY_FUNCTION__);
194
as_value system_showsettings(const fn_call& /*fn*/) {
195
log_unimpl (__PRETTY_FUNCTION__);
200
system_class_init(as_object& global)
202
// _global.System is NOT a class, but a simple object, see System.as
204
static boost::intrusive_ptr<as_object> obj = new as_object(getObjectInterface());
205
attachSystemInterface(*obj);
206
global.init_member("System", obj.get());
209
const std::string& systemLanguage()
211
// Two-letter language code ('en', 'de') corresponding to ISO 639-1
212
// Chinese can be either zh-CN or zh-TW. English used to have a
213
// country (GB, US) qualifier, but that was dropped in version 7 of the player.
214
// This method relies on getting a POSIX-style language code of the form
215
// "zh_TW.utf8", "zh_CN" or "it" from the VM.
216
// It is obviously very easy to extend support to all language codes, but
217
// some scripts rely on there being only 20 possible languages. It could
218
// be a run time option if it's important enough to care.
220
static std::string lang = VM::get().getSystemLanguage();
222
const char* languages[] = {"en", "fr", "ko", "ja", "sv",
223
"de", "es", "it", "zh", "pt",
224
"pl", "hu", "cs", "tr", "fi",
225
"da", "nl", "no", "ru"};
227
const unsigned int size = sizeof (languages) / sizeof (*languages);
229
if (std::find(languages, languages + size, lang.substr(0,2)) != languages + size)
231
if (lang.substr(0,2) == "zh")
233
// Chinese is the only language since the pp version 7
234
// to need an additional qualifier.
235
if (lang.substr(2, 3) == "_TW") lang = "zh-TW";
236
else if (lang.substr(2, 3) == "_CN") lang = "zh-CN";
241
// All other matching cases: retain just the first
248
// Unknown language. We also return this if
249
// getSystemLanguage() returns something unexpected.
257
} // end of gnash namespace