• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "libcef/browser/request_context_handler_map.h"
6 
7 #include "libcef/common/frame_util.h"
8 
9 CefRequestContextHandlerMap::CefRequestContextHandlerMap() = default;
10 CefRequestContextHandlerMap::~CefRequestContextHandlerMap() = default;
11 
AddHandler(const content::GlobalRenderFrameHostId & global_id,CefRefPtr<CefRequestContextHandler> handler)12 void CefRequestContextHandlerMap::AddHandler(
13     const content::GlobalRenderFrameHostId& global_id,
14     CefRefPtr<CefRequestContextHandler> handler) {
15   DCHECK(frame_util::IsValidGlobalId(global_id));
16   DCHECK(handler);
17 
18   render_id_handler_map_.insert(std::make_pair(global_id, handler));
19 }
20 
RemoveHandler(const content::GlobalRenderFrameHostId & global_id)21 void CefRequestContextHandlerMap::RemoveHandler(
22     const content::GlobalRenderFrameHostId& global_id) {
23   DCHECK(frame_util::IsValidGlobalId(global_id));
24 
25   auto it1 = render_id_handler_map_.find(global_id);
26   if (it1 != render_id_handler_map_.end())
27     render_id_handler_map_.erase(it1);
28 }
29 
GetHandler(const content::GlobalRenderFrameHostId & global_id,bool require_frame_match) const30 CefRefPtr<CefRequestContextHandler> CefRequestContextHandlerMap::GetHandler(
31     const content::GlobalRenderFrameHostId& global_id,
32     bool require_frame_match) const {
33   if (frame_util::IsValidGlobalId(global_id)) {
34     const auto it1 = render_id_handler_map_.find(global_id);
35     if (it1 != render_id_handler_map_.end())
36       return it1->second;
37   }
38 
39   if (frame_util::IsValidChildId(global_id.child_id) && !require_frame_match) {
40     // Choose an arbitrary handler for the same process.
41     for (auto& kv : render_id_handler_map_) {
42       if (kv.first.child_id == global_id.child_id)
43         return kv.second;
44     }
45   }
46 
47   return nullptr;
48 }
49