demo_mode_app_untrusted_ui.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021 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_DEMO_MODE_APP_UI_DEMO_MODE_APP_UNTRUSTED_UI_H_
  5. #define ASH_WEBUI_DEMO_MODE_APP_UI_DEMO_MODE_APP_UNTRUSTED_UI_H_
  6. #include "ash/webui/demo_mode_app_ui/mojom/demo_mode_app_untrusted_ui.mojom.h"
  7. #include "base/files/file_path.h"
  8. #include "content/public/browser/web_ui_data_source.h"
  9. #include "content/public/browser/webui_config.h"
  10. #include "mojo/public/cpp/bindings/pending_receiver.h"
  11. #include "mojo/public/cpp/bindings/pending_remote.h"
  12. #include "mojo/public/cpp/bindings/receiver.h"
  13. #include "ui/webui/untrusted_web_ui_controller.h"
  14. namespace ash {
  15. class DemoModeAppUntrustedUIConfig : public content::WebUIConfig {
  16. public:
  17. explicit DemoModeAppUntrustedUIConfig(
  18. base::RepeatingCallback<base::FilePath()> component_path_producer);
  19. ~DemoModeAppUntrustedUIConfig() override;
  20. std::unique_ptr<content::WebUIController> CreateWebUIController(
  21. content::WebUI* web_ui) override;
  22. bool IsWebUIEnabled(content::BrowserContext* browser_context) override;
  23. private:
  24. // Callback that provides the demo app component path to the WebUI controller.
  25. // The path can't be passed directly into the DemoModeAppUntrustedUIConfig
  26. // constructor because the config is created during startup, whereas the
  27. // component isn't loaded until the active demo session has started
  28. //
  29. // TODO(b/234174220): Consider creating a Delegate class that provides the
  30. // component path instead
  31. base::RepeatingCallback<base::FilePath()> component_path_producer_;
  32. };
  33. // The WebUI for chrome-untrusted://demo-mode-app
  34. class DemoModeAppUntrustedUI
  35. : public ui::UntrustedWebUIController,
  36. public mojom::demo_mode::UntrustedPageHandlerFactory {
  37. public:
  38. explicit DemoModeAppUntrustedUI(content::WebUI* web_ui,
  39. base::FilePath component_base_path);
  40. ~DemoModeAppUntrustedUI() override;
  41. DemoModeAppUntrustedUI(const DemoModeAppUntrustedUI&) = delete;
  42. DemoModeAppUntrustedUI& operator=(const DemoModeAppUntrustedUI&) = delete;
  43. void BindInterface(
  44. mojo::PendingReceiver<mojom::demo_mode::UntrustedPageHandlerFactory>
  45. factory);
  46. // Visible for testing
  47. static void SourceDataFromComponent(
  48. const base::FilePath& component_path,
  49. const std::string& resource_path,
  50. content::WebUIDataSource::GotDataCallback callback);
  51. private:
  52. // mojom::DemoModePageHandlerFactory
  53. void CreatePageHandler(
  54. mojo::PendingReceiver<mojom::demo_mode::UntrustedPageHandler> handler)
  55. override;
  56. mojo::Receiver<mojom::demo_mode::UntrustedPageHandlerFactory>
  57. demo_mode_page_factory_{this};
  58. std::unique_ptr<mojom::demo_mode::UntrustedPageHandler>
  59. demo_mode_page_handler_;
  60. WEB_UI_CONTROLLER_TYPE_DECL();
  61. };
  62. } // namespace ash
  63. #endif // ASH_WEBUI_DEMO_MODE_APP_UI_DEMO_MODE_APP_UNTRUSTED_UI_H_