Commit 4a56b5e8 authored by Raine Makelainen's avatar Raine Makelainen Committed by chriadam

[embedlite-components] Add support for site specific UA override. Contributes to JB#34904

This makes possible to use general.useragent.override.* overrides
with simple replace syntax given that complex override is not applied.

Instantiation of the UserAgent is deferred a bit so that we do not
end up initializing UserAgentOverrides before general.useragent.override
is applied. As UserAgent was initialized on that application startup,
the simple hash separated user agent fixing did not work. This happened
because nsIHttpProtocolHandler was not yet aware of the override.
Thus, causing UserAgentOverrides to fail to replace ua.
parent b318fa91
......@@ -51,7 +51,8 @@ UserAgentOverrideHelper.prototype = {
},
getUserAgentForURIAndWindow: function ssua_getUserAgentForURIAndWindow(aURI, aWindow) {
return UserAgent.getUserAgentForWindow(aURI, aWindow, true)
// aWindow is unused / not needed.
return UserAgent.getUserAgentForWindow(aURI)
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsISiteSpecificUserAgent, Ci.nsIObserver,
......@@ -102,7 +103,7 @@ var UserAgent = {
if (this._desktopMode)
return this.DESKTOP_UA;
return this._customUA ? this._customUA : this.DESKTOP_UA;
return this._customUA ? this._customUA : defaultUA;
},
getUserAgentForUriAndTab: function ua_getUserAgentForUriAndTab(aUri) {
......@@ -153,27 +154,19 @@ var UserAgent = {
if (this.overrideMap.has(host)) {
ua = this.overrideMap.get(host);
} else if (this.currentHost && (this.currentHost == windowHost) && this.overrideMap.has(windowHost)) {
} else if (this.overrideMap.has(windowHost)) {
ua = this.overrideMap.get(windowHost);
} else {
ua = this.getUserAgentForWindow(channel.URI, channelWindow, false);
ua = this.getUserAgentForWindow(channel.URI);
}
return ua
},
// Called if onRequest returns empty user-agent.
getUserAgentForWindow: function ua_getUserAgentForWindow(aUri, aWindow, aIsCurrentHost) {
getUserAgentForWindow: function ua_getUserAgentForWindow(aUri) {
// Try to pick 'general.useragent.override.*'
let ua = UserAgentOverrides.getOverrideForURI(aUri);
if (aIsCurrentHost) {
this.currentHost = aUri.asciiHost;
if (aWindow) {
aWindow.addEventListener("beforeunload", this, true);
}
}
let ua = UserAgentOverrides.getOverrideForURI(aUri)
if (!ua) {
ua = this.getUserAgentForUriAndTab(aUri);
}
......@@ -186,15 +179,6 @@ var UserAgent = {
return this.getDefaultUserAgent();
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case "beforeunload": {
this.currentHost = "";
break;
}
}
},
_getRequestLoadContext: function ua_getRequestLoadContext(aRequest) {
if (aRequest && aRequest.notificationCallbacks) {
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment