blob: 1a4b4eef53ddfab751cdea1ac941c6103eafba9f [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]f1a29a02011-10-06 23:08:445#ifndef CONTENT_RENDERER_RENDER_THREAD_IMPL_H_
6#define CONTENT_RENDERER_RENDER_THREAD_IMPL_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"
[email protected]71d6d852009-12-07 22:12:3614#include "base/time.h"
15#include "base/timer.h"
[email protected]037fce02009-01-22 01:42:1516#include "build/build_config.h"
[email protected]7ef40ffe12011-03-08 05:05:2817#include "content/common/child_thread.h"
[email protected]8d128d62011-09-13 22:11:5718#include "content/common/content_export.h"
[email protected]778574e2011-03-21 22:03:5019#include "content/common/css_colors.h"
[email protected]202b54ff2011-04-22 21:36:3820#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]526476902011-10-06 20:34:0621#include "content/public/renderer/render_thread.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]a9fb30aa2011-10-06 06:58:4628class CompositorThread;
[email protected]017022b2009-07-27 23:06:3429class DBMessageFilter;
[email protected]82622452011-07-22 09:57:2030class DevToolsAgentFilter;
[email protected]83f93d32011-11-11 00:43:3031struct DOMStorageMsg_Event_Params;
[email protected]e13ad79b2010-07-22 21:36:5032class GpuChannelHost;
[email protected]70c19a932010-05-14 12:59:1133class IndexedDBDispatcher;
[email protected]8d6cba42011-09-02 10:05:1934class RendererWebKitPlatformSupportImpl;
[email protected]39008c02009-02-11 23:59:2535class SkBitmap;
[email protected]80b161a2011-06-27 17:42:1136class VideoCaptureImplManager;
[email protected]4e6419c2010-01-15 04:50:3437struct ViewMsg_New_Params;
[email protected]83f93d32011-11-11 00:43:3038class WebDatabaseObserverImpl;
[email protected]46f36a492010-07-28 19:36:4139
[email protected]b7c7bcf2009-10-03 07:07:3440namespace WebKit {
41class WebStorageEventDispatcher;
42}
43
[email protected]64ffa0442011-10-03 22:08:3644namespace base {
[email protected]64ffa0442011-10-03 22:08:3645class MessageLoopProxy;
46class Thread;
[email protected]1a771262011-10-31 09:11:1247namespace win {
48class ScopedCOMInitializer;
49}
[email protected]64ffa0442011-10-03 22:08:3650}
51
52namespace content {
53class RenderProcessObserver;
54}
55
[email protected]af7eb3fb2010-09-23 21:31:0656namespace v8 {
57class Extension;
58}
59
[email protected]f1a29a02011-10-06 23:08:4460// The RenderThreadImpl class represents a background thread where RenderView
initial.commit09911bf2008-07-26 23:55:2961// instances live. The RenderThread supports an API that is used by its
62// consumer to talk indirectly to the RenderViews and supporting objects.
63// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:3464// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2965//
66// Most of the communication occurs in the form of IPC messages. They are
67// routed to the RenderThread according to the routing IDs of the messages.
68// The routing IDs correspond to RenderView instances.
[email protected]f1a29a02011-10-06 23:08:4469class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread,
70 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2971 public:
[email protected]f1a29a02011-10-06 23:08:4472 static RenderThreadImpl* current();
[email protected]526476902011-10-06 20:34:0673
[email protected]f1a29a02011-10-06 23:08:4474 RenderThreadImpl();
[email protected]8930d472009-02-21 08:05:2875 // Constructor that's used when running in single process mode.
[email protected]f1a29a02011-10-06 23:08:4476 explicit RenderThreadImpl(const std::string& channel_name);
77 virtual ~RenderThreadImpl();
initial.commit09911bf2008-07-26 23:55:2978
[email protected]c1f50aa2010-02-18 03:46:5779 // Returns the routing ID of the RenderWidget containing the current script
80 // execution context (corresponding to WebFrame::frameForCurrentContext).
81 static int32 RoutingIDForCurrentContext();
82
[email protected]526476902011-10-06 20:34:0683 // content::RenderThread implementation:
84 virtual bool Send(IPC::Message* msg) OVERRIDE;
85 virtual MessageLoop* GetMessageLoop() OVERRIDE;
86 virtual IPC::SyncChannel* GetChannel() OVERRIDE;
[email protected]526476902011-10-06 20:34:0687 virtual std::string GetLocale() OVERRIDE;
88 virtual void AddRoute(int32 routing_id,
89 IPC::Channel::Listener* listener) OVERRIDE;
90 virtual void RemoveRoute(int32 routing_id) OVERRIDE;
[email protected]77fc9b92011-10-15 16:20:3791 virtual int GenerateRoutingID() OVERRIDE;
[email protected]526476902011-10-06 20:34:0692 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
93 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
94 virtual void SetOutgoingMessageFilter(
95 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE;
96 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE;
97 virtual void RemoveObserver(
98 content::RenderProcessObserver* observer) OVERRIDE;
[email protected]359dfa32011-10-12 01:10:1599 virtual void SetResourceDispatcherDelegate(
100 content::ResourceDispatcherDelegate* delegate) OVERRIDE;
[email protected]526476902011-10-06 20:34:06101 virtual void WidgetHidden() OVERRIDE;
102 virtual void WidgetRestored() OVERRIDE;
103 virtual void EnsureWebKitInitialized() OVERRIDE;
104 virtual void RecordUserMetrics(const std::string& action) OVERRIDE;
[email protected]00614a82011-10-07 22:39:31105 virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer(
106 uint32 buffer_size) OVERRIDE;
[email protected]526476902011-10-06 20:34:06107 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
108 virtual bool IsRegisteredExtension(
109 const std::string& v8_extension_name) const OVERRIDE;
[email protected]6593ae12011-11-14 12:09:44110 virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE;
[email protected]526476902011-10-06 20:34:06111 virtual void IdleHandler() OVERRIDE;
[email protected]6593ae12011-11-14 12:09:44112 virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE;
113 virtual void SetIdleNotificationDelayInMs(
114 int64 idle_notification_delay_in_ms) OVERRIDE;
[email protected]526476902011-10-06 20:34:06115#if defined(OS_WIN)
116 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
117 virtual void ReleaseCachedFonts() OVERRIDE;
118#endif
[email protected]1223d6ef2011-03-28 16:47:50119
[email protected]c1f50aa2010-02-18 03:46:57120 // These methods modify how the next message is sent. Normally, when sending
121 // a synchronous message that runs a nested message loop, we need to suspend
122 // callbacks into WebKit. This involves disabling timers and deferring
123 // resource loads. However, there are exceptions when we need to customize
124 // the behavior.
125 void DoNotSuspendWebKitSharedTimer();
126 void DoNotNotifyWebKitOfModalLoop();
127
[email protected]f3150172011-10-22 02:28:45128 // Will be NULL if threaded compositing has not been enabled.
[email protected]a9fb30aa2011-10-06 06:58:46129 CompositorThread* compositor_thread() const {
130 return compositor_thread_.get();
131 }
132
[email protected]f430b5712009-08-21 21:46:31133 AppCacheDispatcher* appcache_dispatcher() const {
134 return appcache_dispatcher_.get();
135 }
136
[email protected]f7eb0a392011-07-12 10:19:51137 AudioInputMessageFilter* audio_input_message_filter() {
138 return audio_input_message_filter_.get();
139 }
140
141 AudioMessageFilter* audio_message_filter() {
142 return audio_message_filter_.get();
143 }
144
[email protected]80b161a2011-06-27 17:42:11145 VideoCaptureImplManager* video_capture_impl_manager() const {
146 return vc_manager_.get();
147 }
148
[email protected]b547fd42009-04-23 23:16:27149 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
150
[email protected]3bf4d532010-03-27 00:23:34151 // Synchronously establish a channel to the GPU plugin if not previously
152 // established or if it has been lost (for example if the GPU plugin crashed).
153 // If there is a pending asynchronous request, it will be completed by the
154 // time this routine returns.
[email protected]7f3a2cf2011-04-06 00:10:50155 GpuChannelHost* EstablishGpuChannelSync(content::CauseForGpuLaunch);
[email protected]3bf4d532010-03-27 00:23:34156
[email protected]6217d392010-03-25 22:08:35157 // Get the GPU channel. Returns NULL if the channel is not established or
158 // has been lost.
159 GpuChannelHost* GetGpuChannel();
160
[email protected]c6a7b862010-08-20 22:19:38161 // Returns a MessageLoopProxy instance corresponding to the message loop
162 // of the thread on which file operations should be run. Must be called
163 // on the renderer's main thread.
164 scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy();
165
[email protected]1784b2f2011-11-24 10:53:48166 // Causes the idle handler to skip sending idle notifications
167 // on the two next scheduled calls, so idle notifications are
168 // not sent for at least one notification delay.
169 void PostponeIdleNotification();
170
[email protected]8930d472009-02-21 08:05:28171 private:
[email protected]edc64de2011-11-17 20:07:38172 virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:29173
[email protected]42f1d7822009-07-23 18:17:55174 void Init();
initial.commit09911bf2008-07-26 23:55:29175
[email protected]b75b8292010-10-01 07:28:25176 void OnSetZoomLevelForCurrentURL(const GURL& url, double zoom_level);
[email protected]56879f932010-12-13 21:05:37177 void OnDOMStorageEvent(const DOMStorageMsg_Event_Params& params);
initial.commit09911bf2008-07-26 23:55:29178 void OnSetNextPageID(int32 next_page_id);
[email protected]b9ab10c2009-08-07 18:09:55179 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]4e6419c2010-01-15 04:50:34180 void OnCreateNewView(const ViewMsg_New_Params& params);
initial.commit09911bf2008-07-26 23:55:29181 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
[email protected]b78e168b2009-09-21 22:05:45182 void OnPurgePluginListCache(bool reload_pages);
[email protected]6eac57a2011-07-12 21:15:09183 void OnNetworkStateChanged(bool online);
[email protected]b3df5a42010-05-11 14:31:09184 void OnGetAccessibilityTree();
[email protected]b69934e2011-10-29 02:51:52185 void OnTempCrashWithData(const GURL& data);
[email protected]b3df5a42010-05-11 14:31:09186
[email protected]1784b2f2011-11-24 10:53:48187 void IdleHandlerInForegroundTab();
188
initial.commit09911bf2008-07-26 23:55:29189 // These objects live solely on the render thread.
[email protected]f1a29a02011-10-06 23:08:44190 scoped_ptr<ScopedRunnableMethodFactory<RenderThreadImpl> > task_factory_;
[email protected]f430b5712009-08-21 21:46:31191 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]31bfae72011-12-16 02:04:38192 scoped_ptr<IndexedDBDispatcher> main_thread_indexed_db_dispatcher_;
[email protected]8d6cba42011-09-02 10:05:19193 scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_;
[email protected]b7c7bcf2009-10-03 07:07:34194 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22195
[email protected]e2b2d4a2009-10-24 03:32:59196 // Used on the renderer and IPC threads.
[email protected]017022b2009-07-27 23:06:34197 scoped_refptr<DBMessageFilter> db_message_filter_;
[email protected]f7eb0a392011-07-12 10:19:51198 scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_;
199 scoped_refptr<AudioMessageFilter> audio_message_filter_;
[email protected]82622452011-07-22 09:57:20200 scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_;
[email protected]017022b2009-07-27 23:06:34201
[email protected]80b161a2011-06-27 17:42:11202 // Used on multiple threads.
203 scoped_refptr<VideoCaptureImplManager> vc_manager_;
204
[email protected]1d4dbde2011-04-01 20:40:35205 // Used on multiple script execution context threads.
206 scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_;
207
[email protected]1a771262011-10-31 09:11:12208 // Initialize COM when using plugins outside the sandbox (Windows only).
209 scoped_ptr<base::win::ScopedCOMInitializer> initialize_com_;
210
[email protected]b547fd42009-04-23 23:16:27211 // If true, then a GetPlugins call is allowed to rescan the disk.
212 bool plugin_refresh_allowed_;
213
[email protected]bee16aab2009-08-26 15:55:03214 // The count of RenderWidgets running through this thread.
215 int widget_count_;
216
217 // The count of hidden RenderWidgets running through this thread.
218 int hidden_widget_count_;
219
220 // The current value of the idle notification timer delay.
[email protected]6593ae12011-11-14 12:09:44221 int64 idle_notification_delay_in_ms_;
[email protected]bee16aab2009-08-26 15:55:03222
[email protected]1784b2f2011-11-24 10:53:48223 // The number of idle handler calls that skip sending idle notifications.
224 int idle_notifications_to_skip_;
225
[email protected]80fc08c52010-03-09 07:43:50226 bool suspend_webkit_shared_timer_;
227 bool notify_webkit_of_modal_loop_;
[email protected]c1f50aa2010-02-18 03:46:57228
[email protected]71d6d852009-12-07 22:12:36229 // Timer that periodically calls IdleHandler.
[email protected]f1a29a02011-10-06 23:08:44230 base::RepeatingTimer<RenderThreadImpl> idle_timer_;
[email protected]71d6d852009-12-07 22:12:36231
[email protected]6217d392010-03-25 22:08:35232 // The channel from the renderer process to the GPU process.
233 scoped_refptr<GpuChannelHost> gpu_channel_;
234
[email protected]c6a7b862010-08-20 22:19:38235 // A lazily initiated thread on which file operations are run.
236 scoped_ptr<base::Thread> file_thread_;
237
[email protected]6779aa12011-03-29 17:32:24238 // Map of registered v8 extensions. The key is the extension name.
239 std::set<std::string> v8_extensions_;
[email protected]2a521c52011-01-26 18:45:21240
[email protected]2db58cf92011-12-01 21:39:01241 bool compositor_initialized_;
[email protected]a9fb30aa2011-10-06 06:58:46242 scoped_ptr<CompositorThread> compositor_thread_;
243
[email protected]64ffa0442011-10-03 22:08:36244 ObserverList<content::RenderProcessObserver> observers_;
[email protected]1223d6ef2011-03-28 16:47:50245
[email protected]f1a29a02011-10-06 23:08:44246 DISALLOW_COPY_AND_ASSIGN(RenderThreadImpl);
initial.commit09911bf2008-07-26 23:55:29247};
248
[email protected]f1a29a02011-10-06 23:08:44249#endif // CONTENT_RENDERER_RENDER_THREAD_IMPL_H_