• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Embedded Framework Authors.
2 // Portions copyright 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "libcef/renderer/chrome/chrome_content_renderer_client_cef.h"
7 
8 #include "libcef/renderer/render_frame_observer.h"
9 #include "libcef/renderer/render_manager.h"
10 #include "libcef/renderer/thread_util.h"
11 
12 #include "content/public/renderer/render_thread.h"
13 
ChromeContentRendererClientCef()14 ChromeContentRendererClientCef::ChromeContentRendererClientCef()
15     : render_manager_(new CefRenderManager) {}
16 
17 ChromeContentRendererClientCef::~ChromeContentRendererClientCef() = default;
18 
19 scoped_refptr<base::SingleThreadTaskRunner>
GetCurrentTaskRunner()20 ChromeContentRendererClientCef::GetCurrentTaskRunner() {
21   // Check if currently on the render thread.
22   if (CEF_CURRENTLY_ON_RT())
23     return render_task_runner_;
24   return nullptr;
25 }
26 
RenderThreadStarted()27 void ChromeContentRendererClientCef::RenderThreadStarted() {
28   ChromeContentRendererClient::RenderThreadStarted();
29 
30   render_task_runner_ = base::ThreadTaskRunnerHandle::Get();
31 }
32 
RenderThreadConnected()33 void ChromeContentRendererClientCef::RenderThreadConnected() {
34   ChromeContentRendererClient::RenderThreadConnected();
35 
36   render_manager_->RenderThreadConnected();
37 }
38 
RenderFrameCreated(content::RenderFrame * render_frame)39 void ChromeContentRendererClientCef::RenderFrameCreated(
40     content::RenderFrame* render_frame) {
41   ChromeContentRendererClient::RenderFrameCreated(render_frame);
42 
43   // Will delete itself when no longer needed.
44   CefRenderFrameObserver* render_frame_observer =
45       new CefRenderFrameObserver(render_frame);
46 
47   bool browser_created;
48   absl::optional<bool> is_windowless;
49   render_manager_->RenderFrameCreated(render_frame, render_frame_observer,
50                                       browser_created, is_windowless);
51   if (is_windowless.has_value() && *is_windowless) {
52     LOG(ERROR) << "The chrome runtime does not support windowless browsers";
53   }
54 }
55 
WebViewCreated(blink::WebView * web_view)56 void ChromeContentRendererClientCef::WebViewCreated(blink::WebView* web_view) {
57   ChromeContentRendererClient::WebViewCreated(web_view);
58 
59   bool browser_created;
60   absl::optional<bool> is_windowless;
61   render_manager_->WebViewCreated(web_view, browser_created, is_windowless);
62   if (is_windowless.has_value() && *is_windowless) {
63     LOG(ERROR) << "The chrome runtime does not support windowless browsers";
64   }
65 }
66 
DevToolsAgentAttached()67 void ChromeContentRendererClientCef::DevToolsAgentAttached() {
68   // WebWorkers may be creating agents on a different thread.
69   if (!render_task_runner_->BelongsToCurrentThread()) {
70     render_task_runner_->PostTask(
71         FROM_HERE,
72         base::BindOnce(&ChromeContentRendererClientCef::DevToolsAgentAttached,
73                        base::Unretained(this)));
74     return;
75   }
76 
77   render_manager_->DevToolsAgentAttached();
78 }
79 
DevToolsAgentDetached()80 void ChromeContentRendererClientCef::DevToolsAgentDetached() {
81   // WebWorkers may be creating agents on a different thread.
82   if (!render_task_runner_->BelongsToCurrentThread()) {
83     render_task_runner_->PostTask(
84         FROM_HERE,
85         base::BindOnce(&ChromeContentRendererClientCef::DevToolsAgentDetached,
86                        base::Unretained(this)));
87     return;
88   }
89 
90   render_manager_->DevToolsAgentDetached();
91 }
92 
ExposeInterfacesToBrowser(mojo::BinderMap * binders)93 void ChromeContentRendererClientCef::ExposeInterfacesToBrowser(
94     mojo::BinderMap* binders) {
95   ChromeContentRendererClient::ExposeInterfacesToBrowser(binders);
96 
97   render_manager_->ExposeInterfacesToBrowser(binders);
98 }