2020-09-25 03:40:47 +02:00
|
|
|
// 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.
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
#ifndef CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_
|
|
|
|
#define CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_
|
2020-09-25 03:40:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "include/internal/cef_ptr.h"
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
#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"
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
namespace blink {
|
|
|
|
class WebFrame;
|
2021-07-23 18:40:13 +02:00
|
|
|
class WebView;
|
|
|
|
} // namespace blink
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class RenderFrame;
|
|
|
|
} // namespace content
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
namespace mojo {
|
|
|
|
class BinderMap;
|
|
|
|
} // namespace mojo
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
class CefBrowserImpl;
|
|
|
|
class CefGuestView;
|
|
|
|
class CefRenderFrameObserver;
|
|
|
|
|
|
|
|
// Singleton object for managing BrowserImpl instances. Only accessed on the
|
|
|
|
// main renderer thread.
|
2021-05-14 18:58:55 +02:00
|
|
|
class CefRenderManager : public cef::mojom::RenderManager {
|
2020-09-25 03:40:47 +02:00
|
|
|
public:
|
2021-05-14 18:58:55 +02:00
|
|
|
CefRenderManager();
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefRenderManager(const CefRenderManager&) = delete;
|
|
|
|
CefRenderManager& operator=(const CefRenderManager&) = delete;
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
~CefRenderManager();
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Returns this singleton instance of this class.
|
2021-05-14 18:58:55 +02:00
|
|
|
static CefRenderManager* Get();
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Called from ContentRendererClient methods of the same name.
|
|
|
|
void RenderThreadConnected();
|
|
|
|
void RenderFrameCreated(content::RenderFrame* render_frame,
|
|
|
|
CefRenderFrameObserver* render_frame_observer,
|
|
|
|
bool& browser_created,
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<bool>& is_windowless);
|
2021-07-23 18:40:13 +02:00
|
|
|
void WebViewCreated(blink::WebView* web_view,
|
|
|
|
bool& browser_created,
|
|
|
|
absl::optional<bool>& is_windowless);
|
2020-09-25 03:40:47 +02:00
|
|
|
void DevToolsAgentAttached();
|
|
|
|
void DevToolsAgentDetached();
|
2021-05-14 18:58:55 +02:00
|
|
|
void ExposeInterfacesToBrowser(mojo::BinderMap* binders);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Returns the browser associated with the specified RenderView.
|
2022-07-21 19:26:10 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> GetBrowserForView(blink::WebView* view);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Returns the browser associated with the specified main WebFrame.
|
|
|
|
CefRefPtr<CefBrowserImpl> GetBrowserForMainFrame(blink::WebFrame* frame);
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Connects to CefBrowserManager in the browser process.
|
|
|
|
mojo::Remote<cef::mojom::BrowserManager>& GetBrowserManager();
|
|
|
|
|
2021-11-29 20:58:09 +01:00
|
|
|
// Returns true if this renderer process is hosting an extension.
|
|
|
|
static bool IsExtensionProcess();
|
|
|
|
|
|
|
|
// Returns true if this renderer process is hosting a PDF.
|
|
|
|
static bool IsPdfProcess();
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
private:
|
|
|
|
friend class CefBrowserImpl;
|
|
|
|
friend class CefGuestView;
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Binds receivers for the RenderManager interface.
|
|
|
|
void BindReceiver(mojo::PendingReceiver<cef::mojom::RenderManager> receiver);
|
|
|
|
|
|
|
|
// cef::mojom::RenderManager methods:
|
|
|
|
void ModifyCrossOriginWhitelistEntry(
|
|
|
|
bool add,
|
|
|
|
cef::mojom::CrossOriginWhiteListEntryPtr entry) override;
|
|
|
|
void ClearCrossOriginWhitelist() override;
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
void WebKitInitialized();
|
|
|
|
|
|
|
|
// Maybe create a new browser object, return the existing one, or return
|
|
|
|
// nullptr for guest views.
|
|
|
|
CefRefPtr<CefBrowserImpl> MaybeCreateBrowser(
|
2022-07-21 19:26:10 +02:00
|
|
|
blink::WebView* web_view,
|
2020-09-25 03:40:47 +02:00
|
|
|
content::RenderFrame* render_frame,
|
|
|
|
bool* browser_created,
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<bool>* is_windowless);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Called from CefBrowserImpl::OnDestruct().
|
|
|
|
void OnBrowserDestroyed(CefBrowserImpl* browser);
|
|
|
|
|
|
|
|
// Returns the guest view associated with the specified RenderView if any.
|
2022-07-21 19:26:10 +02:00
|
|
|
CefGuestView* GetGuestViewForView(blink::WebView* view);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Called from CefGuestView::OnDestruct().
|
|
|
|
void OnGuestViewDestroyed(CefGuestView* guest_view);
|
|
|
|
|
|
|
|
// Map of RenderView pointers to CefBrowserImpl references.
|
2022-07-21 19:26:10 +02:00
|
|
|
using BrowserMap = std::map<blink::WebView*, CefRefPtr<CefBrowserImpl>>;
|
2020-09-25 03:40:47 +02:00
|
|
|
BrowserMap browsers_;
|
|
|
|
|
|
|
|
// Map of RenderView poiners to CefGuestView implementations.
|
2022-07-21 19:26:10 +02:00
|
|
|
using GuestViewMap = std::map<blink::WebView*, std::unique_ptr<CefGuestView>>;
|
2020-09-25 03:40:47 +02:00
|
|
|
GuestViewMap guest_views_;
|
|
|
|
|
|
|
|
// Cross-origin white list entries that need to be registered with WebKit.
|
2021-05-14 18:58:55 +02:00
|
|
|
std::vector<cef::mojom::CrossOriginWhiteListEntryPtr>
|
|
|
|
cross_origin_whitelist_entries_;
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
int devtools_agent_count_ = 0;
|
|
|
|
int uncaught_exception_stack_size_ = 0;
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
mojo::ReceiverSet<cef::mojom::RenderManager> receivers_;
|
|
|
|
|
|
|
|
mojo::Remote<cef::mojom::BrowserManager> browser_manager_;
|
2020-09-25 03:40:47 +02:00
|
|
|
};
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
#endif // CEF_LIBCEF_RENDERER_RENDER_MANAGER_H_
|