My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.dotspots.rpcplus.client.transport.impl;

import com.dotspots.rpcplus.client.dom.RpcWindow;
import com.dotspots.rpcplus.client.transport.HasDocument;
import com.dotspots.rpcplus.client.transport.HasUrlEndpoint;
import com.dotspots.rpcplus.client.transport.TextTransport;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
* Assumes that someone is waiting on the end of the URL for a form post and will return JSON by either assigning it to
* window.name and redirecting back to us or sending us a postMessage.
*
* Supports navigation-click-sound-free operation on IE through ActiveXObject("htmlfile").
*/
public class CrossDomainFrameTransport implements TextTransport, HasUrlEndpoint, HasDocument {
private String url;
private Document document;
private int timeout = 30000;
private String redirect;
private RedirectType redirectType;
private RpcWindow window;
private boolean allowPostMessage = true;

private enum RedirectType {
MANUAL, CLEAR_CACHE, FAVICON
}

public CrossDomainFrameTransport() {
// Favicon redirect is the most stable right now
redirectType = RedirectType.CLEAR_CACHE;
}

protected void setAllowPostMessage(boolean allowPostMessage) {
this.allowPostMessage = allowPostMessage;
}

public void setTimeout(int timeout) {
this.timeout = timeout;
}

public int getTimeout() {
return timeout;
}

public void setUrl(String url) {
this.url = url;
}

public void setDocument(Document document) {
this.document = document;
this.window = RpcWindow.fromDocument(document);
}

/**
* Sets the redirect URL to use the clear.cache.gif (found in most GWT applications).
*/
private String getRedirectToClearCacheGif() {
return GWT.getModuleBaseURL() + "clear.cache.gif";
}

/**
* Sets the redirect URL to use a favicon based on document.domain.
*/
private String getRedirectToFavicon() {
String url = getWindowLocationProtocol(window);

url += "//" + document.getDomain();
String port = getWindowLocationPort(window);
if (port != null) {
url += ":" + port;
}

url += "/favicon.ico";

return url;
}

/**
* Manually set the redirect URL.
*/
public void setRedirect(String redirect) {
this.redirect = redirect;
redirectType = RedirectType.MANUAL;
}

/**
* Redirect to GWT's clear.cache.gif (the default)
*/
public void setRedirectClearCacheGif() {
redirectType = RedirectType.CLEAR_CACHE;
}

/**
* Redirect to the domain's favicon.
*/
public void setRedirectFavicon() {
redirectType = RedirectType.FAVICON;
}

private native String getWindowLocationPort(RpcWindow wnd) /*-{
return wnd.location.port || null;
}-*/;

private native String getWindowLocationProtocol(RpcWindow wnd) /*-{
return wnd.location.protocol;
}-*/;

public void call(String arguments, final AsyncCallback<String> callback) {
String redirect;

switch (redirectType) {
case MANUAL:
redirect = this.redirect;
break;
case CLEAR_CACHE:
redirect = getRedirectToClearCacheGif();
break;
case FAVICON:
redirect = getRedirectToFavicon();
break;
default:
throw new RuntimeException();
}

CrossDomainFrameTransportRequest request;
if (allowPostMessage && window.isPostMessageSupported()) {
request = new PostMessageFrameTransportRequest(arguments, callback, document, url, timeout);
} else {
request = new WindowNameTransportRequest(arguments, callback, document, url, timeout, redirect);
}

request.start();
}
}

Change log

r131 by mmastrac on Dec 11, 2009   Diff
Initial checkin for the new cross-domain
frame transport that uses postMessage
where appropriate. Passes local tests, but
needs to run on the testing cluster.
Go to: 
Sign in to write a code review

Older revisions

r110 by mmastrac on Nov 5, 2009   Diff
If we're reading collections, make
sure they exist before we plow through
them.
Fix for a too-long timeout in
TestThriftRPC
r74 by mmastrac on Aug 19, 2009   Diff
Refactoring to use transport factory
instead of requiring clients to build
transports by hand.
r71 by mmastrac on Aug 13, 2009   Diff
Now that FF1.5 is out of the mix, test
CLEAR_CACHE as the default again
All revisions of this file

File info

Size: 3541 bytes, 136 lines
Powered by Google Project Hosting