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_RENDER_MANAGER_H_ 6 #define CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_ 7 #pragma once 8 9 #include <map> 10 #include <memory> 11 12 #include "include/internal/cef_ptr.h" 13 14 #include "cef/libcef/common/mojom/cef.mojom.h" 15 #include "mojo/public/cpp/bindings/pending_receiver.h" 16 #include "mojo/public/cpp/bindings/receiver_set.h" 17 #include "mojo/public/cpp/bindings/remote.h" 18 #include "third_party/abseil-cpp/absl/types/optional.h" 19 20 namespace blink { 21 class WebFrame; 22 class WebView; 23 } // namespace blink 24 25 namespace content { 26 class RenderFrame; 27 class RenderView; 28 } // namespace content 29 30 namespace mojo { 31 class BinderMap; 32 } // namespace mojo 33 34 class CefBrowserImpl; 35 class CefGuestView; 36 class CefRenderFrameObserver; 37 38 // Singleton object for managing BrowserImpl instances. Only accessed on the 39 // main renderer thread. 40 class CefRenderManager : public cef::mojom::RenderManager { 41 public: 42 CefRenderManager(); 43 44 CefRenderManager(const CefRenderManager&) = delete; 45 CefRenderManager& operator=(const CefRenderManager&) = delete; 46 47 ~CefRenderManager(); 48 49 // Returns this singleton instance of this class. 50 static CefRenderManager* Get(); 51 52 // Called from ContentRendererClient methods of the same name. 53 void RenderThreadConnected(); 54 void RenderFrameCreated(content::RenderFrame* render_frame, 55 CefRenderFrameObserver* render_frame_observer, 56 bool& browser_created, 57 absl::optional<bool>& is_windowless); 58 void WebViewCreated(blink::WebView* web_view, 59 bool& browser_created, 60 absl::optional<bool>& is_windowless); 61 void DevToolsAgentAttached(); 62 void DevToolsAgentDetached(); 63 void ExposeInterfacesToBrowser(mojo::BinderMap* binders); 64 65 // Returns the browser associated with the specified RenderView. 66 CefRefPtr<CefBrowserImpl> GetBrowserForView(content::RenderView* view); 67 68 // Returns the browser associated with the specified main WebFrame. 69 CefRefPtr<CefBrowserImpl> GetBrowserForMainFrame(blink::WebFrame* frame); 70 71 // Connects to CefBrowserManager in the browser process. 72 mojo::Remote<cef::mojom::BrowserManager>& GetBrowserManager(); 73 74 // Returns true if this renderer process is hosting an extension. 75 static bool IsExtensionProcess(); 76 77 // Returns true if this renderer process is hosting a PDF. 78 static bool IsPdfProcess(); 79 80 private: 81 friend class CefBrowserImpl; 82 friend class CefGuestView; 83 84 // Binds receivers for the RenderManager interface. 85 void BindReceiver(mojo::PendingReceiver<cef::mojom::RenderManager> receiver); 86 87 // cef::mojom::RenderManager methods: 88 void ModifyCrossOriginWhitelistEntry( 89 bool add, 90 cef::mojom::CrossOriginWhiteListEntryPtr entry) override; 91 void ClearCrossOriginWhitelist() override; 92 93 void WebKitInitialized(); 94 95 // Maybe create a new browser object, return the existing one, or return 96 // nullptr for guest views. 97 CefRefPtr<CefBrowserImpl> MaybeCreateBrowser( 98 content::RenderView* render_view, 99 content::RenderFrame* render_frame, 100 bool* browser_created, 101 absl::optional<bool>* is_windowless); 102 103 // Called from CefBrowserImpl::OnDestruct(). 104 void OnBrowserDestroyed(CefBrowserImpl* browser); 105 106 // Returns the guest view associated with the specified RenderView if any. 107 CefGuestView* GetGuestViewForView(content::RenderView* view); 108 109 // Called from CefGuestView::OnDestruct(). 110 void OnGuestViewDestroyed(CefGuestView* guest_view); 111 112 // Map of RenderView pointers to CefBrowserImpl references. 113 using BrowserMap = std::map<content::RenderView*, CefRefPtr<CefBrowserImpl>>; 114 BrowserMap browsers_; 115 116 // Map of RenderView poiners to CefGuestView implementations. 117 using GuestViewMap = 118 std::map<content::RenderView*, std::unique_ptr<CefGuestView>>; 119 GuestViewMap guest_views_; 120 121 // Cross-origin white list entries that need to be registered with WebKit. 122 std::vector<cef::mojom::CrossOriginWhiteListEntryPtr> 123 cross_origin_whitelist_entries_; 124 125 int devtools_agent_count_ = 0; 126 int uncaught_exception_stack_size_ = 0; 127 128 mojo::ReceiverSet<cef::mojom::RenderManager> receivers_; 129 130 mojo::Remote<cef::mojom::BrowserManager> browser_manager_; 131 }; 132 133 #endif // CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_ 134