summaryrefslogtreecommitdiffstats
path: root/shared/src
diff options
context:
space:
mode:
authorFlamenco <Flamenco@users.noreply.github.com>2017-07-27 06:24:43 -0400
committerHenri Sara <henri.sara@gmail.com>2017-07-27 13:24:43 +0300
commit410965ddca3e601343f8b759e1a27a2c1b0d0f29 (patch)
tree248f9da31766b7d5a3ed538331bcc1f431810832 /shared/src
parentb4243fe81aefd2f7f61d0a5bc644424616f2312c (diff)
downloadvaadin-framework-410965ddca3e601343f8b759e1a27a2c1b0d0f29.tar.gz
vaadin-framework-410965ddca3e601343f8b759e1a27a2c1b0d0f29.zip
Add support for detecting ChromeOS operating system (#9698)
Diffstat (limited to 'shared/src')
-rw-r--r--shared/src/main/java/com/vaadin/shared/VBrowserDetails.java54
1 files changed, 53 insertions, 1 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java b/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java
index fdf9b5f723..17a7cafff2 100644
--- a/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java
+++ b/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java
@@ -47,11 +47,12 @@ public class VBrowserDetails implements Serializable {
private boolean isWindowsPhone;
private boolean isIPad;
private boolean isIPhone;
+ private boolean isChromeOS;
private OperatingSystem os = OperatingSystem.UNKNOWN;
public enum OperatingSystem {
- UNKNOWN, WINDOWS, MACOSX, LINUX, IOS, ANDROID;
+ UNKNOWN, WINDOWS, MACOSX, LINUX, IOS, ANDROID, CHROMEOS;
}
private float browserEngineVersion = -1;
@@ -217,9 +218,51 @@ public class VBrowserDetails implements Serializable {
} else {
os = OperatingSystem.MACOSX;
}
+ } else if (userAgent.contains("; cros ")){
+ os = OperatingSystem.CHROMEOS;
+ isChromeOS = true;
+ parseChromeOSVersion(userAgent);
}
}
+ // (X11; CrOS armv7l 6946.63.0)
+ private void parseChromeOSVersion(String userAgent) {
+ int start = userAgent.indexOf("; cros ");
+ if (start == -1) {
+ return;
+ }
+ int end = userAgent.indexOf(')', start);
+ if (end == -1) {
+ return;
+ }
+ int cur = end;
+ while (cur >= start && userAgent.charAt(cur) != ' ') {
+ cur--;
+ }
+ if (cur == start) {
+ return;
+ }
+ String osVersionString = userAgent.substring(cur + 1, end);
+ String[] parts = osVersionString.split("\\.");
+ parseChromeOsVersion(parts);
+ }
+
+ private void parseChromeOsVersion(String[] parts) {
+ osMajorVersion = -1;
+ osMinorVersion = -1;
+
+ if (parts.length > 2) {
+ try {
+ osMajorVersion = Integer.parseInt(parts[1]);
+ } catch (Exception e) {
+ }
+ try {
+ osMinorVersion = Integer.parseInt(parts[0]);
+ } catch (Exception e) {
+ }
+ }
+ }
+
private void parseAndroidVersion(String userAgent) {
// Android 5.1;
if (!userAgent.contains("android")) {
@@ -559,6 +602,15 @@ public class VBrowserDetails implements Serializable {
}
/**
+ * Tests if the browser is run on Chrome OS (e.g. a Chromebook).
+ *
+ * @return true if run on Chrome OS, false otherwise
+ */
+ public boolean isChromeOS() {
+ return isChromeOS;
+ }
+
+ /**
* Returns the major version of the operating system. Currently only
* supported for mobile devices (iOS/Android)
*