From: Joonas Lehtinen Date: Mon, 23 Jul 2007 09:18:40 +0000 (+0000) Subject: Better webbrowser impl X-Git-Tag: 6.7.0.beta1~6158 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=88dd2ed5a48efcf2e63d37ace96915668466332e;p=vaadin-framework.git Better webbrowser impl svn changeset:1896/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java index 66bc25e610..68d80b9fba 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java @@ -299,6 +299,11 @@ public class ApplicationServlet extends HttpServlet { Application application = null; try { + // Update browser details + WebBrowser browser = WebApplicationContext.getApplicationContext(request.getSession()).getBrowser(); + browser.updateBrowserProperties(request); + // TODO Add screen height and width to the GWT client + // Gets the application application = getApplication(request); @@ -336,6 +341,8 @@ public class ApplicationServlet extends HttpServlet { // If this is not a download request if (download == null) { + // TODO Clean this branch + // Window renders are not cacheable response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); @@ -354,8 +361,7 @@ public class ApplicationServlet extends HttpServlet { // Sets terminal type for the window, if not already set if (window.getTerminal() == null) { - // TODO !!!! - window.setTerminal(new WebBrowser()); + window.setTerminal(browser); } // Finds theme name diff --git a/src/com/itmill/toolkit/terminal/gwt/server/WebApplicationContext.java b/src/com/itmill/toolkit/terminal/gwt/server/WebApplicationContext.java index fd4a56e34a..e414c0a0b5 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/WebApplicationContext.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/WebApplicationContext.java @@ -65,6 +65,8 @@ public class WebApplicationContext implements ApplicationContext, HttpSessionBin private WeakHashMap formActions = new WeakHashMap(); private HashSet applications = new HashSet(); + + private WebBrowser browser = new WebBrowser(); /** * Creates a new Web Application Context. @@ -293,4 +295,15 @@ public class WebApplicationContext implements ApplicationContext, HttpSessionBin removeApplication(app); } } + + /** Get the web browser associated with this application context. + * + * Because application context is related to the http session and server maintains one session per + * browser-instance, each context has exactly one web browser associated with it. + * + * @return + */ + public WebBrowser getBrowser() { + return browser; + } } diff --git a/src/com/itmill/toolkit/terminal/gwt/server/WebBrowser.java b/src/com/itmill/toolkit/terminal/gwt/server/WebBrowser.java index 52db76fcfd..c065a85deb 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/WebBrowser.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/WebBrowser.java @@ -1,27 +1,86 @@ package com.itmill.toolkit.terminal.gwt.server; +import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; + import com.itmill.toolkit.terminal.Terminal; 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() { - // TODO Auto-generated method stub return null; } + /** Get the height of the users display in pixels. + * + */ public int getScreenHeight() { - // TODO Auto-generated method stub - return 0; + return screenHeight; } + /** Get the width of the users display in pixels. + * + */ public int getScreenWidth() { - // TODO Auto-generated method stub - return 0; + return screenWidth; } + /** Get the browser user-agent string. + * + * @return + */ public String getBrowserApplication() { - // TODO Auto-generated method stub - return ""; + return browserApplication; + } + + void updateBrowserProperties(HttpServletRequest request) { + locale = request.getLocale(); + address = request.getRemoteAddr(); + secureConnection = request.isSecure(); + + String agent = request.getHeader("user-agent"); + if (agent != null) browserApplication = agent; + + String sw = request.getParameter("screenWidth"); + String sh = request.getParameter("screenHeight"); + if (sw != null && sh != null) { + try { + screenHeight = Integer.parseInt(sh); + screenWidth = Integer.parseInt(sw); + } catch (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; } }