This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 396
/
ShumwayBootstrapUtils.jsm
158 lines (134 loc) · 4.48 KB
/
ShumwayBootstrapUtils.jsm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright 2015 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
var EXPORTED_SYMBOLS = ['ShumwayBootstrapUtils'];
const PREF_PREFIX = 'shumway.';
const PREF_IGNORE_CTP = PREF_PREFIX + 'ignoreCTP';
const PREF_WHITELIST = PREF_PREFIX + 'swf.whitelist';
const SWF_CONTENT_TYPE = 'application/x-shockwave-flash';
const PLUGIN_HANLDER_URI = 'chrome://shumway/content/content.html';
let Cc = Components.classes;
let Ci = Components.interfaces;
let Cm = Components.manager;
let Cu = Components.utils;
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');
let Ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
function getBoolPref(pref, def) {
try {
return Services.prefs.getBoolPref(pref);
} catch (ex) {
return def;
}
}
function getStringPref(pref, def) {
try {
return Services.prefs.getComplexValue(pref, Ci.nsISupportsString).data;
} catch (ex) {
return def;
}
}
function log(str) {
var msg = 'ShumwayBootstrapUtils.jsm: ' + str;
Services.console.logStringMessage(msg);
dump(msg + '\n');
}
// Register/unregister a constructor as a factory.
function Factory() {}
Factory.prototype = {
register: function register(targetConstructor) {
var proto = targetConstructor.prototype;
this._classID = proto.classID;
var factory = XPCOMUtils._getFactory(targetConstructor);
this._factory = factory;
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(proto.classID, proto.classDescription,
proto.contractID, factory);
if (proto.classID2) {
this._classID2 = proto.classID2;
registrar.registerFactory(proto.classID2, proto.classDescription,
proto.contractID2, factory);
}
},
unregister: function unregister() {
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
registrar.unregisterFactory(this._classID, this._factory);
if (this._classID2) {
registrar.unregisterFactory(this._classID2, this._factory);
}
}
};
function allowedPlatformForMedia() {
var oscpu = Cc["@mozilla.org/network/protocol;1?name=http"]
.getService(Ci.nsIHttpProtocolHandler).oscpu;
if (oscpu.indexOf('Windows NT') === 0) {
return oscpu.indexOf('Windows NT 5') < 0; // excluding Windows XP
}
if (oscpu.indexOf('Intel Mac OS X') === 0) {
return true;
}
// Other platforms are not supported yet.
return false;
}
var ShumwayBootstrapUtils = {
isRegistered: false,
isJSPluginsSupported: false,
register: function () {
if (this.isRegistered) {
return;
}
this.isRegistered = true;
// Register the components.
this.isJSPluginsSupported = !!Ph.registerFakePlugin &&
getBoolPref('shumway.jsplugins', false);
if (this.isJSPluginsSupported) {
let initPluginDict = {
handlerURI: PLUGIN_HANLDER_URI,
mimeEntries: [
{
type: SWF_CONTENT_TYPE,
description: 'Shockwave Flash',
extension: 'swf'
}
],
niceName: 'Shumway plugin',
name: 'Shumway',
supersedeExisting: true, // TODO verify when jsplugins (bug 558184) is implemented
sandboxScript: 'chrome://shumway/content/plugin.js', // TODO verify when jsplugins (bug 558184) is implemented
version: '10.0.0.0'
};
Ph.registerFakePlugin(initPluginDict);
} else {
Cu.import('resource://shumway/ShumwayStreamConverter.jsm');
let converterFactory = new Factory();
converterFactory.register(ShumwayStreamConverter);
this.converterFactory = converterFactory;
}
},
unregister: function () {
if (!this.isRegistered) {
return;
}
this.isRegistered = false;
// Remove the contract/component.
if (this.isJSPluginsSupported) {
Ph.unregisterFakePlugin(PLUGIN_HANLDER_URI);
} else {
this.converterFactory.unregister();
this.converterFactory = null;
}
}
};