1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/components/SiteSpecificUserAgent.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const Cu = Components.utils; 1.9 +const Cc = Components.classes; 1.10 +const Ci = Components.interfaces; 1.11 + 1.12 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.13 +Cu.import("resource://gre/modules/UserAgentOverrides.jsm"); 1.14 +Cu.import("resource://gre/modules/Services.jsm"); 1.15 + 1.16 +const DEFAULT_UA = Cc["@mozilla.org/network/protocol;1?name=http"] 1.17 + .getService(Ci.nsIHttpProtocolHandler) 1.18 + .userAgent; 1.19 + 1.20 +function SiteSpecificUserAgent() {} 1.21 + 1.22 +SiteSpecificUserAgent.prototype = { 1.23 + getUserAgentForURIAndWindow: function ssua_getUserAgentForURIAndWindow(aURI, aWindow) { 1.24 + let UA; 1.25 + let win = Services.wm.getMostRecentWindow("navigator:browser"); 1.26 + if (win && win.DesktopUserAgent) { 1.27 + UA = win.DesktopUserAgent.getUserAgentForWindow(aWindow); 1.28 + } 1.29 + return UA || UserAgentOverrides.getOverrideForURI(aURI) || DEFAULT_UA; 1.30 + }, 1.31 + 1.32 + classID: Components.ID("{d5234c9d-0ee2-4b3c-9da3-18be9e5cf7e6}"), 1.33 + QueryInterface: XPCOMUtils.generateQI([Ci.nsISiteSpecificUserAgent]) 1.34 +}; 1.35 + 1.36 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SiteSpecificUserAgent]);