// 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_RENDERER_ASSISTANT_BINDINGS_H_ #define CHROMECAST_RENDERER_ASSISTANT_BINDINGS_H_ #include #include #include "base/memory/weak_ptr.h" #include "base/timer/timer.h" #include "chromecast/common/mojom/assistant_messenger.mojom.h" #include "chromecast/renderer/native_bindings_helper.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" namespace chromecast { namespace shell { // When enabled, these bindings can be used to open a message channel with the // Assistant. These bindings are only enabled for a small set of first-party // apps. class AssistantBindings : public CastBinding, public chromecast::mojom::AssistantMessageClient { public: AssistantBindings(content::RenderFrame* frame, const base::Value& feature_config); ~AssistantBindings() override; AssistantBindings(const AssistantBindings&) = delete; AssistantBindings& operator=(const AssistantBindings&) = delete; private: friend class ::chromecast::CastBinding; // chromecast::mojom::AssistantMessageClient implementation: void OnMessage(base::Value message) override; // CastBinding implementation: void Install(v8::Local cast_platform, v8::Isolate* isolate) override; // Binding methods void SetAssistantMessageHandler( v8::Local assistant_message_handler); void SendAssistantRequest(const std::string& request); void ReconnectMessagePipe(); void OnAssistantConnectionError(); void FlushV8ToAssistantQueue(); const mojo::Remote& GetMojoInterface(); base::RepeatingTimer reconnect_assistant_timer_; mojo::Remote assistant_; base::Value feature_config_; mojo::Receiver message_client_binding_; mojo::Remote message_pipe_; std::vector v8_to_assistant_queue_; v8::UniquePersistent assistant_message_handler_; base::WeakPtr weak_this_; base::WeakPtrFactory weak_factory_; }; } // namespace shell } // namespace chromecast #endif // CHROMECAST_RENDERER_ASSISTANT_BINDINGS_H_