Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js

Issue 2300403003: DevTools: patch browser's Chrome version into Chrome user agents for emulation (Closed)
Patch Set: use sprintf, default chrome version for fallback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/common/module.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/common/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698