~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to server/asobj/System.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
 
#ifdef HAVE_CONFIG_H
21
 
#include "gnashconfig.h"
22
 
#endif
23
 
 
24
 
#include "log.h"
25
 
#include "System.h"
26
 
#include "fn_call.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
31
 
 
32
 
#define TF(x) (x ? "t" : "f")
33
 
 
34
 
namespace gnash {
35
 
 
36
 
const std::string& systemLanguage();
37
 
 
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);
44
 
 
45
 
static as_object*
46
 
getSystemSecurityInterface()
47
 
{
48
 
        static boost::intrusive_ptr<as_object> proto;
49
 
        if ( proto == NULL )
50
 
        {
51
 
                proto = new as_object(getObjectInterface());
52
 
                proto->init_member("allowDomain", new builtin_function(system_security_allowdomain));
53
 
 
54
 
                // TODO: only available when SWF >= 7 
55
 
                proto->init_member("allowInsecureDomain", new builtin_function(system_security_allowinsecuredomain));
56
 
 
57
 
                proto->init_member("loadPolicyFile", new builtin_function(system_security_loadpolicyfile));
58
 
        }
59
 
        return proto.get();
60
 
}
61
 
 
62
 
static as_object*
63
 
getSystemCapabilitiesInterface()
64
 
{
65
 
        RcInitFile& rcfile = RcInitFile::getDefaultInstance();
66
 
 
67
 
        // "LNX 9,0,22,0", "MAC 8,0,99,0"
68
 
        // Override in gnashrc
69
 
        const std::string version = VM::get().getPlayerVersion();
70
 
 
71
 
        // Flash 7: "StandAlone", "External", "PlugIn", "ActiveX"
72
 
        // TODO: Implement properly
73
 
        const std::string playerType = "StandAlone";
74
 
 
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();
78
 
 
79
 
        // "Macromedia Windows", "Macromedia Linux", "Macromedia MacOS"
80
 
        // Override in gnashrc
81
 
        const std::string manufacturer = rcfile.getFlashSystemManufacturer();
82
 
 
83
 
        /* Human Interface */
84
 
        const std::string language = systemLanguage();
85
 
 
86
 
        /* Media */
87
 
                
88
 
        // Is audio available?
89
 
        const bool hasAudio = (get_sound_handler() != NULL);
90
 
 
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   */
96
 
        /* in gnashrc.                                          */
97
 
 
98
 
        std::string serverString =
99
 
                        + "OS=" + URL::encode(os) 
100
 
                        + "&A=" + TF(hasAudio)
101
 
                        + "&V=" + URL::encode(version)
102
 
                        + "&PT=" + playerType
103
 
                        + "&L=" + language
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
123
 
                        ;
124
 
                
125
 
        static boost::intrusive_ptr<as_object> proto;
126
 
        if ( proto == NULL )
127
 
        {
128
 
                int flags  = as_prop_flags::dontDelete;
129
 
                    flags |= as_prop_flags::dontEnum;
130
 
                    flags |= as_prop_flags::readOnly;
131
 
 
132
 
                proto = new as_object(getObjectInterface());
133
 
 
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);
141
 
                
142
 
        }
143
 
        return proto.get();
144
 
}
145
 
 
146
 
static void
147
 
attachSystemInterface(as_object& proto)
148
 
{
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));
154
 
}
155
 
 
156
 
static as_object*
157
 
getSystemInterface()
158
 
{
159
 
        static boost::intrusive_ptr<as_object> proto;
160
 
        if ( proto == NULL )
161
 
        {
162
 
                proto = new as_object(getObjectInterface());
163
 
                attachSystemInterface(*proto);
164
 
        }
165
 
        return proto.get();
166
 
}
167
 
 
168
 
system_as_object::system_as_object()
169
 
        :
170
 
        as_object(getSystemInterface()) // pass System inheritence
171
 
{
172
 
}
173
 
 
174
 
as_value system_security_allowdomain(const fn_call& /*fn*/) {
175
 
    log_unimpl (__PRETTY_FUNCTION__);
176
 
    return as_value();
177
 
}
178
 
 
179
 
as_value system_security_allowinsecuredomain(const fn_call& /*fn*/) {
180
 
    log_unimpl (__PRETTY_FUNCTION__);
181
 
    return as_value();
182
 
}
183
 
 
184
 
as_value system_security_loadpolicyfile(const fn_call& /*fn*/) {
185
 
    log_unimpl (__PRETTY_FUNCTION__);
186
 
    return as_value();
187
 
}
188
 
 
189
 
as_value system_setclipboard(const fn_call& /*fn*/) {
190
 
    log_unimpl (__PRETTY_FUNCTION__);
191
 
    return as_value();
192
 
}
193
 
 
194
 
as_value system_showsettings(const fn_call& /*fn*/) {
195
 
    log_unimpl (__PRETTY_FUNCTION__);
196
 
    return as_value();
197
 
}
198
 
 
199
 
void
200
 
system_class_init(as_object& global)
201
 
{
202
 
        // _global.System is NOT a class, but a simple object, see System.as
203
 
 
204
 
        static boost::intrusive_ptr<as_object> obj = new as_object(getObjectInterface());
205
 
        attachSystemInterface(*obj);
206
 
        global.init_member("System", obj.get());
207
 
}
208
 
 
209
 
const std::string& systemLanguage()
210
 
{
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.
219
 
 
220
 
        static std::string lang = VM::get().getSystemLanguage();
221
 
        
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"};
226
 
        
227
 
        const unsigned int size = sizeof (languages) / sizeof (*languages);
228
 
        
229
 
        if (std::find(languages, languages + size, lang.substr(0,2)) != languages + size)
230
 
        {
231
 
                if (lang.substr(0,2) == "zh")
232
 
                {
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";
237
 
                        else lang = "xu";
238
 
                }
239
 
                else
240
 
                {
241
 
                        // All other matching cases: retain just the first
242
 
                        // two characters.
243
 
                        lang.erase(2);
244
 
                }
245
 
        }
246
 
        else
247
 
        {
248
 
                // Unknown language. We also return this if
249
 
                // getSystemLanguage() returns something unexpected. 
250
 
                lang = "xu";
251
 
        }
252
 
 
253
 
        return lang;
254
 
 
255
 
}
256
 
 
257
 
} // end of gnash namespace