~ubuntu-branches/debian/stretch/foxyproxy/stretch

« back to all changes in this revision

Viewing changes to src/components/common.js

  • Committer: Bazaar Package Importer
  • Author(s): Yaroslav Halchenko
  • Date: 2011-04-25 09:41:06 UTC
  • mfrom: (1.2.1 upstream) (9.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110425094106-p6mrvjz0n6acwf9r
Tags: 2.22.6-1
* New upstream bugfix release
  - Should fix firefox/iceweasel 4.0 compatibility (Closes: #604029)
* debian/copyright -- updated copyright years

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
  FoxyProxy
3
 
  Copyright (C) 2006-2009 Eric H. Jung and LeahScape, Inc.
4
 
  http://foxyproxy.mozdev.org/
 
3
  Copyright (C) 2006-#%#% Eric H. Jung and LeahScape, Inc.
 
4
  http://getfoxyproxy.org/
5
5
  eric.jung@yahoo.com
6
6
 
7
7
  This source code is released under the GPL license,
8
8
  available in the LICENSE file at the root of this installation
9
9
  and also online at http://www.gnu.org/licenses/gpl.txt
10
10
**/
11
 
 
12
11
// common fcns used throughout foxyproxy, exposed a an xpcom service
13
12
 
14
13
const CI = Components.interfaces;
15
14
const CC = Components.classes;
 
15
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
16
16
 
17
17
function Common() {
18
18
  this.wrappedJSObject = this;
 
19
  uuid = CC["@leahscape.org/foxyproxy/service;1"].getService().wrappedJSObject.
 
20
    isFoxyProxySimple() ? "foxyproxy-basic@eric.h.jung" : "foxyproxy@eric.h.jung";
 
21
 
 
22
  // Get installed version
 
23
  if ("@mozilla.org/extensions/manager;1" in CC) {
 
24
    // Pre-Gecko 2.0
 
25
    this.version = CC["@mozilla.org/extensions/manager;1"]
 
26
      .getService(CI.nsIExtensionManager)
 
27
      .getItemForID(uuid)
 
28
      .version || "0.0";
 
29
  }
 
30
  else {
 
31
    // Post-Gecko 2.0
 
32
    Components.utils.import("resource://gre/modules/AddonManager.jsm");
 
33
    var self = this;
 
34
    AddonManager.getAddonByID(uuid, function(addon) {self.version = addon.version;});
 
35
  }
19
36
}
20
37
 
21
38
Common.prototype = {
 
39
  QueryInterface: XPCOMUtils.generateQI([CI.nsISupports]),
22
40
  _ios : CC["@mozilla.org/network/io-service;1"].getService(CI.nsIIOService),
23
 
  
24
 
  QueryInterface: function(aIID) {
25
 
    if (!aIID.equals(CI.nsISupports))
26
 
        throw Components.results.NS_ERROR_NO_INTERFACE;
27
 
    return this;
28
 
  },
 
41
  version: null,
29
42
  
30
43
  // Application-independent version of getMostRecentWindow()
31
44
  getMostRecentWindow : function(wm) {
128
141
  },
129
142
  
130
143
  getVersion : function() {
131
 
    try {
132
 
      var fp = CC["@leahscape.org/foxyproxy/service;1"].getService().wrappedJSObject;
133
 
      return CC["@mozilla.org/extensions/manager;1"]
134
 
                .getService(CI.nsIExtensionManager)
135
 
                .getItemForID(fp.isFoxyProxySimple() ? "foxyproxy-basic@eric.h.jung" : "foxyproxy@eric.h.jung")
136
 
                .version || "0.0";
137
 
    }
138
 
    catch (e) {
139
 
      /* this is for development only, really. The only time we'd get into this catch block is if
140
 
       * the extension isn't installed with the correct UUID. That happens when you install FoxyProxy Standard
141
 
       * using this technique: https://developer.mozilla.org/en/Setting_up_extension_development_environment#Firefox_extension_proxy_file
142
 
       * but then switch to using FoxyProxy Basic via the build script (or vice-versa)
143
 
       */
144
 
      return "-1.0"; 
145
 
    }
 
144
    return this.version;
146
145
  },
147
146
 
148
147
  applyTemplate : function(url, strTemplate, caseSensitive) {
294
293
          "chrome://foxyproxy/content/images/16x16.gif",
295
294
          nb.PRIORITY_WARNING_MEDIUM, buttons);
296
295
    }
297
 
  }
298
 
};
299
 
 
300
 
// Factory
301
 
var CommonFactory = {
302
 
  singleton: null,
303
 
  createInstance: function (aOuter, aIID) {
304
 
    if (aOuter != null)
305
 
      throw Components.results.NS_ERROR_NO_AGGREGATION;
306
 
    if (this.singleton == null)
307
 
      this.singleton = new Common();
308
 
    return this.singleton.QueryInterface(aIID);
309
 
  }
310
 
};
311
 
 
312
 
 
313
 
const CLASS_ID = Components.ID("ecbe324b-9ad7-401a-a272-5cc1efba9be6");
314
 
 
315
 
// Module
316
 
var CommonModule = {
317
 
  registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) {
318
 
    aCompMgr = aCompMgr.QueryInterface(CI.nsIComponentRegistrar);
319
 
    aCompMgr.registerFactoryLocation(CLASS_ID, "FoxyProxy Common", "@leahscape.org/foxyproxy/common;1", aFileSpec, aLocation, aType);
320
 
  },
321
 
 
322
 
  unregisterSelf: function(aCompMgr, aLocation, aType) {
323
 
    aCompMgr = aCompMgr.QueryInterface(CI.nsIComponentRegistrar);
324
 
    aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);        
325
296
  },
326
297
  
327
 
  getClassObject: function(aCompMgr, aCID, aIID) {
328
 
    if (!aIID.equals(CI.nsIFactory))
329
 
      throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
330
 
 
331
 
    if (aCID.equals(CLASS_ID))
332
 
      return CommonFactory;
333
 
 
334
 
    throw Components.results.NS_ERROR_NO_INTERFACE;
335
 
  },
336
 
 
337
 
  canUnload: function(aCompMgr) { return true; }
 
298
  classDescription: "FoxyProxy Common Utils",
 
299
  classID: Components.ID("{ecbe324b-9ad7-401a-a272-5cc1efba9be6}"),
 
300
  contractID: "@leahscape.org/foxyproxy/common;1",  
 
301
  _xpcom_factory: {
 
302
    singleton: null,
 
303
    createInstance: function (aOuter, aIID) {
 
304
      if (aOuter)
 
305
        throw Components.results.NS_ERROR_NO_AGGREGATION;
 
306
      if (!this.singleton)
 
307
        this.singleton = new Common();
 
308
      return this.singleton.QueryInterface(aIID);
 
309
    }
 
310
  }
338
311
};
339
312
 
340
 
//module initialization
341
 
function NSGetModule(aCompMgr, aFileSpec) { return CommonModule; }
 
 
b'\\ No newline at end of file'
 
313
/**
 
314
 * XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4)
 
315
 * XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 and earlier (Firefox 3.6)
 
316
 */
 
317
if (XPCOMUtils.generateNSGetFactory)
 
318
  var NSGetFactory = XPCOMUtils.generateNSGetFactory([Common]);
 
319
else
 
320
  var NSGetModule = XPCOMUtils.generateNSGetModule([Common]);
 
 
b'\\ No newline at end of file'