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

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: 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 /**
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 };
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