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

content / public / browser / per_web_ui_browser_interface_broker.h [blame]

// Copyright 2021 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_PUBLIC_BROWSER_PER_WEB_UI_BROWSER_INTERFACE_BROKER_H_
#define CONTENT_PUBLIC_BROWSER_PER_WEB_UI_BROWSER_INTERFACE_BROKER_H_

#include "base/memory/raw_ref.h"
#include "mojo/public/cpp/bindings/binder_map.h"
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/blink/public/mojom/browser_interface_broker.mojom.h"

namespace content {

class WebUIController;
using WebUIBinderMap = mojo::BinderMapWithContext<content::WebUIController*>;
using BinderInitializer = base::RepeatingCallback<void(WebUIBinderMap* map)>;

// A browser interface broker that only binds the interface specified in
// binder_initializers. It should be owned by the |controller| in the
// constructor.
class PerWebUIBrowserInterfaceBroker
    : public blink::mojom::BrowserInterfaceBroker {
 public:
  PerWebUIBrowserInterfaceBroker(
      WebUIController& controller,
      const std::vector<BinderInitializer>& binder_initializers);
  ~PerWebUIBrowserInterfaceBroker() override;

  void GetInterface(mojo::GenericPendingReceiver receiver) override;

  [[nodiscard]] mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker>
  BindNewPipeAndPassRemote();

 private:
  const raw_ref<WebUIController> controller_;
  WebUIBinderMap binder_map_;
  mojo::Receiver<blink::mojom::BrowserInterfaceBroker> receiver_{this};
};
}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_PER_WEB_UI_BROWSER_INTERFACE_BROKER_H_