electron/shell/browser/protocol_registry.h
trop[bot] f08c6f2e85
perf: prefer GURL string_view getters (#43471)
* chore: avoid double-call to url.scheme() in WebContentsZoomController::SetZoomMode()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.scheme_piece() in GetAppInfoHelperForProtocol()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.scheme_piece() in Browser::GetApplicationNameForProtocol()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add std::less<> to HandlersMap

This lets us search it using string_view keys

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: ProtocolRegistry::FindRegistered() now takes a std::string_view

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.scheme_piece() in InspectableWebContents::LoadNetworkResource()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: ProtocolRegistry::FindIntercepted() now takes a std::string_view

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.scheme_piece() in SimpleURLLoaderWrapper::GetURLLoaderFactoryForURL()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.scheme_piece() in ProxyingURLLoaderFactory::CreateLoaderAndStart()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.host_piece() in ElectronWebUIControllerFactory::GetWebUIType()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use gurl.host_piece() in ElectronWebUIControllerFactory::CreateWebUIControllerForURL()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-08-23 20:58:59 -05:00

65 lines
1.9 KiB
C++

// Copyright (c) 2020 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_
#define ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_
#include <string>
#include <string_view>
#include "content/public/browser/content_browser_client.h"
#include "shell/browser/net/electron_url_loader_factory.h"
namespace content {
class BrowserContext;
}
namespace electron {
class ProtocolRegistry {
public:
~ProtocolRegistry();
static ProtocolRegistry* FromBrowserContext(content::BrowserContext*);
using URLLoaderFactoryType =
content::ContentBrowserClient::URLLoaderFactoryType;
void RegisterURLLoaderFactories(
content::ContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories,
bool allow_file_access);
mojo::PendingRemote<network::mojom::URLLoaderFactory>
CreateNonNetworkNavigationURLLoaderFactory(const std::string& scheme);
const HandlersMap& intercept_handlers() const { return intercept_handlers_; }
bool RegisterProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler);
bool UnregisterProtocol(const std::string& scheme);
[[nodiscard]] const HandlersMap::mapped_type* FindRegistered(
std::string_view scheme) const;
bool InterceptProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler);
bool UninterceptProtocol(const std::string& scheme);
[[nodiscard]] const HandlersMap::mapped_type* FindIntercepted(
std::string_view scheme) const;
private:
friend class ElectronBrowserContext;
ProtocolRegistry();
HandlersMap handlers_;
HandlersMap intercept_handlers_;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_PROTOCOL_REGISTRY_H_