aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-12-15 14:22:09 +0200
committerLeif Åstrand <leif@vaadin.com>2011-12-15 14:22:22 +0200
commit129b0c84640afbc3da7fcb217869fd83710ef1f9 (patch)
tree1c41c5d9a62c7c66ab52419e26f3f02d599471e2
parent75141d2b0bf08ff018695d758c573d6f3c673d04 (diff)
downloadvaadin-framework-129b0c84640afbc3da7fcb217869fd83710ef1f9.tar.gz
vaadin-framework-129b0c84640afbc3da7fcb217869fd83710ef1f9.zip
Ensure WebBrowser is updated and available from BrowserDetails (#8098)
-rw-r--r--WebContent/VAADIN/vaadinBootstrap.js78
-rw-r--r--src/com/vaadin/terminal/CombinedRequest.java10
-rw-r--r--src/com/vaadin/terminal/WrappedRequest.java9
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java28
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConnection.java53
-rw-r--r--src/com/vaadin/terminal/gwt/client/BrowserInfo.java84
6 files changed, 149 insertions, 113 deletions
diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js
index 47656d9406..5728903545 100644
--- a/WebContent/VAADIN/vaadinBootstrap.js
+++ b/WebContent/VAADIN/vaadinBootstrap.js
@@ -86,11 +86,8 @@
// Root id
url += ((/\?/).test(url) ? "&" : "?") + "browserDetails";
url += '&rootId=' + getConfig('rootId');
- // Uri fragment
- url += '&f=' + encodeURIComponent(location.hash);
- if (window.name) {
- url += '&wn=' + encodeURIComponent(window.name);
- }
+ url += '&' + vaadin.getBrowserDetailsParameters(appId);
+
// Timestamp to avoid caching
url += '&' + (new Date()).getTime();
@@ -186,6 +183,77 @@
callback(appId);
}
widgetsets[widgetset].pendingApps = null;
+ },
+ getBrowserDetailsParameters: function(parentElementId) {
+ // Screen height and width
+ var url = 'sh=' + window.screen.height;
+ url += '&sw=' + window.screen.width;
+
+ // Window height and width
+ var cw = 0;
+ var ch = 0;
+ if(typeof(window.innerWidth) == 'number') {
+ // Modern browsers
+ cw = window.innerWidth;
+ ch = window.innerHeight;
+ } else {
+ // IE 8
+ cw = document.documentElement.clientWidth;
+ ch = document.documentElement.clientHeight;
+ }
+ url += '&cw=' + cw + '&ch=' + ch;
+
+
+ var d = new Date();
+
+ url += '&curdate=' + d.getTime();
+
+ var tzo1 = d.getTimezoneOffset(); // current offset
+ var dstDiff = 0;
+ var rtzo = tzo1;
+
+ for (var m=12;m>0;m--) {
+ d.setUTCMonth(m);
+ var tzo2 = d.getTimezoneOffset();
+ if (tzo1 != tzo2) {
+ dstDiff = (tzo1 > tzo2 ? tzo1-tzo2 : tzo2-tzo1); // offset w/o DST
+ rtzo = (tzo1 > tzo2 ? tzo1 : tzo2); // offset w/o DST
+ break;
+ }
+ }
+
+ // Time zone offset
+ url += '&tzo=' + tzo1;
+
+ // DST difference
+ url += '&dstd=' + dstDiff;
+
+ // Raw time zone offset
+ url += '&rtzo=' + rtzo;
+
+ // DST in effect?
+ url += '&dston=' + (tzo1 != rtzo);
+
+ var pe = document.getElementById(parentElementId);
+ if (pe) {
+ url += '&vw=' + pe.offsetWidth;
+ url += '&vh=' + pe.offsetHeight;
+ }
+
+ // Uri fragment
+ if (location.hash) {
+ //Remove initial #
+ url += '&fr=' + encodeURIComponent(location.hash.replace(/^#/, ""));
+ }
+ // Window name
+ if (window.name) {
+ url += '&wn=' + encodeURIComponent(window.name);
+ }
+
+ // Detect touch device support
+ try { document.createEvent("TouchEvent"); url += "&td=1";} catch(e){};
+
+ return url;
}
};
diff --git a/src/com/vaadin/terminal/CombinedRequest.java b/src/com/vaadin/terminal/CombinedRequest.java
index ad1c715051..a9367d164d 100644
--- a/src/com/vaadin/terminal/CombinedRequest.java
+++ b/src/com/vaadin/terminal/CombinedRequest.java
@@ -10,6 +10,10 @@ import java.util.Collections;
import java.util.Locale;
import java.util.Map;
+import com.vaadin.Application;
+import com.vaadin.terminal.gwt.server.WebApplicationContext;
+import com.vaadin.terminal.gwt.server.WebBrowser;
+
/**
* A {@link WrappedRequest} with path and parameters from one request and
* {@link WrappedRequest.BrowserDetails} extracted from another request.
@@ -108,6 +112,12 @@ public class CombinedRequest implements WrappedRequest {
public String getWindowName() {
return secondRequest.getParameter("wn");
}
+
+ public WebBrowser getWebBrowser() {
+ WebApplicationContext context = (WebApplicationContext) Application
+ .getCurrentApplication().getContext();
+ return context.getBrowser();
+ }
};
}
diff --git a/src/com/vaadin/terminal/WrappedRequest.java b/src/com/vaadin/terminal/WrappedRequest.java
index d3d5491788..468ba7fa96 100644
--- a/src/com/vaadin/terminal/WrappedRequest.java
+++ b/src/com/vaadin/terminal/WrappedRequest.java
@@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletRequest;
import com.vaadin.Application;
import com.vaadin.RootRequiresMoreInformation;
import com.vaadin.annotations.RootInitRequiresBrowserDetals;
+import com.vaadin.terminal.gwt.server.WebBrowser;
import com.vaadin.ui.Root;
/**
@@ -48,6 +49,14 @@ public interface WrappedRequest extends Serializable {
* @return the string value of window.name in the browser
*/
public String getWindowName();
+
+ /**
+ * Gets a reference to the {@link WebBrowser} object containing
+ * additional information, e.g. screen size and the time zone offset.
+ *
+ * @return the web browser object
+ */
+ public WebBrowser getWebBrowser();
}
/**
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
index 12944cb033..51a620cf27 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
@@ -210,6 +210,8 @@ public class ApplicationConfiguration implements EntryPoint {
private String windowId;
+ private boolean browserDetailsSent = false;
+
static// TODO consider to make this hashmap per application
LinkedList<Command> callbacks = new LinkedList<Command>();
@@ -315,6 +317,11 @@ public class ApplicationConfiguration implements EntryPoint {
communicationError = jsoConfiguration.getConfigError("comErrMsg");
authorizationError = jsoConfiguration.getConfigError("authErrMsg");
+ // boostrap sets initPending to false if it has sent the browser details
+ if (jsoConfiguration.getConfigBoolean("initPending") == Boolean.FALSE) {
+ setBrowserDetailsSent();
+ }
+
}
/**
@@ -588,4 +595,25 @@ public class ApplicationConfiguration implements EntryPoint {
return re.test(uri);
}-*/;
+ /**
+ * Checks whether information from the web browser (e.g. uri fragment and
+ * screen size) has been sent to the server.
+ *
+ * @return <code>true</code> if browser information has already been sent
+ *
+ * @see ApplicationConnection#getNativeBrowserDetailsParameters(String)
+ */
+ public boolean isBrowserDetailsSent() {
+ return browserDetailsSent;
+ }
+
+ /**
+ * Registers that the browser details have been sent.
+ * {@link #isBrowserDetailsSent()} will return
+ * <code> after this method has been invoked.
+ */
+ public void setBrowserDetailsSent() {
+ browserDetailsSent = true;
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index 6f9819086b..3816a4e933 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -26,7 +26,6 @@ import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FocusWidget;
@@ -373,36 +372,31 @@ public class ApplicationConnection {
private String getRepaintAllParameters() {
// collect some client side data that will be sent to server on
// initial uidl request
- int clientHeight = Window.getClientHeight();
- int clientWidth = Window.getClientWidth();
- com.google.gwt.dom.client.Element pe = view.getElement()
- .getParentElement();
- int offsetHeight = pe.getOffsetHeight();
- int offsetWidth = pe.getOffsetWidth();
- int screenWidth = BrowserInfo.get().getScreenWidth();
- int screenHeight = BrowserInfo.get().getScreenHeight();
- int tzOffset = BrowserInfo.get().getTimezoneOffset();
- int rtzOffset = BrowserInfo.get().getRawTimezoneOffset();
- int dstDiff = BrowserInfo.get().getDSTSavings();
- boolean dstInEffect = BrowserInfo.get().isDSTInEffect();
- long curDate = BrowserInfo.get().getCurrentDate().getTime();
+ String nativeBootstrapParameters = getNativeBrowserDetailsParameters(getConfiguration()
+ .getRootPanelId());
String widgetsetVersion = ApplicationConfiguration.VERSION;
- String token = History.getToken();
-
// TODO figure out how client and view size could be used better on
// server. screen size can be accessed via Browser object, but other
// values currently only via transaction listener.
- String parameters = "repaintAll=1&" + "sh=" + screenHeight + "&sw="
- + screenWidth + "&cw=" + clientWidth + "&ch=" + clientHeight
- + "&vw=" + offsetWidth + "&vh=" + offsetHeight + "&fr=" + token
- + "&tzo=" + tzOffset + "&rtzo=" + rtzOffset + "&dstd="
- + dstDiff + "&dston=" + dstInEffect + "&curdate=" + curDate
- + "&wsver=" + widgetsetVersion
- + (BrowserInfo.get().isTouchDevice() ? "&td=1" : "");
+ String parameters = "repaintAll=1&" + nativeBootstrapParameters
+ + "&wsver=" + widgetsetVersion;
return parameters;
}
+ /**
+ * Gets the browser detail parameters that are sent by the bootstrap
+ * javascript for two-request initialization.
+ *
+ * @param parentElementId
+ * @return
+ */
+ private static native String getNativeBrowserDetailsParameters(
+ String parentElementId)
+ /*-{
+ return $wnd.vaadin.getBrowserDetailsParameters(parentElementId);
+ }-*/;
+
protected void repaintAll() {
String repainAllParameters = getRepaintAllParameters();
makeUidlRequest("", repainAllParameters, false);
@@ -1366,7 +1360,18 @@ public class ApplicationConnection {
req.append(VAR_BURST_SEPARATOR);
}
}
- makeUidlRequest(req.toString(), "", forceSync);
+
+ // Include the browser detail parameters if they aren't already sent
+ String extraParams;
+ if (!getConfiguration().isBrowserDetailsSent()) {
+ extraParams = getNativeBrowserDetailsParameters(getConfiguration()
+ .getRootPanelId());
+ getConfiguration().setBrowserDetailsSent();
+ } else {
+ extraParams = "";
+ }
+
+ makeUidlRequest(req.toString(), extraParams, forceSync);
}
private void makeUidlRequest(String string) {
diff --git a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java
index 94192513a0..e5006f4a9c 100644
--- a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java
+++ b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java
@@ -4,8 +4,6 @@
package com.vaadin.terminal.gwt.client;
-import java.util.Date;
-
import com.google.gwt.user.client.ui.RootPanel;
/**
@@ -286,88 +284,6 @@ public class BrowserInfo {
}-*/;
/**
- * Get's the timezone offset from GMT in minutes, as reported by the
- * browser. DST affects this value.
- *
- * @return offset to GMT in minutes
- */
- public native int getTimezoneOffset()
- /*-{
- return new Date().getTimezoneOffset();
- }-*/;
-
- /**
- * Gets the timezone offset from GMT in minutes, as reported by the browser
- * AND adjusted to ignore daylight savings time. DST does not affect this
- * value.
- *
- * @return offset to GMT in minutes
- */
- public native int getRawTimezoneOffset()
- /*-{
- var d = new Date();
- var tzo1 = d.getTimezoneOffset(); // current offset
-
- for (var m=12;m>0;m--) {
- d.setUTCMonth(m);
- var tzo2 = d.getTimezoneOffset();
- if (tzo1 != tzo2) {
- // NOTE js indicates this 'backwards' (e.g -180)
- return (tzo1 > tzo2 ? tzo1 : tzo2); // offset w/o DST
- }
- }
-
- return tzo1; // no DST
-
- }-*/;
-
- /**
- * Gets the difference in minutes between the browser's GMT timezone and
- * DST.
- *
- * @return the amount of minutes that the timezone shifts when DST is in
- * effect
- */
- public native int getDSTSavings()
- /*-{
- var d = new Date();
- var tzo1 = d.getTimezoneOffset(); // current offset
-
- for (var m=12;m>0;m--) {
- d.setUTCMonth(m);
- var tzo2 = d.getTimezoneOffset();
- if (tzo1 != tzo2) {
- // NOTE js indicates this 'backwards' (e.g -180)
- return (tzo1 > tzo2 ? tzo1-tzo2 : tzo2-tzo1); // offset w/o DST
- }
- }
-
- return 0; // no DST
- }-*/;
-
- /**
- * Determines whether daylight savings time (DST) is currently in effect in
- * the region of the browser or not.
- *
- * @return true if the browser resides at a location that currently is in
- * DST
- */
- public boolean isDSTInEffect() {
- return getTimezoneOffset() != getRawTimezoneOffset();
- }
-
- /**
- * 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.
- *
- * @return the current date and time of the browser.
- */
- public Date getCurrentDate() {
- return new Date();
- }
-
- /**
* @return true if the browser runs on a touch based device.
*/
public boolean isTouchDevice() {