зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337905 - Update WebCompat Go Faster addon to version 1.1. r=Felipe
MozReview-Commit-ID: FMgf5E9Obzk --HG-- extra : rebase_source : 99b8bbcb6660e2ad899b7e295b468ec505fa5fdc
This commit is contained in:
Родитель
1470d15357
Коммит
98c6569650
|
@ -16,7 +16,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "eTLDService", "@mozilla.org/network/ef
|
|||
class UAOverrider {
|
||||
constructor(overrides) {
|
||||
this._overrides = {};
|
||||
this._overrideForURICache = new Map();
|
||||
|
||||
this.initOverrides(overrides);
|
||||
}
|
||||
|
@ -49,7 +48,7 @@ class UAOverrider {
|
|||
}
|
||||
|
||||
let channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
let uaOverride = this.getUAForURI(channel.URI);
|
||||
let uaOverride = this.lookupUAOverride(channel.URI);
|
||||
|
||||
if (uaOverride) {
|
||||
console.log("The user agent has been overridden for compatibility reasons.");
|
||||
|
@ -57,36 +56,20 @@ class UAOverrider {
|
|||
}
|
||||
}
|
||||
|
||||
getUAForURI(uri) {
|
||||
let bareUri = uri.specIgnoringRef;
|
||||
if (this._overrideForURICache.has(bareUri)) {
|
||||
// Although the cache could have an entry to a bareUri, `false` is also
|
||||
// a value that could be cached. A `false` cache entry means that there
|
||||
// is no override for this URI.
|
||||
// We cache these to avoid having to walk through all overrides to see
|
||||
// if a domain matches.
|
||||
return this._overrideForURICache.get(bareUri);
|
||||
}
|
||||
|
||||
let finalUA = this.lookupUAOverride(uri);
|
||||
this._overrideForURICache.set(bareUri, finalUA);
|
||||
|
||||
return finalUA;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets called from within the embedded webextension to check
|
||||
* if the current site has been overriden or not. We only check the cached
|
||||
* URI list here, but that's safe in our case since the tabUpdateHandler will
|
||||
* always run after our message observer.
|
||||
* Try to use the eTLDService to get the base domain (will return example.com
|
||||
* for http://foo.bar.example.com/foo/bar).
|
||||
*
|
||||
* However, the eTLDService is a bit picky and throws whenever we pass a
|
||||
* blank host name or an IP into it, see bug 1337785. Since we do not plan on
|
||||
* override UAs for such cases, we simply catch everything and return false.
|
||||
*/
|
||||
hasUAForURIInCache(uri) {
|
||||
let bareUri = uri.specIgnoringRef;
|
||||
if (this._overrideForURICache.has(bareUri)) {
|
||||
return !!this._overrideForURICache.get(bareUri);
|
||||
getBaseDomainFromURI(uri) {
|
||||
try {
|
||||
return eTLDService.getBaseDomain(uri);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,8 +89,8 @@ class UAOverrider {
|
|||
* uriMatchers would return true, the first one gets applied.
|
||||
*/
|
||||
lookupUAOverride(uri) {
|
||||
let baseDomain = eTLDService.getBaseDomain(uri);
|
||||
if (this._overrides[baseDomain]) {
|
||||
let baseDomain = this.getBaseDomainFromURI(uri);
|
||||
if (baseDomain && this._overrides[baseDomain]) {
|
||||
for (let uaOverride of this._overrides[baseDomain]) {
|
||||
if (uaOverride.uriMatcher(uri.specIgnoringRef)) {
|
||||
return uaOverride.uaTransformer(DefaultUA);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<Description about="urn:mozilla:install-manifest">
|
||||
<em:id>webcompat@mozilla.org</em:id>
|
||||
<em:version>1.0</em:version>
|
||||
<em:version>1.1</em:version>
|
||||
<em:type>2</em:type>
|
||||
<em:bootstrap>true</em:bootstrap>
|
||||
<em:multiprocessCompatible>true</em:multiprocessCompatible>
|
||||
|
|
|
@ -17,3 +17,6 @@ FINAL_TARGET_PP_FILES.features['webcompat@mozilla.org'] += [
|
|||
|
||||
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||
JAR_MANIFESTS += ['jar.mn']
|
||||
|
||||
with Files('**'):
|
||||
BUG_COMPONENT = ('Web Compatibility', 'Go Faster')
|
||||
|
|
|
@ -22,7 +22,7 @@ add_task(function test() {
|
|||
}
|
||||
]);
|
||||
|
||||
let finalUA = overrider.getUAForURI(getnsIURI("http://www.example.org/foobar/"));
|
||||
let finalUA = overrider.lookupUAOverride(getnsIURI("http://www.example.org/foobar/"));
|
||||
is(finalUA, "Test UA", "Overrides the UA without a matcher function");
|
||||
});
|
||||
|
||||
|
@ -35,6 +35,6 @@ add_task(function test() {
|
|||
}
|
||||
]);
|
||||
|
||||
let finalUA = overrider.getUAForURI(getnsIURI("http://www.example.org/foobar/"));
|
||||
let finalUA = overrider.lookupUAOverride(getnsIURI("http://www.example.org/foobar/"));
|
||||
isnot(finalUA, "Test UA", "Does not override the UA with the matcher returning false");
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче