diff --git a/devtools/client/commandline/test/browser_cmd_addon.js b/devtools/client/commandline/test/browser_cmd_addon.js index cd07c9e07b58..def608d3fef3 100644 --- a/devtools/client/commandline/test/browser_cmd_addon.js +++ b/devtools/client/commandline/test/browser_cmd_addon.js @@ -126,6 +126,67 @@ function* spawnTest() { exec: { output: 'Test Plug-in 1.0.0.0 enabled.' } + }, + { + setup: 'addon ctp Test_Plug-in_1.0.0.0', + check: { + input: 'addon ctp Test_Plug-in_1.0.0.0', + hints: '', + markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', + status: 'VALID', + args: { + command: { name: 'addon ctp' }, + addon: { + value: function(addon) { + is(addon.name, 'Test Plug-in', 'test plugin name'); + }, + status: 'VALID' + } + } + }, + exec: { + output: 'Test Plug-in 1.0.0.0 set to click-to-play.' + } + }, + { + setup: 'addon ctp OpenH264_Video_Codec_provided_by_Cisco_Systems,_Inc._null', + check: { + input: 'addon ctp OpenH264_Video_Codec_provided_by_Cisco_Systems,_Inc._null', + hints: '', + status: 'VALID', + args: { + command: { name: 'addon ctp' }, + addon: { + value: function(addon) { + is(addon.name, 'OpenH264 Video Codec provided by Cisco Systems, Inc.', 'openh264'); + }, + status: 'VALID' + } + } + }, + exec: { + output: 'OpenH264 Video Codec provided by Cisco Systems, Inc. null cannot be set to click-to-play.' + } + }, + { + setup: 'addon ctp Mochitest_1.0', + check: { + input: 'addon ctp Mochitest_1.0', + hints: '', + status: 'VALID', + args: { + command: { name: 'addon ctp' }, + addon: { + value: function(addon) { + is(addon.name, 'Mochitest', 'mochitest'); + }, + status: 'VALID' + } + } + }, + exec: { + output: 'Mochitest 1.0 cannot be set to click-to-play because it is not a plugin.' + } } ]); diff --git a/devtools/shared/gcli/commands/addon.js b/devtools/shared/gcli/commands/addon.js index f714b159c337..9a38142a3997 100644 --- a/devtools/shared/gcli/commands/addon.js +++ b/devtools/shared/gcli/commands/addon.js @@ -279,6 +279,41 @@ var items = [ return l10n.lookupFormat("addonAlreadyDisabled", [ name ]); } + }, + { + item: "command", + runAt: "client", + name: "addon ctp", + description: l10n.lookup("addonCtpDesc"), + params: [ + { + name: "addon", + type: "addon", + description: l10n.lookup("addonNameDesc") + } + ], + exec: function(args, context) { + let name = (args.addon.name + " " + args.addon.version).trim(); + if (args.addon.type !== "plugin") { + return l10n.lookupFormat("addonCantCtp", [ name ]); + } + + if (!args.addon.userDisabled || + args.addon.userDisabled === true) { + args.addon.userDisabled = AddonManager.STATE_ASK_TO_ACTIVATE; + + if (args.addon.userDisabled !== AddonManager.STATE_ASK_TO_ACTIVATE) { + // Some plugins (e.g. OpenH264 shipped with Firefox) cannot be set to + // click-to-play. Handle this. + + return l10n.lookupFormat("addonNoCtp", [ name ]); + } + + return l10n.lookupFormat("addonCtp", [ name ]); + } + + return l10n.lookupFormat("addonAlreadyCtp", [ name ]); + } } ]; diff --git a/devtools/shared/locales/en-US/gclicommands.properties b/devtools/shared/locales/en-US/gclicommands.properties index 1f32e8955729..7a199ce36340 100644 --- a/devtools/shared/locales/en-US/gclicommands.properties +++ b/devtools/shared/locales/en-US/gclicommands.properties @@ -836,6 +836,30 @@ addonAlreadyDisabled=%S is already disabled. # command when an add-on is disabled. addonDisabled=%S disabled. +# LOCALIZATION NOTE (addonCtpDesc) A very short description of the +# 'addon ctp ' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +addonCtpDesc=Set the specified plugin to click-to-play. + +# LOCALIZATION NOTE (addonCtp) Used in the output of the 'addon ctp' +# command when a plugin is set to click-to-play. +addonCtp=%S set to click-to-play. + +# LOCALIZATION NOTE (addonAlreadyCtp) Used in the output of the +# 'addon ctp' command when an attempt is made to set a plugin to +# click-to-play that is already set to click-to-play. +addonAlreadyCtp=%S is already set to click-to-play. + +# LOCALIZATION NOTE (addonCantCtp) Used in the output of the 'addon +# ctp' command when an attempt is made to set an addon to click-to-play, +# but the addon is not a plugin. +addonCantCtp=%S cannot be set to click-to-play because it is not a plugin. + +# LOCALIZATION NOTE (addonNoCtp) Used in the output of the 'addon +# ctp' command when an attempt is made to set an addon to click-to-play, +# but the plugin cannot be set to click-to-play for some reason. +addonNoCtp=%S cannot be set to click-to-play. + # LOCALIZATION NOTE (exportDesc) A very short description of the 'export' # command. This string is designed to be shown in a menu alongside the command # name, which is why it should be as short as possible.