Skip to content

Commit

Permalink
Fix: only the first entity of a kind was replaced.
Browse files Browse the repository at this point in the history
Also fixes imagebam
  • Loading branch information
nmaier committed Jan 23, 2011
1 parent 1d7fa8f commit 5ea2bb8
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions chrome/content/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ if ('XPCSafeJSObjectWrapper' in this) {
var acURLMaker = {
_io : Serv("@mozilla.org/network/io-service;1", 'nsIIOService'),
_cleaner: /[^/]+$/,

compose: function UM_compose(base, rel) {
var baseURI = this._io.newURI(base, null, null);
try {
rel = rel.replace(/&/, '&');
rel = rel.replace(/"/, '"');
rel = rel.replace(/ /, ' ');
rel = rel.replace(/&/g, '&');
rel = rel.replace(/"/g, '"');
rel = rel.replace(/ /g, ' ');
}
catch (ex) { /* no-op */ }
var realURI = this._io.newURI(
Expand Down Expand Up @@ -108,10 +108,10 @@ acResolver.prototype = {
this.download._acGlobalAttempt = 0;
}


// implemented to avoid infinite retrying
if (this.download._acAttempt >= 3 || this.download._acGlobalAttempt >= 20) {

// get it right back into the chain...
// we pass it back to dta then
// or we retry
Expand All @@ -135,14 +135,14 @@ acResolver.prototype = {
// k. starting... set the params to indicate so
this.download._acAttempt += 1;
this.download._acGlobalAttempt += 1;
this.process();
this.process();
},

process: function DR_process() {

// update the marker
this.download.status = _('acStatus', [this.prefix, this.download._acAttempt - 1]);

// this because invalid (scopewise)...
// doing like this gives us a valid object reference
var inst = this;
Expand Down Expand Up @@ -200,7 +200,7 @@ acResolver.prototype = {

// replace
this.download.urlManager = new UrlManager([new DTA.URL(url)]);

let useServerName = (this.useServerName && !this.useOriginName) || this.type == 'redirector';
if (!dn) {
dn = this.download.urlManager.usable.getUsableFileName();
Expand Down Expand Up @@ -232,10 +232,10 @@ acResolver.prototype = {
this.download._acAttempt += 0.2;
this.download._acGlobalAttempt += 0.2;
}

// do the standard work (dTa implementation)
},

// marks an item as gone
markGone: function acR_markGone(code, status) {
code = code || 404;
Expand All @@ -248,7 +248,7 @@ acResolver.prototype = {
_("error", [code]),
_("failed", [file]) + " " + _("sra", [code]) + ": " + status,
_("error", [code])
);
);
},

// finishing up
Expand All @@ -268,13 +268,13 @@ acResolver.prototype = {
}
},
defaultClean: function acR_defaultClean(n) n.replace(/^([a-z\d]{3}[_\s]|[a-z\d]{5}[_\s])/, ''),

createSandbox: function() {
if (this._sb) {
return this._sb;
}
try {
this._sb = Components.utils.Sandbox(this.download.urlManager.url.spec);
this._sb = Components.utils.Sandbox(this.download.urlManager.url.spec);
let sb = this._sb;
function alert(msg) {
window.alert(maybeWrap(msg));
Expand All @@ -293,23 +293,23 @@ acResolver.prototype = {
Debug.log("Failed to compose URL", ex);
}
}

function implementProxy(name, ctor, getters, setters, props, callbacks, functions) {
function proxyGetters(outerObj, innerObj, getters) {
for each (let getter in getters) {
let _getter = getter;
outerObj['_get_' + _getter] = function() {
return innerObj[_getter];
};
}
}
}
function proxySetters(outerObj, innerObj, setters) {
for each (let setter in setters) {
let _setter = setter;
outerObj['_set_' + _setter] = function(nv) {
return innerObj[_setter] = maybeWrap(nv);
};
}
}
}
function proxyProps(outerObj, innerObj) {
proxyGetters.apply(this, props);
Expand All @@ -320,7 +320,7 @@ acResolver.prototype = {
let _fn = func;
let _rf = null;
if (_fn instanceof Array) {
[_fn, _rf] = _fn;
[_fn, _rf] = _fn;
}
outerObj[_fn] = function() {
let args = Array.map(arguments, function(e) maybeWrap(e));
Expand Down Expand Up @@ -358,7 +358,7 @@ acResolver.prototype = {
}
let script = nv + '.call();';
Components.utils.evalInSandbox(script, sb);
delete sb._cb;
delete sb._cb;
};
}
}
Expand All @@ -369,8 +369,8 @@ acResolver.prototype = {
proxyProps(this, _o, props);
proxyFunctions(this, _o, functions);
proxyCallbacks(this, _o, callbacks);
}
}

let script = 'function ' + name + '() { this._o = new _' + name + '(); }; ' + name + '.prototype = {\n';
for each (let getter in getters.concat(props).concat(callbacks)) {
script += 'get ' + getter + "() { return this._o['_get_" + getter + "'](); },\n";
Expand All @@ -396,13 +396,13 @@ acResolver.prototype = {
['onload', 'onerror'],
['abort', ['getResponseHeader', function(i, f, h) h.match(/cookie/i) ? null : i[f].call(i, h)], 'open', 'send', 'setRequestHeader']
);

try {
Components.utils.evalInSandbox(acSandboxScripts, sb);
}
catch (ex) {
Debug.log("failed to load sanbox scripts", ex);
}
}
sb.importFunction(alert);
sb.importFunction(log);
sb.importFunction(composeURL);
Expand All @@ -427,8 +427,8 @@ acResolver.prototype = {
this.finish();
return;
}
let m = obj.finder.exec(this.responseText);

let m = obj.finder.exec(this.responseText);
if (obj.debug) {
alert(obj.finder)
alert(this.responseText);
Expand All @@ -451,7 +451,7 @@ acResolver.prototype = {
this.markGone();
}
this.finish();
};
};
},
generateSandboxed: function aCR_generateSandboxed(fn) {
return function() {
Expand Down Expand Up @@ -510,16 +510,16 @@ function acFactory(obj) {
if (!obj.type || !obj.match || !obj.prefix) {
throw new Error("Incompatible/Incomplete plugin");
}

this.obj = function() {};
for (let x in acResolver.prototype) {
this.obj.prototype[x] = acResolver.prototype[x];
}
this.obj.prototype.factory = this;

this.test = function(download) !!download.urlManager.url.spec.match(obj.match);
this.type = obj.type;

switch (this.type) {
case 'resolver':
this.obj.prototype.resolve = acResolver.prototype.generateResolve(obj);
Expand All @@ -531,7 +531,7 @@ function acFactory(obj) {
this.finish();
}
break;

case 'sandbox':
if (obj.process) {
this.obj.prototype.process = acResolver.prototype.generateSandboxed(obj.process);
Expand All @@ -544,21 +544,21 @@ function acFactory(obj) {
this.obj.prototype.resolve = this.obj.prototype.defaultResolve;
}
break;

default:
throw new Error("invalid plugin type");

}

if (obj.cleaners) {
this.obj.prototype.postClean = function(n) {
for each (let cleaner in obj.cleaners) {
n = n.replace(cleaner.pattern, cleaner.replacement);
}
return n;
}
}
}

for each (let x in ['type', 'prefix', 'useServerName', 'useOriginName', 'generateName', 'sendInitialReferrer', 'decode', 'omitReferrer', 'static', 'useDefaultClean']) {
// skip unset settings to allow default values in prototype
if (x in obj) {
Expand Down Expand Up @@ -610,7 +610,7 @@ acFactoryManager.prototype = {
}
}
return null;
}
}
};
let acFactories = new acFactoryManager();

Expand All @@ -631,7 +631,7 @@ QueueItem.prototype.resumeDownload = function acQ_resumeDownload() {
if ('_acProcessing' in this) {
return false;
}

let factory = acFactories.find(this);
if (factory) {
try {
Expand Down Expand Up @@ -665,13 +665,13 @@ QueueItem.prototype._acCancel = QueueItem.prototype.cancel;
QueueItem.prototype._acReset = function acQ_reset(justBookKeeping) {
// always reset
delete this._acProcessing;
delete this._acAttempt;
delete this._acAttempt;
delete this._acGlobalAttempt;

if (justBookKeeping) {
return;
}

// non bookkeeping stuff
if (this._acOriginal) {
this.urlManager = this._acOriginal;
Expand Down

0 comments on commit 5ea2bb8

Please sign in to comment.