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