cef/libcef/browser/request_context_handler_map.h
Marshall Greenblatt 955097ea77 Remove usage of FrameTreeNode IDs (see issue #2421)
With the introduction of prerendering in Chromium it is now possible for
RenderFrameHosts (RFH) to move between FrameTrees. As a consequence we can no
longer rely on FrameTreeNode IDs to uniquely identify a RFH over its lifespan.
We must now switch to using GlobalRenderFrameHostId (child_id, frame_routing_id)
instead for that purpose. Additionally, we simplify existing code by using the
GlobalRenderFrameHostId struct in all places that previously used a
(render_process_id, render_frame_id) pair, since these concepts are equivalent.

See https://crbug.com/1179502#c8 for additional background.
2021-08-19 19:41:44 -04:00

51 lines
2.1 KiB
C++

// 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.
#ifndef CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_
#define CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_
#pragma once
#include <map>
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "base/macros.h"
#include "content/public/browser/global_routing_id.h"
// Tracks CefRequestContextHandler associations on a single thread.
class CefRequestContextHandlerMap {
public:
CefRequestContextHandlerMap();
~CefRequestContextHandlerMap();
// Keep track of handlers associated with specific frames. This information
// originates from frame create/delete notifications in
// CefBrowserContentsDelegate or CefMimeHandlerViewGuestDelegate which are
// forwarded via CefRequestContextImpl and CefBrowserContext.
void AddHandler(const content::GlobalRenderFrameHostId& global_id,
CefRefPtr<CefRequestContextHandler> handler);
void RemoveHandler(const content::GlobalRenderFrameHostId& global_id);
// Returns the handler that matches the specified IDs. If
// |require_frame_match| is true only exact matches will be returned. If
// |require_frame_match| is false, and there is not an exact match, then the
// first handler for the same |global_id.child_id| will be returned.
CefRefPtr<CefRequestContextHandler> GetHandler(
const content::GlobalRenderFrameHostId& global_id,
bool require_frame_match) const;
private:
// Map of global ID to handler. These IDs are guaranteed to uniquely
// identify a RFH for its complete lifespan. See documentation on
// RenderFrameHost::GetFrameTreeNodeId() for background.
using RenderIdHandlerMap = std::map<content::GlobalRenderFrameHostId,
CefRefPtr<CefRequestContextHandler>>;
RenderIdHandlerMap render_id_handler_map_;
DISALLOW_COPY_AND_ASSIGN(CefRequestContextHandlerMap);
};
#endif // CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_