blob: 88bd1e894d4c6a28ab1675ffba7dd74f6e17ebd3 [file] [log] [blame]
[email protected]1d4dbde2011-04-01 20:40:351// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]10e6ab572011-04-14 23:42:005#ifndef CONTENT_RENDERER_RENDER_THREAD_H_
6#define CONTENT_RENDERER_RENDER_THREAD_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
[email protected]6779aa12011-03-29 17:32:249#include <set>
[email protected]b68d5ed2009-04-16 02:41:2810#include <string>
[email protected]1bc83062009-02-06 00:16:3711#include <vector>
12
[email protected]1223d6ef2011-03-28 16:47:5013#include "base/observer_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/shared_memory.h"
[email protected]71d6d852009-12-07 22:12:3615#include "base/time.h"
16#include "base/timer.h"
[email protected]037fce02009-01-22 01:42:1517#include "build/build_config.h"
[email protected]7ef40ffe12011-03-08 05:05:2818#include "content/common/child_thread.h"
[email protected]8d128d62011-09-13 22:11:5719#include "content/common/content_export.h"
[email protected]778574e2011-03-21 22:03:5020#include "content/common/css_colors.h"
[email protected]202b54ff2011-04-22 21:36:3821#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]a83d42292010-08-17 22:51:1022#include "ipc/ipc_channel_proxy.h"
[email protected]08397d52011-02-05 01:53:3823#include "ui/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2924
[email protected]1edc16b82009-04-07 17:45:5425class AppCacheDispatcher;
[email protected]f7eb0a392011-07-12 10:19:5126class AudioInputMessageFilter;
27class AudioMessageFilter;
[email protected]017022b2009-07-27 23:06:3428class DBMessageFilter;
[email protected]82622452011-07-22 09:57:2029class DevToolsAgentFilter;
[email protected]39008c02009-02-11 23:59:2530class FilePath;
[email protected]e13ad79b2010-07-22 21:36:5031class GpuChannelHost;
[email protected]70c19a932010-05-14 12:59:1132class IndexedDBDispatcher;
[email protected]55e57d42009-02-25 06:10:1733class RendererHistogram;
[email protected]e13ad79b2010-07-22 21:36:5034class RendererHistogramSnapshots;
[email protected]74be069e82010-06-25 00:12:4935class RendererNetPredictor;
[email protected]8d6cba42011-09-02 10:05:1936class RendererWebKitPlatformSupportImpl;
[email protected]39008c02009-02-11 23:59:2537class SkBitmap;
[email protected]80b161a2011-06-27 17:42:1138class VideoCaptureImplManager;
[email protected]2b437e232010-04-02 01:30:0839class WebDatabaseObserverImpl;
[email protected]cccf90932009-08-23 17:56:2540
[email protected]9b6f40e2009-06-11 15:54:2641struct RendererPreferences;
[email protected]56879f932010-12-13 21:05:3742struct DOMStorageMsg_Event_Params;
[email protected]d6d8f712011-03-10 22:54:4343struct GPUInfo;
[email protected]4e6419c2010-01-15 04:50:3444struct ViewMsg_New_Params;
[email protected]39008c02009-02-11 23:59:2545struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2946
[email protected]46f36a492010-07-28 19:36:4147namespace IPC {
48struct ChannelHandle;
49}
50
[email protected]b7c7bcf2009-10-03 07:07:3451namespace WebKit {
52class WebStorageEventDispatcher;
53}
54
[email protected]64ffa0442011-10-03 22:08:3655namespace base {
56class MessageLoopProxy;
57class Thread;
58}
59
60namespace content {
61class RenderProcessObserver;
62}
63
[email protected]af7eb3fb2010-09-23 21:31:0664namespace v8 {
65class Extension;
66}
67
[email protected]81a34412009-01-05 19:17:2468// The RenderThreadBase is the minimal interface that a RenderView/Widget
69// expects from a render thread. The interface basically abstracts a way to send
70// and receive messages.
[email protected]00c39612010-03-06 02:53:2871//
[email protected]f3ede412010-06-21 22:52:1672// TODO(brettw): This has two different and opposing usage patterns which
[email protected]2b7313f2011-09-28 20:54:0873// make it confusing. It can be accessed through RenderThread::current(), which
74// can be NULL during tests, or it can be passed as RenderThreadBase, which is
75// mocked during tests. It should be changed to RenderThread::current()
76// everywhere.
[email protected]f3ede412010-06-21 22:52:1677//
[email protected]2b7313f2011-09-28 20:54:0878// See crbug.com/98375 for more details.
[email protected]8d128d62011-09-13 22:11:5779class CONTENT_EXPORT RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4480 public:
81 virtual ~RenderThreadBase() {}
82
[email protected]8930d472009-02-21 08:05:2883 virtual bool Send(IPC::Message* msg) = 0;
84
[email protected]8085dbc82008-09-26 22:53:4485 // Called to add or remove a listener for a particular message routing ID.
86 // These methods normally get delegated to a MessageRouter.
87 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
88 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2489
90 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
91 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]bee16aab2009-08-26 15:55:0392
93 // Called by a RenderWidget when it is hidden or restored.
94 virtual void WidgetHidden() = 0;
95 virtual void WidgetRestored() = 0;
[email protected]8085dbc82008-09-26 22:53:4496};
97
initial.commit09911bf2008-07-26 23:55:2998// The RenderThread class represents a background thread where RenderView
99// instances live. The RenderThread supports an API that is used by its
100// consumer to talk indirectly to the RenderViews and supporting objects.
101// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:34102// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:29103//
104// Most of the communication occurs in the form of IPC messages. They are
105// routed to the RenderThread according to the routing IDs of the messages.
106// The routing IDs correspond to RenderView instances.
[email protected]8d128d62011-09-13 22:11:57107class CONTENT_EXPORT RenderThread : public RenderThreadBase,
108 public ChildThread {
initial.commit09911bf2008-07-26 23:55:29109 public:
[email protected]8930d472009-02-21 08:05:28110 // Grabs the IPC channel name from the command line.
111 RenderThread();
112 // Constructor that's used when running in single process mode.
[email protected]11f4857282009-11-13 19:56:17113 explicit RenderThread(const std::string& channel_name);
[email protected]8085dbc82008-09-26 22:53:44114 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:29115
[email protected]8930d472009-02-21 08:05:28116 // Returns the one render thread for this process. Note that this should only
117 // be accessed when running on the render thread itself
[email protected]00c39612010-03-06 02:53:28118 //
119 // TODO(brettw) this should be on the abstract base class instead of here,
[email protected]2b7313f2011-09-28 20:54:08120 // and return the base class' interface instead. See crbug.com/98375.
[email protected]8930d472009-02-21 08:05:28121 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:29122
[email protected]c1f50aa2010-02-18 03:46:57123 // Returns the routing ID of the RenderWidget containing the current script
124 // execution context (corresponding to WebFrame::frameForCurrentContext).
125 static int32 RoutingIDForCurrentContext();
126
[email protected]18ad6772011-09-20 21:51:32127 // Returns the locale string to be used in WebKit.
128 static std::string GetLocale();
129
[email protected]45776222009-07-15 20:21:58130 // Overridden from RenderThreadBase.
[email protected]c1f50aa2010-02-18 03:46:57131 virtual bool Send(IPC::Message* msg);
132 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
133 virtual void RemoveRoute(int32 routing_id);
[email protected]81a34412009-01-05 19:17:24134 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
135 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
[email protected]bee16aab2009-08-26 15:55:03136 virtual void WidgetHidden();
137 virtual void WidgetRestored();
138
[email protected]64ffa0442011-10-03 22:08:36139 void AddObserver(content::RenderProcessObserver* observer);
140 void RemoveObserver(content::RenderProcessObserver* observer);
[email protected]1223d6ef2011-03-28 16:47:50141
[email protected]c1f50aa2010-02-18 03:46:57142 // These methods modify how the next message is sent. Normally, when sending
143 // a synchronous message that runs a nested message loop, we need to suspend
144 // callbacks into WebKit. This involves disabling timers and deferring
145 // resource loads. However, there are exceptions when we need to customize
146 // the behavior.
147 void DoNotSuspendWebKitSharedTimer();
148 void DoNotNotifyWebKitOfModalLoop();
149
[email protected]f430b5712009-08-21 21:46:31150 AppCacheDispatcher* appcache_dispatcher() const {
151 return appcache_dispatcher_.get();
152 }
153
[email protected]70c19a932010-05-14 12:59:11154 IndexedDBDispatcher* indexed_db_dispatcher() const {
155 return indexed_db_dispatcher_.get();
156 }
157
[email protected]f7eb0a392011-07-12 10:19:51158 AudioInputMessageFilter* audio_input_message_filter() {
159 return audio_input_message_filter_.get();
160 }
161
162 AudioMessageFilter* audio_message_filter() {
163 return audio_message_filter_.get();
164 }
165
[email protected]80b161a2011-06-27 17:42:11166 VideoCaptureImplManager* video_capture_impl_manager() const {
167 return vc_manager_.get();
168 }
169
[email protected]b547fd42009-04-23 23:16:27170 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
171
[email protected]6779aa12011-03-29 17:32:24172 double idle_notification_delay_in_s() const {
173 return idle_notification_delay_in_s_;
174 }
175 void set_idle_notification_delay_in_s(double idle_notification_delay_in_s) {
[email protected]d07495f2011-03-29 17:41:28176 idle_notification_delay_in_s_ = idle_notification_delay_in_s;
[email protected]6779aa12011-03-29 17:32:24177 }
178
[email protected]3bf4d532010-03-27 00:23:34179 // Synchronously establish a channel to the GPU plugin if not previously
180 // established or if it has been lost (for example if the GPU plugin crashed).
181 // If there is a pending asynchronous request, it will be completed by the
182 // time this routine returns.
[email protected]7f3a2cf2011-04-06 00:10:50183 GpuChannelHost* EstablishGpuChannelSync(content::CauseForGpuLaunch);
[email protected]3bf4d532010-03-27 00:23:34184
[email protected]6217d392010-03-25 22:08:35185 // Get the GPU channel. Returns NULL if the channel is not established or
186 // has been lost.
187 GpuChannelHost* GetGpuChannel();
188
[email protected]c6a7b862010-08-20 22:19:38189 // Returns a MessageLoopProxy instance corresponding to the message loop
190 // of the thread on which file operations should be run. Must be called
191 // on the renderer's main thread.
192 scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy();
193
[email protected]6779aa12011-03-29 17:32:24194 // Schedule a call to IdleHandler with the given initial delay.
195 void ScheduleIdleHandler(double initial_delay_s);
196
197 // A task we invoke periodically to assist with idle cleanup.
198 void IdleHandler();
199
200 // Registers the given V8 extension with WebKit.
201 void RegisterExtension(v8::Extension* extension);
202
[email protected]c6e27b92011-04-30 17:03:43203 // Returns true iff the extension is registered.
204 bool IsRegisteredExtension(const std::string& v8_extension_name) const;
205
[email protected]d1b8fccc2011-08-03 01:20:13206 // We initialize WebKit as late as possible.
207 void EnsureWebKitInitialized();
208
[email protected]4a7d6392011-09-19 20:55:08209 // Helper function to send over a string to be recorded by user metrics
210 static void RecordUserMetrics(const std::string& action);
211
212#if defined(OS_WIN)
213 // Request that the given font be loaded by the browser so it's cached by the
214 // OS. Please see ChildProcessHost::PreCacheFont for details.
215 static bool PreCacheFont(const LOGFONT& log_font);
[email protected]79fff822011-09-20 03:33:21216
217 // Release cached font.
218 static bool ReleaseCachedFonts();
[email protected]4a7d6392011-09-19 20:55:08219#endif // OS_WIN
220
[email protected]8930d472009-02-21 08:05:28221 private:
[email protected]a95986a82010-12-24 06:19:28222 virtual bool OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29223
[email protected]42f1d7822009-07-23 18:17:55224 void Init();
initial.commit09911bf2008-07-26 23:55:29225
[email protected]b75b8292010-10-01 07:28:25226 void OnSetZoomLevelForCurrentURL(const GURL& url, double zoom_level);
[email protected]56879f932010-12-13 21:05:37227 void OnDOMStorageEvent(const DOMStorageMsg_Event_Params& params);
initial.commit09911bf2008-07-26 23:55:29228 void OnSetNextPageID(int32 next_page_id);
[email protected]b9ab10c2009-08-07 18:09:55229 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]4e6419c2010-01-15 04:50:34230 void OnCreateNewView(const ViewMsg_New_Params& params);
initial.commit09911bf2008-07-26 23:55:29231 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
[email protected]b78e168b2009-09-21 22:05:45232 void OnPurgePluginListCache(bool reload_pages);
[email protected]6eac57a2011-07-12 21:15:09233 void OnNetworkStateChanged(bool online);
[email protected]b3df5a42010-05-11 14:31:09234 void OnGetAccessibilityTree();
235
initial.commit09911bf2008-07-26 23:55:29236 // These objects live solely on the render thread.
[email protected]bee16aab2009-08-26 15:55:03237 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_;
[email protected]f430b5712009-08-21 21:46:31238 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]70c19a932010-05-14 12:59:11239 scoped_ptr<IndexedDBDispatcher> indexed_db_dispatcher_;
[email protected]8d6cba42011-09-02 10:05:19240 scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_;
[email protected]b7c7bcf2009-10-03 07:07:34241 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22242
[email protected]e2b2d4a2009-10-24 03:32:59243 // Used on the renderer and IPC threads.
[email protected]017022b2009-07-27 23:06:34244 scoped_refptr<DBMessageFilter> db_message_filter_;
[email protected]f7eb0a392011-07-12 10:19:51245 scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_;
246 scoped_refptr<AudioMessageFilter> audio_message_filter_;
[email protected]82622452011-07-22 09:57:20247 scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_;
[email protected]017022b2009-07-27 23:06:34248
[email protected]80b161a2011-06-27 17:42:11249 // Used on multiple threads.
250 scoped_refptr<VideoCaptureImplManager> vc_manager_;
251
[email protected]1d4dbde2011-04-01 20:40:35252 // Used on multiple script execution context threads.
253 scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_;
254
[email protected]b547fd42009-04-23 23:16:27255 // If true, then a GetPlugins call is allowed to rescan the disk.
256 bool plugin_refresh_allowed_;
257
[email protected]bee16aab2009-08-26 15:55:03258 // The count of RenderWidgets running through this thread.
259 int widget_count_;
260
261 // The count of hidden RenderWidgets running through this thread.
262 int hidden_widget_count_;
263
264 // The current value of the idle notification timer delay.
265 double idle_notification_delay_in_s_;
266
[email protected]80fc08c52010-03-09 07:43:50267 bool suspend_webkit_shared_timer_;
268 bool notify_webkit_of_modal_loop_;
[email protected]c1f50aa2010-02-18 03:46:57269
[email protected]71d6d852009-12-07 22:12:36270 // Timer that periodically calls IdleHandler.
271 base::RepeatingTimer<RenderThread> idle_timer_;
272
[email protected]6217d392010-03-25 22:08:35273 // The channel from the renderer process to the GPU process.
274 scoped_refptr<GpuChannelHost> gpu_channel_;
275
[email protected]c6a7b862010-08-20 22:19:38276 // A lazily initiated thread on which file operations are run.
277 scoped_ptr<base::Thread> file_thread_;
278
[email protected]6779aa12011-03-29 17:32:24279 // Map of registered v8 extensions. The key is the extension name.
280 std::set<std::string> v8_extensions_;
[email protected]2a521c52011-01-26 18:45:21281
[email protected]64ffa0442011-10-03 22:08:36282 ObserverList<content::RenderProcessObserver> observers_;
[email protected]1223d6ef2011-03-28 16:47:50283
[email protected]1bc83062009-02-06 00:16:37284 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29285};
286
[email protected]10e6ab572011-04-14 23:42:00287#endif // CONTENT_RENDERER_RENDER_THREAD_H_