aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-07 16:33:30 +0300
committerDenis Anisimov <denis@vaadin.com>2014-10-09 14:35:48 +0300
commit709f35aca0f445444c8052015e34113e567a3166 (patch)
tree3492e967f97681e27ae3e75b43e5f946c37dbebe
parent29b57f24f735fc529df3487820bc8f2cb513385a (diff)
downloadvaadin-framework-709f35aca0f445444c8052015e34113e567a3166.tar.gz
vaadin-framework-709f35aca0f445444c8052015e34113e567a3166.zip
isIPad() and isIPhone() methods are added to WebBrowser (#14424,#14423).
Change-Id: I7b3556d5f9c1dd84beec638d7fbff1c5382070a4
-rw-r--r--client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java14
-rw-r--r--server/src/com/vaadin/server/WebBrowser.java20
-rw-r--r--shared/src/com/vaadin/shared/VBrowserDetails.java25
3 files changed, 57 insertions, 2 deletions
diff --git a/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java b/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java
index dd892b19ec..6cd0630137 100644
--- a/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java
+++ b/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java
@@ -85,6 +85,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase {
// assertBrowserMinorVersion(bd, 1);
assertEngineVersion(bd, 536f);
assertIOS(bd, 6, 1);
+ assertIPhone(bd);
}
public void testIPhoneIOS5() {
@@ -95,6 +96,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase {
assertBrowserMinorVersion(bd, 1);
assertEngineVersion(bd, 534f);
assertIOS(bd, 5, 1);
+ assertIPhone(bd);
}
public void testIPhoneIOS4() {
@@ -105,6 +107,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase {
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 532f);
assertIOS(bd, 4, 0);
+ assertIPhone(bd);
}
public void testIPadIOS4() {
@@ -115,6 +118,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase {
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 533f);
assertIOS(bd, 4, 3);
+ assertIPad(bd);
}
public void testAndroid21() {
@@ -539,6 +543,16 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase {
assertOSMinorVersion(browserDetails, minorVersion);
}
+ private void assertIPhone(VBrowserDetails browserDetails) {
+ assertTrue(browserDetails.isIPhone());
+ assertFalse(browserDetails.isIPad());
+ }
+
+ private void assertIPad(VBrowserDetails browserDetails) {
+ assertFalse(browserDetails.isIPhone());
+ assertTrue(browserDetails.isIPad());
+ }
+
private void assertWindows(VBrowserDetails browserDetails) {
assertWindows(browserDetails, false);
}
diff --git a/server/src/com/vaadin/server/WebBrowser.java b/server/src/com/vaadin/server/WebBrowser.java
index 17ba6756b8..cb5979d612 100644
--- a/server/src/com/vaadin/server/WebBrowser.java
+++ b/server/src/com/vaadin/server/WebBrowser.java
@@ -291,6 +291,26 @@ public class WebBrowser implements Serializable {
}
/**
+ * Tests if the browser is run on IPhone.
+ *
+ * @return true if run on IPhone false if the user is not using IPhone or if
+ * no information on the browser is present
+ */
+ public boolean isIPhone() {
+ return browserDetails.isIPhone();
+ }
+
+ /**
+ * Tests if the browser is run on IPad.
+ *
+ * @return true if run on IPad false if the user is not using IPad or if no
+ * information on the browser is present
+ */
+ public boolean isIPad() {
+ return browserDetails.isIPad();
+ }
+
+ /**
* Returns the browser-reported TimeZone offset in milliseconds from GMT.
* This includes possible daylight saving adjustments, to figure out which
* TimeZone the user actually might be in, see
diff --git a/shared/src/com/vaadin/shared/VBrowserDetails.java b/shared/src/com/vaadin/shared/VBrowserDetails.java
index 5fbf9bbb39..a85d031c49 100644
--- a/shared/src/com/vaadin/shared/VBrowserDetails.java
+++ b/shared/src/com/vaadin/shared/VBrowserDetails.java
@@ -43,6 +43,8 @@ public class VBrowserDetails implements Serializable {
private boolean isIE = false;
private boolean isWindowsPhone;
+ private boolean isIPad;
+ private boolean isIPhone;
private OperatingSystem os = OperatingSystem.UNKNOWN;
@@ -176,8 +178,9 @@ public class VBrowserDetails implements Serializable {
} else if (userAgent.contains("macintosh")
|| userAgent.contains("mac osx")
|| userAgent.contains("mac os x")) {
- if (userAgent.contains("ipad") || userAgent.contains("ipod")
- || userAgent.contains("iphone")) {
+ isIPad = userAgent.contains("ipad");
+ isIPhone = userAgent.contains("iphone");
+ if (isIPad || userAgent.contains("ipod") || isIPhone) {
os = OperatingSystem.IOS;
parseIOSVersion(userAgent);
} else {
@@ -474,6 +477,24 @@ public class VBrowserDetails implements Serializable {
}
/**
+ * Tests if the browser is run on iPhone.
+ *
+ * @return
+ */
+ public boolean isIPhone() {
+ return isIPhone;
+ }
+
+ /**
+ * Tests if the browser is run on iPad.
+ *
+ * @return
+ */
+ public boolean isIPad() {
+ return isIPad;
+ }
+
+ /**
* Returns the major version of the operating system. Currently only
* supported for mobile devices (iOS/Android)
*