2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
2011-07-02 12:04:49 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @fileoverview Similar to goog.userAgent.isVersion, but with support for
|
|
|
|
|
* getting the version information when running in a firefox extension.
|
|
|
|
|
*/
|
|
|
|
|
goog.provide('bot.userAgent');
|
|
|
|
|
|
2012-01-13 17:10:50 +00:00
|
|
|
goog.require('goog.string');
|
2011-07-02 12:04:49 +00:00
|
|
|
goog.require('goog.userAgent');
|
2011-10-21 00:20:44 +00:00
|
|
|
goog.require('goog.userAgent.product');
|
2011-07-02 12:04:49 +00:00
|
|
|
goog.require('goog.userAgent.product.isVersion');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-13 17:10:50 +00:00
|
|
|
* Whether the rendering engine version of the current browser is equal to or
|
|
|
|
|
* greater than the given version. This implementation differs from
|
|
|
|
|
* goog.userAgent.isVersion in the following ways:
|
|
|
|
|
* <ol>
|
|
|
|
|
* <li>in a Firefox extension, tests the engine version through the XUL version
|
|
|
|
|
* comparator service, because no window.navigator object is available
|
|
|
|
|
* <li>in IE, compares the given version to the current documentMode
|
|
|
|
|
* </ol>
|
|
|
|
|
*
|
2011-07-02 12:04:49 +00:00
|
|
|
* @param {string|number} version The version number to check.
|
2012-01-13 17:10:50 +00:00
|
|
|
* @return {boolean} Whether the browser engine version is the same or higher
|
|
|
|
|
* than the given version.
|
2011-07-02 12:04:49 +00:00
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.userAgent.isEngineVersion = function (version) {
|
2021-02-19 16:01:03 +00:00
|
|
|
if (goog.userAgent.IE) {
|
2012-11-08 16:22:32 +00:00
|
|
|
return goog.string.compareVersions(
|
2020-11-27 15:46:30 +00:00
|
|
|
/** @type {number} */(goog.userAgent.DOCUMENT_MODE), version) >= 0;
|
2012-01-13 17:10:50 +00:00
|
|
|
} else {
|
2013-06-13 17:16:23 -07:00
|
|
|
return goog.userAgent.isVersionOrHigher(version);
|
2011-07-02 12:04:49 +00:00
|
|
|
}
|
2012-01-13 17:10:50 +00:00
|
|
|
};
|
2011-08-11 12:04:01 +00:00
|
|
|
|
|
|
|
|
|
2012-01-13 17:10:50 +00:00
|
|
|
/**
|
|
|
|
|
* Whether the product version of the current browser is equal to or greater
|
|
|
|
|
* than the given version. This implementation differs from
|
|
|
|
|
* goog.userAgent.product.isVersion in the following ways:
|
|
|
|
|
* <ol>
|
|
|
|
|
* <li>in a Firefox extension, tests the product version through the XUL version
|
|
|
|
|
* comparator service, because no window.navigator object is available
|
|
|
|
|
* <li>on Android, always compares to the version to the OS version
|
|
|
|
|
* </ol>
|
|
|
|
|
*
|
|
|
|
|
* @param {string|number} version The version number to check.
|
|
|
|
|
* @return {boolean} Whether the browser product version is the same or higher
|
|
|
|
|
* than the given version.
|
|
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.userAgent.isProductVersion = function (version) {
|
2021-02-19 16:01:03 +00:00
|
|
|
if (goog.userAgent.product.ANDROID) {
|
2012-01-13 17:10:50 +00:00
|
|
|
return goog.string.compareVersions(
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.userAgent.ANDROID_VERSION_, version) >= 0;
|
2012-01-13 17:10:50 +00:00
|
|
|
} else {
|
|
|
|
|
return goog.userAgent.product.isVersion(version);
|
|
|
|
|
}
|
|
|
|
|
};
|
2011-08-11 12:04:01 +00:00
|
|
|
|
2011-07-02 12:39:21 +00:00
|
|
|
|
2018-10-26 09:33:28 +02:00
|
|
|
/**
|
|
|
|
|
* Whether we are a WebExtension.
|
|
|
|
|
*
|
|
|
|
|
* @const
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.userAgent.WEBEXTENSION = (function () {
|
2018-10-26 09:33:28 +02:00
|
|
|
// The content script global object is different than it's window
|
|
|
|
|
// Which requires accessing the chrome and browser objects through this
|
|
|
|
|
try {
|
2018-10-26 14:45:22 +02:00
|
|
|
return !!((goog.global.chrome || goog.global.browser)['extension']);
|
2018-10-26 09:33:28 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})();
|
2011-10-21 00:20:44 +00:00
|
|
|
|
|
|
|
|
/**
|
2011-12-06 11:44:44 +00:00
|
|
|
* Whether we are on IOS.
|
|
|
|
|
*
|
|
|
|
|
* @const
|
|
|
|
|
* @type {boolean}
|
2011-10-21 00:20:44 +00:00
|
|
|
*/
|
2011-12-06 11:44:44 +00:00
|
|
|
bot.userAgent.IOS = goog.userAgent.product.IPAD ||
|
2020-11-27 15:46:30 +00:00
|
|
|
goog.userAgent.product.IPHONE;
|
2011-12-06 11:44:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether we are on a mobile browser.
|
|
|
|
|
*
|
|
|
|
|
* @const
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
bot.userAgent.MOBILE = bot.userAgent.IOS || goog.userAgent.product.ANDROID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Android Operating System Version.
|
2013-03-10 13:56:37 -07:00
|
|
|
* @private {string}
|
2013-06-14 07:31:01 -07:00
|
|
|
* @const
|
2011-12-06 11:44:44 +00:00
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.userAgent.ANDROID_VERSION_ = (function () {
|
2011-12-06 11:44:44 +00:00
|
|
|
if (goog.userAgent.product.ANDROID) {
|
2012-01-13 17:10:50 +00:00
|
|
|
var userAgentString = goog.userAgent.getUserAgentString();
|
|
|
|
|
var match = /Android\s+([0-9\.]+)/.exec(userAgentString);
|
2012-04-26 17:55:18 +00:00
|
|
|
return match ? match[1] : '0';
|
2011-12-06 11:44:44 +00:00
|
|
|
} else {
|
2012-04-26 17:55:18 +00:00
|
|
|
return '0';
|
2011-12-06 11:44:44 +00:00
|
|
|
}
|
|
|
|
|
})();
|
2012-01-13 17:10:50 +00:00
|
|
|
|
|
|
|
|
|
2012-11-08 16:22:32 +00:00
|
|
|
/**
|
|
|
|
|
* Whether the current document is IE in a documentMode older than 8.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
|
|
|
|
bot.userAgent.IE_DOC_PRE8 = goog.userAgent.IE &&
|
2020-11-27 15:46:30 +00:00
|
|
|
!goog.userAgent.isDocumentModeOrHigher(8);
|
2012-11-08 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
2012-01-13 17:10:50 +00:00
|
|
|
/**
|
|
|
|
|
* Whether the current document is IE in IE9 (or newer) standards mode.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
2013-06-14 07:31:01 -07:00
|
|
|
bot.userAgent.IE_DOC_9 = goog.userAgent.isDocumentModeOrHigher(9);
|
2012-01-13 17:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the current document is IE in a documentMode older than 9.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
2012-11-08 16:22:32 +00:00
|
|
|
bot.userAgent.IE_DOC_PRE9 = goog.userAgent.IE &&
|
2020-11-27 15:46:30 +00:00
|
|
|
!goog.userAgent.isDocumentModeOrHigher(9);
|
2012-11-08 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the current document is IE in IE10 (or newer) standards mode.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
2013-06-14 07:31:01 -07:00
|
|
|
bot.userAgent.IE_DOC_10 = goog.userAgent.isDocumentModeOrHigher(10);
|
2012-11-08 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the current document is IE in a documentMode older than 10.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
|
|
|
|
bot.userAgent.IE_DOC_PRE10 = goog.userAgent.IE &&
|
2020-11-27 15:46:30 +00:00
|
|
|
!goog.userAgent.isDocumentModeOrHigher(10);
|
2012-11-08 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the current browser is Android pre-gingerbread.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
|
|
|
|
bot.userAgent.ANDROID_PRE_GINGERBREAD = goog.userAgent.product.ANDROID &&
|
2020-11-27 15:46:30 +00:00
|
|
|
!bot.userAgent.isProductVersion(2.3);
|
2013-08-16 11:53:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the current browser is Android pre-icecreamsandwich
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
|
|
|
|
bot.userAgent.ANDROID_PRE_ICECREAMSANDWICH = goog.userAgent.product.ANDROID &&
|
2020-11-27 15:46:30 +00:00
|
|
|
!bot.userAgent.isProductVersion(4);
|
2013-08-16 11:53:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the current browser is Safari 6.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @const
|
|
|
|
|
*/
|
|
|
|
|
bot.userAgent.SAFARI_6 = goog.userAgent.product.SAFARI &&
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.userAgent.isProductVersion(6);
|
2013-10-09 12:50:50 -04:00
|
|
|
|
2013-11-13 12:56:36 -08:00
|
|
|
|
2013-10-09 12:50:50 -04:00
|
|
|
/**
|
|
|
|
|
* Whether the current browser is Windows Phone.
|
2013-10-09 13:49:28 -04:00
|
|
|
* @type {boolean}
|
2013-10-09 12:50:50 -04:00
|
|
|
* @const
|
|
|
|
|
*/
|
2013-10-09 13:49:28 -04:00
|
|
|
bot.userAgent.WINDOWS_PHONE = goog.userAgent.IE &&
|
2020-11-27 15:46:30 +00:00
|
|
|
goog.userAgent.getUserAgentString().indexOf('IEMobile') != -1;
|