protocol_registry.h 1.7 KB

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