[module.json extensions] console actions

Bug: 1134103
Change-Id: I6b03d3202df9bc5dc9b46b33dd95a93b2b5c777b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2648907
Commit-Queue: Andres Olivares <[email protected]>
Reviewed-by: Tim van der Lippe <[email protected]>
diff --git a/front_end/console/ConsoleView.js b/front_end/console/ConsoleView.js
index f456c46..5ce5b51 100644
--- a/front_end/console/ConsoleView.js
+++ b/front_end/console/ConsoleView.js
@@ -1671,6 +1671,9 @@
   }
 }
 
+/** @type {!ActionDelegate} */
+let actionDelegateInstance;
+
 /**
  * @implements {UI.ActionRegistration.ActionDelegate}
  */
@@ -1700,6 +1703,20 @@
     }
     return false;
   }
+
+  /**
+   * @param {{forceNew: ?boolean}=} opts
+   * @return {!ActionDelegate}
+  }
+   */
+  static instance(opts = {forceNew: null}) {
+    const {forceNew} = opts;
+    if (!actionDelegateInstance || forceNew) {
+      actionDelegateInstance = new ActionDelegate();
+    }
+
+    return actionDelegateInstance;
+  }
 }
 
 /** @type {!WeakMap<!ConsoleViewMessage, number>} */
diff --git a/front_end/console/console-meta.ts b/front_end/console/console-meta.ts
index ee2931a..f40745a 100644
--- a/front_end/console/console-meta.ts
+++ b/front_end/console/console-meta.ts
@@ -21,6 +21,13 @@
   return loadedConsoleModule;
 }
 
+function maybeRetrieveContextTypes<T = unknown>(getClassCallBack: (consoleModule: typeof Console) => T[]): T[] {
+  if (loadedConsoleModule === undefined) {
+    return [];
+  }
+  return getClassCallBack(loadedConsoleModule);
+}
+
 UI.ViewManager.registerViewExtension({
   location: UI.ViewManager.ViewLocationValues.PANEL,
   id: 'console',
@@ -45,3 +52,66 @@
     return Console.ConsolePanel.WrapperView.instance();
   },
 });
