blob: df6bf556b76777670e10739eddecda9dd900b8ee [file] [log] [blame]
[email protected]d3d6325d2012-01-03 21:17:361// Copyright (c) 2012 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]b3e83de2012-02-07 03:33:2817#include "content/common/child_process.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]c26ad882012-02-07 06:41:2021#include "content/common/gpu/client/gpu_channel_host.h"
[email protected]202b54ff2011-04-22 21:36:3822#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]526476902011-10-06 20:34:0623#include "content/public/renderer/render_thread.h"
[email protected]a83d42292010-08-17 22:51:1024#include "ipc/ipc_channel_proxy.h"
[email protected]08397d52011-02-05 01:53:3825#include "ui/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2926
[email protected]1edc16b82009-04-07 17:45:5427class AppCacheDispatcher;
[email protected]f7eb0a392011-07-12 10:19:5128class AudioInputMessageFilter;
29class AudioMessageFilter;
[email protected]a9fb30aa2011-10-06 06:58:4630class CompositorThread;
[email protected]017022b2009-07-27 23:06:3431class DBMessageFilter;
[email protected]82622452011-07-22 09:57:2032class DevToolsAgentFilter;
[email protected]83f93d32011-11-11 00:43:3033struct DOMStorageMsg_Event_Params;
[email protected]e13ad79b2010-07-22 21:36:5034class GpuChannelHost;
[email protected]70c19a932010-05-14 12:59:1135class IndexedDBDispatcher;
[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]4e6419c2010-01-15 04:50:3439struct ViewMsg_New_Params;
[email protected]83f93d32011-11-11 00:43:3040class WebDatabaseObserverImpl;
[email protected]46f36a492010-07-28 19:36:4141
[email protected]b7c7bcf2009-10-03 07:07:3442namespace WebKit {
[email protected]d8cd8372012-03-09 10:49:5143class WebMediaStreamCenter;
44class WebMediaStreamCenterClient;
[email protected]b7c7bcf2009-10-03 07:07:3445class WebStorageEventDispatcher;
46}
47
[email protected]64ffa0442011-10-03 22:08:3648namespace base {
49class MessageLoopProxy;
50class Thread;
[email protected]1a771262011-10-31 09:11:1251namespace win {
52class ScopedCOMInitializer;
53}
[email protected]64ffa0442011-10-03 22:08:3654}
55
56namespace content {
[email protected]d8cd8372012-03-09 10:49:5157class MediaStreamCenter;
[email protected]64ffa0442011-10-03 22:08:3658class RenderProcessObserver;
59}
60
[email protected]af7eb3fb2010-09-23 21:31:0661namespace v8 {
62class Extension;
63}
64
[email protected]f1a29a02011-10-06 23:08:4465// The RenderThreadImpl class represents a background thread where RenderView
initial.commit09911bf2008-07-26 23:55:2966// instances live. The RenderThread supports an API that is used by its
67// consumer to talk indirectly to the RenderViews and supporting objects.
68// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:3469// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2970//
71// Most of the communication occurs in the form of IPC messages. They are
72// routed to the RenderThread according to the routing IDs of the messages.
73// The routing IDs correspond to RenderView instances.
[email protected]f1a29a02011-10-06 23:08:4474class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread,
[email protected]b3e83de2012-02-07 03:33:2875 public ChildThread,
76 public GpuChannelHostFactory {
initial.commit09911bf2008-07-26 23:55:2977 public:
[email protected]f1a29a02011-10-06 23:08:4478 static RenderThreadImpl* current();
[email protected]526476902011-10-06 20:34:0679
[email protected]f1a29a02011-10-06 23:08:4480 RenderThreadImpl();
[email protected]8930d472009-02-21 08:05:2881 // Constructor that's used when running in single process mode.
[email protected]f1a29a02011-10-06 23:08:4482 explicit RenderThreadImpl(const std::string& channel_name);
83 virtual ~RenderThreadImpl();
initial.commit09911bf2008-07-26 23:55:2984
[email protected]c1f50aa2010-02-18 03:46:5785 // Returns the routing ID of the RenderWidget containing the current script
86 // execution context (corresponding to WebFrame::frameForCurrentContext).
87 static int32 RoutingIDForCurrentContext();
88
[email protected]58436a12012-03-21 17:10:2689 // When initializing WebKit, ensure that any schemes needed for the content
90 // module are registered properly. Static to allow sharing with tests.
91 static void RegisterSchemes();
92
[email protected]526476902011-10-06 20:34:0693 // content::RenderThread implementation:
94 virtual bool Send(IPC::Message* msg) OVERRIDE;
95 virtual MessageLoop* GetMessageLoop() OVERRIDE;
96 virtual IPC::SyncChannel* GetChannel() OVERRIDE;
[email protected]526476902011-10-06 20:34:0697 virtual std::string GetLocale() OVERRIDE;
[email protected]07bb6332012-01-21 01:07:5798 virtual IPC::SyncMessageFilter* GetSyncMessageFilter() OVERRIDE;
[email protected]526476902011-10-06 20:34:0699 virtual void AddRoute(int32 routing_id,
100 IPC::Channel::Listener* listener) OVERRIDE;
101 virtual void RemoveRoute(int32 routing_id) OVERRIDE;
[email protected]77fc9b92011-10-15 16:20:37102 virtual int GenerateRoutingID() OVERRIDE;
[email protected]526476902011-10-06 20:34:06103 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
104 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
105 virtual void SetOutgoingMessageFilter(
106 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE;
107 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE;
108 virtual void RemoveObserver(
109 content::RenderProcessObserver* observer) OVERRIDE;
[email protected]359dfa32011-10-12 01:10:15110 virtual void SetResourceDispatcherDelegate(
111 content::ResourceDispatcherDelegate* delegate) OVERRIDE;
[email protected]526476902011-10-06 20:34:06112 virtual void WidgetHidden() OVERRIDE;
113 virtual void WidgetRestored() OVERRIDE;
114 virtual void EnsureWebKitInitialized() OVERRIDE;
115 virtual void RecordUserMetrics(const std::string& action) OVERRIDE;
[email protected]00614a82011-10-07 22:39:31116 virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer(
117 uint32 buffer_size) OVERRIDE;
[email protected]526476902011-10-06 20:34:06118 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
119 virtual bool IsRegisteredExtension(
120 const std::string& v8_extension_name) const OVERRIDE;
[email protected]6593ae12011-11-14 12:09:44121 virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE;
[email protected]526476902011-10-06 20:34:06122 virtual void IdleHandler() OVERRIDE;
[email protected]6593ae12011-11-14 12:09:44123 virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE;
124 virtual void SetIdleNotificationDelayInMs(
125 int64 idle_notification_delay_in_ms) OVERRIDE;
[email protected]526476902011-10-06 20:34:06126#if defined(OS_WIN)
127 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
128 virtual void ReleaseCachedFonts() OVERRIDE;
129#endif
[email protected]1223d6ef2011-03-28 16:47:50130
[email protected]988aacf2012-02-12 18:10:03131 // content::ChildThread:
132 virtual bool IsWebFrameValid(WebKit::WebFrame* frame) OVERRIDE;
133
[email protected]b3e83de2012-02-07 03:33:28134 // GpuChannelHostFactory implementation:
135 virtual bool IsMainThread() OVERRIDE;
136 virtual bool IsIOThread() OVERRIDE;
137 virtual MessageLoop* GetMainLoop() OVERRIDE;
[email protected]5b040e592012-02-10 02:56:10138 virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() OVERRIDE;
[email protected]b3e83de2012-02-07 03:33:28139 virtual base::WaitableEvent* GetShutDownEvent() OVERRIDE;
140 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(
141 uint32 size) OVERRIDE;
142 virtual int32 CreateViewCommandBuffer(
143 int32 surface_id,
144 const GPUCreateCommandBufferConfig& init_params) OVERRIDE;
145
146 // Synchronously establish a channel to the GPU plugin if not previously
147 // established or if it has been lost (for example if the GPU plugin crashed).
148 // If there is a pending asynchronous request, it will be completed by the
149 // time this routine returns.
150 virtual GpuChannelHost* EstablishGpuChannelSync(
151 content::CauseForGpuLaunch) OVERRIDE;
152
153
[email protected]c1f50aa2010-02-18 03:46:57154 // These methods modify how the next message is sent. Normally, when sending
155 // a synchronous message that runs a nested message loop, we need to suspend
156 // callbacks into WebKit. This involves disabling timers and deferring
157 // resource loads. However, there are exceptions when we need to customize
158 // the behavior.
159 void DoNotSuspendWebKitSharedTimer();
160 void DoNotNotifyWebKitOfModalLoop();
161
[email protected]f3150172011-10-22 02:28:45162 // Will be NULL if threaded compositing has not been enabled.
[email protected]a9fb30aa2011-10-06 06:58:46163 CompositorThread* compositor_thread() const {
164 return compositor_thread_.get();
165 }
166
[email protected]f430b5712009-08-21 21:46:31167 AppCacheDispatcher* appcache_dispatcher() const {
168 return appcache_dispatcher_.get();
169 }
170
[email protected]f7eb0a392011-07-12 10:19:51171 AudioInputMessageFilter* audio_input_message_filter() {
172 return audio_input_message_filter_.get();
173 }
174
175 AudioMessageFilter* audio_message_filter() {
176 return audio_message_filter_.get();
177 }
178
[email protected]d8cd8372012-03-09 10:49:51179 // Creates the embedder implementation of WebMediaStreamCenter.
180 // The resulting object is owned by WebKit and deleted by WebKit at tear-down.
181 WebKit::WebMediaStreamCenter* CreateMediaStreamCenter(
182 WebKit::WebMediaStreamCenterClient* client);
183
[email protected]80b161a2011-06-27 17:42:11184 VideoCaptureImplManager* video_capture_impl_manager() const {
185 return vc_manager_.get();
186 }
187
[email protected]b547fd42009-04-23 23:16:27188 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
189
[email protected]6217d392010-03-25 22:08:35190 // Get the GPU channel. Returns NULL if the channel is not established or
191 // has been lost.
192 GpuChannelHost* GetGpuChannel();
193
[email protected]c6a7b862010-08-20 22:19:38194 // Returns a MessageLoopProxy instance corresponding to the message loop
195 // of the thread on which file operations should be run. Must be called
196 // on the renderer's main thread.
197 scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy();
198
[email protected]1784b2f2011-11-24 10:53:48199 // Causes the idle handler to skip sending idle notifications
200 // on the two next scheduled calls, so idle notifications are
201 // not sent for at least one notification delay.
202 void PostponeIdleNotification();
203
[email protected]8930d472009-02-21 08:05:28204 private:
[email protected]edc64de2011-11-17 20:07:38205 virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:29206
[email protected]42f1d7822009-07-23 18:17:55207 void Init();
initial.commit09911bf2008-07-26 23:55:29208
[email protected]4e2a25a2012-01-27 00:42:08209 void OnSetZoomLevelForCurrentURL(const std::string& host, double zoom_level);
[email protected]56879f932010-12-13 21:05:37210 void OnDOMStorageEvent(const DOMStorageMsg_Event_Params& params);
[email protected]b9ab10c2009-08-07 18:09:55211 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]4e6419c2010-01-15 04:50:34212 void OnCreateNewView(const ViewMsg_New_Params& params);
initial.commit09911bf2008-07-26 23:55:29213 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
[email protected]b78e168b2009-09-21 22:05:45214 void OnPurgePluginListCache(bool reload_pages);
[email protected]6eac57a2011-07-12 21:15:09215 void OnNetworkStateChanged(bool online);
[email protected]b3df5a42010-05-11 14:31:09216 void OnGetAccessibilityTree();
[email protected]b69934e2011-10-29 02:51:52217 void OnTempCrashWithData(const GURL& data);
[email protected]b3df5a42010-05-11 14:31:09218
[email protected]1784b2f2011-11-24 10:53:48219 void IdleHandlerInForegroundTab();
220
initial.commit09911bf2008-07-26 23:55:29221 // These objects live solely on the render thread.
[email protected]f430b5712009-08-21 21:46:31222 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]31bfae72011-12-16 02:04:38223 scoped_ptr<IndexedDBDispatcher> main_thread_indexed_db_dispatcher_;
[email protected]8d6cba42011-09-02 10:05:19224 scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_;
[email protected]b7c7bcf2009-10-03 07:07:34225 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22226
[email protected]d8cd8372012-03-09 10:49:51227 // Used on the render thread and deleted by WebKit at shutdown.
228 content::MediaStreamCenter* media_stream_center_;
229
[email protected]e2b2d4a2009-10-24 03:32:59230 // Used on the renderer and IPC threads.
[email protected]017022b2009-07-27 23:06:34231 scoped_refptr<DBMessageFilter> db_message_filter_;
[email protected]f7eb0a392011-07-12 10:19:51232 scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_;
233 scoped_refptr<AudioMessageFilter> audio_message_filter_;
[email protected]82622452011-07-22 09:57:20234 scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_;
[email protected]017022b2009-07-27 23:06:34235
[email protected]80b161a2011-06-27 17:42:11236 // Used on multiple threads.
237 scoped_refptr<VideoCaptureImplManager> vc_manager_;
238
[email protected]1d4dbde2011-04-01 20:40:35239 // Used on multiple script execution context threads.
240 scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_;
241
[email protected]1a771262011-10-31 09:11:12242 // Initialize COM when using plugins outside the sandbox (Windows only).
243 scoped_ptr<base::win::ScopedCOMInitializer> initialize_com_;
244
[email protected]b547fd42009-04-23 23:16:27245 // If true, then a GetPlugins call is allowed to rescan the disk.
246 bool plugin_refresh_allowed_;
247
[email protected]bee16aab2009-08-26 15:55:03248 // The count of RenderWidgets running through this thread.
249 int widget_count_;
250
251 // The count of hidden RenderWidgets running through this thread.
252 int hidden_widget_count_;
253
254 // The current value of the idle notification timer delay.
[email protected]6593ae12011-11-14 12:09:44255 int64 idle_notification_delay_in_ms_;
[email protected]bee16aab2009-08-26 15:55:03256
[email protected]1784b2f2011-11-24 10:53:48257 // The number of idle handler calls that skip sending idle notifications.
258 int idle_notifications_to_skip_;
259
[email protected]80fc08c52010-03-09 07:43:50260 bool suspend_webkit_shared_timer_;
261 bool notify_webkit_of_modal_loop_;
[email protected]c1f50aa2010-02-18 03:46:57262
[email protected]71d6d852009-12-07 22:12:36263 // Timer that periodically calls IdleHandler.
[email protected]f1a29a02011-10-06 23:08:44264 base::RepeatingTimer<RenderThreadImpl> idle_timer_;
[email protected]71d6d852009-12-07 22:12:36265
[email protected]6217d392010-03-25 22:08:35266 // The channel from the renderer process to the GPU process.
267 scoped_refptr<GpuChannelHost> gpu_channel_;
268
[email protected]c6a7b862010-08-20 22:19:38269 // A lazily initiated thread on which file operations are run.
270 scoped_ptr<base::Thread> file_thread_;
271
[email protected]6779aa12011-03-29 17:32:24272 // Map of registered v8 extensions. The key is the extension name.
273 std::set<std::string> v8_extensions_;
[email protected]2a521c52011-01-26 18:45:21274
[email protected]2db58cf92011-12-01 21:39:01275 bool compositor_initialized_;
[email protected]a9fb30aa2011-10-06 06:58:46276 scoped_ptr<CompositorThread> compositor_thread_;
277
[email protected]64ffa0442011-10-03 22:08:36278 ObserverList<content::RenderProcessObserver> observers_;
[email protected]1223d6ef2011-03-28 16:47:50279
[email protected]f1a29a02011-10-06 23:08:44280 DISALLOW_COPY_AND_ASSIGN(RenderThreadImpl);
initial.commit09911bf2008-07-26 23:55:29281};
282
[email protected]f1a29a02011-10-06 23:08:44283#endif // CONTENT_RENDERER_RENDER_THREAD_IMPL_H_