Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..31f1ec0b1ed4fcae6da9a9027754abebe17de40b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +WebInspector.BrowserVersionInfo = { |
| + DefaultChromeVersion: "54.0.2834.0", |
| + |
| + /** |
| + * @param {string} uaString |
| + * @param {string} sectionName |
| + * @return {string} |
| + */ |
| + patchUserAgentWithCurrentVersion: function(uaString, sectionName) |
| + { |
| + var currentVersion = WebInspector.BrowserVersionInfo._getVersion(sectionName); |
| + if (!currentVersion || uaString.indexOf("%s") === -1) |
|
allada
2016/09/02 21:08:05
Can we add a test to make sure if a user adds a cu
luoe
2016/09/02 23:08:09
Done.
|
| + return uaString; |
| + return String.sprintf(uaString, currentVersion); |
| + }, |
| + |
| + /** |
| + * @param {string} sectionName |
| + * @return {?string} |
| + */ |
| + _getVersion: function(sectionName) |
| + { |
| + // Extracts a version string from navigator.userAgent |
| + // e.g. _getVersion("Chrome") === "1.2.3.4" when user agent is: "Chrome/1.2.3.4" |
| + if (!sectionName || sectionName.indexOf("/") !== -1) |
| + return WebInspector.BrowserVersionInfo._defaultVersion(sectionName); |
| + var userAgent = navigator.userAgent; |
| + var sectionRegex = new RegExp("(?:^|[^\\w])" + sectionName + "/([^\\s]+)"); |
|
allada
2016/09/02 21:08:05
var sectionRegex = new RegExp("(?:^|[^\\w])" + sec
luoe
2016/09/02 23:08:09
escapeForRegExp: done
This function just wants to
|
| + var sectionMatch = userAgent.match(sectionRegex); |
| + if (sectionMatch.length < 2) |
| + return WebInspector.BrowserVersionInfo._defaultVersion(sectionName); |
| + return sectionMatch[1]; |
| + }, |
| + |
| + /** |
| + * @param {string} sectionName |
| + * @return {?string} |
| + */ |
| + _defaultVersion: function(sectionName) |
| + { |
| + if (sectionName === "Chrome") |
| + return WebInspector.BrowserVersionInfo.DefaultChromeVersion; |
| + return null; |
| + } |
| +}; |