• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Embedded Framework Authors.
2 // Portions copyright (c) 2011 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 #ifndef CEF_LIBCEF_RENDERER_ALLOY_ALLOY_CONTENT_RENDERER_CLIENT_H_
7 #define CEF_LIBCEF_RENDERER_ALLOY_ALLOY_CONTENT_RENDERER_CLIENT_H_
8 #pragma once
9 
10 #include <list>
11 #include <map>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include "libcef/renderer/browser_impl.h"
17 
18 #include "base/compiler_specific.h"
19 #include "base/task/current_thread.h"
20 #include "base/task/single_thread_task_runner.h"
21 #include "chrome/common/plugin.mojom.h"
22 #include "chrome/renderer/media/chrome_key_systems_provider.h"
23 #include "content/public/renderer/content_renderer_client.h"
24 #include "content/public/renderer/render_thread.h"
25 #include "mojo/public/cpp/bindings/generic_pending_receiver.h"
26 #include "services/service_manager/public/cpp/local_interface_provider.h"
27 
28 namespace extensions {
29 class CefExtensionsRendererClient;
30 class Dispatcher;
31 class DispatcherDelegate;
32 class ExtensionsClient;
33 class ExtensionsRendererClient;
34 class ResourceRequestPolicy;
35 }  // namespace extensions
36 
37 namespace visitedlink {
38 class VisitedLinkReader;
39 }
40 
41 namespace web_cache {
42 class WebCacheImpl;
43 }
44 
45 class AlloyRenderThreadObserver;
46 class CefRenderManager;
47 class ChromePDFPrintClient;
48 class SpellCheck;
49 
50 class AlloyContentRendererClient
51     : public content::ContentRendererClient,
52       public service_manager::LocalInterfaceProvider,
53       public base::CurrentThread::DestructionObserver {
54  public:
55   AlloyContentRendererClient();
56 
57   AlloyContentRendererClient(const AlloyContentRendererClient&) = delete;
58   AlloyContentRendererClient& operator=(const AlloyContentRendererClient&) =
59       delete;
60 
61   ~AlloyContentRendererClient() override;
62 
63   // Returns the singleton AlloyContentRendererClient instance.
64   // This method is deprecated and should not be used in new callsites.
65   static AlloyContentRendererClient* Get();
66 
67   // Render thread task runner.
render_task_runner()68   base::SingleThreadTaskRunner* render_task_runner() const {
69     return render_task_runner_.get();
70   }
71 
72   // Returns the task runner for the current thread. Returns NULL if the current
73   // thread is not the main render process thread.
74   scoped_refptr<base::SingleThreadTaskRunner> GetCurrentTaskRunner();
75 
76   // Perform cleanup work that needs to occur before shutdown when running in
77   // single-process mode. Blocks until cleanup is complete.
78   void RunSingleProcessCleanup();
79 
80   // ContentRendererClient implementation.
81   void PostIOThreadCreated(
82       base::SingleThreadTaskRunner* io_thread_task_runner) override;
83   void RenderThreadStarted() override;
84   void ExposeInterfacesToBrowser(mojo::BinderMap* binders) override;
85   void RenderThreadConnected() override;
86   void RenderFrameCreated(content::RenderFrame* render_frame) override;
87   void WebViewCreated(blink::WebView* web_view) override;
88   bool IsPluginHandledExternally(content::RenderFrame* render_frame,
89                                  const blink::WebElement& plugin_element,
90                                  const GURL& original_url,
91                                  const std::string& mime_type) override;
92   bool OverrideCreatePlugin(content::RenderFrame* render_frame,
93                             const blink::WebPluginParams& params,
94                             blink::WebPlugin** plugin) override;
95   void WillSendRequest(blink::WebLocalFrame* frame,
96                        ui::PageTransition transition_type,
97                        const blink::WebURL& url,
98                        const net::SiteForCookies& site_for_cookies,
99                        const url::Origin* initiator_origin,
100                        GURL* new_url) override;
101   uint64_t VisitedLinkHash(const char* canonical_url, size_t length) override;
102   bool IsLinkVisited(uint64_t link_hash) override;
103   bool IsOriginIsolatedPepperPlugin(const base::FilePath& plugin_path) override;
104   void AddSupportedKeySystems(
105       std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems)
106       override;
107   bool IsKeySystemsUpdateNeeded() override;
108   void RunScriptsAtDocumentStart(content::RenderFrame* render_frame) override;
109   void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override;
110   void RunScriptsAtDocumentIdle(content::RenderFrame* render_frame) override;
111   void DevToolsAgentAttached() override;
112   void DevToolsAgentDetached() override;
113   std::unique_ptr<blink::URLLoaderThrottleProvider>
114   CreateURLLoaderThrottleProvider(
115       blink::URLLoaderThrottleProviderType provider_type) override;
116 
117   // service_manager::LocalInterfaceProvider implementation.
118   void GetInterface(const std::string& name,
119                     mojo::ScopedMessagePipeHandle request_handle) override;
120 
121   // MessageLoopCurrent::DestructionObserver implementation.
122   void WillDestroyCurrentMessageLoop() override;
123 
124  private:
125   void OnBrowserCreated(content::RenderView* render_view,
126                         absl::optional<bool> is_windowless);
127 
128   // Perform cleanup work for single-process mode.
129   void RunSingleProcessCleanupOnUIThread();
130 
131   // Time at which this object was created. This is very close to the time at
132   // which the RendererMain function was entered.
133   base::TimeTicks main_entry_time_;
134 
135   std::unique_ptr<CefRenderManager> render_manager_;
136 
137   scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_;
138   std::unique_ptr<AlloyRenderThreadObserver> observer_;
139   std::unique_ptr<web_cache::WebCacheImpl> web_cache_impl_;
140   std::unique_ptr<SpellCheck> spellcheck_;
141   std::unique_ptr<visitedlink::VisitedLinkReader> visited_link_slave_;
142 
143   std::unique_ptr<ChromePDFPrintClient> pdf_print_client_;
144 
145   std::unique_ptr<extensions::ExtensionsClient> extensions_client_;
146   std::unique_ptr<extensions::CefExtensionsRendererClient>
147       extensions_renderer_client_;
148 
149   // Used to refresh the list of supported key systems after Widevine is
150   // installed as a component update.
151   ChromeKeySystemsProvider key_systems_provider_;
152 
153   // Used in single-process mode to test when cleanup is complete.
154   // Access must be protected by |single_process_cleanup_lock_|.
155   bool single_process_cleanup_complete_ = false;
156   base::Lock single_process_cleanup_lock_;
157 };
158 
159 #endif  // CEF_LIBCEF_RENDERER_ALLOY_ALLOY_CONTENT_RENDERER_CLIENT_H_
160