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

« back to all changes in this revision

Viewing changes to src/components/proxy.js

  • Committer: Package Import Robot
  • Author(s): Georg Koppen
  • Date: 2011-11-18 11:12:37 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20111118111237-r5fg91nr5dwfl01n
Tags: 3.3-2
cleaned up source package (removed .svn directories and .xpi files) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
  FoxyProxy
3
 
  Copyright (C) 2006-#%#% Eric H. Jung and LeahScape, Inc.
 
3
  Copyright (C) 2006-#%#% Eric H. Jung and FoxyProxy, Inc.
4
4
  http://getfoxyproxy.org/
5
5
  eric.jung@yahoo.com
6
6
 
88
88
  // nsProtocolProxyService.cpp#488 
89
89
  this.wpad.url = "http://wpad/wpad.dat";
90
90
  this._mode = "manual"; // manual, auto, direct, random
 
91
  this._autoconfMode = "pac";
91
92
  this._enabled = true;
92
93
  this.selectedTabIndex = 1; /* default tab is the proxy details tab */
93
94
  this.lastresort = false;
94
95
  this.id = this.fp.proxies.uniqueRandom();
95
 
  this.noInternalIPs = false;
96
96
}
97
97
 
98
98
Proxy.prototype = {
99
99
  direct: proxyService.newProxyInfo("direct", "", -1, 0, 0, null),
100
100
  animatedIcons: true,
101
101
  includeInCycle: true,
 
102
  noInternalIPs: false,
102
103
  _color: DEFAULT_COLOR,
103
104
  colorString: "nmbado",
104
105
  _proxyDNS: true,
123
124
    this.manualconf.fromDOM(node.getElementsByTagName("manualconf").item(0));
124
125
    // 1.1 used "manual" instead of "mode" and was true/false only (for manual or auto)
125
126
    this._mode = node.hasAttribute("manual") ?
126
 
          (node.getAttribute("manual") == "true" ? "manual" : "auto") :
127
 
        node.getAttribute("mode");
128
 
          this._mode = this._mode || "manual";
 
127
      (node.getAttribute("manual") == "true" ? "manual" : "auto") :
 
128
      node.getAttribute("mode");
 
129
    this._mode = this._mode || "manual";
 
130
    // New for 3.3. If the proxy had "wpad" as its mode select "wpad" as
 
131
    // autoconfMode otherwise the default, "pac", is used.
 
132
    if (this._mode !== "wpad") {
 
133
      this._autoconfMode = gGetSafeAttr(node, "autoconfMode", "pac");
 
134
    } else {
 
135
      // The mode was WPAD but that is not available anymore starting with 3.3.
 
136
      // There is only "auto" as proxy mode (we choose it) and two autoconf
 
137
      // modes, "wpad" and "pac", now (we choose former). 
 
138
      this._mode = "auto";
 
139
      this._autoconfMode = gGetSafeAttr(node, "autoconfMode", "wpad"); 
 
140
    }
129
141
    this.selectedTabIndex = node.getAttribute("selectedTabIndex") || "0";
130
142
    if (this.fp.isFoxyProxySimple() && this.selectedTabIndex > 1)
131
143
      this.selectedTabIndex = 1; /* FoxyProxy Simple only has 2 tabs */
135
147
    this.color = gGetSafeAttr(node, "color", DEFAULT_COLOR);    
136
148
    
137
149
    this.noInternalIPs = node.hasAttribute("noInternalIPs") ?
138
 
      node.getAttribute("noInternalIPs") : false;
 
150
      node.getAttribute("noInternalIPs") == "true" : false;
139
151
    for (var i=0,temp=node.getElementsByTagName("match"); i<temp.length; i++) {
140
152
      var j = this.matches.length;
141
153
      this.matches[j] = new Match();
165
177
    e.setAttribute("color", this._color);
166
178
    e.setAttribute("proxyDNS", this._proxyDNS);
167
179
    e.setAttribute("noInternalIPs", this.noInternalIPs);
 
180
    e.setAttribute("autoconfMode", this._autoconfMode);
168
181
 
169
182
    var matchesElem = doc.createElement("matches");
170
183
    e.appendChild(matchesElem);
292
305
    }
293
306
    this.fromDOM(proxyElem, true);
294
307
  },  
 
