Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 /** | 7 /** |
8 * @fileOverview Firefox Sync integration | 8 * @fileOverview Firefox Sync integration |
9 */ | 9 */ |
10 | 10 |
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
12 Cu.import("resource://gre/modules/Services.jsm"); | 12 Cu.import("resource://gre/modules/Services.jsm"); |
13 | 13 |
14 let {FilterStorage} = require("filterStorage"); | 14 let {FilterStorage} = require("filterStorage"); |
15 let {FilterNotifier} = require("filterNotifier"); | 15 let {FilterNotifier} = require("filterNotifier"); |
16 let {Synchronizer} = require("synchronizer"); | 16 let {Synchronizer} = require("synchronizer"); |
17 let {Subscription, SpecialSubscription, DownloadableSubscription, ExternalSubscr iption} = require("subscriptionClasses"); | 17 let {Subscription, SpecialSubscription, DownloadableSubscription, ExternalSubscr iption} = require("subscriptionClasses"); |
18 let {Filter, ActiveFilter} = require("filterClasses"); | 18 let {Filter, ActiveFilter} = require("filterClasses"); |
19 | 19 |
20 // Firefox Sync classes are set later in initEngine() | |
21 let Service, Engines, SyncEngine, Store, Tracker; | |
22 | |
20 /** | 23 /** |
21 * ID of the only record stored | 24 * ID of the only record stored |
22 * @type String | 25 * @type String |
23 */ | 26 */ |
24 let filtersRecordID = "6fad6286-8207-46b6-aa39-8e0ce0bd7c49"; | 27 let filtersRecordID = "6fad6286-8207-46b6-aa39-8e0ce0bd7c49"; |
25 | 28 |
26 /** | |
27 * Weave tracker class (is set when Weave is initialized). | |
28 */ | |
29 let Tracker = null; | |
30 | |
31 let Sync = exports.Sync = | 29 let Sync = exports.Sync = |
32 { | 30 { |
33 /** | 31 /** |
34 * Will be set to true if/when Weave starts up. | 32 * Will be set to true if/when Weave starts up. |
35 * @type Boolean | 33 * @type Boolean |
36 */ | 34 */ |
37 initialized: false, | 35 initialized: false, |
38 | 36 |
39 /** | 37 /** |
40 * Whether Weave requested us to track changes. | 38 * Whether Weave requested us to track changes. |
41 * @type Boolean | 39 * @type Boolean |
42 */ | 40 */ |
43 trackingEnabled: false, | 41 trackingEnabled: false, |
44 | 42 |
45 /** | 43 /** |
46 * Returns Adblock Plus sync engine. | 44 * Returns Adblock Plus sync engine. |
47 * @result Engine | 45 * @result Engine |
48 */ | 46 */ |
49 getEngine: function() | 47 getEngine: function() |
50 { | 48 { |
51 if (this.initialized) | 49 if (this.initialized) |
52 return Weave.Engines.get("adblockplus"); | 50 return Engines.get("adblockplus"); |
53 else | 51 else |
54 return null; | 52 return null; |
55 } | 53 } |
56 }; | 54 }; |
57 | 55 |
58 /** | 56 /** |
59 * Listens to notifications from Sync service. | 57 * Listens to notifications from Sync service. |
60 */ | 58 */ |
61 let SyncServiceObserver = | 59 let SyncServiceObserver = |
62 { | 60 { |
(...skipping 23 matching lines...) Expand all Loading... | |
86 { | 84 { |
87 Services.obs.removeObserver(this, "weave:service:ready"); | 85 Services.obs.removeObserver(this, "weave:service:ready"); |
88 } catch (e) {} | 86 } catch (e) {} |
89 Services.obs.removeObserver(this, "weave:engine:start-tracking"); | 87 Services.obs.removeObserver(this, "weave:engine:start-tracking"); |
90 Services.obs.removeObserver(this, "weave:engine:stop-tracking"); | 88 Services.obs.removeObserver(this, "weave:engine:stop-tracking"); |
91 }.bind(this)); | 89 }.bind(this)); |
92 }, | 90 }, |
93 | 91 |
94 initEngine: function() | 92 initEngine: function() |
95 { | 93 { |
96 Cu.import("resource://services-sync/main.js"); | 94 ({Engines, SyncEngine, Store, Tracker} = Cu.import("resource://services-sync /engines.js")); |
Felix Dahlke
2012/10/30 17:44:12
Why surround this with parentheses?
Wladimir Palant
2012/10/30 18:53:49
Because otherwise {...} is a block statement and y
| |
95 if (typeof Engines == "undefined") | |
96 { | |
97 ({Service} = Cu.import("resource://services-sync/service.js")); | |
Felix Dahlke
2012/10/30 17:44:12
Same here, are those parentheses necessary?
| |
98 Engines = Service.engineManager; | |
99 } | |
97 | 100 |
98 Tracker = Weave.SyncEngine.prototype._trackerObj; | 101 ABPEngine.prototype.__proto__ = SyncEngine.prototype; |
99 ABPEngine.prototype.__proto__ = Weave.SyncEngine.prototype; | 102 ABPStore.prototype.__proto__ = Store.prototype; |
100 ABPStore.prototype.__proto__ = Weave.Store.prototype; | |
101 ABPTracker.prototype.__proto__ = Tracker.prototype; | 103 ABPTracker.prototype.__proto__ = Tracker.prototype; |
102 | 104 |
103 Weave.Engines.register(ABPEngine); | 105 Engines.register(ABPEngine); |
104 onShutdown.add(function() | 106 onShutdown.add(function() |
105 { | 107 { |
106 Weave.Engines.unregister("adblockplus"); | 108 Engines.unregister("adblockplus"); |
107 }); | 109 }); |
108 }, | 110 }, |
109 | 111 |
110 observe: function(subject, topic, data) | 112 observe: function(subject, topic, data) |
111 { | 113 { |
112 switch (topic) | 114 switch (topic) |
113 { | 115 { |
114 case "weave:service:ready": | 116 case "weave:service:ready": |
115 if (Sync.initialized) | 117 if (Sync.initialized) |
116 return; | 118 return; |
(...skipping 12 matching lines...) Expand all Loading... | |
129 trackerInstance.stopTracking(); | 131 trackerInstance.stopTracking(); |
130 break; | 132 break; |
131 } | 133 } |
132 }, | 134 }, |
133 | 135 |
134 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]), | 136 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]), |
135 }; | 137 }; |
136 | 138 |
137 function ABPEngine() | 139 function ABPEngine() |
138 { | 140 { |
139 Weave.SyncEngine.call(this, "AdblockPlus"); | 141 SyncEngine.call(this, "AdblockPlus", Service); |
140 } | 142 } |
141 ABPEngine.prototype = | 143 ABPEngine.prototype = |
142 { | 144 { |
143 _storeObj: ABPStore, | 145 _storeObj: ABPStore, |
144 _trackerObj: ABPTracker, | 146 _trackerObj: ABPTracker, |
145 version: 1, | 147 version: 1, |
146 | 148 |
147 _reconcile: function(item) | 149 _reconcile: function(item) |
148 { | 150 { |
149 // Always process server data, we will do the merging ourselves | 151 // Always process server data, we will do the merging ourselves |
150 return true; | 152 return true; |
151 } | 153 } |
152 }; | 154 }; |
153 | 155 |
154 function ABPStore(name) | 156 function ABPStore(name, engine) |
155 { | 157 { |
156 Weave.Store.call(this, name); | 158 Store.call(this, name, engine); |
157 } | 159 } |
158 ABPStore.prototype = | 160 ABPStore.prototype = |
159 { | 161 { |
160 getAllIDs: function() | 162 getAllIDs: function() |
161 { | 163 { |
162 let result = {} | 164 let result = {} |
163 result[filtersRecordID] = true; | 165 result[filtersRecordID] = true; |
164 return result; | 166 return result; |
165 }, | 167 }, |
166 | 168 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 // Data wiped, forget about local changes now | 351 // Data wiped, forget about local changes now |
350 trackerInstance.clearPrivateChanges() | 352 trackerInstance.clearPrivateChanges() |
351 } | 353 } |
352 }; | 354 }; |
353 | 355 |
354 /** | 356 /** |
355 * Hack to allow store to use the tracker - store tracker pointer globally. | 357 * Hack to allow store to use the tracker - store tracker pointer globally. |
356 */ | 358 */ |
357 let trackerInstance = null; | 359 let trackerInstance = null; |
358 | 360 |
359 function ABPTracker(name) | 361 function ABPTracker(name, engine) |
360 { | 362 { |
361 Tracker.call(this, name); | 363 Tracker.call(this, name, engine); |
362 | 364 |
363 this.privateTracker = new Tracker(name + ".private"); | 365 this.privateTracker = new Tracker(name + ".private", engine); |
364 trackerInstance = this; | 366 trackerInstance = this; |
365 | 367 |
366 this.onChange = this.onChange.bind(this); | 368 this.onChange = this.onChange.bind(this); |
367 | 369 |
368 if (Sync.trackingEnabled) | 370 if (Sync.trackingEnabled) |
369 this.startTracking(); | 371 this.startTracking(); |
370 } | 372 } |
371 ABPTracker.prototype = | 373 ABPTracker.prototype = |
372 { | 374 { |
373 privateTracker: null, | 375 privateTracker: null, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 case "filter.added": | 439 case "filter.added": |
438 case "filter.removed": | 440 case "filter.removed": |
439 case "filter.disabled": | 441 case "filter.disabled": |
440 this.addPrivateChange("filter " + item.text); | 442 this.addPrivateChange("filter " + item.text); |
441 break; | 443 break; |
442 } | 444 } |
443 } | 445 } |
444 }; | 446 }; |
445 | 447 |
446 SyncServiceObserver.init(); | 448 SyncServiceObserver.init(); |
OLD | NEW |