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