Changeset 866
- Timestamp:
- 2008-03-09 01:22:05 (10 months ago)
- Files:
-
- trunk/chrome/content/common/module.js (added)
- trunk/components/debugService.js (modified) (6 diffs)
- trunk/components/filterManager.js (modified) (13 diffs)
- trunk/components/migrationService.js (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/components/debugService.js
r743 r866 41 41 const FileStream = new Components.Constructor('@mozilla.org/network/file-output-stream;1', 'nsIFileOutputStream', 'init'); 42 42 const ScriptError = new Components.Constructor('@mozilla.org/scripterror;1', 'nsIScriptError', 'init'); 43 43 44 function include(uri) { 45 Cc["@mozilla.org/moz/jssubscript-loader;1"] 46 .getService(Ci.mozIJSSubScriptLoader) 47 .loadSubScript(uri); 48 } 49 include("chrome://dta/content/common/module.js"); 50 44 51 var DebugService = { 45 // nsIClassInfo46 classID: Components.ID("{0B82FEBB-59A1-41d7-B31D-D5A686E11A69}"),47 contractID: "@downthemall.net/debug-service;1",48 classDescription: "DownThemAll! Debug Service",49 implementationLanguage: 0x02,50 flags: (1 << 0) | (1 << 2), // SINGLETON | MAIN_THREAD_ONLY51 classIDNoAlloc: this.classID,52 getHelperForLanguage: function() {53 return null;54 },55 getInterfaces: function(count) {56 // XXX57 count.value = 0;58 return null;59 },60 61 implementsIID: function DS_implementID(iid) {62 return [63 Ci.nsISupports,64 Ci.nsISupportsWeakReference,65 Ci.nsIWeakReference,66 Ci.nsIObserver,67 Ci.nsIClassInfo,68 Ci.nsIFactory,69 Ci.dtaIDebugService70 ].some(function(e) { return iid.equals(e); });71 },72 // nsiSupports73 QueryInterface: function DS_QI(iid) {74 if (this.implementsIID(iid)) {75 return this;76 }77 throw res.NS_ERROR_NO_INTERFACE;78 },79 80 // nsiWeakReference81 QueryReferent: function DS_QR(iid) {82 return this;83 },84 85 // nsiSupportsWeakReference86 GetWeakReference: function DS_GWR() {87 return this;88 },89 90 // nsIFactory91 createInstance: function (outer, iid) {92 if (outer != null) {93 throw res.NS_ERROR_NO_AGGREGATION;94 }95 if (this.implementsIID(iid)) {96 this._init();97 return this;98 }99 throw res.NS_ERROR_INVALID_ARG;100 },101 102 52 // nsIObserver 103 53 observe: function DS_observe(subject, topic, prefName) { … … 105 55 }, 106 56 107 _init: function DS__init() {57 init: function DS_init() { 108 58 this._cs = Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService); 109 59 this._pb = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch2); … … 122 72 // No-Op 123 73 } 124 this._init = new Function();74 delete this.init; 125 75 }, 126 76 get file() { … … 142 92 return String(value).replace(/\b(\d)\b/g, "0$1"); 143 93 }, 144 _log: function DS__ dump(msg, e) {94 _log: function DS__log(msg, e) { 145 95 try { 146 96 if (msg == "" && typeof(e) != "object") { … … 187 137 } 188 138 189 var f = new FileStream(this. _file, 0x04 | 0x08 | 0x10, 0664, 0);139 var f = new FileStream(this.file, 0x04 | 0x08 | 0x10, 0664, 0); 190 140 f.write(text, text.length); 191 141 f.close(); … … 209 159 throw res.NS_ERROR_FAILURE; 210 160 } 211 },212 213 _firstTime: true,214 registerSelf: function DS_registerSelf(compMgr, fileSpec, location, type) {215 try {216 error("registering");217 218 if (!this._firstTime) {219 return;220 }221 this._firstTime = false;222 223 compMgr.QueryInterface(Ci.nsIComponentRegistrar)224 .registerFactoryLocation(225 this.classID,226 this.classDescription,227 this.contractID,228 fileSpec,229 location,230 type231 );232 }233 catch (ex) {234 error(ex);235 }236 },237 unregisterSelf: function DS_unregisterSelf(compMgr, fileSpec, location) {238 compMgr.QueryInterface(Ci.nsIComponentRegistrar)239 .unregisterFactoryLocation(240 this.classID,241 fileSpec242 );243 },244 getClassObject: function DS_getClassObject(compMgr, cid, iid) {245 if (cid.equals(this.classID)) {246 return this;247 }248 throw Components.results.NS_ERROR_NO_INTERFACE;249 },250 canUnload: function DS_canUnload(compMgr) {251 return true;252 161 } 253 162 }; 163 implementComponent( 164 DebugService, 165 Components.ID("{0B82FEBB-59A1-41d7-B31D-D5A686E11A69}"), 166 "@downthemall.net/debug-service;1", 167 "DownThemAll! Debug Service", 168 [Ci.nsIObserver, Ci.dtaIDebugService] 169 ); 254 170 255 171 // entrypoint 256 172 function NSGetModule(compMgr, fileSpec) { 257 return DebugService;173 return new ServiceModule(DebugService, false); 258 174 } trunk/components/filterManager.js
r860 r866 35 35 * ***** END LICENSE BLOCK ***** */ 36 36 37 const CC = Components.classes; 38 const CI = Components.interfaces; 37 const Cc = Components.classes; 38 const Ci = Components.interfaces; 39 const Cr = Components.results; 40 39 41 const Exception = Components.Exception; 40 42 … … 44 46 const NS_ERROR_INVALID_ARG = Components.results.NS_ERROR_INVALID_ARG; 45 47 46 const LINK_FILTER = C I.dtaIFilter.LINK_FILTER;47 const IMAGE_FILTER = C I.dtaIFilter.IMAGE_FILTER;48 const LINK_FILTER = Ci.dtaIFilter.LINK_FILTER; 49 const IMAGE_FILTER = Ci.dtaIFilter.IMAGE_FILTER; 48 50 49 51 function include(uri) { 50 C C["@mozilla.org/moz/jssubscript-loader;1"]51 .getService(C I.mozIJSSubScriptLoader)52 Cc["@mozilla.org/moz/jssubscript-loader;1"] 53 .getService(Ci.mozIJSSubScriptLoader) 52 54 .loadSubScript(uri); 53 55 } 54 55 function debug(str, ex) { 56 try { 57 var DTA_Debug = Components.classes['@downthemall.net/debug-service;1'] 58 .getService(Components.interfaces.dtaIDebugService); 59 debug = function(str, ex) { 60 if (ex) { 61 DTA_Debug.log(str, ex); 62 } 63 else { 64 DTA_Debug.logString(str); 65 } 66 } 67 debug(str, ex); 68 } 69 catch (ex) { 70 Components.utils.reportError(str + ": " + ex); 71 } 72 } 56 include("chrome://dta/content/common/module.js"); 73 57 74 58 // no not create DTA_Filter yourself, managed by DTA_FilterManager … … 78 62 } 79 63 Filter.prototype = { 80 81 LINK_FILTER: (1 << 0),82 IMAGE_FILTER: (1 << 1),83 84 _modified: false,85 _regs: [],86 87 // nsIClassInfo88 classID: Components.ID("{1CF86DC0-33A7-43b3-BDDE-7ADC3B35D114}"),89 contractID: "@downthemall.net/filter;2",90 classDescription: "DownThemAll! Filter",91 implementationLanguage: 0x02,92 flags: (1 << 2), // MAIN_THREAD_ONLY93 classIDNoAlloc: this.classID,94 getHelperForLanguage: function() {95 return null;96 },97 getInterfaces: function(count) {98 // XXX99 count.value = 0;100 return null;101 },102 103 QueryInterface: function F_QI(iid) {104 if (105 iid.equals(CI.nsISupports)106 || iid.equals(CI.nsIClassInfo)107 || iid.equals(CI.dtaIFilter)108 ) {109 return this;110 }111 throw NS_ERROR_NO_INTERFACE;112 },113 114 64 // exported 115 65 get id() { … … 304 254 var rv = this._prefs.getComplexValue( 305 255 pref, 306 C I.nsISupportsString256 Ci.nsISupportsString 307 257 ); 308 258 return rv.data; … … 310 260 311 261 setMultiBytePref: function F_setMultiBytePref(pref, value) { 312 var str = C C["@mozilla.org/supports-string;1"]313 .createInstance(C I.nsISupportsString);262 var str = Cc["@mozilla.org/supports-string;1"] 263 .createInstance(Ci.nsISupportsString); 314 264 str.data = value; 315 265 this._prefs.setComplexValue( 316 266 pref, 317 C I.nsISupportsString,267 Ci.nsISupportsString, 318 268 str 319 269 ); … … 326 276 } 327 277 }; 278 implementComponent( 279 Filter.prototype, 280 Components.ID("{1CF86DC0-33A7-43b3-BDDE-7ADC3B35D114}"), 281 "@downthemall.net/filter;2", 282 "DownThemAll! Filter", 283 [Ci.dtaIFilter] 284 ); 328 285 329 286 function FilterEnumerator(filters) { … … 334 291 QueryInterface: function FE_QI(iid) { 335 292 if ( 336 iid.equals(C omponents.intefaces.nsISupports)337 || iid.equals(C omponents.intefaces.nsISimpleEnumerator)293 iid.equals(Ci.nsISupports) 294 || iid.equals(Ci.nsISimpleEnumerator) 338 295 ) { 339 296 return this; … … 354 311 // XXX: reload() should be called delayed when we observe changes (as many changes might come in) 355 312 var FilterManager = { 356 357 // nsIClassInfo358 classID: Components.ID("{435FC5E5-D4F0-47a1-BDC1-F325B78188F3}"),359 contractID: "@downthemall.net/filtermanager;2",360 classDescription: "DownThemAll! Filtermanager",361 implementationLanguage: 0x02,362 flags: (1 << 0) | (1 << 2), // SINGLETON | MAIN_THREAD_ONLY363 classIDNoAlloc: this.classID,364 getHelperForLanguage: function() {365 return null;366 },367 getInterfaces: function(count) {368 // XXX369 count.value = 0;370 return null;371 },372 373 implementsIID: function FM_implementID(iid) {374 return [375 CI.nsISupports,376 CI.nsISupportsWeakReference,377 CI.nsIWeakReference,378 CI.nsIObserver,379 CI.nsIClassInfo,380 CI.nsITimerCallback,381 this.classID382 ].some(function(e) { return iid.equals(e); });383 },384 385 313 _done: true, 386 314 _mustReload: true, 387 _prefs: CC['@mozilla.org/preferences-service;1'] 388 .getService(CI.nsIPrefService) 315 316 _prefs: Cc['@mozilla.org/preferences-service;1'] 317 .getService(Ci.nsIPrefService) 389 318 .getBranch("extensions.dta.filters."), 390 _timer: CC['@mozilla.org/timer;1'] 391 .createInstance(CI.nsITimer), 319 320 _timer: Cc['@mozilla.org/timer;1'] 321 .createInstance(Ci.nsITimer), 392 322 393 323 _init: function FM_init() { 394 this._prefs = this._prefs.QueryInterface(C I.nsIPrefBranch2);324 this._prefs = this._prefs.QueryInterface(Ci.nsIPrefBranch2); 395 325 396 326 // load those localized labels for default filters. 397 327 this._localizedLabels = {}; 398 var b = C C['@mozilla.org/intl/stringbundle;1']399 .getService(C I.nsIStringBundleService)328 var b = Cc['@mozilla.org/intl/stringbundle;1'] 329 .getService(Ci.nsIStringBundleService) 400 330 .createBundle("chrome://dta/locale/filters.properties"); 401 331 var e = b.getSimpleEnumeration(); 402 332 while (e.hasMoreElements()) { 403 var prop = e.getNext().QueryInterface(C I.nsIPropertyElement);333 var prop = e.getNext().QueryInterface(Ci.nsIPropertyElement); 404 334 this._localizedLabels[prop.key] = prop.value; 405 335 } … … 482 412 483 413 // notify all observers 484 var observerService = C C["@mozilla.org/observer-service;1"]485 .getService(C I.nsIObserverService);414 var observerService = Cc["@mozilla.org/observer-service;1"] 415 .getService(Ci.nsIObserverService); 486 416 observerService.notifyObservers(this, 'DTA:filterschanged', null); 487 417 }, … … 504 434 return this._filters[id]; 505 435 } 506 throw new Components.Exception("invalid filter specified: " + id);436 throw new Exception("invalid filter specified: " + id); 507 437 }, 508 438 … … 515 445 // we will use unique ids for user-supplied filters. 516 446 // no need to keep track of the actual number of filters or an index. 517 var uuid = C C["@mozilla.org/uuid-generator;1"]518 .getService(C I.nsIUUIDGenerator)447 var uuid = Cc["@mozilla.org/uuid-generator;1"] 448 .getService(Ci.nsIUUIDGenerator) 519 449 .generateUUID(); 520 450 … … 570 500 }, 571 501 572 // nsiSupports573 QueryInterface: function FM_QI(iid) {574 if (this.implementsIID(iid)) {575 return this;576 }577 throw NS_ERROR_NO_INTERFACE;578 },579 580 // nsiWeakReference581 QueryReferent: function FM_QR(iid) {582 return this;583 },584 585 // nsiSupportsWeakReference586 GetWeakReference: function FM_GWR() {587 return this;588 },589 590 502 // nsIObserver 591 503 observe: function FM_observe(subject, topic, prefName) { … … 611 523 this.reload(); 612 524 } 613 614 525 }; 526 implementComponent( 527 FilterManager, 528 Components.ID("{435FC5E5-D4F0-47a1-BDC1-F325B78188F3}"), 529 "@downthemall.net/filtermanager;2", 530 "DownThemAll! Filtermanager", 531 [Ci.nsITimerCallback, Ci.nsIObserver, Ci.dtaIFilterManager] 532 ); 615 533 FilterManager._init(); 616 617 var Module = {618 _firstTime: true,619 620 registerSelf: function M_registerSelf(compMgr, fileSpec, location, type) {621 if (!this._firstTime) {622 return;623 }624 this._firstTime = false;625 626 compMgr.QueryInterface(CI.nsIComponentRegistrar)627 .registerFactoryLocation(628 FilterManager.classID,629 FilterManager.classDescription,630 FilterManager.contractID,631 fileSpec,632 location,633 type634 );635 CC['@mozilla.org/categorymanager;1']636 .getService(CI.nsICategoryManager)637 .addCategoryEntry('app-startup', FilterManager.contractID, FilterManager.contractID, true, true, null);638 },639 unregisterSelf: function(compMgr, fileSpec, location) {640 compMgr.QueryInterface(CI.nsIComponentRegistrar)641 .unregisterFactoryLocation(642 FileManager.classID,643 fileSpec644 );645 CC['@mozilla.org/categorymanager;1']646 .getService(CI.nsICategoryManager)647 .deleteCategoryEntry('app-startup', FileManager.contractID, true);648 },649 getClassObject: function (compMgr, cid, iid) {650 if (cid.equals(FilterManager.classID)) {651 return this;652 }653 throw NS_ERROR_NO_INTERFACE;654 },655 canUnload: function(compMgr) {656 return true;657 },658 659 // nsIFactory660 QueryInterface : function(aIID) {661 if (aIID.equals(CI.nsIFactory)) {662 return this;663 }664 665 return NS_ERROR_NO_INTERFACE;666 },667 createInstance: function (outer, iid) {668 if (outer != null) {669 throw NS_ERROR_NO_AGGREGATION;670 }671 if (FilterManager.implementsIID(iid)) {672 return FilterManager;673 }674 throw NS_ERROR_INVALID_ARG;675 }676 }677 534 678 535 // entrypoint 679 536 function NSGetModule(compMgr, fileSpec) { 680 return Module;537 return new ServiceModule(FilterManager, true); 681 538 } trunk/components/migrationService.js
r751 r866 35 35 * ***** END LICENSE BLOCK ***** */ 36 36 37 38 const Cc = Components.classes; 39 const Ci = Components.interfaces; 40 37 41 function include(uri) { 38 C C["@mozilla.org/moz/jssubscript-loader;1"]39 .getService(C I.mozIJSSubScriptLoader)42 Cc["@mozilla.org/moz/jssubscript-loader;1"] 43 .getService(Ci.mozIJSSubScriptLoader) 40 44 .loadSubScript(uri); 41 45 } 42 43 const CC = Components.classes; 44 const CI = Components.interfaces; 45 const error = Components.utils.reportError; 46 include("chrome://dta/content/common/module.js"); 47 46 48 47 49 var MigrationService = { 48 49 // nsIClassInfo50 classID: Components.ID("{F66539C8-2590-4e69-B189-F9F8595A7670}"),51 contractID: "@downthemall.net/migration-service;1",52 classDescription: "DownThemAll! Migration Service",53 implementationLanguage: 0x02,54 flags: (1 << 0) | (1 << 2), // SINGLETON | MAIN_THREAD_ONLY55 classIDNoAlloc: this.classID,56 getHelperForLanguage: function() {57 return null;58 },59 getInterfaces: function(count) {60 // XXX61 count.value = 0;62 return null;63 },64 65 implementsIID: function FM_implementID(iid) {66 return [67 CI.nsISupports,68 CI.nsISupportsWeakReference,69 CI.nsIWeakReference,70 CI.nsIObserver,71 CI.nsIClassInfo72 ].some(function(e) { return iid.equals(e); });73 },74 75 50 _init: function MM_init() { 76 51 // observer registration 77 C C['@mozilla.org/observer-service;1']78 .getService(C I.nsIObserverService)52 Cc['@mozilla.org/observer-service;1'] 53 .getService(Ci.nsIObserverService) 79 54 .addObserver(this, "final-ui-startup", true); 80 55 }, … … 85 60 86 61 try { 87 DTA_debug.logString("current " + DTA_VERSION);62 debug("current " + DTA_VERSION); 88 63 var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"] 89 64 .getService(Components.interfaces.nsIVersionComparator); … … 93 68 return; 94 69 } 95 DTA_debug.logString("MigrationManager: migration started");70 debug.logString("MigrationManager: migration started"); 96 71 if (vc.compare(lastVersion, "1.0a1") < 0) { 97 72 this._execute(['Prefs', 'DropDowns', 'Filters', 'Remove']); … … 112 87 } 113 88 catch(ex) { 114 DTA_debug.log("MigrationManager:", ex);89 debug("MigrationManager:", ex); 115 90 try { 116 91 DTA_preferences.resetDTA("version"); … … 137 112 // pre-1.0: convert prefs 138 113 _migratePrefs: function MM_migratePrefs() { 139 DTA_debug.logString("migrating prefs");114 debug("migrating prefs"); 140 115 const toMigrate = [ 141 116 ['context.infophrases', 'infophrases', true], … … 183 158 // pre 1.0: migrate Filters 184 159 _migrateFilters: function MM_migrateFilters() { 185 DTA_debug.log("migrating filters");160 debug("migrating filters"); 186 161 const defFilters = [ 187 162 "/\./", "/\\./", '/(\\.*)/', … … 193 168 "/\\/[^\\/\\?]+\\.png$/" 194 169 ]; 195 const LINK_FILTER = C I.dtaIFilter.LINK_FILTER;196 const IMAGE_FILTER = C I.dtaIFilter.IMAGE_FILTER;197 const prefs = C C['@mozilla.org/preferences-service;1']170 const LINK_FILTER = Ci.dtaIFilter.LINK_FILTER; 171 const IMAGE_FILTER = Ci.dtaIFilter.IMAGE_FILTER; 172 const prefs = Cc['@mozilla.org/preferences-service;1'] 198 173 .getService(Components.interfaces.nsIPrefService) 199 174 .getBranch("extensions.dta.context.") … … 230 205 // pre 1.0: dropdown history 231 206 _migrateDropDowns: function MM_migrateDropdowns() { 232 DTA_debug.logString("migrating dropdowns");207 debug("migrating dropdowns"); 233 208 ['renaming', 'filter', 'directory'].forEach( 234 209 function(e) { … … 255 230 }, 256 231 257 // nsiSupports258 QueryInterface: function MM_QI(iid) {259 if (this.implementsIID(iid)) {260 return this;261 }262 throw Components.results.NS_ERROR_NO_INTERFACE;263 },264 265 // nsiWeakReference266 QueryReferent: function MM_QR(iid) {267 return this;268 },269 270 // nsiSupportsWeakReference271 GetWeakReference: function MM_GWR() {272 return this;273 },274 275 232 // nsIObserver 276 233 observe: function MM_observe(subject, topic, prefName) { … … 280 237 } 281 238 }; 239 implementComponent( 240 MigrationService, 241 Components.ID("{F66539C8-2590-4e69-B189-F9F8595A7670}"), 242 "@downthemall.net/migration-service;1", 243 "DownThemAll! Migration Service", 244 [Ci.nsIObserver] 245 ); 282 246 MigrationService._init(); 283 284 var Module = {285 _firstTime: true,286 287 registerSelf: function M_registerSelf(compMgr, fileSpec, location, type) {288 if (!this._firstTime) {289 return;290 }291 this._firstTime = false;292 293 compMgr.QueryInterface(CI.nsIComponentRegistrar)294 .registerFactoryLocation(295 MigrationService.classID,296 MigrationService.classDescription,297 MigrationService.contractID,298 fileSpec,299 location,300 type301 );302 CC['@mozilla.org/categorymanager;1']303 .getService(CI.nsICategoryManager)304 .addCategoryEntry('app-startup', MigrationService.contractID, MigrationService.contractID, true, true, null);305 },306 unregisterSelf: function(compMgr, fileSpec, location) {307 compMgr.QueryInterface(CI.nsIComponentRegistrar)308 .unregisterFactoryLocation(309 MigrationService.classID,310 fileSpec311 );312 CC['@mozilla.org/categorymanager;1']313 .getService(CI.nsICategoryManager)314 .deleteCategoryEntry('app-startup', MigrationService.contractID, true);315 },316 getClassObject: function (compMgr, cid, iid) {317 if (cid.equals(MigrationService.classID)) {318 return this;319 }320 throw Components.results.NS_ERROR_NO_INTERFACE;321 },322 canUnload: function(compMgr) {323 return true;324 },325 326 // nsIFactory327 QueryInterface : function(aIID) {328 if (aIID.equals(CI.nsIFactory)) {329 return this;330 }331 332 return Components.results.NS_ERROR_NO_INTERFACE;333 },334 createInstance: function (outer, iid) {335 if (outer != null) {336 throw Components.results.NS_ERROR_NO_AGGREGATION;337 }338 if (MigrationService.implementsIID(iid)) {339 return MigrationService;340 }341 throw Components.results.NS_ERROR_INVALID_ARG;342 }343 }344 247 345 248 // entrypoint 346 249 function NSGetModule(compMgr, fileSpec) { 347 return Module;250 return new ServiceModule(MigrationService, true); 348 251 }
