1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.event;
16
17 import org.htmlunit.BrowserVersion;
18 import org.htmlunit.html.DomNode;
19 import org.htmlunit.javascript.JavaScriptEngine;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstructor;
22 import org.htmlunit.javascript.configuration.JsxGetter;
23 import org.htmlunit.javascript.configuration.JsxSetter;
24
25
26
27
28
29
30
31
32
33
34
35 @JsxClass
36 public class BeforeUnloadEvent extends Event {
37 private Object returnValue_;
38
39
40
41
42 public BeforeUnloadEvent() {
43 super("");
44 returnValue_ = "";
45 }
46
47
48
49
50 @JsxConstructor
51 public void jsConstructor() {
52 throw JavaScriptEngine.typeError("Illegal Constructor");
53 }
54
55
56
57
58
59
60
61 public BeforeUnloadEvent(final DomNode domNode, final String type) {
62 super(domNode, type);
63
64 setBubbles(false);
65 setReturnValue(getReturnValueDefault(getBrowserVersion()));
66 }
67
68 @Override
69 public void initEvent(final String type, final boolean bubbles, final boolean cancelable) {
70 super.initEvent(type, bubbles, cancelable);
71 setReturnValue(getReturnValueDefault(getBrowserVersion()));
72 }
73
74 private static Object getReturnValueDefault(final BrowserVersion browserVersion) {
75
76
77 return "";
78 }
79
80
81
82
83 public boolean isBeforeUnloadMessageSet() {
84 return !getReturnValueDefault(getBrowserVersion()).equals(getReturnValue());
85 }
86
87
88
89
90 @JsxGetter
91 @Override
92 public Object getReturnValue() {
93 return returnValue_;
94 }
95
96
97
98
99
100 @JsxSetter
101 @Override
102 public void setReturnValue(final Object returnValue) {
103 returnValue_ = returnValue;
104 }
105
106 @Override
107 void handlePropertyHandlerReturnValue(final Object returnValue) {
108 super.handlePropertyHandlerReturnValue(returnValue);
109
110 final BrowserVersion browserVersion = getBrowserVersion();
111
112
113 if (returnValue != null) {
114
115 if (getReturnValueDefault(browserVersion).equals(getReturnValue())) {
116 setReturnValue(returnValue);
117 }
118 }
119 }
120 }