2019-10-01 15:55:16 +02:00
|
|
|
// Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/request_context_handler_map.h"
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
#include "libcef/common/frame_util.h"
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
CefRequestContextHandlerMap::CefRequestContextHandlerMap() = default;
|
|
|
|
CefRequestContextHandlerMap::~CefRequestContextHandlerMap() = default;
|
|
|
|
|
|
|
|
void CefRequestContextHandlerMap::AddHandler(
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
2019-10-01 15:55:16 +02:00
|
|
|
CefRefPtr<CefRequestContextHandler> handler) {
|
2021-08-19 23:07:44 +02:00
|
|
|
DCHECK(frame_util::IsValidGlobalId(global_id));
|
2019-10-01 15:55:16 +02:00
|
|
|
DCHECK(handler);
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
render_id_handler_map_.insert(std::make_pair(global_id, handler));
|
2019-10-01 15:55:16 +02:00
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
void CefRequestContextHandlerMap::RemoveHandler(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id) {
|
|
|
|
DCHECK(frame_util::IsValidGlobalId(global_id));
|
2019-10-01 15:55:16 +02:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
auto it1 = render_id_handler_map_.find(global_id);
|
2019-10-01 15:55:16 +02:00
|
|
|
if (it1 != render_id_handler_map_.end())
|
|
|
|
render_id_handler_map_.erase(it1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContextHandler> CefRequestContextHandlerMap::GetHandler(
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
2019-10-01 15:55:16 +02:00
|
|
|
bool require_frame_match) const {
|
2021-08-19 23:07:44 +02:00
|
|
|
if (frame_util::IsValidGlobalId(global_id)) {
|
|
|
|
const auto it1 = render_id_handler_map_.find(global_id);
|
2019-10-01 15:55:16 +02:00
|
|
|
if (it1 != render_id_handler_map_.end())
|
|
|
|
return it1->second;
|
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
if (frame_util::IsValidChildId(global_id.child_id) && !require_frame_match) {
|
2019-10-01 15:55:16 +02:00
|
|
|
// Choose an arbitrary handler for the same process.
|
|
|
|
for (auto& kv : render_id_handler_map_) {
|
2021-08-19 23:07:44 +02:00
|
|
|
if (kv.first.child_id == global_id.child_id)
|
2019-10-01 15:55:16 +02:00
|
|
|
return kv.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|