protocol_registry.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2020 Slack Technologies, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_
  5. #define ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_
  6. #include <string>
  7. #include "content/public/browser/content_browser_client.h"
  8. #include "shell/browser/net/electron_url_loader_factory.h"
  9. namespace content {
  10. class BrowserContext;
  11. }
  12. namespace electron {
  13. class ProtocolRegistry {
  14. public:
  15. ~ProtocolRegistry();
  16. static ProtocolRegistry* FromBrowserContext(content::BrowserContext*);
  17. using URLLoaderFactoryType =
  18. content::ContentBrowserClient::URLLoaderFactoryType;
  19. void RegisterURLLoaderFactories(
  20. content::ContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories,
  21. bool allow_file_access);
  22. mojo::PendingRemote<network::mojom::URLLoaderFactory>
  23. CreateNonNetworkNavigationURLLoaderFactory(const std::string& scheme);
  24. const HandlersMap& intercept_handlers() const { return intercept_handlers_; }
  25. bool RegisterProtocol(ProtocolType type,
  26. const std::string& scheme,
  27. const ProtocolHandler& handler);
  28. bool UnregisterProtocol(const std::string& scheme);
  29. [[nodiscard]] const HandlersMap::mapped_type* FindRegistered(
  30. const std::string& scheme) const;
  31. bool InterceptProtocol(ProtocolType type,
  32. const std::string& scheme,
  33. const ProtocolHandler& handler);
  34. bool UninterceptProtocol(const std::string& scheme);
  35. [[nodiscard]] const HandlersMap::mapped_type* FindIntercepted(
  36. const std::string& scheme) const;
  37. private:
  38. friend class ElectronBrowserContext;
  39. ProtocolRegistry();
  40. HandlersMap handlers_;
  41. HandlersMap intercept_handlers_;
  42. };
  43. } // namespace electron
  44. #endif // ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_