summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2018-02-01 18:00:54 +0200
committerIlia Motornyi <elmot@vaadin.com>2018-02-01 18:00:54 +0200
commit875c98972e9c3da25a7c9c54cb267871921d4804 (patch)
tree8eb05e0dcf5aaf0321c96ebcbd65e53dc7b22850 /shared
parent5f5a6ebfd7db9f1fc6de4a515423837280310e86 (diff)
downloadvaadin-framework-875c98972e9c3da25a7c9c54cb267871921d4804.tar.gz
vaadin-framework-875c98972e9c3da25a7c9c54cb267871921d4804.zip
Add method for getting complete browser version (#10490)
Fixes #10461
Diffstat (limited to 'shared')
-rw-r--r--shared/src/main/java/com/vaadin/shared/VBrowserDetails.java55
1 files changed, 41 insertions, 14 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java b/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java
index b33e82c1a3..20e3071d0e 100644
--- a/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java
+++ b/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java
@@ -18,6 +18,8 @@ package com.vaadin.shared;
import java.io.Serializable;
import java.util.Locale;
+import com.google.gwt.regexp.shared.RegExp;
+
/**
* Class that parses the user agent string from the browser and provides
* information about the browser. Used internally by
@@ -59,6 +61,7 @@ public class VBrowserDetails implements Serializable {
private float browserEngineVersion = -1;
private int browserMajorVersion = -1;
private int browserMinorVersion = -1;
+ private String browserVersion;
private int osMajorVersion = -1;
private int osMinorVersion = -1;
@@ -143,25 +146,27 @@ public class VBrowserDetails implements Serializable {
// Browser version
try {
+ RegExp versionRegExp = RegExp.compile("[\\w\\.]*", "g");
if (isIE) {
if (userAgent.indexOf("msie") == -1) {
// IE 11+
int rvPos = userAgent.indexOf("rv:");
if (rvPos >= 0) {
- String tmp = userAgent.substring(rvPos + 3);
- tmp = tmp.replaceFirst("(\\.[0-9]+).+", "$1");
- parseVersionString(tmp);
+ int i = rvPos + "rv:".length();
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent)
+ .getGroup(0);
+ parseVersionString(browserVersion);
}
} else if (isTrident) {
// See
// https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
setIEMode((int) browserEngineVersion + 4);
} else {
- String ieVersionString = userAgent
- .substring(userAgent.indexOf("msie ") + 5);
- ieVersionString = safeSubstring(ieVersionString, 0,
- ieVersionString.indexOf(";"));
- parseVersionString(ieVersionString);
+ int i = userAgent.indexOf("msie ") + 5;
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
}
} else if (isFirefox) {
int i = userAgent.indexOf(" firefox/");
@@ -170,7 +175,9 @@ public class VBrowserDetails implements Serializable {
} else {
i = userAgent.indexOf(" fxios/") + " fxios/".length();
}
- parseVersionString(safeSubstring(userAgent, i, i + 5));
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
} else if (isChrome) {
int i = userAgent.indexOf(" chrome/");
if (i != -1) {
@@ -178,10 +185,14 @@ public class VBrowserDetails implements Serializable {
} else {
i = userAgent.indexOf(" crios/") + " crios/".length();
}
- parseVersionString(safeSubstring(userAgent, i, i + 5));
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
} else if (isSafari) {
int i = userAgent.indexOf(" version/") + 9;
- parseVersionString(safeSubstring(userAgent, i, i + 5));
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
} else if (isOpera) {
int i = userAgent.indexOf(" version/");
if (i != -1) {
@@ -190,14 +201,20 @@ public class VBrowserDetails implements Serializable {
} else {
i = userAgent.indexOf("opera/") + 6;
}
- parseVersionString(safeSubstring(userAgent, i, i + 5));
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
} else if (isEdge) {
int i = userAgent.indexOf(" edge/") + 6;
- parseVersionString(safeSubstring(userAgent, i, i + 8));
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
} else if (isPhantomJS) {
String prefix = " phantomjs/";
int i = userAgent.indexOf(prefix) + prefix.length();
- parseVersionString(safeSubstring(userAgent, i, i + 5));
+ versionRegExp.setLastIndex(i);
+ browserVersion = versionRegExp.exec(userAgent).getGroup(0);
+ parseVersionString(browserVersion);
}
} catch (Exception e) {
// Browser version parsing failed
@@ -521,6 +538,15 @@ public class VBrowserDetails implements Serializable {
}
/**
+ * Gets the complete browser version as string.
+ *
+ * @return the complete browser version or {@code null} if unknown
+ */
+ public final String getBrowserVersion() {
+ return browserVersion;
+ }
+
+ /**
* Sets the version for IE based on the documentMode. This is used to return
* the correct the correct IE version when the version from the user agent
* string and the value of the documentMode property do not match.
@@ -531,6 +557,7 @@ public class VBrowserDetails implements Serializable {
public void setIEMode(int documentMode) {
browserMajorVersion = documentMode;
browserMinorVersion = 0;
+ browserVersion = browserMajorVersion + "." + browserMinorVersion;
}
/**