File: lens_composebox_controller.h

package info (click to toggle)
chromium 140.0.7339.127-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,192,880 kB
  • sloc: cpp: 35,093,808; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,503; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (88 lines) | stat: -rw-r--r-- 3,230 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_LENS_LENS_COMPOSEBOX_CONTROLLER_H_
#define CHROME_BROWSER_UI_LENS_LENS_COMPOSEBOX_CONTROLLER_H_

#include <memory>
#include <set>

#include "base/memory/raw_ptr.h"
#include "chrome/browser/profiles/profile.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/lens_server_proto/aim_communication.pb.h"
#include "ui/webui/resources/cr_components/composebox/composebox.mojom.h"

class LensSearchController;

namespace lens {
class LensSessionMetricsLogger;
class LensComposeboxHandler;

// Controller for the Lens compose box. This class is responsible for handling
// communications between the Lens WebUI compose box and other Lens components,
// as well as storing any state needed for the compose box. Note: This class is
// different from the LensSearchboxController, which is responsible for the old,
// non-AIM search box.
class LensComposeboxController {
 public:
  explicit LensComposeboxController(
      LensSearchController* lens_search_controller,
      Profile* profile);
  ~LensComposeboxController();

  // This method is used to set up communication between this instance and the
  // compose box WebUI. This is called by the WebUIController when the WebUI is
  // executing javascript and has bound the handler.
  void BindComposebox(
      mojo::PendingReceiver<composebox::mojom::PageHandler> pending_handler,
      mojo::PendingRemote<composebox::mojom::Page> pending_page,
      mojo::PendingReceiver<searchbox::mojom::PageHandler>
          pending_searchbox_handler);

  // Issues a composebox query to the side panel results. If this is called when
  // the user is in AIM, issues a follow up query. Otherwise, issues a new AIM
  // session query.
  void IssueComposeboxQuery(const std::string& query_text);

  // Called when the focus state of the composebox changes.
  void OnFocusChanged(bool focused);

  // Cleans up any any state associated with this UI instance.
  void CloseUI();

  // Handles AIM messages from the side panel remote UI.
  void OnAimMessage(const std::vector<uint8_t>& message);

  // Returns the session metrics logger for the current Lens session.
  LensSessionMetricsLogger* GetSessionMetricsLogger();

  LensComposeboxHandler* composebox_handler_for_testing() {
    return composebox_handler_.get();
  }

 private:
  // Builds a SubmitQuery ClientToAimMessage message to send to the side panel
  // remote UI.
  lens::ClientToAimMessage BuildSubmitQueryMessage(
      const std::string& query_text);

  // Owns this.
  const raw_ptr<LensSearchController> lens_search_controller_;

  // Guarantee to outlive this.
  const raw_ptr<Profile> profile_;

  // The remote UI's capabilities.
  std::set<lens::FeatureCapability> remote_ui_capabilities_;

  // The class responsible for handling messages between the compose box and
  // the WebUI.
  std::unique_ptr<LensComposeboxHandler> composebox_handler_;
};
}  // namespace lens

#endif  // CHROME_BROWSER_UI_LENS_LENS_COMPOSEBOX_CONTROLLER_H_