Bug 1156065 - Send cloneable messages from SiteSpecificUserAgent.js to fix UA overrides r=billm

This commit is contained in:
Tim Taubert 2015-05-25 21:47:08 +02:00
Родитель 77fcecf9b0
Коммит 6f36e89b4d
2 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -46,7 +46,7 @@ SiteSpecificUserAgent.prototype = {
return cachedResult; return cachedResult;
} }
let data = { uri: aURI }; let data = { host: aURI.asciiHost };
let result = cpmm.sendRpcMessage("Useragent:GetOverride", data)[0] || HTTP_PROTO_HANDLER.userAgent; let result = cpmm.sendRpcMessage("Useragent:GetOverride", data)[0] || HTTP_PROTO_HANDLER.userAgent;
if (this.userAgentCache.size >= MAX_CACHE_SIZE) { if (this.userAgentCache.size >= MAX_CACHE_SIZE) {

Просмотреть файл

@ -30,7 +30,9 @@ var gUpdatedOverrides;
var gOverrideForHostCache = new Map; var gOverrideForHostCache = new Map;
var gInitialized = false; var gInitialized = false;
var gOverrideFunctions = [ var gOverrideFunctions = [
function (aHttpChannel) { return UserAgentOverrides.getOverrideForURI(aHttpChannel.URI); } function (aHttpChannel) {
return UserAgentOverrides.getOverrideForURI(aHttpChannel.URI.asciiHost);
}
]; ];
var gBuiltUAs = new Map; var gBuiltUAs = new Map;
@ -71,20 +73,19 @@ this.UserAgentOverrides = {
gOverrideFunctions.unshift(callback); gOverrideFunctions.unshift(callback);
}, },
getOverrideForURI: function uao_getOverrideForURI(aURI) { getOverrideForURI: function uao_getOverrideForURI(aHost) {
let host = aURI.asciiHost;
if (!gInitialized || if (!gInitialized ||
(!gOverrides.size && !gUpdatedOverrides) || (!gOverrides.size && !gUpdatedOverrides) ||
!(host)) { !(aHost)) {
return null; return null;
} }
let override = gOverrideForHostCache.get(host); let override = gOverrideForHostCache.get(aHost);
if (override !== undefined) if (override !== undefined)
return override; return override;
function findOverride(overrides) { function findOverride(overrides) {
let searchHost = host; let searchHost = aHost;
let userAgent = overrides.get(searchHost); let userAgent = overrides.get(searchHost);
while (!userAgent) { while (!userAgent) {
@ -104,7 +105,7 @@ this.UserAgentOverrides = {
if (gOverrideForHostCache.size >= MAX_OVERRIDE_FOR_HOST_CACHE_SIZE) { if (gOverrideForHostCache.size >= MAX_OVERRIDE_FOR_HOST_CACHE_SIZE) {
gOverrideForHostCache.clear(); gOverrideForHostCache.clear();
} }
gOverrideForHostCache.set(host, override); gOverrideForHostCache.set(aHost, override);
return override; return override;
}, },
@ -125,8 +126,8 @@ this.UserAgentOverrides = {
let name = aMessage.name; let name = aMessage.name;
switch (name) { switch (name) {
case OVERRIDE_MESSAGE: case OVERRIDE_MESSAGE:
let uri = aMessage.data.uri; let host = aMessage.data.host;
return this.getOverrideForURI(uri); return this.getOverrideForURI(host);
default: default:
throw("Wrong Message in UserAgentOverride: " + name); throw("Wrong Message in UserAgentOverride: " + name);
} }