Convert ui/ to ESM

- ViewManager has been extracted from View
- Action has been extracted from ActionRegistry
- ContextFlavorListener has been extracted from Context

Bug: 1006759
Change-Id: Iff41f3a7db4dcbd6da90fd5752923e32af03bac8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827294
Commit-Queue: Tim Van der Lippe <[email protected]>
Reviewed-by: Yang Guo <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#702390}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0ffd51ccac853da7c8ec3d91ae868bc61626b29b
diff --git a/front_end/ui/ActionRegistry.js b/front_end/ui/ActionRegistry.js
index 247505e..7f99098 100644
--- a/front_end/ui/ActionRegistry.js
+++ b/front_end/ui/ActionRegistry.js
@@ -4,7 +4,7 @@
 /**
  * @unrestricted
  */
-UI.ActionRegistry = class {
+export default class ActionRegistry {
   constructor() {
     /** @type {!Map.<string, !UI.Action>} */
     this._actionsById = new Map();
@@ -52,7 +52,7 @@
     actionIds.forEach(function(actionId) {
       const action = this._actionsById.get(actionId);
       if (action) {
-        extensions.push(action._extension);
+        extensions.push(action.extension());
       }
     }, this);
     return context.applicableExtensions(extensions).valuesArray().map(extensionToAction.bind(this));
@@ -74,164 +74,16 @@
   action(actionId) {
     return this._actionsById.get(actionId) || null;
   }
-};
+}
 
-/**
- * @unrestricted
- */
-UI.Action = class extends Common.Object {
-  /**
-   * @param {!Root.Runtime.Extension} extension
-   */
-  constructor(extension) {
-    super();
-    this._extension = extension;
-    this._enabled = true;
-    this._toggled = false;
-  }
+/* Legacy exported object*/
+self.UI = self.UI || {};
 
-  /**
-   * @return {string}
-   */
-  id() {
-    return this._extension.descriptor()['actionId'];
-  }
+/* Legacy exported object*/
+UI = UI || {};
 
-  /**
-   * @return {!Promise.<boolean>}
-   */
-  execute() {
-    return this._extension.instance().then(handleAction.bind(this));
-
-    /**
-     * @param {!Object} actionDelegate
-     * @return {boolean}
-     * @this {UI.Action}
-     */
-    function handleAction(actionDelegate) {
-      const actionId = this._extension.descriptor()['actionId'];
-      const delegate = /** @type {!UI.ActionDelegate} */ (actionDelegate);
-      return delegate.handleAction(UI.context, actionId);
-    }
-  }
-
-  /**
-   * @return {string}
-   */
-  icon() {
-    return this._extension.descriptor()['iconClass'] || '';
-  }
-
-  /**
-   * @return {string}
-   */
-  toggledIcon() {
-    return this._extension.descriptor()['toggledIconClass'] || '';
-  }
-
-  /**
-   * @return {boolean}
-   */
-  toggleWithRedColor() {
-    return !!this._extension.descriptor()['toggleWithRedColor'];
-  }
-
-  /**
-   * @param {boolean} enabled
-   */
-  setEnabled(enabled) {
-    if (this._enabled === enabled) {
-      return;
-    }
-
-    this._enabled = enabled;
-    this.dispatchEventToListeners(UI.Action.Events.Enabled, enabled);
-  }
-
-  /**
-   * @return {boolean}
-   */
-  enabled() {
-    return this._enabled;
-  }
-
-  /**
-   * @return {string}
-   */
-  category() {
-    return ls(this._extension.descriptor()['category'] || '');
-  }
-
-  /**
-   * @return {string}
-   */
-  tags() {
-    return this._extension.descriptor()['tags'] || '';
-  }
-
-  /**
-   * @return {boolean}
-   */
-  toggleable() {
-    return !!this._extension.descriptor()['toggleable'];
-  }
-
-  /**
-   * @return {string}
-   */
-  title() {
-    let title = this._extension.title() || '';
-    const options = this._extension.descriptor()['options'];
-    if (options) {
-      for (const pair of options) {
-        if (pair['value'] !== this._toggled) {
-          title = pair['title'];
-        }
-      }
-    }
-    return ls(title);
-  }
-
-  /**
-   * @return {boolean}
-   */
-  toggled() {
-    return this._toggled;
-  }
-
-  /**
-   * @param {boolean} toggled
-   */
-  setToggled(toggled) {
-    console.assert(this.toggleable(), 'Shouldn\'t be toggling an untoggleable action', this.id());
-    if (this._toggled === toggled) {
-      return;
-    }
-
-    this._toggled = toggled;
-    this.dispatchEventToListeners(UI.Action.Events.Toggled, toggled);
-  }
-};
-
-/** @enum {symbol} */
-UI.Action.Events = {
-  Enabled: Symbol('Enabled'),
-  Toggled: Symbol('Toggled')
-};
-
-/**
- * @interface
- */
-UI.ActionDelegate = function() {};
-
-UI.ActionDelegate.prototype = {
-  /**
-   * @param {!UI.Context} context
-   * @param {string} actionId
-   * @return {boolean}
-   */
-  handleAction(context, actionId) {}
-};
+/** @constructor */
+UI.ActionRegistry = ActionRegistry;
 
 /** @type {!UI.ActionRegistry} */
 UI.actionRegistry;