Skip to content

Commit

Permalink
web: Support menu embed/object attribute (part of #4258)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs authored and adrian17 committed Aug 28, 2021
1 parent b5ee94a commit 3982f3a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,13 @@ impl Player {
})
}

pub fn set_show_menu(&mut self, show_menu: bool) {
self.mutate_with_update_context(|context| {
let stage = context.stage;
stage.set_show_menu(context, show_menu);
})
}

pub fn handle_event(&mut self, event: PlayerEvent) {
if cfg!(feature = "avm_debug") {
if let PlayerEvent::KeyDown {
Expand Down
9 changes: 9 additions & 0 deletions web/packages/core/src/load-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ export interface BaseLoadOptions {
* @default null
*/
base?: string | null;

/**
* If set to true, the built-in context menu items are visible
*
* This is equivalent to Stage.showMenu.
*
* @default true
*/
menu?: boolean;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions web/packages/core/src/ruffle-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FUTURESPLASH_MIMETYPE,
FLASH7_AND_8_MIMETYPE,
FLASH_MOVIE_MIMETYPE,
isBuiltInContextMenuVisible,
isScriptAccessAllowed,
isSwfFilename,
RufflePlayer,
Expand Down Expand Up @@ -39,6 +40,7 @@ export class RuffleEmbed extends RufflePlayer {
const allowScriptAccess =
this.attributes.getNamedItem("allowScriptAccess")?.value ??
null;
const menu = this.attributes.getNamedItem("menu")?.value ?? null;

// Kick off the SWF download.
this.load({
Expand All @@ -50,6 +52,7 @@ export class RuffleEmbed extends RufflePlayer {
parameters: this.attributes.getNamedItem("flashvars")?.value,
backgroundColor: this.attributes.getNamedItem("bgcolor")?.value,
base: this.attributes.getNamedItem("base")?.value,
menu: isBuiltInContextMenuVisible(menu),
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions web/packages/core/src/ruffle-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FLASH7_AND_8_MIMETYPE,
FLASH_MOVIE_MIMETYPE,
FLASH_ACTIVEX_CLASSID,
isBuiltInContextMenuVisible,
isScriptAccessAllowed,
isSwfFilename,
RufflePlayer,
Expand Down Expand Up @@ -118,6 +119,8 @@ export class RuffleObject extends RufflePlayer {
this.getAttribute("base")
);

const menu = findCaseInsensitive(this.params, "menu", null);

if (url) {
const options: URLLoadOptions = { url };
options.allowScriptAccess = isScriptAccessAllowed(
Expand All @@ -133,6 +136,7 @@ export class RuffleObject extends RufflePlayer {
if (base) {
options.base = base;
}
options.menu = isBuiltInContextMenuVisible(menu);

// Kick off the SWF download.
this.load(options);
Expand Down
13 changes: 13 additions & 0 deletions web/packages/core/src/ruffle-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,19 @@ export function isScriptAccessAllowed(
}
}

/**
* Returns whether a SWF file should show the built-in context menu items.
*
* @param menu The value of the `menu` attribute.
* @returns True if the built-in context items should be shown.
*/
export function isBuiltInContextMenuVisible(menu: string | null): boolean {
if (menu === "true" || menu === null) {
return true;
}
return false;
}

/**
* Returns whether the given filename ends in a known flash extension.
*
Expand Down
5 changes: 5 additions & 0 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ pub struct Config {
#[serde(rename = "base")]
base_url: Option<String>,

#[serde(rename = "menu")]
show_menu: bool,

#[serde(rename = "warnOnUnsupportedContent")]
warn_on_unsupported_content: bool,

Expand All @@ -155,6 +158,7 @@ impl Default for Config {
fn default() -> Self {
Self {
allow_script_access: false,
show_menu: true,
background_color: Default::default(),
letterbox: Default::default(),
upgrade_to_https: true,
Expand Down Expand Up @@ -488,6 +492,7 @@ impl Ruffle {
core.set_letterbox(config.letterbox);
core.set_warn_on_unsupported_content(config.warn_on_unsupported_content);
core.set_max_execution_duration(config.max_execution_duration);
core.set_show_menu(config.show_menu);

// Create the external interface.
if allow_script_access {
Expand Down

0 comments on commit 3982f3a

Please sign in to comment.