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 "content/public/browser/global_routing_id.h" 15 16 // Tracks CefRequestContextHandler associations on a single thread. 17 class CefRequestContextHandlerMap { 18 public: 19 CefRequestContextHandlerMap(); 20 21 CefRequestContextHandlerMap(const CefRequestContextHandlerMap&) = delete; 22 CefRequestContextHandlerMap& operator=(const CefRequestContextHandlerMap&) = 23 delete; 24 25 ~CefRequestContextHandlerMap(); 26 27 // Keep track of handlers associated with specific frames. This information 28 // originates from frame create/delete notifications in 29 // CefBrowserContentsDelegate or CefMimeHandlerViewGuestDelegate which are 30 // forwarded via CefRequestContextImpl and CefBrowserContext. 31 void AddHandler(const content::GlobalRenderFrameHostId& global_id, 32 CefRefPtr<CefRequestContextHandler> handler); 33 void RemoveHandler(const content::GlobalRenderFrameHostId& global_id); 34 35 // Returns the handler that matches the specified IDs. If 36 // |require_frame_match| is true only exact matches will be returned. If 37 // |require_frame_match| is false, and there is not an exact match, then the 38 // first handler for the same |global_id.child_id| will be returned. 39 CefRefPtr<CefRequestContextHandler> GetHandler( 40 const content::GlobalRenderFrameHostId& global_id, 41 bool require_frame_match) const; 42 43 private: 44 // Map of global ID to handler. These IDs are guaranteed to uniquely 45 // identify a RFH for its complete lifespan. See documentation on 46 // RenderFrameHost::GetFrameTreeNodeId() for background. 47 using RenderIdHandlerMap = std::map<content::GlobalRenderFrameHostId, 48 CefRefPtr<CefRequestContextHandler>>; 49 RenderIdHandlerMap render_id_handler_map_; 50 }; 51 52 #endif // CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_HANDLER_MAP_ 53