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

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: 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 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..31f1ec0b1ed4fcae6da9a9027754abebe17de40b
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/common/BrowserVersionInfo.js
@@ -0,0 +1,49 @@
+// 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)
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.
+ return uaString;
+ 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"
+ if (!sectionName || sectionName.indexOf("/") !== -1)
+ return WebInspector.BrowserVersionInfo._defaultVersion(sectionName);
+ var userAgent = navigator.userAgent;
+ 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
+ var sectionMatch = userAgent.match(sectionRegex);
+ if (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;
+ }
+};
« 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