protocol_registry.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const HandlersMap& handlers() const { return handlers_; }
  26. bool RegisterProtocol(ProtocolType type,
  27. const std::string& scheme,
  28. const ProtocolHandler& handler);
  29. bool UnregisterProtocol(const std::string& scheme);
  30. bool IsProtocolRegistered(const std::string& scheme);
  31. bool InterceptProtocol(ProtocolType type,
  32. const std::string& scheme,
  33. const ProtocolHandler& handler);
  34. bool UninterceptProtocol(const std::string& scheme);
  35. bool IsProtocolIntercepted(const std::string& scheme);
  36. private:
  37. friend class ElectronBrowserContext;
  38. ProtocolRegistry();
  39. HandlersMap handlers_;
  40. HandlersMap intercept_handlers_;
  41. };
  42. } // namespace electron
  43. #endif // ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_