File: nearby_internals_ui_trigger_handler.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (123 lines) | stat: -rw-r--r-- 5,807 bytes parent folder | download | duplicates (9)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2020 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_WEBUI_NEARBY_INTERNALS_NEARBY_INTERNALS_UI_TRIGGER_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_NEARBY_INTERNALS_NEARBY_INTERNALS_UI_TRIGGER_HANDLER_H_

#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service.h"
#include "chrome/browser/nearby_sharing/share_target_discovered_callback.h"
#include "chrome/browser/nearby_sharing/transfer_update_callback.h"
#include "content/public/browser/web_ui_message_handler.h"

namespace content {
class BrowserContext;
}  // namespace content

// WebUIMessageHandler for to trigger NearbySharingService UI events.
class NearbyInternalsUiTriggerHandler : public content::WebUIMessageHandler,
                                        public TransferUpdateCallback,
                                        public ShareTargetDiscoveredCallback {
 public:
  explicit NearbyInternalsUiTriggerHandler(content::BrowserContext* context);
  NearbyInternalsUiTriggerHandler(const NearbyInternalsUiTriggerHandler&) =
      delete;
  NearbyInternalsUiTriggerHandler& operator=(
      const NearbyInternalsUiTriggerHandler&) = delete;
  ~NearbyInternalsUiTriggerHandler() override;

  // content::WebUIMessageHandler:
  void RegisterMessages() override;

  // TransferUpdateCallback:
  void OnTransferUpdate(const ShareTarget& share_target,
                        const TransferMetadata& transfer_metadata) override;

  // ShareTargetDiscoveryCallback:
  void OnShareTargetDiscovered(ShareTarget share_target) override;
  void OnShareTargetLost(ShareTarget share_target) override;

 private:
  // Triggers WebUIListener event after corresponding event is triggered in
  // NearbyShareService to pass callback to JavaScript to eventually be
  // displayed.
  void OnAcceptCalled(NearbySharingService::StatusCodes status_codes);
  void OnOpenCalled(NearbySharingService::StatusCodes status_codes);
  void OnRejectCalled(NearbySharingService::StatusCodes status_codes);
  void OnCancelCalled(NearbySharingService::StatusCodes status_codes);

  // Message handler callback that initializes JavaScript.
  void InitializeContents(const base::Value::List& args);

  // Message handler callback that triggers SendText in the NearbyShareService.
  void SendText(const base::Value::List& args);

  // Message handler callback that triggers Accept in the NearbyShareService.
  void Accept(const base::Value::List& args);

  // Message handler callback that triggers Reject in the NearbyShareService.
  void Reject(const base::Value::List& args);

  // Message handler callback that triggers Cancel in the NearbyShareService.
  void Cancel(const base::Value::List& args);

  // Message handler callback that triggers Open in the NearbyShareService.
  void Open(const base::Value::List& args);

  // Message handler callback that calls RegisterSendSurface in the
  // NearbySharingService with a Foreground SendSurfaceState.
  // The NearbyInternalsUiTriggerHandler instance acts as the send surface,
  // playing the role of both the TransferUpdateCallback and the
  // ShareTargetDiscoveredCallback.
  void RegisterSendSurfaceForeground(const base::Value::List& args);

  // Message handler callback that calls RegisterSendSurface in the
  // NearbySharingService with a Background SendSurfaceState.
  // The NearbyInternalsUiTriggerHandler instance acts as the send surface,
  // playing the role of both the TransferUpdateCallback and the
  // ShareTargetDiscoveredCallback.
  void RegisterSendSurfaceBackground(const base::Value::List& args);

  // Message handler callback that calls UnregisterSendSurface in the
  // NearbySharingService. The NearbyInternalsUiTriggerHandler instance acts as
  // the send surface to be unregistered.
  void UnregisterSendSurface(const base::Value::List& args);

  // Message handler callback that calls RegisterReceiveSurface in the
  // NearbySharingService with a Foreground receive surface state.
  // The NearbyInternalsUiTriggerHandler instance acts as the receive surface,
  // playing the role of both the TransferUpdateCallback and the
  // ShareTargetDiscoveredCallback.
  void RegisterReceiveSurfaceForeground(const base::Value::List& args);

  // Message handler callback that calls RegisterReceiveSurface in the
  // NearbySharingService with a Background receive surface state.
  // The NearbyInternalsUiTriggerHandler instance acts as the receive surface,
  // playing the role of both the TransferUpdateCallback and the
  // ShareTargetDiscoveredCallback.
  void RegisterReceiveSurfaceBackground(const base::Value::List& args);

  // Message handler callback that calls UnregisterReceiveSurface in the
  // NearbySharingService. The NearbyInternalsUiTriggerHandler instance acts as
  // the receive surface to be unregistered.
  void UnregisterReceiveSurface(const base::Value::List& args);

  // Message handler callback that calls ShowSuccess in the
  // NearbySharingService's NearbyNotificationManager.
  void ShowReceivedNotification(const base::Value::List& args);

  // Message handler callback that calls IsScanning, IsTransferring,
  // IsReceivingFile, IsSendingFile, IsConnecting, and IsInHighVisibility in the
  // NearbySharingService and passes booleans to JavaScript to eventually be
  // displayed.
  void GetState(const base::Value::List& args);

  const raw_ptr<content::BrowserContext> context_;
  base::flat_map<std::string, ShareTarget> id_to_share_target_map_;
  base::WeakPtrFactory<NearbyInternalsUiTriggerHandler> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_UI_WEBUI_NEARBY_INTERNALS_NEARBY_INTERNALS_UI_TRIGGER_HANDLER_H_