| 1 |
// Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Utilities for getting details about the user's platform. |
| 17 |
*/ |
| 18 |
|
| 19 |
goog.provide('goog.userAgent.platform'); |
| 20 |
|
| 21 |
goog.require('goog.string'); |
| 22 |
goog.require('goog.userAgent'); |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Detects the version of the OS/platform the browser is running in. Not |
| 27 |
* supported for Linux, where an empty string is returned. |
| 28 |
* |
| 29 |
* @private |
| 30 |
* @return {string} The platform version. |
| 31 |
*/ |
| 32 |
goog.userAgent.platform.determineVersion_ = function() { |
| 33 |
var re; |
| 34 |
if (goog.userAgent.WINDOWS) { |
| 35 |
re = /Windows NT ([0-9.]+)/; |
| 36 |
var match = re.exec(goog.userAgent.getUserAgentString()); |
| 37 |
if (match) { |
| 38 |
return match[1]; |
| 39 |
} else { |
| 40 |
return '0'; |
| 41 |
} |
| 42 |
} else if (goog.userAgent.MAC) { |
| 43 |
re = /10[_.][0-9_.]+/; |
| 44 |
var match = re.exec(goog.userAgent.getUserAgentString()); |
| 45 |
// Note: some old versions of Camino do not report an OSX version. |
| 46 |
// Default to 10. |
| 47 |
return match ? match[0].replace(/_/g, '.') : '10'; |
| 48 |
} else if (goog.userAgent.ANDROID) { |
| 49 |
re = /Android\s+([^\);]+)(\)|;)/; |
| 50 |
var match = re.exec(goog.userAgent.getUserAgentString()); |
| 51 |
return match ? match[1] : ''; |
| 52 |
} else if ( |
| 53 |
goog.userAgent.IPHONE || goog.userAgent.IPAD || goog.userAgent.IPOD) { |
| 54 |
re = /(?:iPhone|CPU)\s+OS\s+(\S+)/; |
| 55 |
var match = re.exec(goog.userAgent.getUserAgentString()); |
| 56 |
// Report the version as x.y.z and not x_y_z |
| 57 |
return match ? match[1].replace(/_/g, '.') : ''; |
| 58 |
} |
| 59 |
|
| 60 |
return ''; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* The version of the platform. We don't determine the version of Linux. |
| 66 |
* For Windows, we only look at the NT version. Non-NT-based versions |
| 67 |
* (e.g. 95, 98, etc.) are given version 0.0. |
| 68 |
* @type {string} |
| 69 |
*/ |
| 70 |
goog.userAgent.platform.VERSION = goog.userAgent.platform.determineVersion_(); |
| 71 |
|
| 72 |
|
| 73 |
/** |
| 74 |
* Whether the user agent platform version is higher or the same as the given |
| 75 |
* version. |
| 76 |
* |
| 77 |
* @param {string|number} version The version to check. |
| 78 |
* @return {boolean} Whether the user agent platform version is higher or the |
| 79 |
* same as the given version. |
| 80 |
*/ |
| 81 |
goog.userAgent.platform.isVersion = function(version) { |
| 82 |
return goog.string.compareVersions( |
| 83 |
goog.userAgent.platform.VERSION, version) >= 0; |
| 84 |
}; |