Index: third_party/google_input_tools/third_party/closure_library/closure/goog/labs/useragent/browser.js |
diff --git a/third_party/google_input_tools/third_party/closure_library/closure/goog/labs/useragent/browser.js b/third_party/google_input_tools/third_party/closure_library/closure/goog/labs/useragent/browser.js |
index 2a53f126056e8562be4e652862bbcbf66c640f3f..75e319176b5fc17c72ce76fcfa3c56f81c6b2776 100644 |
--- a/third_party/google_input_tools/third_party/closure_library/closure/goog/labs/useragent/browser.js |
+++ b/third_party/google_input_tools/third_party/closure_library/closure/goog/labs/useragent/browser.js |
@@ -19,16 +19,21 @@ |
* sub-namespaces in goog.labs.userAgent, goog.labs.userAgent.platform, |
* goog.labs.userAgent.device respectively.) |
* |
+ * @author martone@google.com (Andy Martone) |
*/ |
goog.provide('goog.labs.userAgent.browser'); |
goog.require('goog.array'); |
-goog.require('goog.asserts'); |
goog.require('goog.labs.userAgent.util'); |
+goog.require('goog.object'); |
goog.require('goog.string'); |
+// TODO(nnaze): Refactor to remove excessive exclusion logic in matching |
+// functions. |
+ |
+ |
/** |
* @return {boolean} Whether the user's browser is Opera. |
* @private |
@@ -50,6 +55,15 @@ goog.labs.userAgent.browser.matchIE_ = function() { |
/** |
+ * @return {boolean} Whether the user's browser is Edge. |
+ * @private |
+ */ |
+goog.labs.userAgent.browser.matchEdge_ = function() { |
+ return goog.labs.userAgent.util.matchUserAgent('Edge'); |
+}; |
+ |
+ |
+/** |
* @return {boolean} Whether the user's browser is Firefox. |
* @private |
*/ |
@@ -64,9 +78,38 @@ goog.labs.userAgent.browser.matchFirefox_ = function() { |
*/ |
goog.labs.userAgent.browser.matchSafari_ = function() { |
return goog.labs.userAgent.util.matchUserAgent('Safari') && |
- !goog.labs.userAgent.util.matchUserAgent('Chrome') && |
- !goog.labs.userAgent.util.matchUserAgent('CriOS') && |
- !goog.labs.userAgent.util.matchUserAgent('Android'); |
+ !(goog.labs.userAgent.browser.matchChrome_() || |
+ goog.labs.userAgent.browser.matchCoast_() || |
+ goog.labs.userAgent.browser.matchOpera_() || |
+ goog.labs.userAgent.browser.matchEdge_() || |
+ goog.labs.userAgent.browser.isSilk() || |
+ goog.labs.userAgent.util.matchUserAgent('Android')); |
+}; |
+ |
+ |
+/** |
+ * @return {boolean} Whether the user's browser is Coast (Opera's Webkit-based |
+ * iOS browser). |
+ * @private |
+ */ |
+goog.labs.userAgent.browser.matchCoast_ = function() { |
+ return goog.labs.userAgent.util.matchUserAgent('Coast'); |
+}; |
+ |
+ |
+/** |
+ * @return {boolean} Whether the user's browser is iOS Webview. |
+ * @private |
+ */ |
+goog.labs.userAgent.browser.matchIosWebview_ = function() { |
+ // iOS Webview does not show up as Chrome or Safari. Also check for Opera's |
+ // WebKit-based iOS browser, Coast. |
+ return (goog.labs.userAgent.util.matchUserAgent('iPad') || |
+ goog.labs.userAgent.util.matchUserAgent('iPhone')) && |
+ !goog.labs.userAgent.browser.matchSafari_() && |
+ !goog.labs.userAgent.browser.matchChrome_() && |
+ !goog.labs.userAgent.browser.matchCoast_() && |
+ goog.labs.userAgent.util.matchUserAgent('AppleWebKit'); |
}; |
@@ -75,8 +118,10 @@ goog.labs.userAgent.browser.matchSafari_ = function() { |
* @private |
*/ |
goog.labs.userAgent.browser.matchChrome_ = function() { |
- return goog.labs.userAgent.util.matchUserAgent('Chrome') || |
- goog.labs.userAgent.util.matchUserAgent('CriOS'); |
+ return (goog.labs.userAgent.util.matchUserAgent('Chrome') || |
+ goog.labs.userAgent.util.matchUserAgent('CriOS')) && |
+ !goog.labs.userAgent.browser.matchOpera_() && |
+ !goog.labs.userAgent.browser.matchEdge_(); |
}; |
@@ -85,9 +130,13 @@ goog.labs.userAgent.browser.matchChrome_ = function() { |
* @private |
*/ |
goog.labs.userAgent.browser.matchAndroidBrowser_ = function() { |
+ // Android can appear in the user agent string for Chrome on Android. |
+ // This is not the Android standalone browser if it does. |
return goog.labs.userAgent.util.matchUserAgent('Android') && |
- !goog.labs.userAgent.util.matchUserAgent('Chrome') && |
- !goog.labs.userAgent.util.matchUserAgent('CriOS'); |
+ !(goog.labs.userAgent.browser.isChrome() || |
+ goog.labs.userAgent.browser.isFirefox() || |
+ goog.labs.userAgent.browser.isOpera() || |
+ goog.labs.userAgent.browser.isSilk()); |
}; |
@@ -104,6 +153,12 @@ goog.labs.userAgent.browser.isIE = goog.labs.userAgent.browser.matchIE_; |
/** |
+ * @return {boolean} Whether the user's browser is Edge. |
+ */ |
+goog.labs.userAgent.browser.isEdge = goog.labs.userAgent.browser.matchEdge_; |
+ |
+ |
+/** |
* @return {boolean} Whether the user's browser is Firefox. |
*/ |
goog.labs.userAgent.browser.isFirefox = |
@@ -118,6 +173,21 @@ goog.labs.userAgent.browser.isSafari = |
/** |
+ * @return {boolean} Whether the user's browser is Coast (Opera's Webkit-based |
+ * iOS browser). |
+ */ |
+goog.labs.userAgent.browser.isCoast = |
+ goog.labs.userAgent.browser.matchCoast_; |
+ |
+ |
+/** |
+ * @return {boolean} Whether the user's browser is iOS Webview. |
+ */ |
+goog.labs.userAgent.browser.isIosWebview = |
+ goog.labs.userAgent.browser.matchIosWebview_; |
+ |
+ |
+/** |
* @return {boolean} Whether the user's browser is Chrome. |
*/ |
goog.labs.userAgent.browser.isChrome = |
@@ -158,13 +228,49 @@ goog.labs.userAgent.browser.getVersion = function() { |
return goog.labs.userAgent.browser.getIEVersion_(userAgentString); |
} |
+ var versionTuples = goog.labs.userAgent.util.extractVersionTuples( |
+ userAgentString); |
+ |
+ // Construct a map for easy lookup. |
+ var versionMap = {}; |
+ goog.array.forEach(versionTuples, function(tuple) { |
+ // Note that the tuple is of length three, but we only care about the |
+ // first two. |
+ var key = tuple[0]; |
+ var value = tuple[1]; |
+ versionMap[key] = value; |
+ }); |
+ |
+ var versionMapHasKey = goog.partial(goog.object.containsKey, versionMap); |
+ |
+ // Gives the value with the first key it finds, otherwise empty string. |
+ function lookUpValueWithKeys(keys) { |
+ var key = goog.array.find(keys, versionMapHasKey); |
+ return versionMap[key] || ''; |
+ } |
+ |
+ // Check Opera before Chrome since Opera 15+ has "Chrome" in the string. |
+ // See |
+ // http://my.opera.com/ODIN/blog/2013/07/15/opera-user-agent-strings-opera-15-and-beyond |
if (goog.labs.userAgent.browser.isOpera()) { |
- return goog.labs.userAgent.browser.getOperaVersion_(userAgentString); |
+ // Opera 10 has Version/10.0 but Opera/9.8, so look for "Version" first. |
+ // Opera uses 'OPR' for more recent UAs. |
+ return lookUpValueWithKeys(['Version', 'Opera', 'OPR']); |
} |
- var versionTuples = |
- goog.labs.userAgent.util.extractVersionTuples(userAgentString); |
- return goog.labs.userAgent.browser.getVersionFromTuples_(versionTuples); |
+ // Check Edge before Chrome since it has Chrome in the string. |
+ if (goog.labs.userAgent.browser.isEdge()) { |
+ return lookUpValueWithKeys(['Edge']); |
+ } |
+ |
+ if (goog.labs.userAgent.browser.isChrome()) { |
+ return lookUpValueWithKeys(['Chrome', 'CriOS']); |
+ } |
+ |
+ // Usually products browser versions are in the third tuple after "Mozilla" |
+ // and the engine. |
+ var tuple = versionTuples[2]; |
+ return tuple && tuple[1] || ''; |
}; |
@@ -233,39 +339,3 @@ goog.labs.userAgent.browser.getIEVersion_ = function(userAgent) { |
} |
return version; |
}; |
- |
- |
-/** |
- * Determines Opera version. More information: |
- * http://my.opera.com/ODIN/blog/2013/07/15/opera-user-agent-strings-opera-15-and-beyond |
- * |
- * @param {string} userAgent The User-Agent. |
- * @return {string} |
- * @private |
- */ |
-goog.labs.userAgent.browser.getOperaVersion_ = function(userAgent) { |
- var versionTuples = |
- goog.labs.userAgent.util.extractVersionTuples(userAgent); |
- var lastTuple = goog.array.peek(versionTuples); |
- if (lastTuple[0] == 'OPR' && lastTuple[1]) { |
- return lastTuple[1]; |
- } |
- |
- return goog.labs.userAgent.browser.getVersionFromTuples_(versionTuples); |
-}; |
- |
- |
-/** |
- * Nearly all User-Agents start with Mozilla/N.0. This looks at the second tuple |
- * for the actual browser version number. |
- * @param {!Array.<!Array.<string>>} versionTuples |
- * @return {string} The version or empty string if it cannot be determined. |
- * @private |
- */ |
-goog.labs.userAgent.browser.getVersionFromTuples_ = function(versionTuples) { |
- // versionTuples[2] (The first X/Y tuple after the parenthesis) contains the |
- // browser version number. |
- goog.asserts.assert(versionTuples.length > 2, |
- 'Couldn\'t extract version tuple from user agent string'); |
- return versionTuples[2] && versionTuples[2][1] ? versionTuples[2][1] : ''; |
-}; |