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 #ifndef CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_ 6 #define CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_ 7 #pragma once 8 9 #include <map> 10 11 #include "include/cef_request_context.h" 12 #include "include/cef_request_context_handler.h" 13 14 #include "base/macros.h" 15 16 // Tracks CefRequestContextHandler associations on a single thread. 17 class CefRequestContextHandlerMap { 18 public: 19 CefRequestContextHandlerMap(); 20 ~CefRequestContextHandlerMap(); 21 22 // Keep track of handlers associated with specific frames. This information 23 // originates from frame create/delete notifications in 24 // CefBrowserContentsDelegate or CefMimeHandlerViewGuestDelegate which are 25 // forwarded via CefRequestContextImpl and CefBrowserContext. 26 void AddHandler(int render_process_id, 27 int render_frame_id, 28 int frame_tree_node_id, 29 CefRefPtr<CefRequestContextHandler> handler); 30 void RemoveHandler(int render_process_id, 31 int render_frame_id, 32 int frame_tree_node_id); 33 34 // Returns the handler that matches the specified IDs. Pass -1 for unknown 35 // values. If |require_frame_match| is true only exact matches will be 36 // returned. If |require_frame_match| is false, and there is not an exact 37 // match, then the first handler for the same |render_process_id| will be 38 // returned. 39 CefRefPtr<CefRequestContextHandler> GetHandler( 40 int render_process_id, 41 int render_frame_id, 42 int frame_tree_node_id, 43 bool require_frame_match) const; 44 45 private: 46 // Map of (render_process_id, render_frame_id) to handler. 47 typedef std::map<std::pair<int, int>, CefRefPtr<CefRequestContextHandler>> 48 RenderIdHandlerMap; 49 RenderIdHandlerMap render_id_handler_map_; 50 51 // Map of frame_tree_node_id to handler. Keeping this map is necessary 52 // because, when navigating the main frame, a new (pre-commit) network request 53 // will be created before the RenderFrameHost. Consequently we can't rely 54 // on valid render IDs. See https://crbug.com/776884 for background. 55 typedef std::map<int, CefRefPtr<CefRequestContextHandler>> NodeIdHandlerMap; 56 NodeIdHandlerMap node_id_handler_map_; 57 58 DISALLOW_COPY_AND_ASSIGN(CefRequestContextHandlerMap); 59 }; 60 61 #endif // CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_ 62