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. 4 5/** 6 * @fileoverview Utilities for working with platforms. 7 */ 8 9 10goog.provide('cvox.PlatformFilter'); 11goog.provide('cvox.PlatformUtil'); 12 13goog.require('cvox.ChromeVox'); 14 15/** 16 * @enum 17 */ 18cvox.PlatformFilter = { 19 NONE: 0, 20 WINDOWS: 1, 21 MAC: 2, 22 LINUX: 4, 23 WML: 7, 24 CHROMEOS: 8, 25 ANDROID: 16 26}; 27 28 29/** 30 *Checks whether the given filter matches the current platform. An undefined 31 * filter always matches the current platform. 32 * @param {undefined|cvox.PlatformFilter|number} filter The filter. 33 * @return {boolean} Whether the filter matches the current platform. 34 */ 35cvox.PlatformUtil.matchesPlatform = function(filter) { 36 var uA = navigator.userAgent; 37 if (filter == undefined) { 38 return true; 39 } else if (uA.indexOf('Android') != -1) { 40 return (filter & cvox.PlatformFilter.ANDROID) != 0; 41 } else if (uA.indexOf('Win') != -1) { 42 return (filter & cvox.PlatformFilter.WINDOWS) != 0; 43 } else if (uA.indexOf('Mac') != -1) { 44 return (filter & cvox.PlatformFilter.MAC) != 0; 45 } else if (uA.indexOf('Linux') != -1) { 46 return (filter & cvox.PlatformFilter.LINUX) != 0; 47 } else if (uA.indexOf('CrOS') != -1) { 48 return (filter & cvox.PlatformFilter.CHROMEOS) != 0; 49 } 50 return false; 51}; 52