+
+UI.ActionRegistration.registerActionExtension({
+  actionId: 'console.show',
+  category: UI.ActionRegistration.ActionCategory.CONSOLE,
+  title: (): Platform.UIString.LocalizedString => ls`Show Console`,
+  async loadActionDelegate() {
+    const Console = await loadConsoleModule();
+    return Console.ConsoleView.ActionDelegate.instance();
+  },
+  bindings: [
+    {
+      shortcut: 'Ctrl+`',
+      keybindSets: [
+        UI.ActionRegistration.KeybindSet.DEVTOOLS_DEFAULT,
+        UI.ActionRegistration.KeybindSet.VS_CODE,
+      ],
+    },
+  ],
+});
+
+UI.ActionRegistration.registerActionExtension({
+  actionId: 'console.clear',
+  category: UI.ActionRegistration.ActionCategory.CONSOLE,
+  title: (): Platform.UIString.LocalizedString => ls`Clear console`,
+  iconClass: UI.ActionRegistration.IconClass.LARGEICON_CLEAR,
+  async loadActionDelegate() {
+    const Console = await loadConsoleModule();
+    return Console.ConsoleView.ActionDelegate.instance();
+  },
+  contextTypes() {
+    return maybeRetrieveContextTypes(Console => [Console.ConsoleView.ConsoleView]);
+  },
+  bindings: [
+    {
+      shortcut: 'Ctrl+L',
+    },
+    {
+      shortcut: 'Meta+K',
+      platform: UI.ActionRegistration.Platforms.Mac,
+    },
+  ],
+});
+
+UI.ActionRegistration.registerActionExtension({
+  actionId: 'console.clear.history',
+  category: UI.ActionRegistration.ActionCategory.CONSOLE,
+  title: (): Platform.UIString.LocalizedString => ls`Clear console history`,
+  async loadActionDelegate() {
+    const Console = await loadConsoleModule();
+    return Console.ConsoleView.ActionDelegate.instance();
+  },
+});
+
+UI.ActionRegistration.registerActionExtension({
+  actionId: 'console.create-pin',
+  category: UI.ActionRegistration.ActionCategory.CONSOLE,
+  title: (): Platform.UIString.LocalizedString => ls`Create live expression`,
+  iconClass: UI.ActionRegistration.IconClass.LARGEICON_VISIBILITY,
+  async loadActionDelegate() {
+    const Console = await loadConsoleModule();
+    return Console.ConsoleView.ActionDelegate.instance();
+  },
+});
diff --git a/front_end/console/module.json b/front_end/console/module.json
index a8cb82e..ad37c9e 100644
--- a/front_end/console/module.json
+++ b/front_end/console/module.json
@@ -8,57 +8,6 @@
       "className": "Console.ConsolePanel.ConsoleRevealer"
     },
     {
-      "type": "action",
-      "actionId": "console.show",
-      "category": "Console",
-      "title": "Show Console",
-      "className": "Console.ConsoleView.ActionDelegate",
-      "bindings": [
-        {
-          "shortcut": "Ctrl+`",
-          "keybindSets": [
-            "devToolsDefault",
-            "vsCode"
-          ]
-        }
-      ]
-    },
-    {
-      "type": "action",
-      "category": "Console",
-      "contextTypes": [
-        "Console.ConsoleView"
-      ],
-      "actionId": "console.clear",
-      "title": "Clear console",
-      "iconClass": "largeicon-clear",
-      "className": "Console.ConsoleView.ActionDelegate",
-      "bindings": [
-        {
-          "shortcut": "Ctrl+L"
-        },
-        {
-          "platform": "mac",
-          "shortcut": "Meta+K"
-        }
-      ]
-    },
-    {
-      "type": "action",
-      "category": "Console",
-      "actionId": "console.clear.history",
-      "title": "Clear console history",
-      "className": "Console.ConsoleView.ActionDelegate"
-    },
-    {
-      "type": "action",
-      "category": "Console",
-      "actionId": "console.create-pin",
-      "iconClass": "largeicon-visibility",
-      "className": "Console.ConsoleView.ActionDelegate",
-      "title": "Create live expression"
-    },
-    {
       "type": "setting",
       "category": "Console",
       "title": "Hide network messages",
diff --git a/front_end/ui/ActionRegistration.ts b/front_end/ui/ActionRegistration.ts
index d9da7f7..136026b 100644
--- a/front_end/ui/ActionRegistration.ts
+++ b/front_end/ui/ActionRegistration.ts
@@ -316,6 +316,7 @@
   NETWORK: ls`Network`,
   MEMORY: ls`Memory`,
   JAVASCRIPT_PROFILER: ls`JavaScript Profiler`,
+  CONSOLE: ls`Console`,
 };
 
 type ActionCategory = typeof ActionCategory[keyof typeof ActionCategory];
@@ -325,6 +326,8 @@
   LARGEICON_START_RECORDING = 'largeicon-start-recording',
   LARGEICON_STOP_RECORDING = 'largeicon-stop-recording',
   LARGEICON_REFRESH = 'largeicon-refresh',
+  LARGEICON_CLEAR = 'largeicon-clear',
+  LARGEICON_VISIBILITY = 'largeicon-visibility',
 }
 
 export const enum KeybindSet {
@@ -363,11 +366,11 @@
   /**
    * The type of the icon used to trigger the action.
    */
-  iconClass?: string;
+  iconClass?: IconClass;
   /**
    * Whether the style of the icon toggles on interaction.
    */
-  toggledIconClass?: string;
+  toggledIconClass?: IconClass;
   /**
    * Whether the class 'toolbar-toggle-with-red-color' is toggled on the icon on interaction.
    */