// Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can // be found in the LICENSE file. #ifndef CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_ #define CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_ #pragma once #include #include #include "include/internal/cef_ptr.h" #include "cef/libcef/common/mojom/cef.mojom.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/remote.h" #include "third_party/abseil-cpp/absl/types/optional.h" namespace blink { class WebFrame; } namespace content { class RenderFrame; class RenderView; } // namespace content namespace mojo { class BinderMap; } // namespace mojo class CefBrowserImpl; class CefGuestView; class CefRenderFrameObserver; // Singleton object for managing BrowserImpl instances. Only accessed on the // main renderer thread. class CefRenderManager : public cef::mojom::RenderManager { public: CefRenderManager(); ~CefRenderManager(); // Returns this singleton instance of this class. static CefRenderManager* Get(); // Called from ContentRendererClient methods of the same name. void RenderThreadConnected(); void RenderFrameCreated(content::RenderFrame* render_frame, CefRenderFrameObserver* render_frame_observer, bool& browser_created, absl::optional& is_windowless); void RenderViewCreated(content::RenderView* render_view, bool& browser_created, absl::optional& is_windowless); void DevToolsAgentAttached(); void DevToolsAgentDetached(); void ExposeInterfacesToBrowser(mojo::BinderMap* binders); // Returns the browser associated with the specified RenderView. CefRefPtr GetBrowserForView(content::RenderView* view); // Returns the browser associated with the specified main WebFrame. CefRefPtr GetBrowserForMainFrame(blink::WebFrame* frame); // Connects to CefBrowserManager in the browser process. mojo::Remote& GetBrowserManager(); private: friend class CefBrowserImpl; friend class CefGuestView; // Binds receivers for the RenderManager interface. void BindReceiver(mojo::PendingReceiver receiver); // cef::mojom::RenderManager methods: void ModifyCrossOriginWhitelistEntry( bool add, cef::mojom::CrossOriginWhiteListEntryPtr entry) override; void ClearCrossOriginWhitelist() override; void WebKitInitialized(); // Maybe create a new browser object, return the existing one, or return // nullptr for guest views. CefRefPtr MaybeCreateBrowser( content::RenderView* render_view, content::RenderFrame* render_frame, bool* browser_created, absl::optional* is_windowless); // Called from CefBrowserImpl::OnDestruct(). void OnBrowserDestroyed(CefBrowserImpl* browser); // Returns the guest view associated with the specified RenderView if any. CefGuestView* GetGuestViewForView(content::RenderView* view); // Called from CefGuestView::OnDestruct(). void OnGuestViewDestroyed(CefGuestView* guest_view); // Map of RenderView pointers to CefBrowserImpl references. typedef std::map> BrowserMap; BrowserMap browsers_; // Map of RenderView poiners to CefGuestView implementations. typedef std::map> GuestViewMap; GuestViewMap guest_views_; // Cross-origin white list entries that need to be registered with WebKit. std::vector cross_origin_whitelist_entries_; int devtools_agent_count_ = 0; int uncaught_exception_stack_size_ = 0; mojo::ReceiverSet receivers_; mojo::Remote browser_manager_; DISALLOW_COPY_AND_ASSIGN(CefRenderManager); }; #endif // CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_