Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/useragent/platform.js
4504 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Utilities for getting details about the user's platform.
9
*/
10
11
goog.provide('goog.userAgent.platform');
12
13
goog.require('goog.string');
14
goog.require('goog.userAgent');
15
16
17
/**
18
* Detects the version of the OS/platform the browser is running in. Not
19
* supported for Linux, where an empty string is returned.
20
*
21
* @private
22
* @return {string} The platform version.
23
*/
24
goog.userAgent.platform.determineVersion_ = function() {
25
'use strict';
26
var re;
27
if (goog.userAgent.WINDOWS) {
28
re = /Windows NT ([0-9.]+)/;
29
var match = re.exec(goog.userAgent.getUserAgentString());
30
if (match) {
31
return match[1];
32
} else {
33
return '0';
34
}
35
} else if (goog.userAgent.MAC) {
36
re = /1[0|1][_.][0-9_.]+/;
37
var match = re.exec(goog.userAgent.getUserAgentString());
38
// Note: some old versions of Camino do not report an OSX version.
39
// Default to 10.
40
return match ? match[0].replace(/_/g, '.') : '10';
41
} else if (goog.userAgent.ANDROID) {
42
re = /Android\s+([^\);]+)(\)|;)/;
43
var match = re.exec(goog.userAgent.getUserAgentString());
44
return match ? match[1] : '';
45
} else if (
46
goog.userAgent.IPHONE || goog.userAgent.IPAD || goog.userAgent.IPOD) {
47
re = /(?:iPhone|CPU)\s+OS\s+(\S+)/;
48
var match = re.exec(goog.userAgent.getUserAgentString());
49
// Report the version as x.y.z and not x_y_z
50
return match ? match[1].replace(/_/g, '.') : '';
51
}
52
53
return '';
54
};
55
56
57
/**
58
* The version of the platform. We don't determine the version of Linux.
59
* For Windows, we only look at the NT version. Non-NT-based versions
60
* (e.g. 95, 98, etc.) are given version 0.0.
61
* @type {string}
62
*/
63
goog.userAgent.platform.VERSION = goog.userAgent.platform.determineVersion_();
64
65
66
/**
67
* Whether the user agent platform version is higher or the same as the given
68
* version.
69
*
70
* @param {string|number} version The version to check.
71
* @return {boolean} Whether the user agent platform version is higher or the
72
* same as the given version.
73
*/
74
goog.userAgent.platform.isVersion = function(version) {
75
'use strict';
76
return goog.string.compareVersions(
77
goog.userAgent.platform.VERSION, version) >= 0;
78
};
79
80