mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-23 15:01:14 +02:00
remove deprecated code
This commit is contained in:
@@ -142,9 +142,6 @@ export default class ContentWrap extends Component {
|
|||||||
const versionMatch = navigator.userAgent.match(/Chrome\/(\d+)/);
|
const versionMatch = navigator.userAgent.match(/Chrome\/(\d+)/);
|
||||||
|
|
||||||
const shouldInlineJs = true;
|
const shouldInlineJs = true;
|
||||||
// !window.webkitRequestFileSystem ||
|
|
||||||
// !window.IS_EXTENSION ||
|
|
||||||
// (versionMatch && +versionMatch[1] >= 104);
|
|
||||||
var contents = getCompleteHtml(
|
var contents = getCompleteHtml(
|
||||||
html,
|
html,
|
||||||
css,
|
css,
|
||||||
@@ -160,81 +157,52 @@ export default class ContentWrap extends Component {
|
|||||||
trackEvent.hasTrackedCode = true;
|
trackEvent.hasTrackedCode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldInlineJs) {
|
if (this.detachedWindow) {
|
||||||
if (this.detachedWindow) {
|
log('✉️ Sending message to detached window');
|
||||||
log('✉️ Sending message to detached window');
|
this.detachedWindow.postMessage({ contents }, '*');
|
||||||
this.detachedWindow.postMessage({ contents }, '*');
|
|
||||||
} else {
|
|
||||||
// 1. we refresh the frame so that all JS is cleared in the frame. this will
|
|
||||||
// break the iframe since sandboxed frame isn't served by SW (needed for offline support)
|
|
||||||
// 2. we cache and remove the sandbox attribute and refresh again so that it gets served by SW
|
|
||||||
// 3. we add back cached sandbox attr & write the contents to the iframe
|
|
||||||
const refreshAndDo = fn => {
|
|
||||||
frameRefreshPromise =
|
|
||||||
frameRefreshPromise ||
|
|
||||||
// Race earlier had a settimeout too as a fallback. It was removed because onload
|
|
||||||
// was firing 100% times.
|
|
||||||
// TODO: remove race
|
|
||||||
Promise.race([
|
|
||||||
new Promise(resolve => {
|
|
||||||
this.frame.onload = () => {
|
|
||||||
resolve('onload');
|
|
||||||
};
|
|
||||||
})
|
|
||||||
]);
|
|
||||||
|
|
||||||
frameRefreshPromise.then(resolutionReason => {
|
|
||||||
frameRefreshPromise = null;
|
|
||||||
log('resolved with ', resolutionReason);
|
|
||||||
fn();
|
|
||||||
});
|
|
||||||
// Setting to blank string cause frame to reload
|
|
||||||
// if (window.IS_EXTENSION) {
|
|
||||||
// this.frame.src = '';
|
|
||||||
// } else {
|
|
||||||
this.frame.src = this.frame.src;
|
|
||||||
// }
|
|
||||||
};
|
|
||||||
const writeInsideIframe = () => {
|
|
||||||
if (!cachedSandboxAttribute && window.DEBUG) {
|
|
||||||
// alert('sandbox empty');
|
|
||||||
}
|
|
||||||
log('sending PM');
|
|
||||||
|
|
||||||
// if (window.IS_EXTENSION) {
|
|
||||||
// this.frame.contentDocument.open();
|
|
||||||
// this.frame.contentDocument.write(contents);
|
|
||||||
// this.frame.contentDocument.close();
|
|
||||||
// } else {
|
|
||||||
this.frame.contentWindow.postMessage({ contents }, '*');
|
|
||||||
// }
|
|
||||||
};
|
|
||||||
// refreshAndDo(() => {
|
|
||||||
// cachedSandboxAttribute = this.frame.getAttribute('sandbox');
|
|
||||||
// // console.log('removing sandbox', sandbox);
|
|
||||||
// // this.frame.setAttribute('sweet', sandbox);
|
|
||||||
// // this.frame.removeAttribute('sandbox');
|
|
||||||
// refreshAndDo(writeInsideIframe);
|
|
||||||
// });
|
|
||||||
refreshAndDo(writeInsideIframe);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// DEPRECATED
|
// 1. we refresh the frame so that all JS is cleared in the frame. this will
|
||||||
// we need to store user script in external JS file to prevent inline-script
|
// break the iframe since sandboxed frame isn't served by SW (needed for offline support)
|
||||||
// CSP from affecting it.
|
// 2. we cache and remove the sandbox attribute and refresh again so that it gets served by SW
|
||||||
writeFile('script.js', blobjs, () => {
|
// 3. we add back cached sandbox attr & write the contents to the iframe
|
||||||
writeFile('preview.html', blob, () => {
|
const refreshAndDo = fn => {
|
||||||
var origin = chrome.i18n.getMessage()
|
frameRefreshPromise =
|
||||||
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}`
|
frameRefreshPromise ||
|
||||||
: `${location.origin}`;
|
// Race earlier had a settimeout too as a fallback. It was removed because onload
|
||||||
var src = `filesystem:${origin}/temporary/preview.html`;
|
// was firing 100% times.
|
||||||
if (this.detachedWindow) {
|
// TODO: remove race
|
||||||
this.detachedWindow.postMessage({ url: src }, '*');
|
Promise.race([
|
||||||
} else {
|
new Promise(resolve => {
|
||||||
this.frame.src = src;
|
this.frame.onload = () => {
|
||||||
}
|
resolve('onload');
|
||||||
|
};
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
frameRefreshPromise.then(resolutionReason => {
|
||||||
|
frameRefreshPromise = null;
|
||||||
|
log('resolved with ', resolutionReason);
|
||||||
|
fn();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
this.frame.src = this.frame.src;
|
||||||
|
};
|
||||||
|
const writeInsideIframe = () => {
|
||||||
|
if (!cachedSandboxAttribute && window.DEBUG) {
|
||||||
|
// alert('sandbox empty');
|
||||||
|
}
|
||||||
|
log('sending PM');
|
||||||
|
|
||||||
|
this.frame.contentWindow.postMessage({ contents }, '*');
|
||||||
|
};
|
||||||
|
// refreshAndDo(() => {
|
||||||
|
// cachedSandboxAttribute = this.frame.getAttribute('sandbox');
|
||||||
|
// // console.log('removing sandbox', sandbox);
|
||||||
|
// // this.frame.setAttribute('sweet', sandbox);
|
||||||
|
// // this.frame.removeAttribute('sandbox');
|
||||||
|
// refreshAndDo(writeInsideIframe);
|
||||||
|
// });
|
||||||
|
refreshAndDo(writeInsideIframe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cleanupErrors(lang) {
|
cleanupErrors(lang) {
|
||||||
|
Reference in New Issue
Block a user