untrusted_web_ui_controller_factory.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 UI_WEBUI_UNTRUSTED_WEB_UI_CONTROLLER_FACTORY_H_
  5. #define UI_WEBUI_UNTRUSTED_WEB_UI_CONTROLLER_FACTORY_H_
  6. #include "content/public/browser/web_ui_controller_factory.h"
  7. class GURL;
  8. namespace content {
  9. class BrowserContext;
  10. class WebUIController;
  11. class WebUIConfig;
  12. } // namespace content
  13. namespace ui {
  14. // Factory class for WebUIControllers for chrome-untrusted:// URLs.
  15. //
  16. // To add a new WebUIController, subclass ui::WebUIConfig and add it to
  17. // `CreateConfigs()` in the .cc.
  18. class UntrustedWebUIControllerFactory : public content::WebUIControllerFactory {
  19. public:
  20. UntrustedWebUIControllerFactory();
  21. ~UntrustedWebUIControllerFactory() override;
  22. UntrustedWebUIControllerFactory(const UntrustedWebUIControllerFactory&) =
  23. delete;
  24. UntrustedWebUIControllerFactory& operator=(
  25. const UntrustedWebUIControllerFactory&) = delete;
  26. content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
  27. const GURL& url) final;
  28. bool UseWebUIForURL(content::BrowserContext* browser_context,
  29. const GURL& url) final;
  30. std::unique_ptr<content::WebUIController> CreateWebUIControllerForURL(
  31. content::WebUI* web_ui,
  32. const GURL& url) final;
  33. protected:
  34. // Map of hosts to their corresponding WebUIConfigs.
  35. using WebUIConfigMap =
  36. base::flat_map<std::string, std::unique_ptr<content::WebUIConfig>>;
  37. virtual const WebUIConfigMap& GetWebUIConfigMap() = 0;
  38. private:
  39. // Returns the WebUIConfig for |url| if it's registered and the WebUI is
  40. // enabled. (WebUIs can be disabled based on the profile or feature flags.)
  41. content::WebUIConfig* GetConfigIfWebUIEnabled(
  42. content::BrowserContext* browser_context,
  43. const GURL& url);
  44. };
  45. } // namespace ui
  46. #endif // UI_WEBUI_UNTRUSTED_WEB_UI_CONTROLLER_FACTORY_H_