refactor: ginify protocol (#22812)
This commit is contained in:
parent
b3d3ac4e0f
commit
e73d5e3db5
12 changed files with 192 additions and 112 deletions
58
shell/browser/protocol_registry.cc
Normal file
58
shell/browser/protocol_registry.cc
Normal file
|
@ -0,0 +1,58 @@
|
|||
// 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.
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "shell/browser/electron_browser_context.h"
|
||||
#include "shell/browser/protocol_registry.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
// static
|
||||
ProtocolRegistry* ProtocolRegistry::FromBrowserContext(
|
||||
content::BrowserContext* context) {
|
||||
return static_cast<ElectronBrowserContext*>(context)->protocol_registry();
|
||||
}
|
||||
|
||||
ProtocolRegistry::ProtocolRegistry() {}
|
||||
|
||||
ProtocolRegistry::~ProtocolRegistry() = default;
|
||||
|
||||
void ProtocolRegistry::RegisterURLLoaderFactories(
|
||||
content::ContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories) {
|
||||
for (const auto& it : handlers_) {
|
||||
factories->emplace(it.first, std::make_unique<ElectronURLLoaderFactory>(
|
||||
it.second.first, it.second.second));
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtocolRegistry::RegisterProtocol(ProtocolType type,
|
||||
const std::string& scheme,
|
||||
const ProtocolHandler& handler) {
|
||||
return base::TryEmplace(handlers_, scheme, type, handler).second;
|
||||
}
|
||||
|
||||
bool ProtocolRegistry::UnregisterProtocol(const std::string& scheme) {
|
||||
return handlers_.erase(scheme) != 0;
|
||||
}
|
||||
|
||||
bool ProtocolRegistry::IsProtocolRegistered(const std::string& scheme) {
|
||||
return base::Contains(handlers_, scheme);
|
||||
}
|
||||
|
||||
bool ProtocolRegistry::InterceptProtocol(ProtocolType type,
|
||||
const std::string& scheme,
|
||||
const ProtocolHandler& handler) {
|
||||
return base::TryEmplace(intercept_handlers_, scheme, type, handler).second;
|
||||
}
|
||||
|
||||
bool ProtocolRegistry::UninterceptProtocol(const std::string& scheme) {
|
||||
return intercept_handlers_.erase(scheme) != 0;
|
||||
}
|
||||
|
||||
bool ProtocolRegistry::IsProtocolIntercepted(const std::string& scheme) {
|
||||
return base::Contains(intercept_handlers_, scheme);
|
||||
}
|
||||
|
||||
} // namespace electron
|
Loading…
Add table
Add a link
Reference in a new issue