Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 WebInspector.BrowserVersionInfo = { | |
| 6 /** | |
| 7 * @param {string} uaString | |
| 8 * @param {string} sectionName | |
| 9 * @return {string} | |
| 10 */ | |
| 11 patchUserAgentWithCurrentVersion: function(uaString, sectionName) | |
| 12 { | |
| 13 var currentVersion = WebInspector.BrowserVersionInfo._getVersion(section Name); | |
| 14 if (!currentVersion || !sectionName) | |
| 15 return uaString; | |
| 16 | |
| 17 var sectionRegex = new RegExp("((?:^|[^\\w])" + sectionName + "/)([^\\s] +)"); | |
| 18 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 :)
| |
| 19 }, | |
| 20 | |
| 21 /** | |
| 22 * @param {string} sectionName | |
| 23 * @return {?string} | |
| 24 */ | |
| 25 _getVersion: function(sectionName) | |
| 26 { | |
| 27 // Extracts a version string from navigator.userAgent | |
| 28 // e.g. _getVersion("Chrome") === "1.2.3.4" when user agent is: "Chrome/ 1.2.3.4" | |
| 29 if (!sectionName || sectionName.indexOf("/") !== -1) | |
| 30 return null; | |
| 31 var userAgent = navigator.userAgent; | |
| 32 var sectionRegex = new RegExp("(?:^|[^\\w])" + sectionName + "/([^\\s]+) "); | |
| 33 var sectionMatch = userAgent.match(sectionRegex); | |
| 34 if (sectionMatch.length < 2) | |
| 35 return null; | |
| 36 return sectionMatch[1]; | |
| 37 } | |
| 38 }; | |
| OLD | NEW |