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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js
diff --git a/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js
new file mode 100644
index 0000000000000000000000000000000000000000..30916a44f859c007bdbce6c13d28b37c60279d74
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js
@@ -0,0 +1,38 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+WebInspector.BrowserVersionInfo = {
+ /**
+ * @param {string} uaString
+ * @param {string} sectionName
+ * @return {string}
+ */
+ patchUserAgentWithCurrentVersion: function(uaString, sectionName)
+ {
+ var currentVersion = WebInspector.BrowserVersionInfo._getVersion(sectionName);
+ if (!currentVersion || !sectionName)
+ return uaString;
+
+ var sectionRegex = new RegExp("((?:^|[^\\w])" + sectionName + "/)([^\\s]+)");
+ 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 :)
+ },
+
+ /**
+ * @param {string} sectionName
+ * @return {?string}
+ */
+ _getVersion: function(sectionName)
+ {
+ // Extracts a version string from navigator.userAgent
+ // e.g. _getVersion("Chrome") === "1.2.3.4" when user agent is: "Chrome/1.2.3.4"
+ if (!sectionName || sectionName.indexOf("/") !== -1)
+ return null;
+ var userAgent = navigator.userAgent;
+ var sectionRegex = new RegExp("(?:^|[^\\w])" + sectionName + "/([^\\s]+)");
+ var sectionMatch = userAgent.match(sectionRegex);
+ if (sectionMatch.length < 2)
+ return null;
+ return sectionMatch[1];
+ }
+};
« 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