com.vaadin.flow.server.
Class WebBrowser
- java.lang.Object
-
- com.vaadin.flow.server.WebBrowser
-
All Implemented Interfaces:
Direct Known Subclasses:
public class WebBrowser extends Object implements Serializable
Class that provides information about the web browser the user is using. Provides information such as browser name and version, screen resolution and IP address.
Since:
1.0.
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description WebBrowser()
-
Method Summary
All Methods Modifier and Type Method and Description String
getAddress()
Gets the IP-address of the web browser, if available.
String
getBrowserApplication()
Get the browser user-agent string.
int
getBrowserMajorVersion()
Gets the major version of the browser the user is using.
int
getBrowserMinorVersion()
Gets the minor version of the browser the user is using.
Date
getCurrentDate()
Returns the current date and time of the browser.
int
getDSTSavings()
Returns the offset in milliseconds between the browser's GMT TimeZone and DST.
Locale
getLocale()
Gets the locale reported by the browser.
int
getRawTimezoneOffset()
Returns the browser-reported TimeZone offset in milliseconds from GMT ignoring possible daylight saving adjustments that may be in effect in the browser.
int
getScreenHeight()
Gets the height of the screen in pixels.
int
getScreenWidth()
Gets the width of the screen in pixels.
String
getTimeZoneId()
Returns the TimeZone Id (like "Europe/Helsinki") provided by the browser (if the browser supports this feature).
int
getTimezoneOffset()
Returns the browser-reported TimeZone offset in milliseconds from GMT.
boolean
isAndroid()
Tests if the browser is run on Android.
boolean
isChrome()
Tests whether the user is using Chrome.
boolean
isChromeOS()
Tests if the browser is run on ChromeOS (e.g.
boolean
isDSTInEffect()
Returns whether daylight saving time (DST) is currently in effect in the region of the browser or not.
boolean
isEdge()
Tests whether the user is using Edge.
boolean
isEs5AdapterNeeded()
Checks if the browser needs `custom-elements-es5-adapter.js` to be loaded.
boolean
isEs6Supported()
Checks if the browser supports ECMAScript 6, based on the user agent.
boolean
isFirefox()
Tests whether the user is using Firefox.
boolean
isIE()
Tests whether the user is using Internet Explorer.
boolean
isIOS()
Tests if the browser is run in iOS.
boolean
isIPad()
Tests if the browser is run on IPad.
boolean
isIPhone()
Tests if the browser is run on IPhone.
boolean
isLinux()
Tests whether the user is using Linux.
boolean
isMacOSX()
Tests whether the user is using Mac OS X.
boolean
isOpera()
Tests whether the user is using Opera.
boolean
isSafari()
Tests whether the user is using Safari.
boolean
isSecureConnection()
Checks if the connection was established using HTTPS.
boolean
isTooOldToFunctionProperly()
Checks if the browser is so old that it simply won't work with a Vaadin application.
boolean
isTouchDevice()
Checks if the browser supports touch events.
boolean
isWindows()
Tests whether the user is using Windows.
boolean
isWindowsPhone()
Tests whether the user is using Windows Phone.
void
updateRequestDetails(VaadinRequest request)
For internal use only.
-
-
-
Method Detail
-
getScreenHeight
public int getScreenHeight()
Gets the height of the screen in pixels. This is the full screen resolution and not the height available for the application.
Returns:
the height of the screen in pixels.
-
getScreenWidth
public int getScreenWidth()
Gets the width of the screen in pixels. This is the full screen resolution and not the width available for the application.
Returns:
the width of the screen in pixels.
-
getBrowserApplication
public String getBrowserApplication()
Get the browser user-agent string.
Returns:
The raw browser userAgent string
-
getAddress
public String getAddress()
Gets the IP-address of the web browser, if available.
Returns:
IP-address in 1.12.123.123 -format or null if the address is not available
-
getLocale
public Locale getLocale()
Gets the locale reported by the browser.
Returns:
the browser reported locale
-
isSecureConnection
public boolean isSecureConnection()
Checks if the connection was established using HTTPS.
Returns:
true if HTTPS was used, false otherwise
-
isFirefox
public boolean isFirefox()
Tests whether the user is using Firefox.
Returns:
true if the user is using Firefox, false if the user is not using Firefox or if no information on the browser is present
-
isIE
public boolean isIE()
Tests whether the user is using Internet Explorer.
Returns:
true if the user is using Internet Explorer, false if the user is not using Internet Explorer or if no information on the browser is present
-
isEdge
public boolean isEdge()
Tests whether the user is using Edge.
Returns:
true if the user is using Edge, false if the user is not using Edge or if no information on the browser is present
-
isSafari
public boolean isSafari()
Tests whether the user is using Safari. Note that Chrome on iOS is not detected as Safari but as Chrome although the underlying browser engine is the same.
Returns:
true if the user is using Safari, false if the user is not using Safari or if no information on the browser is present
-
isOpera
public boolean isOpera()
Tests whether the user is using Opera.
Returns:
true if the user is using Opera, false if the user is not using Opera or if no information on the browser is present
-
isChrome
public boolean isChrome()
Tests whether the user is using Chrome.
Returns:
true if the user is using Chrome, false if the user is not using Chrome or if no information on the browser is present
-
getBrowserMajorVersion
public int getBrowserMajorVersion()
Gets the major version of the browser the user is using.
Note that Internet Explorer in IE7 compatibility mode might return 8 in some cases even though it should return 7.
Returns:
The major version of the browser or -1 if not known.
-
getBrowserMinorVersion
public int getBrowserMinorVersion()
Gets the minor version of the browser the user is using.
Returns:
The minor version of the browser or -1 if not known.
See Also:
-
isLinux
public boolean isLinux()
Tests whether the user is using Linux.
Returns:
true if the user is using Linux, false if the user is not using Linux or if no information on the browser is present
-
isMacOSX
public boolean isMacOSX()
Tests whether the user is using Mac OS X.
Returns:
true if the user is using Mac OS X, false if the user is not using Mac OS X or if no information on the browser is present
-
isWindows
public boolean isWindows()
Tests whether the user is using Windows.
Returns:
true if the user is using Windows, false if the user is not using Windows or if no information on the browser is present
-
isWindowsPhone
public boolean isWindowsPhone()
Tests whether the user is using Windows Phone.
Returns:
true if the user is using Windows Phone, false if the user is not using Windows Phone or if no information on the browser is present
-
isAndroid
public boolean isAndroid()
Tests if the browser is run on Android.
Returns:
true if run on Android false if the user is not using Android or if no information on the browser is present
-
isIOS
public boolean isIOS()
Tests if the browser is run in iOS.
Returns:
true if run in iOS false if the user is not using iOS or if no information on the browser is present
-
isIPhone
public boolean isIPhone()
Tests if the browser is run on IPhone.
Returns:
true if run on IPhone false if the user is not using IPhone or if no information on the browser is present
-
isIPad
public boolean isIPad()
Tests if the browser is run on IPad.
Returns:
true if run on IPad false if the user is not using IPad or if no information on the browser is present
-
isChromeOS
public boolean isChromeOS()
Tests if the browser is run on ChromeOS (e.g. a Chromebook).
Returns:
true if run on ChromeOS false if the user is not using ChromeOS or if no information on the browser is present
-
getTimezoneOffset
public int getTimezoneOffset()
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
getRawTimezoneOffset()
.Returns:
timezone offset in milliseconds, 0 if not available
See Also:
-
getTimeZoneId
public String getTimeZoneId()
Returns the TimeZone Id (like "Europe/Helsinki") provided by the browser (if the browser supports this feature).
Returns:
the TimeZone Id if provided by the browser, null otherwise.
See Also:
-
getRawTimezoneOffset
public int getRawTimezoneOffset()
Returns the browser-reported TimeZone offset in milliseconds from GMT ignoring possible daylight saving adjustments that may be in effect in the browser.
You can use this to figure out which TimeZones the user could actually be in by calling
TimeZone.getAvailableIDs(int)
.If
getRawTimezoneOffset()
andgetTimezoneOffset()
returns the same value, the browser is either in a zone that does not currently have daylight saving time, or in a zone that never has daylight saving time.Returns:
timezone offset in milliseconds excluding DST, 0 if not available
-
getDSTSavings
public int getDSTSavings()
Returns the offset in milliseconds between the browser's GMT TimeZone and DST.
Returns:
the number of milliseconds that the TimeZone shifts when DST is in effect
-
isDSTInEffect
public boolean isDSTInEffect()
Returns whether daylight saving time (DST) is currently in effect in the region of the browser or not.
Returns:
true if the browser resides at a location that currently is in DST
-
getCurrentDate
public Date getCurrentDate()
Returns the current date and time of the browser. This will not be entirely accurate due to varying network latencies, but should provide a close-enough value for most cases. Also note that the returned Date object uses servers default time zone, not the clients.
To get the actual date and time shown in the end users computer, you can do something like:
WebBrowser browser = ...; SimpleTimeZone timeZone = new SimpleTimeZone(browser.getTimezoneOffset(), "Fake client time zone"); DateFormat format = DateFormat.getDateTimeInstance(); format.setTimeZone(timeZone); myLabel.setValue(format.format(browser.getCurrentDate()));
Returns:
the current date and time of the browser.
See Also:
-
isTouchDevice
public boolean isTouchDevice()
Checks if the browser supports touch events.
Returns:
true if the browser is detected to support touch events, false otherwise
-
updateRequestDetails
public void updateRequestDetails(VaadinRequest request)
For internal use only. Updates all properties in the class according to the given information.
Parameters:
request
- the Vaadin request to read the information from
-
isTooOldToFunctionProperly
public boolean isTooOldToFunctionProperly()
Checks if the browser is so old that it simply won't work with a Vaadin application. Can be used to redirect to an alternative page, show alternative content or similar. When this method returns true chances are very high that the browser won't work and it does not make sense to direct the user to the Vaadin application.
Returns:
true if the browser won't work, false if not the browser is supported or might work
-
isEs6Supported
public boolean isEs6Supported()
Checks if the browser supports ECMAScript 6, based on the user agent. Web components must be compiled to ECMAScript 5 when running on browsers without support to ECMAScript 6.
Returns:
true
if the browser supports ES6,false
otherwise.
-
isEs5AdapterNeeded
public boolean isEs5AdapterNeeded()
Checks if the browser needs `custom-elements-es5-adapter.js` to be loaded.
Returns:
true
if the browser needs the adapter,false
otherwise.
-
-