Skip to content

Commit fcec4fe

Browse files
author
zhourenjian
committed
Support Browser#setText for different domain scenarios
1 parent 7712231 commit fcec4fe

File tree

1 file changed

+23
-6
lines changed
  • sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/browser

1 file changed

+23
-6
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/browser/Browser.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,8 @@ public boolean setText(String html) {
14011401
try {
14021402
var doc = handle.contentWindow.document;
14031403
doc.open ();
1404-
if (O$.isIE) {
1404+
if (O$.isIE && window["xss.domain.enabled"] == true
1405+
&& domain != null && domain.length > 0) {
14051406
doc.domain = domain;
14061407
}
14071408
doc.write (html);
@@ -1420,12 +1421,17 @@ public boolean setText(String html) {
14201421
* @j2sNative
14211422
var handle = arguments[0];
14221423
var html = arguments[1];
1423-
var domain = document.domain;
1424-
if (O$.isIE) {
1424+
var domain = null;
1425+
try {
1426+
domain = document.domain;
1427+
} catch (e) {}
1428+
if (O$.isIE && window["xss.domain.enabled"] == true
1429+
&& domain != null && domain.length > 0) {
14251430
document.domain = domain;
14261431
}
14271432
if (handle.contentWindow != null) {
1428-
if (O$.isIE) {
1433+
if (O$.isIE && window["xss.domain.enabled"] == true
1434+
&& domain != null && domain.length > 0) {
14291435
handle.contentWindow.location = "javascript:document.open();document.domain='" + domain + "';document.close();void(0);";
14301436
} else {
14311437
handle.contentWindow.location = "about:blank";
@@ -1436,13 +1442,24 @@ public boolean setText(String html) {
14361442
try {
14371443
var doc = handle.contentWindow.document;
14381444
doc.open ();
1439-
if (O$.isIE) {
1445+
if (O$.isIE && window["xss.domain.enabled"] == true
1446+
&& domain != null && domain.length > 0) {
14401447
doc.domain = domain;
14411448
}
14421449
doc.write (html);
14431450
doc.close ();
14441451
} catch (e) {
1445-
window.setTimeout (this.generateLazyIframeWriting (handle, domain, html), 25);
1452+
if (O$.isIE && (domain == null || domain.length == 0)
1453+
&& e.message != null && e.message.indexOf ("Access is denied") != -1) {
1454+
var jsHTML = html.replaceAll("\\\\", "\\\\\\\\")
1455+
.replaceAll("\r", "\\\\r")
1456+
.replaceAll("\n", "\\\\n")
1457+
.replaceAll("\"", "\\\\\"");
1458+
handle.src = "javascript:document.open();document.write (\"" + jsHTML + "\");document.close();void(0);";
1459+
// In IE 8.0, it is still failing ...
1460+
} else {
1461+
window.setTimeout (this.generateLazyIframeWriting (handle, domain, html), 25);
1462+
}
14461463
}
14471464
*/
14481465
private native void iframeDocumentWrite(Object handle, String html);

0 commit comments

Comments
 (0)