// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

[
  {
    "namespace": "terminalPrivate",
    "compiler_options": {
      "implemented_in": "chrome/browser/extensions/api/terminal/terminal_private_api.h"
    },
    "description": "none",
    "types": [
      {
        "id": "OutputType",
        "type": "string",
        "enum": ["stdout", "stderr", "exit"],
        "description": "Type of the output stream from which output came. When process exits, output type will be set to exit"
      }
    ],
    "functions": [
      {
        "name": "openTerminalProcess",
        "type": "function",
        "description": "Starts new process.",
        "parameters": [
          {
            "type": "string",
            "name": "processName",
            "description": "Name of the process to open. May be 'crosh' or 'vmshell'."
          },
          {
            "type": "array",
            "items": {
              "type": "string"
            },
            "name": "args",
            "optional": true,
            "description": "Command line arguments to pass to the process."
          }
        ],
        "returns_async": {
          "name": "callback",
          "description": "Resolves with the ID of the launched process. If no process was launched, the promise is rejected.",
          "parameters": [
            {
              "name": "id",
              "description": "Id of the launched process.",
              "type": "string"
            }
          ]
        }
      },
      {
        "name": "openVmshellProcess",
        "type": "function",
        "description": "Starts new vmshell process.",
        "parameters": [
          {
            "type": "array",
            "items": {
              "type": "string"
            },
            "name": "args",
            "optional": true,
            "description": "Command line arguments to pass to vmshell."
          }
        ],
        "returns_async": {
          "name": "callback",
          "description": "Resolves with the ID of the launched vmshell process. If no process was launched, the promise is rejected.",
          "parameters": [
            {
              "name": "id",
              "description": "Id of the launched vmshell process.",
              "type": "string"
            }
          ]
        }
      },
      {
        "name": "closeTerminalProcess",
        "type": "function",
        "description": "Closes previously opened process from either openTerminalProcess or openVmshellProcess.",
        "parameters": [
          {
            "name": "id",
            "type": "string",
            "description": "Unique id of the process we want to close."
          }
        ],
        "returns_async": {
          "name": "callback",
          "optional": true,
          "description": "Resolves with the success of the function.",
          "parameters": [
            {
              "name": "success",
              "type": "boolean"
            }
          ]
        }
      },
      {
        "name": "sendInput",
        "type": "function",
        "description": "Sends input that will be routed to stdin of the process with the specified id.",
        "parameters": [
          {
            "name": "id",
            "type": "string",
            "description": "The id of the process to which we want to send input."
          },
          {
            "name": "input",
            "type": "string",
            "description": "Input we are sending to the process."
          }
        ],
        "returns_async": {
          "name": "callback",
          "optional": true,
          "description": "Resolves with success.",
          "parameters": [
            {
              "name": "success",
              "type": "boolean"
            }
          ]
        }
      },
      {
        "name": "onTerminalResize",
        "type": "function",
        "description": "Notify the process with the id id that terminal window size has changed.",
        "parameters": [
          {
            "name": "id",
            "type": "string",
            "description": "The id of the process."
          },
          {
            "name": "width",
            "type": "integer",
            "description": "New window width (as column count)."
          },
          {
            "name": "height",
            "type": "integer",
            "description": "New window height (as row count)."
          }
        ],
        "returns_async": {
          "name": "callback",
          "optional": true,
          "description": "Resolves with success.",
          "parameters": [
            {
              "name": "success",
              "type": "boolean"
            }
          ]
        }
      },
      {
        "name": "ackOutput",
        "type": "function",
        "description": "Called from |onProcessOutput| when the event is dispatched to terminal extension. Observing the terminal process output will be paused after |onProcessOutput| is dispatched until this method is called.",
        "parameters": [
          {
            "name": "id",
            "type": "string",
            "description": "The id of the process to which |onProcessOutput| was dispatched."
          }
        ]
      },
      {
        "name": "openWindow",
        "type": "function",
        "description": "Open a Terminal app window/tab",
        "parameters": [
          {
            "name": "data",
            "type": "object",
	    "optional": true,
            "properties": {
              "url": {
                "description": "The url for the new Terminal window.",
                "optional": true,
		"type": "string"
              },
	      "asTab": {
		"description": "Instead of openning a new window, open it as a new tab in the current app window.",
                "optional": true,
		"type": "boolean"
	      }
	    }
          }
        ]
      },
      {
        "name": "openOptionsPage",
        "type": "function",
        "description": "Open the Terminal Settings page.",
        "parameters": [],
        "returns_async": {
          "name": "callback",
          "description": "Promise that resolves when complete.",
          "parameters": []
        }
      },
      {
        "name": "openSettingsSubpage",
        "type": "function",
        "description": "Open the System Settings at the specified subpage.",
        "parameters": [
          {
            "type": "string",
            "name": "subpage",
            "description": "Name of subpage to open.  Currently only 'crostini' supported."
          }
        ],
        "returns_async": {
          "name": "callback",
          "description": "Promise that resolves when complete.",
          "parameters": []
        }
      },
      {
        "name": "getOSInfo",
        "type": "function",
        "description": "Returns an object containing info about ChromeOS settings that affect the Terminal, e.g. which feature flags are enabled.",
        "parameters": [],
        "returns_async": {
          "name": "callback",
          "description": "Resolves with the info object.",
          "parameters": [
            {
              "name": "info",
              "type": "object",
              "properties": {
                "tast": {
                  "description": "True if tast extension is installed.",
                  "type": "boolean"
                }
              },
              "description": "Information about which features are enabled."
            }
          ]
        }
      },
      {
        "name": "getPrefs",
        "type": "function",
        "description": "Returns specified pref values, ignoring any not in allowlist.",
        "parameters": [
          {
            "name": "paths",
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Paths of prefs to fetch."
          }
        ],
        "returns_async": {
          "name": "callback",
          "description": "Resolves with prefs.",
          "parameters": [
            {
              "name": "prefs",
              "type": "object",
              "additionalProperties":
                {
                  "type": "any" ,
                  "preserveNull": true
                },
              "description": "prefs keyed by paths.",
              "preserveNull": true
            }
          ]
        }
      },
      {
        "name": "setPrefs",
        "type": "function",
        "description": "Sets specified prefs, ignoring any not in allowlist.",
        "parameters": [
          {
            "name": "prefs",
            "type": "object",
            "description": "Prefs to update keyed by paths.",
            "additionalProperties":
              {
                "type": "any" ,
                "preserveNull": true
              },
            "preserveNull": true
          }
        ],
        "returns_async": {
          "name": "callback",
          "description": "Resolves when complete.",
          "parameters": []
        }
      }
    ],
    "events": [
      {
        "name": "onProcessOutput",
        "type": "function",
        "description": "Fired when an opened process writes something to its output. Observing further process output will be blocked until |ackOutput| for the terminal is called. Internally, first event argument will be ID of the tab that contains terminal instance for which this event is intended. This argument will be stripped before passing the event to the extension.",
        "parameters": [
          {
            "name": "id",
            "type": "string",
            "description": "Id of the process from which the output came."
          },
          {
            "name": "type",
            "$ref": "OutputType",
            "description": "Type of the output stream from which output came. When process exits, output type will be set to exit"
          },
          {
            "name": "data",
            "type": "binary",
            "description": "Data that was written to the output stream."
          }
        ]
      },
      {
        "name": "onPrefChanged",
        "type": "function",
        "description": "Fired when pref changes.",
        "parameters": [
          {
            "name": "prefs",
            "type": "object",
            "description": "Prefs keyed by paths.",
            "additionalProperties":
              {
                "type": "any" ,
                "preserveNull": true
              },
            "preserveNull": true
          }
        ]
      }
    ]
  }
]