308
 
 
309
  set autoconfMode(e) {
 
310
    this._autoconfMode = e;
 
311
  },
 
312
 
 
313
  get autoconfMode() {
 
314
    return this._autoconfMode;
 
315
  },
295
316
  
296
317
  set proxyDNS(e) {
297
318
    this._proxyDNS = e;
331
352
    this._enabled = e;
332
353
    if (this.shouldLoadPAC()) {
333
354
      if (this._mode === "auto") {
334
 
        this.autoconf.loadPAC();
335
 
      } else {
336
 
        this.wpad.loadPAC();
 
355
        if (this._autoconfMode === "pac") {
 
356
          this.autoconf.loadPAC();
 
357
        } else if (this._autoconfMode === "wpad") {
 
358
          this.wpad.loadPAC();
 
359
        }
337
360
      }
338
361
    } 
339
362
    this.handleTimer();
342
365
  get enabled() {return this._enabled;},
343
366
 
344
367
  shouldLoadPAC : function() {
345
 
    if ((this._mode == "auto" || this._mode == "wpad") &&
346
 
         this._enabled) {
 
368
    if (this._mode == "auto" && this._enabled) {
347
369
      var m = this.fp.mode;
348
370
      return m == this.id || m == "patterns" || m == "random" ||
349
371
        m == "roundrobin";
354
376
    this._mode = m;
355
377
    if (this.shouldLoadPAC()) {
356
378
      if (this._mode === "auto") {
357
 
        this.autoconf.loadPAC();
358
 
      } else {
359
 
        this.wpad.loadPAC();
 
379
        if (this._autoconfMode === "pac") {
 
380
          this.autoconf.loadPAC();
 
381
        } else if (this._autoconfMode === "wpad") {
 
382
          this.wpad.loadPAC();
 
383
        }
360
384
      }
361
385
    } 
362
386
    this.handleTimer();
367
391
    // it changes our mode to "direct" or disables us.
368
392
    if (this.shouldLoadPAC()) {
369
393
      if (this._mode === "auto") {
370
 
        this.autoconf.loadPAC();
371
 
      } else {
372
 
        this.wpad.loadPAC();
 
394
        if (this._autoconfMode === "pac") {
 
395
          this.autoconf.loadPAC();
 
396
        } else if (this._autoconfMode === "wpad") {
 
397
          this.wpad.loadPAC();
 
398
        }
373
399
      }
374
400
    } 
375
401
    // Some integrity maintenance: if this is a manual proxy and
390
416
 
391
417
  handleTimer : function() {
392
418
    let ac;
393
 
    if (this._mode === "auto") {
 
419
    if (this._autoconfMode === "pac") {
394
420
      ac = this.autoconf; 
395
 
    } else {
 
421
    } else if (this._autoconfMode === "wpad") {
396
422
      ac = this.wpad;
397
423
    } 
398
424
    // always always always cancel first before doing anything 
399
 
    ac.timer.cancel();
 
425
    if (ac) {
 
426
      ac.timer.cancel();
 
427
    }
400
428
    if (this.shouldLoadPAC() && ac._autoReload) {
401
429
      ac.timer.initWithCallback(ac, ac._reloadFreqMins*60000,
402
430
        CI.nsITimer.TYPE_REPEATING_SLACK);
518
546
  getProxy : function(spec, host, mp) {
519
547
    switch (this._mode) {
520
548
      case "manual":return this.manualconf.proxy;
521
 
      case "wpad":return this.resolve(spec, host, mp, true);
522
 
      case "auto":return this.resolve(spec, host, mp, false);
 
549
      case "auto":
 
550
        if (this._autoconfMode === "pac") {
 
551
          return this.resolve(spec, host, mp, false);
 
552
        } else {
 
553
          // WPAD
 
554
          return this.resolve(spec, host, mp, true);
 
555
        }
523
556
      case "direct":return this.direct;
524
557
    }
525
558
  },