1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOWNLOADS_UI_H_
6 #define CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOWNLOADS_UI_H_
7 
8 #include <memory>
9 
10 #include "base/macros.h"
11 #include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
12 #include "mojo/public/cpp/bindings/pending_receiver.h"
13 #include "mojo/public/cpp/bindings/pending_remote.h"
14 #include "mojo/public/cpp/bindings/receiver.h"
15 #include "ui/base/layout.h"
16 #include "ui/webui/mojo_web_ui_controller.h"
17 
18 namespace base {
19 class RefCountedMemory;
20 }
21 
22 class DownloadsDOMHandler;
23 
24 class DownloadsUI : public ui::MojoWebUIController,
25                     public downloads::mojom::PageHandlerFactory {
26  public:
27   explicit DownloadsUI(content::WebUI* web_ui);
28   ~DownloadsUI() override;
29 
30   static base::RefCountedMemory* GetFaviconResourceBytes(
31       ui::ScaleFactor scale_factor);
32 
33   // Instantiates the implementor of the mojom::PageHandlerFactory mojo
34   // interface passing the pending receiver that will be internally bound.
35   void BindInterface(
36       mojo::PendingReceiver<downloads::mojom::PageHandlerFactory> receiver);
37 
38  private:
39   // downloads::mojom::PageHandlerFactory:
40   void CreatePageHandler(
41       mojo::PendingRemote<downloads::mojom::Page> page,
42       mojo::PendingReceiver<downloads::mojom::PageHandler> receiver) override;
43 
44   std::unique_ptr<DownloadsDOMHandler> page_handler_;
45 
46   mojo::Receiver<downloads::mojom::PageHandlerFactory> page_factory_receiver_{
47       this};
48 
49   WEB_UI_CONTROLLER_TYPE_DECL();
50 
51   DISALLOW_COPY_AND_ASSIGN(DownloadsUI);
52 };
53 
54 #endif  // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_DOWNLOADS_UI_H_
55