-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
HTMLIFrameElement.ts
238 lines (211 loc) · 5.03 KB
/
HTMLIFrameElement.ts
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import Event from '../../event/Event.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import BrowserWindow from '../../window/BrowserWindow.js';
import Document from '../document/Document.js';
import HTMLElement from '../html-element/HTMLElement.js';
import Node from '../node/Node.js';
import NamedNodeMap from '../../named-node-map/NamedNodeMap.js';
import HTMLIFrameElementNamedNodeMap from './HTMLIFrameElementNamedNodeMap.js';
import CrossOriginBrowserWindow from '../../window/CrossOriginBrowserWindow.js';
import IBrowserFrame from '../../browser/types/IBrowserFrame.js';
import HTMLIFrameElementPageLoader from './HTMLIFrameElementPageLoader.js';
import DOMTokenList from '../../dom-token-list/DOMTokenList.js';
/**
* HTML Iframe Element.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement.
*/
export default class HTMLIFrameElement extends HTMLElement {
// Public properties
public cloneNode: (deep?: boolean) => HTMLIFrameElement;
// Events
public onload: (event: Event) => void | null = null;
public onerror: (event: Event) => void | null = null;
// Internal properties
public override [PropertySymbol.attributes]: NamedNodeMap;
public [PropertySymbol.sandbox]: DOMTokenList = null;
// Private properties
#contentWindowContainer: { window: BrowserWindow | CrossOriginBrowserWindow | null } = {
window: null
};
#pageLoader: HTMLIFrameElementPageLoader;
/**
* Constructor.
*
* @param browserFrame Browser frame.
*/
constructor(browserFrame: IBrowserFrame) {
super();
this.#pageLoader = new HTMLIFrameElementPageLoader({
element: this,
contentWindowContainer: this.#contentWindowContainer,
browserParentFrame: browserFrame
});
this[PropertySymbol.attributes] = new HTMLIFrameElementNamedNodeMap(this, this.#pageLoader);
}
/**
* Returns source.
*
* @returns Source.
*/
public get src(): string {
return this.getAttribute('src') || '';
}
/**
* Sets source.
*
* @param src Source.
*/
public set src(src: string) {
this.setAttribute('src', src);
}
/**
* Returns allow.
*
* @returns Allow.
*/
public get allow(): string {
return this.getAttribute('allow') || '';
}
/**
* Sets allow.
*
* @param allow Allow.
*/
public set allow(allow: string) {
this.setAttribute('allow', allow);
}
/**
* Returns height.
*
* @returns Height.
*/
public get height(): string {
return this.getAttribute('height') || '';
}
/**
* Sets height.
*
* @param height Height.
*/
public set height(height: string) {
this.setAttribute('height', height);
}
/**
* Returns width.
*
* @returns Width.
*/
public get width(): string {
return this.getAttribute('width') || '';
}
/**
* Sets width.
*
* @param width Width.
*/
public set width(width: string) {
this.setAttribute('width', width);
}
/**
* Returns name.
*
* @returns Name.
*/
public get name(): string {
return this.getAttribute('name') || '';
}
/**
* Sets name.
*
* @param name Name.
*/
public set name(name: string) {
this.setAttribute('name', name);
}
/**
* Returns sandbox.
*
* @returns Sandbox.
*/
public get sandbox(): DOMTokenList {
if (!this[PropertySymbol.sandbox]) {
this[PropertySymbol.sandbox] = new DOMTokenList(this, 'sandbox');
}
return <DOMTokenList>this[PropertySymbol.sandbox];
}
/**
* Sets sandbox.
*/
public set sandbox(sandbox: string) {
this.setAttribute('sandbox', sandbox);
}
/**
* Returns srcdoc.
*
* @returns Srcdoc.
*/
public get srcdoc(): string {
return this.getAttribute('srcdoc') || '';
}
/**
* Sets srcdoc.
*
* @param srcdoc Srcdoc.
*/
public set srcdoc(srcdoc: string) {
this.setAttribute('srcdoc', srcdoc);
}
/**
* Returns referrer policy.
*/
public get referrerPolicy(): string {
return this.getAttribute('referrerpolicy') || '';
}
/**
* Sets referrer policy.
*
* @param referrerPolicy Referrer policy.
*/
public set referrerPolicy(referrerPolicy: string) {
this.setAttribute('referrerpolicy', referrerPolicy);
}
/**
* Returns content document.
*
* @returns Content document.
*/
public get contentDocument(): Document | null {
return (<BrowserWindow>this.#contentWindowContainer.window)?.document ?? null;
}
/**
* Returns content window.
*
* @returns Content window.
*/
public get contentWindow(): BrowserWindow | CrossOriginBrowserWindow | null {
return this.#contentWindowContainer.window;
}
/**
* @override
*/
public override [PropertySymbol.connectToNode](parentNode: Node = null): void {
const isConnected = this[PropertySymbol.isConnected];
const isParentConnected = parentNode ? parentNode[PropertySymbol.isConnected] : false;
super[PropertySymbol.connectToNode](parentNode);
if (isConnected !== isParentConnected) {
if (isParentConnected) {
this.#pageLoader.loadPage();
} else {
this.#pageLoader.unloadPage();
}
}
}
/**
* @override
*/
public override [PropertySymbol.cloneNode](deep = false): HTMLIFrameElement {
return <HTMLIFrameElement>super[PropertySymbol.cloneNode](deep);
}
}