1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_ 6 #define CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_ 7 #pragma once 8 9 #include "include/cef_request_context.h" 10 #include "include/cef_request_context_handler.h" 11 #include "include/cef_scheme.h" 12 13 #include "libcef/browser/request_context_handler_map.h" 14 15 #include "content/public/browser/browser_thread.h" 16 17 namespace content { 18 struct GlobalRenderFrameHostId; 19 } 20 21 class GURL; 22 23 // Stores state that will be accessed on the IO thread. Life span is controlled 24 // by CefBrowserContext. Created on the UI thread but accessed and destroyed on 25 // the IO thread. See browser_context.h for an object relationship diagram. 26 class CefIOThreadState : public base::RefCountedThreadSafe< 27 CefIOThreadState, 28 content::BrowserThread::DeleteOnIOThread> { 29 public: 30 CefIOThreadState(); 31 32 CefIOThreadState(const CefIOThreadState&) = delete; 33 CefIOThreadState& operator=(const CefIOThreadState&) = delete; 34 35 // See comments in CefRequestContextHandlerMap. 36 void AddHandler(const content::GlobalRenderFrameHostId& global_id, 37 CefRefPtr<CefRequestContextHandler> handler); 38 void RemoveHandler(const content::GlobalRenderFrameHostId& global_id); 39 CefRefPtr<CefRequestContextHandler> GetHandler( 40 const content::GlobalRenderFrameHostId& global_id, 41 bool require_frame_match) const; 42 43 // Manage scheme handler factories associated with this context. 44 void RegisterSchemeHandlerFactory(const std::string& scheme_name, 45 const std::string& domain_name, 46 CefRefPtr<CefSchemeHandlerFactory> factory); 47 void ClearSchemeHandlerFactories(); 48 CefRefPtr<CefSchemeHandlerFactory> GetSchemeHandlerFactory(const GURL& url); 49 50 private: 51 friend struct content::BrowserThread::DeleteOnThread< 52 content::BrowserThread::IO>; 53 friend class base::DeleteHelper<CefIOThreadState>; 54 55 ~CefIOThreadState(); 56 57 void InitOnIOThread(); 58 59 // Map IDs to CefRequestContextHandler objects. 60 CefRequestContextHandlerMap handler_map_; 61 62 // Map (scheme, domain) to factories. 63 using SchemeHandlerFactoryMap = std::map<std::pair<std::string, std::string>, 64 CefRefPtr<CefSchemeHandlerFactory>>; 65 SchemeHandlerFactoryMap scheme_handler_factory_map_; 66 }; 67 68 #endif // CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_ 69