forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbindings_manager_web_runtime.h
75 lines (60 loc) · 3.02 KB
/
bindings_manager_web_runtime.h
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
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMECAST_CAST_CORE_BINDINGS_MANAGER_WEB_RUNTIME_H_
#define CHROMECAST_CAST_CORE_BINDINGS_MANAGER_WEB_RUNTIME_H_
#include <map>
#include <memory>
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "chromecast/bindings/public/mojom/api_bindings.mojom.h"
#include "chromecast/cast_core/message_port_service.h"
#include "components/cast/api_bindings/manager.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/openscreen/src/cast/cast_core/api/v2/core_application_service.grpc.pb.h"
#include "third_party/openscreen/src/cast/cast_core/api/web/message_channel.pb.h"
namespace chromecast {
// This class will be initialized with a set of bindings received over gRPC and
// will inject them into the app's CastWebContents when the page loads. It then
// handles connecting PortConnector requests from those bindings by making gRPC
// ApiBindings requests to Cast Core. There should be one instance of this
// class for a single CastWebContents.
class BindingsManagerWebRuntime final : public cast_api_bindings::Manager,
public chromecast::mojom::ApiBindings {
public:
// |cast_web_contents|, |grpc_cq|, and |core_app_stub| all need to outlive
// |this|.
BindingsManagerWebRuntime(
grpc::CompletionQueue* grpc_cq,
cast::v2::CoreApplicationService::Stub* core_app_stub);
~BindingsManagerWebRuntime() override;
BindingsManagerWebRuntime(const BindingsManagerWebRuntime&) = delete;
BindingsManagerWebRuntime(BindingsManagerWebRuntime&&) = delete;
BindingsManagerWebRuntime& operator=(const BindingsManagerWebRuntime&) =
delete;
BindingsManagerWebRuntime& operator=(BindingsManagerWebRuntime&&) = delete;
void AddBinding(base::StringPiece binding_script);
void HandleMessage(const cast::web::Message& message,
cast::web::MessagePortStatus* response);
// Returns a mojo::PendingRemote bound to |this|.
// At most one bound remote can exist at the same time.
mojo::PendingRemote<mojom::ApiBindings> CreateRemote();
private:
// Callback invoked when client of mojom::ApiBindings disconnects.
void OnMojoClientDisconnected();
// cast_api_bindings::Manager overrides.
void AddBinding(base::StringPiece binding_name,
base::StringPiece binding_script) override;
// chromecast::mojom::ApiBindings implementation.
void GetAll(GetAllCallback callback) override;
void Connect(const std::string& port_name,
blink::MessagePortDescriptor port) override;
int next_script_id_{0};
// Stores all bindings, keyed on the string-based IDs provided by the
// ApiBindings interface.
std::map<std::string, std::string> bindings_;
mojo::Receiver<mojom::ApiBindings> receiver_{this};
MessagePortService message_port_service_;
};
} // namespace chromecast
#endif // CHROMECAST_CAST_CORE_BINDINGS_MANAGER_WEB_RUNTIME_H_