Add data attributes to declaratively control Ruffle.
This commit is contained in:
parent
fe782e5db3
commit
485f166df3
|
@ -1,6 +1,12 @@
|
|||
import { define_legacy_elements, interdict_static_content, interdict_dynamic_content, falsify_plugin_detection } from "../../js-src/interdiction";
|
||||
import { interdict } from "../../js-src/interdiction";
|
||||
import { get_config_options, DEFAULT_CONFIG } from "../../js-src/config";
|
||||
|
||||
define_legacy_elements();
|
||||
interdict_static_content();
|
||||
interdict_dynamic_content();
|
||||
falsify_plugin_detection();
|
||||
let html = document.getElementsByTagName("html")[0];
|
||||
let page_options = get_config_options(html);
|
||||
|
||||
if (!page_options.optout) {
|
||||
let interdictions = page_options.interdict || DEFAULT_CONFIG.interdict;
|
||||
interdict(interdictions);
|
||||
} else {
|
||||
console.log("WebExtension Ruffle execution prohibited by page");
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Retrieve the declarative configuration options of the given element.
|
||||
*
|
||||
* This is intended to be used with the HTML element of a page. It allows web
|
||||
* pages to signal to both self-hosted and WebExtension versions of Ruffle what
|
||||
* their authorial intent is.
|
||||
*
|
||||
* The following data attributes are recognized:
|
||||
*
|
||||
* * data-ruffle-optout - Signals to the Ruffle Extension that the page would
|
||||
* like to opt out of having Ruffle loaded onto it. Has no effect on the
|
||||
* self-hosted version of Ruffle.
|
||||
* * data-ruffle-version - Indicates that this page self-hosts Ruffle, and
|
||||
* optionally indicates the version of Ruffle present on the page.
|
||||
* * data-ruffle-interdict - Indicates what legacy content interdictions are
|
||||
* allowed. This setting is respected by both WebExtension and self-hosted
|
||||
* Ruffle identically. The default of `static-content,plugin-detect` will be
|
||||
* provided if not specified. The following are valid interdictions:
|
||||
* * static-content - Replace static `<object>` and `<embed>` elements.
|
||||
* Enabled by default.
|
||||
* * dynamic-content - Replace dynamically-added `<object>` and `<embed>`
|
||||
* elements using a `MutationObserver`. Not enabled by default, as this
|
||||
* interdiction is expensive.
|
||||
* * plugin-detect - Alter the `window` in order to fool plugin detects. You
|
||||
* will not be able to detect the native version of Flash dynamically if
|
||||
* enabled.
|
||||
*
|
||||
* Defaults mentioned above are not applied by this function.
|
||||
*/
|
||||
export function get_config_options(elem) {
|
||||
let values = {};
|
||||
|
||||
values.optout = elem.dataset.ruffle-optout !== undefined;
|
||||
if (elem.dataset.ruffle-version !== undefined) {
|
||||
values.version = elem.dataset.ruffle-version;
|
||||
}
|
||||
|
||||
if (elem.dataset.ruffle-interdict !== undefined) {
|
||||
values.interdict = elem.dataset.ruffle-interdict.split(",").map((v) => v.trim());
|
||||
}
|
||||
}
|
||||
|
||||
export const DEFAULT_CONFIG = {
|
||||
"optout": false,
|
||||
"interdict": ["static-content", "plugin-detect"]
|
||||
};
|
|
@ -69,4 +69,22 @@ export function interdict_dynamic_content() {
|
|||
|
||||
export function falsify_plugin_detection() {
|
||||
install_plugin(FLASH_PLUGIN);
|
||||
}
|
||||
|
||||
export function interdict(interdiction_list) {
|
||||
if (interdiction_list.indexOf("static-content") !== -1 || interdiction_list.indexOf("dynamic-content") !== -1) {
|
||||
define_legacy_elements();
|
||||
}
|
||||
|
||||
if (interdiction_list.indexOf("static-content") !== -1) {
|
||||
interdict_static_content();
|
||||
}
|
||||
|
||||
if (interdiction_list.indexOf("dynamic-content") !== -1) {
|
||||
interdict_dynamic_content();
|
||||
}
|
||||
|
||||
if (interdiction_list.indexOf("plugin-detect") !== -1) {
|
||||
falsify_plugin_detection();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
import { define_legacy_elements, interdict_static_content, interdict_dynamic_content, falsify_plugin_detection } from "../../js-src/interdiction";
|
||||
import { interdict } from "../../js-src/interdiction";
|
||||
import { get_config_options, DEFAULT_CONFIG } from "../../js-src/config";
|
||||
|
||||
define_legacy_elements();
|
||||
interdict_static_content();
|
||||
let html = document.getElementsByTagName("html")[0];
|
||||
let page_options = get_config_options(html);
|
||||
let interdictions = page_options.interdict || DEFAULT_CONFIG.interdict;
|
||||
interdict(interdictions);
|
Loading…
Reference in New Issue