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..30916a44f859c007bdbce6c13d28b37c60279d74 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js |
| @@ -0,0 +1,38 @@ |
| +// 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 = { |
| + /** |
| + * @param {string} uaString |
| + * @param {string} sectionName |
| + * @return {string} |
| + */ |
| + patchUserAgentWithCurrentVersion: function(uaString, sectionName) |
| + { |
| + var currentVersion = WebInspector.BrowserVersionInfo._getVersion(sectionName); |
| + if (!currentVersion || !sectionName) |
| + return uaString; |
| + |
| + var sectionRegex = new RegExp("((?:^|[^\\w])" + sectionName + "/)([^\\s]+)"); |
| + return uaString.replace(sectionRegex, "$1" + currentVersion); |
|
allada
2016/09/02 18:16:25
Lets not use a regex replace for this, lets use: r
allada
2016/09/02 18:16:25
How are we handling cases where the user wants to
luoe
2016/09/02 20:43:10
Okay, it now uses %s in the strings, as it's more
luoe
2016/09/02 20:43:10
Maybe not in this CL :)
|
| + }, |
| + |
| + /** |
| + * @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 null; |
| + var userAgent = navigator.userAgent; |
| + var sectionRegex = new RegExp("(?:^|[^\\w])" + sectionName + "/([^\\s]+)"); |
| + var sectionMatch = userAgent.match(sectionRegex); |
| + if (sectionMatch.length < 2) |
| + return null; |
| + return sectionMatch[1]; |
| + } |
| +}; |