Debian Codegraph @

closure-library/closure/goog/useragent/product.js

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