file_manager_ui.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2020 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. #ifndef ASH_WEBUI_FILE_MANAGER_FILE_MANAGER_UI_H_
  5. #define ASH_WEBUI_FILE_MANAGER_FILE_MANAGER_UI_H_
  6. #include <memory>
  7. #include "ash/webui/file_manager/file_manager_ui_delegate.h"
  8. #include "ash/webui/file_manager/mojom/file_manager.mojom.h"
  9. #include "content/public/browser/web_ui.h"
  10. #include "content/public/browser/web_ui_data_source.h"
  11. #include "mojo/public/cpp/bindings/pending_receiver.h"
  12. #include "mojo/public/cpp/bindings/pending_remote.h"
  13. #include "mojo/public/cpp/bindings/receiver.h"
  14. #include "ui/web_dialogs/web_dialog_ui.h"
  15. namespace ash {
  16. namespace file_manager {
  17. class FileManagerPageHandler;
  18. // WebUI controller for chrome://file-manager.
  19. class FileManagerUI : public ui::MojoWebDialogUI,
  20. public mojom::PageHandlerFactory {
  21. public:
  22. FileManagerUI(content::WebUI* web_ui,
  23. std::unique_ptr<FileManagerUIDelegate> delegate);
  24. ~FileManagerUI() override;
  25. FileManagerUI(const FileManagerUI&) = delete;
  26. FileManagerUI& operator=(const FileManagerUI&) = delete;
  27. void BindInterface(
  28. mojo::PendingReceiver<mojom::PageHandlerFactory> pending_receiver);
  29. const FileManagerUIDelegate* delegate() { return delegate_.get(); }
  30. // Get the number of open File Manager windows.
  31. // Should be called on UI thread.
  32. static int GetNumInstances();
  33. private:
  34. content::WebUIDataSource* CreateTrustedAppDataSource(int window_number);
  35. // mojom::PageHandlerFactory:
  36. void CreatePageHandler(
  37. mojo::PendingRemote<mojom::Page> pending_page,
  38. mojo::PendingReceiver<mojom::PageHandler> pending_page_handler) override;
  39. std::unique_ptr<FileManagerUIDelegate> delegate_;
  40. mojo::Receiver<mojom::PageHandlerFactory> page_factory_receiver_{this};
  41. std::unique_ptr<FileManagerPageHandler> page_handler_;
  42. // Counts the number of active Files SWA instances. This counter goes up every
  43. // time a new window is opened and down every time a window is closed.
  44. static inline int instance_count_ = 0;
  45. // Counts the total number of windows opened. Unlike the instance_count_ this
  46. // counter never is decremented.
  47. static inline int window_counter_ = 0;
  48. WEB_UI_CONTROLLER_TYPE_DECL();
  49. };
  50. } // namespace file_manager
  51. } // namespace ash
  52. #endif // ASH_WEBUI_FILE_MANAGER_FILE_MANAGER_UI_H_