mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 18:20:14 +00:00
bug5048: started implementing cross-window messaging infrastructure
This commit is contained in:
1 parent
6fd96c4190
commit
cdbed1c7f3
15 files changed
+341
-4
No files matched your search
@@ -1,3 +1,2 @@
|
||||
/bin/
|
||||
/bin/
|
||||
/bin/
|
||||
/com.sap.*
|
||||
+1
@@ -0,0 +1 @@
|
||||
com.*
|
||||
@@ -13,6 +13,7 @@ Require-Bundle: com.google.gwt.user;bundle-version="2.8.2";resolution:=optional,
|
||||
com.sap.sse.filestorage,
|
||||
com.sap.sse.security.common
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Web-ContextPath: /gwt-base
|
||||
Import-Package: com.sap.sse.security,
|
||||
javax.servlet;version="3.1.0",
|
||||
javax.servlet.descriptor;version="3.1.0",
|
||||
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<!doctype html>
|
||||
<!-- The DOCTYPE declaration above will set the -->
|
||||
<!-- browser's rendering engine into -->
|
||||
<!-- "Standards Mode". Replacing this declaration -->
|
||||
<!-- with a "Quirks Mode" doctype may lead to some -->
|
||||
<!-- differences in layout. -->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<!-- -->
|
||||
<!-- Consider inlining CSS to reduce the number of requested files -->
|
||||
<!-- -->
|
||||
<link rel="shortcut icon" type="image/x-icon" href="images/sap.ico" />
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Any title is fine -->
|
||||
<!-- -->
|
||||
<title>Load this into an IFrame and create a MessagePort for that IFrame, then you can send and receive messages</title>
|
||||
|
||||
<!-- -->
|
||||
<!-- This script loads your compiled module. -->
|
||||
<!-- If you add any GWT meta tags, they must -->
|
||||
<!-- be added before this line. -->
|
||||
<!-- -->
|
||||
<script type="text/javascript" src="com.sap.sse.gwt.Messaging/com.sap.sse.gwt.Messaging.nocache.js"></script>
|
||||
</head>
|
||||
|
||||
<!-- -->
|
||||
<!-- The body can have arbitrary html, or -->
|
||||
<!-- you can leave the body empty if you want -->
|
||||
<!-- to create a completely dynamic UI. -->
|
||||
<!-- -->
|
||||
<body>
|
||||
<!-- OPTIONAL: include this if you want history support -->
|
||||
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
|
||||
|
||||
<!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
|
||||
<noscript>
|
||||
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
|
||||
Your web browser must have JavaScript enabled
|
||||
in order for this application to display correctly.
|
||||
</div>
|
||||
</noscript>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<!doctype html>
|
||||
<!-- The DOCTYPE declaration above will set the -->
|
||||
<!-- browser's rendering engine into -->
|
||||
<!-- "Standards Mode". Replacing this declaration -->
|
||||
<!-- with a "Quirks Mode" doctype may lead to some -->
|
||||
<!-- differences in layout. -->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<!-- -->
|
||||
<!-- Consider inlining CSS to reduce the number of requested files -->
|
||||
<!-- -->
|
||||
<link rel="shortcut icon" type="image/x-icon" href="images/sap.ico" />
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Any title is fine -->
|
||||
<!-- -->
|
||||
<title>Messaging Test</title>
|
||||
|
||||
<!-- -->
|
||||
<!-- This script loads your compiled module. -->
|
||||
<!-- If you add any GWT meta tags, they must -->
|
||||
<!-- be added before this line. -->
|
||||
<!-- -->
|
||||
<script type="text/javascript" src="com.sap.sse.gwt.MessagingTest/com.sap.sse.gwt.MessagingTest.nocache.js"></script>
|
||||
</head>
|
||||
|
||||
<!-- -->
|
||||
<!-- The body can have arbitrary html, or -->
|
||||
<!-- you can leave the body empty if you want -->
|
||||
<!-- to create a completely dynamic UI. -->
|
||||
<!-- -->
|
||||
<body>
|
||||
<!-- OPTIONAL: include this if you want history support -->
|
||||
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
|
||||
|
||||
<!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
|
||||
<noscript>
|
||||
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
|
||||
Your web browser must have JavaScript enabled
|
||||
in order for this application to display correctly.
|
||||
</div>
|
||||
</noscript>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
|
||||
<!-- Disable directory listing: -->
|
||||
<servlet>
|
||||
<servlet-name>default</servlet-name>
|
||||
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet
|
||||
</servlet-class>
|
||||
<init-param>
|
||||
<param-name>dirAllowed</param-name>
|
||||
<param-value>false</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>useFileMappedBuffer</param-name>
|
||||
<param-value>false</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
|
||||
</web-app>
|
||||
@@ -2,7 +2,9 @@ source.. = src/,\
|
||||
resources/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
.,\
|
||||
com.sap.sse.gwt.MessagingTest/,\
|
||||
com.sap.sse.gwt.Messaging/
|
||||
src.includes = resources/,\
|
||||
src/
|
||||
|
||||
@@ -9,7 +9,18 @@
|
||||
</parent>
|
||||
<artifactId>com.sap.sse.gwt</artifactId>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.elemental2</groupId>
|
||||
<artifactId>elemental2-core</artifactId>
|
||||
<version>1.0.0-RC1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.elemental2</groupId>
|
||||
<artifactId>elemental2-dom</artifactId>
|
||||
<version>1.0.0-RC1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Could not determine the version of your GWT SDK; using the module DTD from GWT 1.6.4. You may want to change this. -->
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
|
||||
<module>
|
||||
<!-- Inherit the core Web Toolkit stuff. -->
|
||||
<inherits name='com.google.gwt.user.User'/>
|
||||
<inherits name='com.google.gwt.debug.Debug'/>
|
||||
<inherits name='com.google.gwt.ajaxloader.AjaxLoader' />
|
||||
<inherits name="com.google.gwt.resources.Resources" />
|
||||
<inherits name="com.google.gwt.logging.Logging"/>
|
||||
|
||||
<!-- Other module inherits -->
|
||||
<inherits name="com.sap.sse.gwt.EmulatedJRE" />
|
||||
<inherits name="com.sap.sse.gwt.SSESharedGWT" />
|
||||
<inherits name="com.sap.sse.SSECommon" />
|
||||
<super-source path="jre" />
|
||||
|
||||
<entry-point class='com.sap.sse.gwt.client.messaging.MessagingEntryPoint'/>
|
||||
|
||||
<set-property name="gwt.logging.enabled" value="TRUE"/>
|
||||
<set-property name="gwt.logging.logLevel" value="FINE"/>
|
||||
|
||||
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
|
||||
<set-property name="gwt.logging.developmentModeHandler" value="DISABLED" />
|
||||
<set-property name="gwt.logging.systemHandler" value="ENABLED" />
|
||||
|
||||
<!-- Turning CSS obfuscation off -->
|
||||
<set-configuration-property name="CssResource.style" value="pretty"/>
|
||||
<!-- Turning CSS obfuscation on, which is the default -->
|
||||
<!-- <set-configuration-property name="CssResource.style" value="obf"/> -->
|
||||
|
||||
<set-configuration-property name="CssResource.enableGss" value="true" />
|
||||
<set-configuration-property name="CssResource.conversionMode" value="strict" />
|
||||
|
||||
<source path='client'/>
|
||||
</module>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Could not determine the version of your GWT SDK; using the module DTD from GWT 1.6.4. You may want to change this. -->
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
|
||||
<module>
|
||||
<!-- Inherit the core Web Toolkit stuff. -->
|
||||
<inherits name='com.google.gwt.user.User'/>
|
||||
<inherits name='com.google.gwt.debug.Debug'/>
|
||||
<inherits name='com.google.gwt.ajaxloader.AjaxLoader' />
|
||||
<inherits name="com.google.gwt.resources.Resources" />
|
||||
<inherits name="com.google.gwt.logging.Logging"/>
|
||||
|
||||
<!-- Other module inherits -->
|
||||
<inherits name="com.sap.sse.gwt.EmulatedJRE" />
|
||||
<inherits name="com.sap.sse.gwt.SSESharedGWT" />
|
||||
<inherits name="com.sap.sse.SSECommon" />
|
||||
<super-source path="jre" />
|
||||
|
||||
<entry-point class='com.sap.sse.gwt.client.messaging.MessagingTestEntryPoint'/>
|
||||
|
||||
<set-property name="gwt.logging.enabled" value="TRUE"/>
|
||||
<set-property name="gwt.logging.logLevel" value="FINE"/>
|
||||
|
||||
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
|
||||
<set-property name="gwt.logging.developmentModeHandler" value="DISABLED" />
|
||||
<set-property name="gwt.logging.systemHandler" value="ENABLED" />
|
||||
|
||||
<!-- Turning CSS obfuscation off -->
|
||||
<set-configuration-property name="CssResource.style" value="pretty"/>
|
||||
<!-- Turning CSS obfuscation on, which is the default -->
|
||||
<!-- <set-configuration-property name="CssResource.style" value="obf"/> -->
|
||||
|
||||
<set-configuration-property name="CssResource.enableGss" value="true" />
|
||||
<set-configuration-property name="CssResource.conversionMode" value="strict" />
|
||||
|
||||
<source path='client'/>
|
||||
</module>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.sap.sse.gwt.client.messaging;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.sap.sse.gwt.client.StorageEvent;
|
||||
|
||||
public class MessageEvent<T> extends JavaScriptObject {
|
||||
protected MessageEvent() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static interface Handler {
|
||||
void onStorageChange(StorageEvent event);
|
||||
}
|
||||
|
||||
public final native T getData() /*-{
|
||||
return this.data;
|
||||
}-*/;
|
||||
|
||||
public final native String getLastEventId() /*-{
|
||||
return this.lastEventId;
|
||||
}-*/;
|
||||
|
||||
public final native String getOrigin() /*-{
|
||||
return this.origin;
|
||||
}-*/;
|
||||
|
||||
public final MessagePort getSource() {
|
||||
return getWindowSource().cast();
|
||||
}
|
||||
|
||||
private final native JavaScriptObject getWindowSource() /*-{
|
||||
return this.source;
|
||||
}-*/;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.sap.sse.gwt.client.messaging;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
public interface MessageListener<T> {
|
||||
default void onMessageReceived(JavaScriptObject jsMessageEvent) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final MessageEvent<T> messageEvent = (MessageEvent<T>) jsMessageEvent.cast();
|
||||
this.onMessageReceived(messageEvent);
|
||||
}
|
||||
|
||||
void onMessageReceived(MessageEvent<T> messageEvent);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.sap.sse.gwt.client.messaging;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.dom.client.IFrameElement;
|
||||
|
||||
/**
|
||||
* The handle to a {@code Window} in the DOM which can be used to post a message to and to register a message event
|
||||
* listener on.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class MessagePort extends JavaScriptObject {
|
||||
protected MessagePort() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static final native MessagePort getGlobalWindow() /*-{
|
||||
return $wnd;
|
||||
}-*/;
|
||||
|
||||
public static final native MessagePort getCurrentWindow() /*-{
|
||||
return window;
|
||||
}-*/;
|
||||
|
||||
public static final native MessagePort getFromIframe(IFrameElement iframe) /*-{
|
||||
return iframe.contentWindow;
|
||||
}-*/;
|
||||
|
||||
public final native <T> void postMessage(T message, String targetOrigin) /*-{
|
||||
this.postMessage(message, targetOrigin);
|
||||
}-*/;
|
||||
|
||||
public final native <T> void addMessageListener(MessageListener<T> listener) /*-{
|
||||
this.addEventListener("message",
|
||||
function(messageEvent) {
|
||||
listener.@com.sap.sse.gwt.client.messaging.MessageListener::onMessageReceived(Lcom/google/gwt/core/client/JavaScriptObject;)(messageEvent);
|
||||
});
|
||||
}-*/;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.sap.sse.gwt.client.messaging;
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
|
||||
public class MessagingEntryPoint implements EntryPoint {
|
||||
@Override
|
||||
public void onModuleLoad() {
|
||||
GWT.log("This is Messaging Entry Point");
|
||||
final MessagePort messagePort = MessagePort.getGlobalWindow();
|
||||
messagePort.addMessageListener(new MessageListener<String>() {
|
||||
@Override
|
||||
public void onMessageReceived(MessageEvent<String> messageEvent) {
|
||||
GWT.log("Received "+messageEvent.getData()+" from origin "+messageEvent.getOrigin());
|
||||
messageEvent.getSource().postMessage("Response to "+messageEvent.getData(), "*");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.sap.sse.gwt.client.messaging;
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.IFrameElement;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
|
||||
public class MessagingTestEntryPoint implements EntryPoint {
|
||||
|
||||
@Override
|
||||
public void onModuleLoad() {
|
||||
GWT.log("Hello World");
|
||||
final MessagePort localPort = MessagePort.getCurrentWindow();
|
||||
localPort.addMessageListener(messageEvent -> GWT.log("Received " + messageEvent.getData() + " from origin " + messageEvent.getOrigin()));
|
||||
final IFrameElement iframe1 = Document.get().createIFrameElement();
|
||||
iframe1.setSrc("http://localhost:8888/gwt-base/Messaging.html");
|
||||
Document.get().getBody().appendChild(iframe1);
|
||||
final Button button = new Button("Test");
|
||||
final MessagePort globalPort = MessagePort.getFromIframe(iframe1);
|
||||
button.addClickHandler(e -> {
|
||||
globalPort.postMessage("Hello iFrame!", "*");
|
||||
});
|
||||
RootPanel.get().add(button);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user