1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
21 * osName: remoting.Os,
24 * chromeVersion: string
32 * Returns full Chrome version.
35 remoting.getChromeVersion = function() {
36 return remoting.getSystemInfo().chromeVersion;
40 * Tests whether we are running on Mac.
42 * @return {boolean} True if the platform is Mac.
44 remoting.platformIsMac = function() {
45 return remoting.getSystemInfo().osName === remoting.Os.MAC;
49 * Tests whether we are running on Windows.
51 * @return {boolean} True if the platform is Windows.
53 remoting.platformIsWindows = function() {
54 return remoting.getSystemInfo().osName === remoting.Os.WINDOWS;
58 * Tests whether we are running on Linux.
60 * @return {boolean} True if the platform is Linux.
62 remoting.platformIsLinux = function() {
63 return remoting.getSystemInfo().osName === remoting.Os.LINUX;
67 * Tests whether we are running on ChromeOS.
69 * @return {boolean} True if the platform is ChromeOS.
71 remoting.platformIsChromeOS = function() {
72 return remoting.getSystemInfo().osName === remoting.Os.CHROMEOS;
76 * @return {?remoting.SystemInfo}
78 remoting.getSystemInfo = function() {
79 var userAgent = remoting.getUserAgent();
81 /** @type {remoting.SystemInfo} */
84 osName: remoting.Os.UNKNOWN,
89 // See platform_unittest.js for sample user agent strings.
90 var chromeVersion = new RegExp('Chrome/([0-9.]*)').exec(userAgent);
91 if (chromeVersion && chromeVersion.length >= 2) {
92 result.chromeVersion = chromeVersion[1];
95 var match = new RegExp('Windows NT ([0-9\\.]*)').exec(userAgent);
96 if (match && (match.length >= 2)) {
97 result.osName = remoting.Os.WINDOWS;
98 result.osVersion = match[1];
102 match = new RegExp('Linux ([a-zA-Z0-9_]*)').exec(userAgent);
103 if (match && (match.length >= 2)) {
104 result.osName = remoting.Os.LINUX;
105 result.osVersion = '';
106 result.cpu = match[1];
110 match = new RegExp('([a-zA-Z]*) Mac OS X ([0-9_]*)').exec(userAgent);
111 if (match && (match.length >= 3)) {
112 result.osName = remoting.Os.MAC;
113 result.osVersion = match[2].replace(/_/g, '.');
114 result.cpu = match[1];
118 match = new RegExp('CrOS ([a-zA-Z0-9_]*) ([0-9.]*)').exec(userAgent);
119 if (match && (match.length >= 3)) {
120 result.osName = remoting.Os.CHROMEOS;
121 result.osVersion = match[2];
122 result.cpu = match[1];
129 * To be overwritten by unit test.
133 remoting.getUserAgent = function() {
134 return navigator.userAgent;