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

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: tests, escape, nullcheck 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
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)
17 return uaString;
18 console.assert(uaString.indexOf("%s") === uaString.lastIndexOf("%s"), "U ser agent string contains multiple %s");
19 return String.sprintf(uaString, currentVersion);
20 },
21
22 /**
23 * @param {string} sectionName
24 * @return {?string}
25 */
26 _getVersion: function(sectionName)
27 {
28 // Extracts a version string from navigator.userAgent
29 // e.g. _getVersion("Chrome") === "1.2.3.4" when user agent is: "Chrome/ 1.2.3.4"
dgozman 2016/09/02 23:42:45 I think doesn't work for content shell. Can we gen
luoe 2016/09/03 00:08:15 Can you show me how this breaks? I patched a bran
dgozman 2016/09/03 01:17:42 I was thinking that content shell has different UA
30 if (!sectionName || sectionName.indexOf("/") !== -1)
31 return WebInspector.BrowserVersionInfo._defaultVersion(sectionName);
32 var userAgent = navigator.userAgent;
33 var sectionRegex = new RegExp("(?:^|[^\\w])" + sectionName.escapeForRegE xp() + "/([^\\s]+)");
allada 2016/09/02 23:48:29 nit: lets use "(?:^|\\W)" and "/(\\S+)"
luoe 2016/09/03 00:08:14 Done.
34 var sectionMatch = userAgent.match(sectionRegex);
35 if (!sectionMatch || sectionMatch.length < 2)
36 return WebInspector.BrowserVersionInfo._defaultVersion(sectionName);
37 return sectionMatch[1];
38 },
39
40 /**
41 * @param {string} sectionName
42 * @return {?string}
43 */
44 _defaultVersion: function(sectionName)
45 {
46 if (sectionName === "Chrome")
47 return WebInspector.BrowserVersionInfo.DefaultChromeVersion;
48 return null;
49 }
50 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698