Bug 1106353 - [gcli] Extend `addon` to handle click-to-play. r=mratcliffe
authorAlex Jordan <alex@strugee.net>
Sat, 02 Jan 2016 17:40:18 -0800
changeset 320221 117b84fe44cefbc230cc01e34fa02d7b1e089477
parent 320220 1b36e59457e7688791b5fb7438e3c28a90f3b71d
child 320222 273505970b6c7bdd07f43b42ffe096976d609936
push id9164
push useratolfsen@mozilla.com
push dateSat, 09 Jan 2016 21:37:35 +0000
reviewersmratcliffe
bugs1106353
milestone46.0a1
Bug 1106353 - [gcli] Extend `addon` to handle click-to-play. r=mratcliffe
devtools/client/commandline/test/browser_cmd_addon.js
devtools/shared/gcli/commands/addon.js
devtools/shared/locales/en-US/gclicommands.properties
--- a/devtools/client/commandline/test/browser_cmd_addon.js
+++ b/devtools/client/commandline/test/browser_cmd_addon.js
@@ -121,14 +121,75 @@ function* spawnTest() {
             },
             status: 'VALID'
           }
         }
       },
       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.'
+      }
     }
   ]);
 
   yield helpers.closeToolbar(options);
   yield helpers.closeTab(options);
 }
--- a/devtools/shared/gcli/commands/addon.js
+++ b/devtools/shared/gcli/commands/addon.js
@@ -274,12 +274,47 @@ var items = [
       if (!args.addon.userDisabled ||
           args.addon.userDisabled === AddonManager.STATE_ASK_TO_ACTIVATE) {
         args.addon.userDisabled = true;
         return l10n.lookupFormat("addonDisabled", [ name ]);
       }
 
       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 ]);
+    }
   }
 ];
 
 exports.items = addonManagerActive ? items : [];
--- a/devtools/shared/locales/en-US/gclicommands.properties
+++ b/devtools/shared/locales/en-US/gclicommands.properties
@@ -831,16 +831,40 @@ addonDisableDesc=Disable the specified a
 # 'addon disable' command when an attempt is made to disable an add-on that is
 # already disabled.
 addonAlreadyDisabled=%S is already disabled.
 
 # LOCALIZATION NOTE (addonDisabled) Used in the output of the 'addon disable'
 # command when an add-on is disabled.
 addonDisabled=%S disabled.
 
+# LOCALIZATION NOTE (addonCtpDesc) A very short description of the
+# 'addon ctp <type>' 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.
 exportDesc=Export resources
 
 # LOCALIZATION NOTE (exportHtmlDesc) A very short description of the 'export
 # html' 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.