summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/server/WebBrowser.java
blob: 2ec726fc6a7e30ebc46edd3efd2b76dac45f94b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.vaadin.terminal.gwt.server;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import com.vaadin.terminal.Terminal;

@SuppressWarnings("serial")
public class WebBrowser implements Terminal {

    private int screenHeight = 0;
    private int screenWidth = 0;
    private String browserApplication = null;
    private Locale locale;
    private String address;
    private boolean secureConnection;

    /**
     * There is no default-theme for this terminal type.
     * 
     * @return Allways returns null.
     */
    public String getDefaultTheme() {
        return null;
    }

    /**
     * Get the height of the users display in pixels.
     * 
     */
    public int getScreenHeight() {
        return screenHeight;
    }

    /**
     * Get the width of the users display in pixels.
     * 
     */
    public int getScreenWidth() {
        return screenWidth;
    }

    /**
     * Get the browser user-agent string.
     * 
     * @return
     */
    public String getBrowserApplication() {
        return browserApplication;
    }

    void updateBrowserProperties(HttpServletRequest request) {
        locale = request.getLocale();
        address = request.getRemoteAddr();
        secureConnection = request.isSecure();

        final String agent = request.getHeader("user-agent");
        if (agent != null) {
            browserApplication = agent;
        }

        final String sw = request.getParameter("screenWidth");
        final String sh = request.getParameter("screenHeight");
        if (sw != null && sh != null) {
            try {
                screenHeight = Integer.parseInt(sh);
                screenWidth = Integer.parseInt(sw);
            } catch (final NumberFormatException e) {
                screenHeight = screenWidth = 0;
            }
        }
    }

    /**
     * Get the IP-address of the web browser.
     * 
     * @return IP-address in 1.12.123.123 -format
     */
    public String getAddress() {
        return address;
    }

    /** Get the default locate of the browser. */
    public Locale getLocale() {
        return locale;
    }

    /** Is the connection made using HTTPS? */
    public boolean isSecureConnection() {
        return secureConnection;
    }

}