• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Embedded Framework 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 #include "libcef/browser/browser_manager.h"
6 
7 #include "libcef/browser/browser_info_manager.h"
8 #include "libcef/browser/origin_whitelist_impl.h"
9 #include "libcef/common/frame_util.h"
10 
11 #include "content/public/browser/render_process_host.h"
12 #include "mojo/public/cpp/bindings/pending_receiver.h"
13 #include "mojo/public/cpp/bindings/self_owned_receiver.h"
14 #include "services/service_manager/public/cpp/binder_registry.h"
15 
CefBrowserManager(int render_process_id)16 CefBrowserManager::CefBrowserManager(int render_process_id)
17     : render_process_id_(render_process_id) {}
18 
19 CefBrowserManager::~CefBrowserManager() = default;
20 
21 // static
ExposeInterfacesToRenderer(service_manager::BinderRegistry * registry,blink::AssociatedInterfaceRegistry * associated_registry,content::RenderProcessHost * host)22 void CefBrowserManager::ExposeInterfacesToRenderer(
23     service_manager::BinderRegistry* registry,
24     blink::AssociatedInterfaceRegistry* associated_registry,
25     content::RenderProcessHost* host) {
26   registry->AddInterface(base::BindRepeating(
27       [](int render_process_id,
28          mojo::PendingReceiver<cef::mojom::BrowserManager> receiver) {
29         mojo::MakeSelfOwnedReceiver(
30             std::make_unique<CefBrowserManager>(render_process_id),
31             std::move(receiver));
32       },
33       host->GetID()));
34 }
35 
36 // static
37 mojo::Remote<cef::mojom::RenderManager>
GetRenderManagerForProcess(content::RenderProcessHost * host)38 CefBrowserManager::GetRenderManagerForProcess(
39     content::RenderProcessHost* host) {
40   mojo::Remote<cef::mojom::RenderManager> client;
41   host->BindReceiver(client.BindNewPipeAndPassReceiver());
42   return client;
43 }
44 
GetNewRenderThreadInfo(cef::mojom::BrowserManager::GetNewRenderThreadInfoCallback callback)45 void CefBrowserManager::GetNewRenderThreadInfo(
46     cef::mojom::BrowserManager::GetNewRenderThreadInfoCallback callback) {
47   auto info = cef::mojom::NewRenderThreadInfo::New();
48   GetCrossOriginWhitelistEntries(&info->cross_origin_whitelist_entries);
49   std::move(callback).Run(std::move(info));
50 }
51 
GetNewBrowserInfo(int32_t render_frame_routing_id,cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback)52 void CefBrowserManager::GetNewBrowserInfo(
53     int32_t render_frame_routing_id,
54     cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback) {
55   CefBrowserInfoManager::GetInstance()->OnGetNewBrowserInfo(
56       frame_util::MakeGlobalId(render_process_id_, render_frame_routing_id),
57       std::move(callback));
58 }
59