chromium/chromeos/ash/services/ime/public/mojom/ime_service.mojom

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

module ash.ime.mojom;

import "chromeos/ash/services/ime/public/mojom/connection_factory.mojom";
import "chromeos/ash/services/ime/public/mojom/input_engine.mojom";
import "chromeos/ash/services/ime/public/mojom/input_method.mojom";
import "chromeos/ash/services/ime/public/mojom/input_method_host.mojom";
import "chromeos/ash/services/ime/public/mojom/input_method_user_data.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "url/mojom/url.mojom";
import "sandbox/policy/mojom/sandbox.mojom";

// IME on ChromeOS consists of three parts:
// - The IME running in an extension to provide a soft keyboard
// - The sandboxed, core IME service running in ChromeOS (responsible for
//   processing input and turning it into characters/symbols)
// - The IME framework running in the Chrome browser process, that brokers
//   between the IME extension and the IME service. It also provides additional
//   functionality to the IME service (for downloading IME data as needed).
// TODO(b/214153032): Paraphrase and modernise this documentation block. There
// are currently quite some vague and/or oudated bits.

// Manages access to a set of IMEs, implemented by the IME service
// itself. The IME framework in the browser process is responsible for brokering
// the connection between the IME service and the IME extension, but does not
// otherwise participate.
interface InputEngineManager {
  // Sets up a bidirectional binary connection with the input engine identified
  // by |ime_spec|. On success, |success| is true and binary input data can be
  // sent to the engine by the channel using |to_engine_request|. The channel
  // interface |from_engine| is implemented on the client and used to receive
  // data sent from the engine.
  // On failure (e.g. input engine is not found), |success| is false.
  // |extra| is an optional serialized data for setting up the IME engine. It is
  // serialized as binary because the engine is a shared library and |extra|
  // needs to be passed to it via a C interface.
  // TODO(b/214153032): Rename to ConnectToProtoModeSharedLibInputMethod(), to
  // better reflect what this does. Also, paraphrase documentation above.
  ConnectToImeEngine(string ime_spec,
                     pending_receiver<InputChannel> to_engine_request,
                     pending_remote<InputChannel> from_engine,
                     array<uint8> extra)
                     => (bool success);

  // Initializes the mojo pipe used for messaging between the shared library
  // and Chromium. Any messaging interfaces used will need to be associated
  // to this pipe (see AssociatedInterfaces documentation for more details).
  // TODO(b/214153032): Rename to InitializeMojoModeSharedLibConnectionFactory()
  // to better reflect what this does. Also, paraphrase documentation above.
  InitializeConnectionFactory(
    pending_receiver<ConnectionFactory> connection_factory)
    => (bool success);
};

// Implemented in the browser process, used to perform network requests or
// access privileged resources on behalf of the core IME service in ChromeOS.
interface PlatformAccessProvider {
  // Download language module from a allowlisted url to a given path.
  // Provider will validate the url and return an empty file path if it's
  // invalid or downloading fails.
  DownloadImeFileTo(url.mojom.Url url,
                    mojo_base.mojom.FilePath file_path) =>
                        (mojo_base.mojom.FilePath file_path);
};

// The main interface to the IME service, which runs in a Chrome utility
// process to handle IME related operations. There are two clients of the IME
// service: the browser process for certain first-party input methods and the
// renderer process running the first-party IME extension.
[ServiceSandbox=sandbox.mojom.Sandbox.kIme]
interface ImeService {
  // Injects a remote PlatformAccessProvider interface that the service can use
  // to request privileged operations from the client (i.e. the browser).
  SetPlatformAccessProvider(pending_remote<PlatformAccessProvider> provider);

  // Binds an InputEngineManager interface.
  BindInputEngineManager(pending_receiver<InputEngineManager> receiver);


  // Bind a receiver to an InputMethodUserDataService interface.
  BindInputMethodUserDataService(
    pending_receiver<InputMethodUserDataService> receiver);
};