// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview Similar to goog.userAgent.isVersion, but with support for19* getting the version information when running in a firefox extension.20*/21goog.provide('bot.userAgent');2223goog.require('goog.string');24goog.require('goog.userAgent');25goog.require('goog.userAgent.product');26goog.require('goog.userAgent.product.isVersion');272829/**30* Whether the rendering engine version of the current browser is equal to or31* greater than the given version. This implementation differs from32* goog.userAgent.isVersion in the following ways:33* <ol>34* <li>in a Firefox extension, tests the engine version through the XUL version35* comparator service, because no window.navigator object is available36* <li>in IE, compares the given version to the current documentMode37* </ol>38*39* @param {string|number} version The version number to check.40* @return {boolean} Whether the browser engine version is the same or higher41* than the given version.42*/43bot.userAgent.isEngineVersion = function (version) {44if (goog.userAgent.IE) {45return goog.string.compareVersions(46/** @type {number} */(goog.userAgent.DOCUMENT_MODE), version) >= 0;47} else {48return goog.userAgent.isVersionOrHigher(version);49}50};515253/**54* Whether the product version of the current browser is equal to or greater55* than the given version. This implementation differs from56* goog.userAgent.product.isVersion in the following ways:57* <ol>58* <li>in a Firefox extension, tests the product version through the XUL version59* comparator service, because no window.navigator object is available60* <li>on Android, always compares to the version to the OS version61* </ol>62*63* @param {string|number} version The version number to check.64* @return {boolean} Whether the browser product version is the same or higher65* than the given version.66*/67bot.userAgent.isProductVersion = function (version) {68if (goog.userAgent.product.ANDROID) {69return goog.string.compareVersions(70bot.userAgent.ANDROID_VERSION_, version) >= 0;71} else {72return goog.userAgent.product.isVersion(version);73}74};757677/**78* Whether we are a WebExtension.79*80* @const81* @type {boolean}82*/83bot.userAgent.WEBEXTENSION = (function () {84// The content script global object is different than it's window85// Which requires accessing the chrome and browser objects through this86try {87return !!((goog.global.chrome || goog.global.browser)['extension']);88} catch (e) {89return false;90}91})();9293/**94* Whether we are on IOS.95*96* @const97* @type {boolean}98*/99bot.userAgent.IOS = goog.userAgent.product.IPAD ||100goog.userAgent.product.IPHONE;101102103/**104* Whether we are on a mobile browser.105*106* @const107* @type {boolean}108*/109bot.userAgent.MOBILE = bot.userAgent.IOS || goog.userAgent.product.ANDROID;110111112/**113* Android Operating System Version.114* @private {string}115* @const116*/117bot.userAgent.ANDROID_VERSION_ = (function () {118if (goog.userAgent.product.ANDROID) {119var userAgentString = goog.userAgent.getUserAgentString();120var match = /Android\s+([0-9\.]+)/.exec(userAgentString);121return match ? match[1] : '0';122} else {123return '0';124}125})();126127128/**129* Whether the current document is IE in a documentMode older than 8.130* @type {boolean}131* @const132*/133bot.userAgent.IE_DOC_PRE8 = goog.userAgent.IE &&134!goog.userAgent.isDocumentModeOrHigher(8);135136137/**138* Whether the current document is IE in IE9 (or newer) standards mode.139* @type {boolean}140* @const141*/142bot.userAgent.IE_DOC_9 = goog.userAgent.isDocumentModeOrHigher(9);143144145/**146* Whether the current document is IE in a documentMode older than 9.147* @type {boolean}148* @const149*/150bot.userAgent.IE_DOC_PRE9 = goog.userAgent.IE &&151!goog.userAgent.isDocumentModeOrHigher(9);152153154/**155* Whether the current document is IE in IE10 (or newer) standards mode.156* @type {boolean}157* @const158*/159bot.userAgent.IE_DOC_10 = goog.userAgent.isDocumentModeOrHigher(10);160161162/**163* Whether the current document is IE in a documentMode older than 10.164* @type {boolean}165* @const166*/167bot.userAgent.IE_DOC_PRE10 = goog.userAgent.IE &&168!goog.userAgent.isDocumentModeOrHigher(10);169170171/**172* Whether the current browser is Android pre-gingerbread.173* @type {boolean}174* @const175*/176bot.userAgent.ANDROID_PRE_GINGERBREAD = goog.userAgent.product.ANDROID &&177!bot.userAgent.isProductVersion(2.3);178179180/**181* Whether the current browser is Android pre-icecreamsandwich182* @type {boolean}183* @const184*/185bot.userAgent.ANDROID_PRE_ICECREAMSANDWICH = goog.userAgent.product.ANDROID &&186!bot.userAgent.isProductVersion(4);187188189/**190* Whether the current browser is Safari 6.191* @type {boolean}192* @const193*/194bot.userAgent.SAFARI_6 = goog.userAgent.product.SAFARI &&195bot.userAgent.isProductVersion(6);196197198/**199* Whether the current browser is Windows Phone.200* @type {boolean}201* @const202*/203bot.userAgent.WINDOWS_PHONE = goog.userAgent.IE &&204goog.userAgent.getUserAgentString().indexOf('IEMobile') != -1;205206207