product.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 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. * @fileoverview Detects the specific browser and not just the rendering engine.
  16. *
  17. */
  18. goog.provide('goog.userAgent.product');
  19. goog.require('goog.labs.userAgent.browser');
  20. goog.require('goog.labs.userAgent.platform');
  21. goog.require('goog.userAgent');
  22. /**
  23. * @define {boolean} Whether the code is running on the Firefox web browser.
  24. */
  25. goog.define('goog.userAgent.product.ASSUME_FIREFOX', false);
  26. /**
  27. * @define {boolean} Whether we know at compile-time that the product is an
  28. * iPhone.
  29. */
  30. goog.define('goog.userAgent.product.ASSUME_IPHONE', false);
  31. /**
  32. * @define {boolean} Whether we know at compile-time that the product is an
  33. * iPad.
  34. */
  35. goog.define('goog.userAgent.product.ASSUME_IPAD', false);
  36. /**
  37. * @define {boolean} Whether we know at compile-time that the product is an
  38. * AOSP browser or WebView inside a pre KitKat Android phone or tablet.
  39. */
  40. goog.define('goog.userAgent.product.ASSUME_ANDROID', false);
  41. /**
  42. * @define {boolean} Whether the code is running on the Chrome web browser on
  43. * any platform or AOSP browser or WebView in a KitKat+ Android phone or tablet.
  44. */
  45. goog.define('goog.userAgent.product.ASSUME_CHROME', false);
  46. /**
  47. * @define {boolean} Whether the code is running on the Safari web browser.
  48. */
  49. goog.define('goog.userAgent.product.ASSUME_SAFARI', false);
  50. /**
  51. * Whether we know the product type at compile-time.
  52. * @type {boolean}
  53. * @private
  54. */
  55. goog.userAgent.product.PRODUCT_KNOWN_ = goog.userAgent.ASSUME_IE ||
  56. goog.userAgent.ASSUME_EDGE || goog.userAgent.ASSUME_OPERA ||
  57. goog.userAgent.product.ASSUME_FIREFOX ||
  58. goog.userAgent.product.ASSUME_IPHONE ||
  59. goog.userAgent.product.ASSUME_IPAD ||
  60. goog.userAgent.product.ASSUME_ANDROID ||
  61. goog.userAgent.product.ASSUME_CHROME ||
  62. goog.userAgent.product.ASSUME_SAFARI;
  63. /**
  64. * Whether the code is running on the Opera web browser.
  65. * @type {boolean}
  66. */
  67. goog.userAgent.product.OPERA = goog.userAgent.OPERA;
  68. /**
  69. * Whether the code is running on an IE web browser.
  70. * @type {boolean}
  71. */
  72. goog.userAgent.product.IE = goog.userAgent.IE;
  73. /**
  74. * Whether the code is running on an Edge web browser.
  75. * @type {boolean}
  76. */
  77. goog.userAgent.product.EDGE = goog.userAgent.EDGE;
  78. /**
  79. * Whether the code is running on the Firefox web browser.
  80. * @type {boolean}
  81. */
  82. goog.userAgent.product.FIREFOX = goog.userAgent.product.PRODUCT_KNOWN_ ?
  83. goog.userAgent.product.ASSUME_FIREFOX :
  84. goog.labs.userAgent.browser.isFirefox();
  85. /**
  86. * Whether the user agent is an iPhone or iPod (as in iPod touch).
  87. * @return {boolean}
  88. * @private
  89. */
  90. goog.userAgent.product.isIphoneOrIpod_ = function() {
  91. return goog.labs.userAgent.platform.isIphone() ||
  92. goog.labs.userAgent.platform.isIpod();
  93. };
  94. /**
  95. * Whether the code is running on an iPhone or iPod touch.
  96. *
  97. * iPod touch is considered an iPhone for legacy reasons.
  98. * @type {boolean}
  99. */
  100. goog.userAgent.product.IPHONE = goog.userAgent.product.PRODUCT_KNOWN_ ?
  101. goog.userAgent.product.ASSUME_IPHONE :
  102. goog.userAgent.product.isIphoneOrIpod_();
  103. /**
  104. * Whether the code is running on an iPad.
  105. * @type {boolean}
  106. */
  107. goog.userAgent.product.IPAD = goog.userAgent.product.PRODUCT_KNOWN_ ?
  108. goog.userAgent.product.ASSUME_IPAD :
  109. goog.labs.userAgent.platform.isIpad();
  110. /**
  111. * Whether the code is running on AOSP browser or WebView inside
  112. * a pre KitKat Android phone or tablet.
  113. * @type {boolean}
  114. */
  115. goog.userAgent.product.ANDROID = goog.userAgent.product.PRODUCT_KNOWN_ ?
  116. goog.userAgent.product.ASSUME_ANDROID :
  117. goog.labs.userAgent.browser.isAndroidBrowser();
  118. /**
  119. * Whether the code is running on the Chrome web browser on any platform
  120. * or AOSP browser or WebView in a KitKat+ Android phone or tablet.
  121. * @type {boolean}
  122. */
  123. goog.userAgent.product.CHROME = goog.userAgent.product.PRODUCT_KNOWN_ ?
  124. goog.userAgent.product.ASSUME_CHROME :
  125. goog.labs.userAgent.browser.isChrome();
  126. /**
  127. * @return {boolean} Whether the browser is Safari on desktop.
  128. * @private
  129. */
  130. goog.userAgent.product.isSafariDesktop_ = function() {
  131. return goog.labs.userAgent.browser.isSafari() &&
  132. !goog.labs.userAgent.platform.isIos();
  133. };
  134. /**
  135. * Whether the code is running on the desktop Safari web browser.
  136. * Note: the legacy behavior here is only true for Safari not running
  137. * on iOS.
  138. * @type {boolean}
  139. */
  140. goog.userAgent.product.SAFARI = goog.userAgent.product.PRODUCT_KNOWN_ ?
  141. goog.userAgent.product.ASSUME_SAFARI :
  142. goog.userAgent.product.isSafariDesktop_();