Skip to content

Commit

Permalink
[embedlite-components] Don't use overrides when window.location doesn…
Browse files Browse the repository at this point in the history
…'t match to current location. Contributes to JB#34904

The current location is reset on "beforeunload" event.
  • Loading branch information
rainemak committed May 6, 2016
1 parent 9ff7635 commit f0f9c6b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions jscomps/UserAgentOverrideHelper.js
Expand Up @@ -51,8 +51,7 @@ UserAgentOverrideHelper.prototype = {
},

getUserAgentForURIAndWindow: function ssua_getUserAgentForURIAndWindow(aURI, aWindow) {
// aWindow is unused / not needed.
return UserAgent.getUserAgentForWindow(aURI)
return UserAgent.getUserAgentForWindow(aURI, aWindow, true)
},

QueryInterface: XPCOMUtils.generateQI([Ci.nsISiteSpecificUserAgent, Ci.nsIObserver,
Expand All @@ -65,6 +64,7 @@ var UserAgent = {
overrideMap: new Map,
initilized: false,
DESKTOP_UA: null,
currentHost: "",
GOOGLE_DOMAIN: /(^|\.)google\.com$/,
GOOGLE_MAPS_DOMAIN: /(^|\.)maps\.google\.com$/,
YOUTUBE_DOMAIN: /(^|\.)youtube\.com$/,
Expand Down Expand Up @@ -153,19 +153,27 @@ var UserAgent = {

if (this.overrideMap.has(host)) {
ua = this.overrideMap.get(host);
} else if (this.overrideMap.has(windowHost)) {
} else if (this.currentHost && (this.currentHost == windowHost) && this.overrideMap.has(windowHost)) {
ua = this.overrideMap.get(windowHost);
} else {
ua = this.getUserAgentForWindow(channel.URI);
ua = this.getUserAgentForWindow(channel.URI, channelWindow, false);
}

return ua
},

// Called if onRequest returns empty user-agent.
getUserAgentForWindow: function ua_getUserAgentForWindow(aUri) {
getUserAgentForWindow: function ua_getUserAgentForWindow(aUri, aWindow, aIsCurrentHost) {
// Try to pick 'general.useragent.override.*'
let ua = UserAgentOverrides.getOverrideForURI(aUri)
let ua = UserAgentOverrides.getOverrideForURI(aUri);

if (aIsCurrentHost) {
this.currentHost = aUri.asciiHost;
if (aWindow) {
aWindow.addEventListener("beforeunload", this, true);
}
}

if (!ua) {
ua = this.getUserAgentForUriAndTab(aUri);
}
Expand All @@ -178,6 +186,15 @@ 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 {
Expand Down

0 comments on commit f0f9c6b

Please sign in to comment.