michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cu = Components.utils; michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/UserAgentOverrides.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: const DEFAULT_UA = Cc["@mozilla.org/network/protocol;1?name=http"] michael@0: .getService(Ci.nsIHttpProtocolHandler) michael@0: .userAgent; michael@0: michael@0: function SiteSpecificUserAgent() {} michael@0: michael@0: SiteSpecificUserAgent.prototype = { michael@0: getUserAgentForURIAndWindow: function ssua_getUserAgentForURIAndWindow(aURI, aWindow) { michael@0: let UA; michael@0: let win = Services.wm.getMostRecentWindow("navigator:browser"); michael@0: if (win && win.DesktopUserAgent) { michael@0: UA = win.DesktopUserAgent.getUserAgentForWindow(aWindow); michael@0: } michael@0: return UA || UserAgentOverrides.getOverrideForURI(aURI) || DEFAULT_UA; michael@0: }, michael@0: michael@0: classID: Components.ID("{d5234c9d-0ee2-4b3c-9da3-18be9e5cf7e6}"), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsISiteSpecificUserAgent]) michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SiteSpecificUserAgent]);