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 DefaultChromeVersion: "54.0.2834.0", | |
| 7 | |
| 8 /** | |
| 9 * @param {string} uaString | |
| 10 * @param {string} sectionName | |
| 11 * @return {string} | |
| 12 */ | |
| 13 patchUserAgentWithCurrentVersion: function(uaString, sectionName) | |
| 14 { | |
| 15 var currentVersion = WebInspector.BrowserVersionInfo._getVersion(section Name); | |
| 16 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.
| |
| 17 return uaString; | |
| 18 return String.sprintf(uaString, currentVersion); | |
| 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 WebInspector.BrowserVersionInfo._defaultVersion(sectionName); | |
| 31 var userAgent = navigator.userAgent; | |
| 32 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
| |
| 33 var sectionMatch = userAgent.match(sectionRegex); | |
| 34 if (sectionMatch.length < 2) | |
| 35 return WebInspector.BrowserVersionInfo._defaultVersion(sectionName); | |
| 36 return sectionMatch[1]; | |
| 37 }, | |
| 38 | |
| 39 /** | |
| 40 * @param {string} sectionName | |
| 41 * @return {?string} | |
| 42 */ | |
| 43 _defaultVersion: function(sectionName) | |
| 44 { | |
| 45 if (sectionName === "Chrome") | |
| 46 return WebInspector.BrowserVersionInfo.DefaultChromeVersion; | |
| 47 return null; | |
| 48 } | |
| 49 }; | |
| OLD | NEW |