UNPKG

2.75 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import { Widget } from '@lumino/widgets';
4/**
5 * A Lumino widget which wraps an IFrame.
6 */
7export class IFrame extends Widget {
8 /**
9 * Create a new IFrame widget.
10 */
11 constructor(options = {}) {
12 super({ node: Private.createNode() });
13 this._sandbox = [];
14 this.addClass('jp-IFrame');
15 this.sandbox = options.sandbox || [];
16 this.referrerPolicy = options.referrerPolicy || 'no-referrer';
17 }
18 /**
19 * Referrer policy for the iframe.
20 *
21 * #### Notes
22 * By default, `no-referrer` is chosen.
23 *
24 * For more information, see
25 * https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy
26 */
27 get referrerPolicy() {
28 return this._referrerPolicy;
29 }
30 set referrerPolicy(value) {
31 if (this._referrerPolicy === value) {
32 return;
33 }
34 this._referrerPolicy = value;
35 const iframe = this.node.querySelector('iframe');
36 iframe.setAttribute('referrerpolicy', value);
37 }
38 /**
39 * Exceptions to the sandboxing.
40 *
41 * #### Notes
42 * By default, all sandboxing security policies are enabled.
43 * This setting allows the user to selectively disable these
44 * policies. This should be done with care, as it can
45 * introduce security risks, and possibly allow malicious
46 * sites to execute code in a JupyterLab session.
47 *
48 * For more information, see
49 * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
50 */
51 get sandbox() {
52 return this._sandbox.slice();
53 }
54 set sandbox(values) {
55 this._sandbox = values.slice();
56 const iframe = this.node.querySelector('iframe');
57 const exceptions = values.length ? values.join(' ') : '';
58 iframe.setAttribute('sandbox', exceptions);
59 }
60 /**
61 * The url of the IFrame.
62 */
63 get url() {
64 return this.node.querySelector('iframe').getAttribute('src') || '';
65 }
66 set url(url) {
67 this.node.querySelector('iframe').setAttribute('src', url);
68 }
69}
70/**
71 * A namespace for private data.
72 */
73var Private;
74(function (Private) {
75 /**
76 * Create the main content node of an iframe widget.
77 */
78 function createNode() {
79 const node = document.createElement('div');
80 const iframe = document.createElement('iframe');
81 iframe.setAttribute('sandbox', '');
82 iframe.style.height = '100%';
83 iframe.style.width = '100%';
84 node.appendChild(iframe);
85 return node;
86 }
87 Private.createNode = createNode;
88})(Private || (Private = {}));
89//# sourceMappingURL=iframe.js.map
\No newline at end of file