mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 773160: expose a reduced 'navigator' object to social frameworker workers. r=gavin
This commit is contained in:
parent
37f0a0f325
commit
f8595357d1
@ -99,7 +99,7 @@ FrameWorker.prototype = {
|
||||
'atob', 'btoa', 'clearInterval', 'clearTimeout', 'dump',
|
||||
'setInterval', 'setTimeout', 'XMLHttpRequest',
|
||||
'MozBlobBuilder', 'FileReader', 'Blob',
|
||||
'navigator', 'location'];
|
||||
'location'];
|
||||
workerAPI.forEach(function(fn) {
|
||||
try {
|
||||
// XXX Need to unwrap for this to work - find out why!
|
||||
@ -109,6 +109,25 @@ FrameWorker.prototype = {
|
||||
Cu.reportError("FrameWorker: failed to import API "+fn+"\n"+e+"\n");
|
||||
}
|
||||
});
|
||||
// the "navigator" object in a worker is a subset of the full navigator;
|
||||
// specifically, just the interfaces 'NavigatorID' and 'NavigatorOnLine'
|
||||
let navigator = {
|
||||
__exposedProps__: {
|
||||
"appName": "r",
|
||||
"appVersion": "r",
|
||||
"platform": "r",
|
||||
"userAgent": "r",
|
||||
"onLine": "r"
|
||||
},
|
||||
// interface NavigatorID
|
||||
appName: workerWindow.navigator.appName,
|
||||
appVersion: workerWindow.navigator.appVersion,
|
||||
platform: workerWindow.navigator.platform,
|
||||
userAgent: workerWindow.navigator.userAgent,
|
||||
// interface NavigatorOnLine
|
||||
get onLine() workerWindow.navigator.onLine
|
||||
};
|
||||
sandbox.navigator = navigator;
|
||||
|
||||
// and we delegate ononline and onoffline events to the worker.
|
||||
// See http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workerglobalscope
|
||||
|
@ -405,5 +405,63 @@ let tests = {
|
||||
cbnext();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
testNavigator: function(cbnext) {
|
||||
let run = function() {
|
||||
let port;
|
||||
ononline = function() {
|
||||
port.postMessage({topic: "ononline", data: navigator.onLine});
|
||||
}
|
||||
onoffline = function() {
|
||||
port.postMessage({topic: "onoffline", data: navigator.onLine});
|
||||
}
|
||||
onconnect = function(e) {
|
||||
port = e.ports[0];
|
||||
port.postMessage({topic: "ready",
|
||||
data: {
|
||||
appName: navigator.appName,
|
||||
appVersion: navigator.appVersion,
|
||||
platform: navigator.platform,
|
||||
userAgent: navigator.userAgent,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2);
|
||||
let oldManage = ioService.manageOfflineStatus;
|
||||
let oldOffline = ioService.offline;
|
||||
|
||||
ioService.manageOfflineStatus = false;
|
||||
let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testNavigator");
|
||||
let expected_topic = "onoffline";
|
||||
let expected_data = false;
|
||||
worker.port.onmessage = function(e) {
|
||||
is(e.data.topic, "ready");
|
||||
for each (let attr in ['appName', 'appVersion', 'platform', 'userAgent']) {
|
||||
// each attribute must be a string with length > 0.
|
||||
is(typeof e.data.data[attr], "string");
|
||||
ok(e.data.data[attr].length > 0);
|
||||
}
|
||||
|
||||
worker.port.onmessage = function(e) {
|
||||
// a handler specifically for the offline notification.
|
||||
is(e.data.topic, "onoffline");
|
||||
is(e.data.data, false);
|
||||
|
||||
// add another handler specifically for the 'online' case.
|
||||
worker.port.onmessage = function(e) {
|
||||
is(e.data.topic, "ononline");
|
||||
is(e.data.data, true);
|
||||
// all good!
|
||||
ioService.manageOfflineStatus = oldManage;
|
||||
ioService.offline = oldOffline;
|
||||
worker.terminate();
|
||||
cbnext();
|
||||
}
|
||||
ioService.offline = false;
|
||||
}
|
||||
ioService.offline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user