# lib/goog/useragent/product.js

    1// Copyright 2008 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 at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// 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 and13// limitations under the License.1415/**16 * @fileoverview Detects the specific browser and not just the rendering engine.17 *18 */1920goog.provide('goog.userAgent.product');2122goog.require('goog.userAgent');232425/**26 * @define {boolean} Whether the code is running on the Firefox web browser.27 */28goog.define('goog.userAgent.product.ASSUME_FIREFOX', false);293031/**32 * @define {boolean} Whether the code is running on the Camino web browser.33 */34goog.define('goog.userAgent.product.ASSUME_CAMINO', false);353637/**38 * @define {boolean} Whether we know at compile-time that the product is an39 *     iPhone.40 */41goog.define('goog.userAgent.product.ASSUME_IPHONE', false);424344/**45 * @define {boolean} Whether we know at compile-time that the product is an46 *     iPad.47 */48goog.define('goog.userAgent.product.ASSUME_IPAD', false);495051/**52 * @define {boolean} Whether we know at compile-time that the product is an53 *     Android phone.54 */55goog.define('goog.userAgent.product.ASSUME_ANDROID', false);565758/**59 * @define {boolean} Whether the code is running on the Chrome web browser.60 */61goog.define('goog.userAgent.product.ASSUME_CHROME', false);626364/**65 * @define {boolean} Whether the code is running on the Safari web browser.66 */67goog.define('goog.userAgent.product.ASSUME_SAFARI', false);686970/**71 * Whether we know the product type at compile-time.72 * @type {boolean}73 * @private74 */75goog.userAgent.product.PRODUCT_KNOWN_ =76    goog.userAgent.ASSUME_IE ||77    goog.userAgent.ASSUME_OPERA ||78    goog.userAgent.product.ASSUME_FIREFOX ||79    goog.userAgent.product.ASSUME_CAMINO ||80    goog.userAgent.product.ASSUME_IPHONE ||81    goog.userAgent.product.ASSUME_IPAD ||82    goog.userAgent.product.ASSUME_ANDROID ||83    goog.userAgent.product.ASSUME_CHROME ||84    goog.userAgent.product.ASSUME_SAFARI;858687/**88 * Right now we just focus on Tier 1-3 browsers at:89 * http://wiki/Nonconf/ProductPlatformGuidelines90 * As well as the YUI grade A browsers at:91 * http://developer.yahoo.com/yui/articles/gbs/92 *93 * @private94 */95goog.userAgent.product.init_ = function() {9697  /**98   * Whether the code is running on the Firefox web browser.99   * @type {boolean}100   * @private101   */102  goog.userAgent.product.detectedFirefox_ = false;103104  /**105   * Whether the code is running on the Camino web browser.106   * @type {boolean}107   * @private108   */109  goog.userAgent.product.detectedCamino_ = false;110111  /**112   * Whether the code is running on an iPhone or iPod touch.113   * @type {boolean}114   * @private115   */116  goog.userAgent.product.detectedIphone_ = false;117118  /**119   * Whether the code is running on an iPad120   * @type {boolean}121   * @private122   */123  goog.userAgent.product.detectedIpad_ = false;124125  /**126   * Whether the code is running on the default browser on an Android phone.127   * @type {boolean}128   * @private129   */130  goog.userAgent.product.detectedAndroid_ = false;131132  /**133   * Whether the code is running on the Chrome web browser.134   * @type {boolean}135   * @private136   */137  goog.userAgent.product.detectedChrome_ = false;138139  /**140   * Whether the code is running on the Safari web browser.141   * @type {boolean}142   * @private143   */144  goog.userAgent.product.detectedSafari_ = false;145146  var ua = goog.userAgent.getUserAgentString();147  if (!ua) {148    return;149  }150151  // The order of the if-statements in the following code is important.152  // For example, in the WebKit section, we put Chrome in front of Safari153  // because the string 'Safari' is present on both of those browsers'154  // userAgent strings as well as the string we are looking for.155  // The idea is to prevent accidental detection of more than one client.156157  if (ua.indexOf('Firefox') != -1) {158    goog.userAgent.product.detectedFirefox_ = true;159  } else if (ua.indexOf('Camino') != -1) {160    goog.userAgent.product.detectedCamino_ = true;161  } else if (ua.indexOf('iPhone') != -1 || ua.indexOf('iPod') != -1) {162    goog.userAgent.product.detectedIphone_ = true;163  } else if (ua.indexOf('iPad') != -1) {164    goog.userAgent.product.detectedIpad_ = true;165  } else if (ua.indexOf('Chrome') != -1) {166    goog.userAgent.product.detectedChrome_ = true;167  } else if (ua.indexOf('Android') != -1) {168    goog.userAgent.product.detectedAndroid_ = true;169  } else if (ua.indexOf('Safari') != -1) {170    goog.userAgent.product.detectedSafari_ = true;171  }172};173174if (!goog.userAgent.product.PRODUCT_KNOWN_) {175  goog.userAgent.product.init_();176}177178179/**180 * Whether the code is running on the Opera web browser.181 * @type {boolean}182 */183goog.userAgent.product.OPERA = goog.userAgent.OPERA;184185186/**187 * Whether the code is running on an IE web browser.188 * @type {boolean}189 */190goog.userAgent.product.IE = goog.userAgent.IE;191192193/**194 * Whether the code is running on the Firefox web browser.195 * @type {boolean}196 */197goog.userAgent.product.FIREFOX = goog.userAgent.product.PRODUCT_KNOWN_ ?198    goog.userAgent.product.ASSUME_FIREFOX :199    goog.userAgent.product.detectedFirefox_;200201202/**203 * Whether the code is running on the Camino web browser.204 * @type {boolean}205 */206goog.userAgent.product.CAMINO = goog.userAgent.product.PRODUCT_KNOWN_ ?207    goog.userAgent.product.ASSUME_CAMINO :208    goog.userAgent.product.detectedCamino_;209210211/**212 * Whether the code is running on an iPhone or iPod touch.213 * @type {boolean}214 */215goog.userAgent.product.IPHONE = goog.userAgent.product.PRODUCT_KNOWN_ ?216    goog.userAgent.product.ASSUME_IPHONE :217    goog.userAgent.product.detectedIphone_;218219220/**221 * Whether the code is running on an iPad.222 * @type {boolean}223 */224goog.userAgent.product.IPAD = goog.userAgent.product.PRODUCT_KNOWN_ ?225    goog.userAgent.product.ASSUME_IPAD :226    goog.userAgent.product.detectedIpad_;227228229/**230 * Whether the code is running on the default browser on an Android phone.231 * @type {boolean}232 */233goog.userAgent.product.ANDROID = goog.userAgent.product.PRODUCT_KNOWN_ ?234    goog.userAgent.product.ASSUME_ANDROID :235    goog.userAgent.product.detectedAndroid_;236237238/**239 * Whether the code is running on the Chrome web browser.240 * @type {boolean}241 */242goog.userAgent.product.CHROME = goog.userAgent.product.PRODUCT_KNOWN_ ?243    goog.userAgent.product.ASSUME_CHROME :244    goog.userAgent.product.detectedChrome_;245246247/**248 * Whether the code is running on the Safari web browser.249 * @type {boolean}250 */251goog.userAgent.product.SAFARI = goog.userAgent.product.PRODUCT_KNOWN_ ?252    goog.userAgent.product.ASSUME_SAFARI :253    goog.userAgent.product.detectedSafari_;