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 class GURL; 18 19 // Stores state that will be accessed on the IO thread. Life span is controlled 20 // by CefBrowserContext. Created on the UI thread but accessed and destroyed on 21 // the IO thread. See browser_context.h for an object relationship diagram. 22 class CefIOThreadState : public base::RefCountedThreadSafe< 23 CefIOThreadState, 24 content::BrowserThread::DeleteOnIOThread> { 25 public: 26 CefIOThreadState(); 27 28 // See comments in CefRequestContextHandlerMap. 29 void AddHandler(int render_process_id, 30 int render_frame_id, 31 int frame_tree_node_id, 32 CefRefPtr<CefRequestContextHandler> handler); 33 void RemoveHandler(int render_process_id, 34 int render_frame_id, 35 int frame_tree_node_id); 36 CefRefPtr<CefRequestContextHandler> GetHandler( 37 int render_process_id, 38 int render_frame_id, 39 int frame_tree_node_id, 40 bool require_frame_match) const; 41 42 // Manage scheme handler factories associated with this context. 43 void RegisterSchemeHandlerFactory(const std::string& scheme_name, 44 const std::string& domain_name, 45 CefRefPtr<CefSchemeHandlerFactory> factory); 46 void ClearSchemeHandlerFactories(); 47 CefRefPtr<CefSchemeHandlerFactory> GetSchemeHandlerFactory(const GURL& url); 48 49 private: 50 friend struct content::BrowserThread::DeleteOnThread< 51 content::BrowserThread::IO>; 52 friend class base::DeleteHelper<CefIOThreadState>; 53 54 ~CefIOThreadState(); 55 56 void InitOnIOThread(); 57 58 // Map IDs to CefRequestContextHandler objects. 59 CefRequestContextHandlerMap handler_map_; 60 61 // Map (scheme, domain) to factories. 62 typedef std::map<std::pair<std::string, std::string>, 63 CefRefPtr<CefSchemeHandlerFactory>> 64 SchemeHandlerFactoryMap; 65 SchemeHandlerFactoryMap scheme_handler_factory_map_; 66 67 DISALLOW_COPY_AND_ASSIGN(CefIOThreadState); 68 }; 69 70 #endif // CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_ 71