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

ash / webui / files_internals / files_internals_ui.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WEBUI_FILES_INTERNALS_FILES_INTERNALS_UI_H_
#define ASH_WEBUI_FILES_INTERNALS_FILES_INTERNALS_UI_H_

#include "ash/webui/common/chrome_os_webui_config.h"
#include "ash/webui/files_internals/files_internals_page_handler.h"
#include "ash/webui/files_internals/files_internals_ui_delegate.h"
#include "ash/webui/files_internals/mojom/files_internals.mojom.h"
#include "ash/webui/files_internals/url_constants.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/url_constants.h"
#include "ui/webui/mojo_web_ui_controller.h"

namespace ash {

class FilesInternalsUI;

// WebUIConfig for chrome://files-internals
class FilesInternalsUIConfig : public ChromeOSWebUIConfig<FilesInternalsUI> {
 public:
  explicit FilesInternalsUIConfig(
      CreateWebUIControllerFunc create_controller_func)
      : ChromeOSWebUIConfig(content::kChromeUIScheme,
                            ash::kChromeUIFilesInternalsHost,
                            create_controller_func) {}
};

// WebUIController for chrome://files-internals/.
class FilesInternalsUI : public ui::MojoWebUIController {
 public:
  FilesInternalsUI(content::WebUI* web_ui,
                   std::unique_ptr<FilesInternalsUIDelegate> delegate);
  FilesInternalsUI(const FilesInternalsUI&) = delete;
  FilesInternalsUI& operator=(const FilesInternalsUI&) = delete;
  ~FilesInternalsUI() override;

  void BindInterface(
      mojo::PendingReceiver<mojom::files_internals::PageHandler> receiver);

  FilesInternalsUIDelegate* delegate();

 private:
  void CallSetRequestFilter(content::WebUIDataSource* data_source);
  void HandleRequest(const std::string& url,
                     content::WebUIDataSource::GotDataCallback callback);

  WEB_UI_CONTROLLER_TYPE_DECL();

  std::unique_ptr<FilesInternalsUIDelegate> delegate_;
  std::unique_ptr<FilesInternalsPageHandler> page_handler_;

  base::WeakPtrFactory<FilesInternalsUI> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_WEBUI_FILES_INTERNALS_FILES_INTERNALS_UI_H_