1 // Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can 3 // be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_RENDERER_BROWSER_MANAGER_H_ 6 #define CEF_LIBCEF_RENDERER_BROWSER_MANAGER_H_ 7 #pragma once 8 9 #include <map> 10 #include <memory> 11 12 #include "include/internal/cef_ptr.h" 13 14 #include "base/optional.h" 15 16 namespace blink { 17 class WebFrame; 18 } 19 20 namespace content { 21 class RenderFrame; 22 class RenderView; 23 } // namespace content 24 25 struct Cef_CrossOriginWhiteListEntry_Params; 26 class CefBrowserImpl; 27 class CefGuestView; 28 class CefRenderFrameObserver; 29 30 // Singleton object for managing BrowserImpl instances. Only accessed on the 31 // main renderer thread. 32 class CefBrowserManager { 33 public: 34 CefBrowserManager(); 35 ~CefBrowserManager(); 36 37 // Returns this singleton instance of this class. 38 static CefBrowserManager* Get(); 39 40 // Called from ContentRendererClient methods of the same name. 41 void RenderThreadConnected(); 42 void RenderFrameCreated(content::RenderFrame* render_frame, 43 CefRenderFrameObserver* render_frame_observer, 44 bool& browser_created, 45 base::Optional<bool>& is_windowless); 46 void RenderViewCreated(content::RenderView* render_view, 47 bool& browser_created, 48 base::Optional<bool>& is_windowless); 49 void DevToolsAgentAttached(); 50 void DevToolsAgentDetached(); 51 52 // Returns the browser associated with the specified RenderView. 53 CefRefPtr<CefBrowserImpl> GetBrowserForView(content::RenderView* view); 54 55 // Returns the browser associated with the specified main WebFrame. 56 CefRefPtr<CefBrowserImpl> GetBrowserForMainFrame(blink::WebFrame* frame); 57 58 private: 59 friend class CefBrowserImpl; 60 friend class CefGuestView; 61 62 void WebKitInitialized(); 63 64 // Maybe create a new browser object, return the existing one, or return 65 // nullptr for guest views. 66 CefRefPtr<CefBrowserImpl> MaybeCreateBrowser( 67 content::RenderView* render_view, 68 content::RenderFrame* render_frame, 69 bool* browser_created, 70 base::Optional<bool>* is_windowless); 71 72 // Called from CefBrowserImpl::OnDestruct(). 73 void OnBrowserDestroyed(CefBrowserImpl* browser); 74 75 // Returns the guest view associated with the specified RenderView if any. 76 CefGuestView* GetGuestViewForView(content::RenderView* view); 77 78 // Called from CefGuestView::OnDestruct(). 79 void OnGuestViewDestroyed(CefGuestView* guest_view); 80 81 // Map of RenderView pointers to CefBrowserImpl references. 82 typedef std::map<content::RenderView*, CefRefPtr<CefBrowserImpl>> BrowserMap; 83 BrowserMap browsers_; 84 85 // Map of RenderView poiners to CefGuestView implementations. 86 typedef std::map<content::RenderView*, std::unique_ptr<CefGuestView>> 87 GuestViewMap; 88 GuestViewMap guest_views_; 89 90 // Cross-origin white list entries that need to be registered with WebKit. 91 typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList; 92 CrossOriginList cross_origin_whitelist_entries_; 93 94 int devtools_agent_count_ = 0; 95 int uncaught_exception_stack_size_ = 0; 96 97 DISALLOW_COPY_AND_ASSIGN(CefBrowserManager); 98 }; 99 100 #endif // CEF_LIBCEF_RENDERER_BROWSER_MANAGER_H_ 101