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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
const {classes: Cc, interfaces: Ci, utils: Cu, manager: Cm} = Components;
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
const cid = '{17a84227-28f4-453d-9b80-9ae75a5682e0}';
const contractId = '@mozilla.org/test-update-provider;1';
function TestUpdateProvider() {}
TestUpdateProvider.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemUpdateProvider]),
checkForUpdate: function() {
dump('check for update');
this._listener.onUpdateAvailable('test-type', 'test-version', 'test-description', Date.now().valueOf(), 5566);
},
startDownload: function() {
dump('test start download');
this._listener.onProgress(10, 100);
},
stopDownload: function() {
dump('test stop download');
},
applyUpdate: function() {
dump('apply update');
},
setParameter: function(name, value) {
dump('set parameter');
return (name === 'dummy' && value === 'dummy-value');
},
getParameter: function(name) {
dump('get parameter');
if (name === 'dummy') {
return 'dummy-value';
}
},
setListener: function(listener) {
this._listener = listener;
},
unsetListener: function() {
this._listener = null;
},
};
var factory = {
createInstance: function(outer, iid) {
if (outer) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return new TestUpdateProvider().QueryInterface(iid);
},
lockFactory: function(aLock) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
};
Cm.nsIComponentRegistrar.registerFactory(Components.ID(cid), '', contractId, factory);
var cm = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
cm.addCategoryEntry('system-update-provider', 'DummyProvider',
contractId + ',' + cid, false, true);
Cu.import('resource://gre/modules/SystemUpdateService.jsm');
this.SystemUpdateService.addProvider('{17a84227-28f4-453d-9b80-9ae75a5682e0}',
'@mozilla.org/test-update-provider;1',
'DummyProvider');
|