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

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: 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 side-by-side diff with in-line comments
Download patch
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..150d75674a3517c42aa13947e06877c75d722953
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js
@@ -0,0 +1,50 @@
+// 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 = {
+ DefaultChromeVersion: "54.0.2834.0",
+
+ /**
+ * @param {string} uaString
+ * @param {string} sectionName
+ * @return {string}
+ */
+ patchUserAgentWithCurrentVersion: function(uaString, sectionName)
+ {
+ var currentVersion = WebInspector.BrowserVersionInfo._getVersion(sectionName);
+ if (!currentVersion || uaString.indexOf("%s") === -1)
+ return uaString;
+ console.assert(uaString.indexOf("%s") === uaString.lastIndexOf("%s"), "User agent string contains multiple %s");
+ return String.sprintf(uaString, currentVersion);
+ },
+
+ /**
+ * @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"
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
+ if (!sectionName || sectionName.indexOf("/") !== -1)
+ return WebInspector.BrowserVersionInfo._defaultVersion(sectionName);
+ var userAgent = navigator.userAgent;
+ var sectionRegex = new RegExp("(?:^|[^\\w])" + sectionName.escapeForRegExp() + "/([^\\s]+)");
allada 2016/09/02 23:48:29 nit: lets use "(?:^|\\W)" and "/(\\S+)"
luoe 2016/09/03 00:08:14 Done.
+ var sectionMatch = userAgent.match(sectionRegex);
+ if (!sectionMatch || sectionMatch.length < 2)
+ return WebInspector.BrowserVersionInfo._defaultVersion(sectionName);
+ return sectionMatch[1];
+ },
+
+ /**
+ * @param {string} sectionName
+ * @return {?string}
+ */
+ _defaultVersion: function(sectionName)
+ {
+ if (sectionName === "Chrome")
+ return WebInspector.BrowserVersionInfo.DefaultChromeVersion;
+ return null;
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698