sample_system_web_app_ui.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 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_SAMPLE_SYSTEM_WEB_APP_UI_SAMPLE_SYSTEM_WEB_APP_UI_H_
  5. #define ASH_WEBUI_SAMPLE_SYSTEM_WEB_APP_UI_SAMPLE_SYSTEM_WEB_APP_UI_H_
  6. #if defined(OFFICIAL_BUILD)
  7. #error Sample System Web App should only be included in unofficial builds.
  8. #endif
  9. #include <memory>
  10. #include "ash/webui/sample_system_web_app_ui/mojom/sample_system_web_app_ui.mojom.h"
  11. #include "ash/webui/sample_system_web_app_ui/sample_page_handler.h"
  12. #include "ash/webui/sample_system_web_app_ui/url_constants.h"
  13. #include "ash/webui/system_apps/public/system_web_app_ui_config.h"
  14. #include "content/public/browser/webui_config.h"
  15. #include "mojo/public/cpp/bindings/pending_receiver.h"
  16. #include "mojo/public/cpp/bindings/pending_remote.h"
  17. #include "mojo/public/cpp/bindings/receiver.h"
  18. #include "ui/webui/mojo_web_ui_controller.h"
  19. namespace ash {
  20. class SampleSystemWebAppUI;
  21. // The WebUIConfig for chrome://sample-system-web-app/.
  22. class SampleSystemWebAppUIConfig
  23. : public SystemWebAppUIConfig<SampleSystemWebAppUI> {
  24. public:
  25. SampleSystemWebAppUIConfig()
  26. : SystemWebAppUIConfig(kChromeUISampleSystemWebAppHost,
  27. SystemWebAppType::SAMPLE) {}
  28. };
  29. class SampleSystemWebAppUI : public ui::MojoWebUIController,
  30. public mojom::sample_swa::PageHandlerFactory {
  31. public:
  32. explicit SampleSystemWebAppUI(content::WebUI* web_ui);
  33. SampleSystemWebAppUI(const SampleSystemWebAppUI&) = delete;
  34. SampleSystemWebAppUI& operator=(const SampleSystemWebAppUI&) = delete;
  35. ~SampleSystemWebAppUI() override;
  36. void BindInterface(
  37. mojo::PendingReceiver<mojom::sample_swa::PageHandlerFactory> factory);
  38. void CreateParentPage(
  39. mojo::PendingRemote<mojom::sample_swa::ChildUntrustedPage> child_page,
  40. mojo::PendingReceiver<mojom::sample_swa::ParentTrustedPage> parent_page);
  41. private:
  42. // mojom::sample_swa::PageHandlerFactory:
  43. void CreatePageHandler(
  44. mojo::PendingReceiver<mojom::sample_swa::PageHandler> handler,
  45. mojo::PendingRemote<mojom::sample_swa::Page> page) override;
  46. mojo::Receiver<mojom::sample_swa::PageHandlerFactory> sample_page_factory_{
  47. this};
  48. // Handles requests from the user visible page. Created when navigating to the
  49. // WebUI page, should live as long as the WebUIController. In most cases this
  50. // matches the lifetime of the page. If the WebUIController is re-used for
  51. // same-origin navigations, it is recreated when the navigation commits.
  52. std::unique_ptr<PageHandler> sample_page_handler_;
  53. // Called navigating to a WebUI page to create page handler.
  54. void WebUIPrimaryPageChanged(content::Page& page) override;
  55. WEB_UI_CONTROLLER_TYPE_DECL();
  56. };
  57. } // namespace ash
  58. #endif // ASH_WEBUI_SAMPLE_SYSTEM_WEB_APP_UI_SAMPLE_SYSTEM_WEB_APP_UI_H_