// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_MANAGED_INTERFACE_H_ #define CONTENT_BROWSER_WEBUI_WEB_UI_MANAGED_INTERFACE_H_ #include <memory> #include <utility> #include "base/memory/raw_ptr.h" #include "base/supports_user_data.h" #include "content/common/content_export.h" #include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_managed_interface.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" namespace content { WebUIManagedInterfaceNoPageHandler; // WebUIManagedInterface is an optional base class for implementing classes // that interact with Mojo endpoints e.g. implement a Mojo interface or // communicate with a Mojo Remote. // // This class provides automated handling of Mojo endpoint bindings and // lifetime management. The subclass object is created when Create() is // called and destroyed when the associated WebUI document is removed or // navigates away. // // To implement interface Foo, use the following code: // class FooImpl : public WebUIManagedInterface<FooImpl, Foo> { ... } // // Additionally, to communiate with remote interface Bar: // class FooBarImpl : public WebUIManagedInterface<FooBarImpl, Foo, Bar> { ... // } // // To implement no interface but only communicate with a remote interface: // class Baz : public WebUIManagedInterface< // Baz, // WebUIManagedInterfaceNoPageHandler, // BarObserver> { ... } // // TODO(crbug.com/40257252): provide helpers to retrieve InterfaceImpl objects. template <typename InterfaceImpl, typename PageHandler, typename Page = void> requires(!std::is_void_v<PageHandler> || !std::is_void_v<Page>) class WebUIManagedInterface : public WebUIManagedInterfaceBase { … }; } // namespace content #endif // CONTENT_BROWSER_WEBUI_WEB_UI_MANAGED_INTERFACE_H_