[email protected] | d3d6325d | 2012-01-03 21:17:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_RENDER_THREAD_IMPL_H_ |
| 6 | #define CONTENT_RENDERER_RENDER_THREAD_IMPL_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 9 | #include <set> |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 10 | #include <string> |
[email protected] | 1bc8306 | 2009-02-06 00:16:37 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 13 | #include "base/observer_list.h" |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 14 | #include "base/time.h" |
| 15 | #include "base/timer.h" |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 7ef40ffe1 | 2011-03-08 05:05:28 | [diff] [blame] | 17 | #include "content/common/child_thread.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 18 | #include "content/common/content_export.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 19 | #include "content/common/css_colors.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 20 | #include "content/common/gpu/gpu_process_launch_causes.h" |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 21 | #include "content/public/renderer/render_thread.h" |
[email protected] | a83d4229 | 2010-08-17 22:51:10 | [diff] [blame] | 22 | #include "ipc/ipc_channel_proxy.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 23 | #include "ui/gfx/native_widget_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 25 | class AppCacheDispatcher; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 26 | class AudioInputMessageFilter; |
| 27 | class AudioMessageFilter; |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 28 | class CompositorThread; |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 29 | class DBMessageFilter; |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 30 | class DevToolsAgentFilter; |
[email protected] | 83f93d3 | 2011-11-11 00:43:30 | [diff] [blame] | 31 | struct DOMStorageMsg_Event_Params; |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 32 | class GpuChannelHost; |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 33 | class IndexedDBDispatcher; |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 34 | class RendererWebKitPlatformSupportImpl; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 35 | class SkBitmap; |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 36 | class VideoCaptureImplManager; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 37 | struct ViewMsg_New_Params; |
[email protected] | 83f93d3 | 2011-11-11 00:43:30 | [diff] [blame] | 38 | class WebDatabaseObserverImpl; |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 39 | |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 40 | namespace WebKit { |
| 41 | class WebStorageEventDispatcher; |
| 42 | } |
| 43 | |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 44 | namespace base { |
| 45 | class MessageLoopProxy; |
| 46 | class Thread; |
[email protected] | 1a77126 | 2011-10-31 09:11:12 | [diff] [blame] | 47 | namespace win { |
| 48 | class ScopedCOMInitializer; |
| 49 | } |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | namespace content { |
| 53 | class RenderProcessObserver; |
| 54 | } |
| 55 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 56 | namespace v8 { |
| 57 | class Extension; |
| 58 | } |
| 59 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 60 | // The RenderThreadImpl class represents a background thread where RenderView |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | // 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] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 64 | // process (i.e., their corresponding TabContents). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | // |
| 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] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 69 | class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread, |
| 70 | public ChildThread { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 71 | public: |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 72 | static RenderThreadImpl* current(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 73 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 74 | RenderThreadImpl(); |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 75 | // Constructor that's used when running in single process mode. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 76 | explicit RenderThreadImpl(const std::string& channel_name); |
| 77 | virtual ~RenderThreadImpl(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 79 | // 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] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 83 | // content::RenderThread implementation: |
| 84 | virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 85 | virtual MessageLoop* GetMessageLoop() OVERRIDE; |
| 86 | virtual IPC::SyncChannel* GetChannel() OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 87 | virtual std::string GetLocale() OVERRIDE; |
[email protected] | 07bb633 | 2012-01-21 01:07:57 | [diff] [blame] | 88 | virtual IPC::SyncMessageFilter* GetSyncMessageFilter() OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 89 | virtual void AddRoute(int32 routing_id, |
| 90 | IPC::Channel::Listener* listener) OVERRIDE; |
| 91 | virtual void RemoveRoute(int32 routing_id) OVERRIDE; |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 92 | virtual int GenerateRoutingID() OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 93 | virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; |
| 94 | virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; |
| 95 | virtual void SetOutgoingMessageFilter( |
| 96 | IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE; |
| 97 | virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE; |
| 98 | virtual void RemoveObserver( |
| 99 | content::RenderProcessObserver* observer) OVERRIDE; |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 100 | virtual void SetResourceDispatcherDelegate( |
| 101 | content::ResourceDispatcherDelegate* delegate) OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 102 | virtual void WidgetHidden() OVERRIDE; |
| 103 | virtual void WidgetRestored() OVERRIDE; |
| 104 | virtual void EnsureWebKitInitialized() OVERRIDE; |
| 105 | virtual void RecordUserMetrics(const std::string& action) OVERRIDE; |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 106 | virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer( |
| 107 | uint32 buffer_size) OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 108 | virtual void RegisterExtension(v8::Extension* extension) OVERRIDE; |
| 109 | virtual bool IsRegisteredExtension( |
| 110 | const std::string& v8_extension_name) const OVERRIDE; |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 111 | virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 112 | virtual void IdleHandler() OVERRIDE; |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 113 | virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE; |
| 114 | virtual void SetIdleNotificationDelayInMs( |
| 115 | int64 idle_notification_delay_in_ms) OVERRIDE; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 116 | #if defined(OS_WIN) |
| 117 | virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE; |
| 118 | virtual void ReleaseCachedFonts() OVERRIDE; |
| 119 | #endif |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 120 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 121 | // These methods modify how the next message is sent. Normally, when sending |
| 122 | // a synchronous message that runs a nested message loop, we need to suspend |
| 123 | // callbacks into WebKit. This involves disabling timers and deferring |
| 124 | // resource loads. However, there are exceptions when we need to customize |
| 125 | // the behavior. |
| 126 | void DoNotSuspendWebKitSharedTimer(); |
| 127 | void DoNotNotifyWebKitOfModalLoop(); |
| 128 | |
[email protected] | f315017 | 2011-10-22 02:28:45 | [diff] [blame] | 129 | // Will be NULL if threaded compositing has not been enabled. |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 130 | CompositorThread* compositor_thread() const { |
| 131 | return compositor_thread_.get(); |
| 132 | } |
| 133 | |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 134 | AppCacheDispatcher* appcache_dispatcher() const { |
| 135 | return appcache_dispatcher_.get(); |
| 136 | } |
| 137 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 138 | AudioInputMessageFilter* audio_input_message_filter() { |
| 139 | return audio_input_message_filter_.get(); |
| 140 | } |
| 141 | |
| 142 | AudioMessageFilter* audio_message_filter() { |
| 143 | return audio_message_filter_.get(); |
| 144 | } |
| 145 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 146 | VideoCaptureImplManager* video_capture_impl_manager() const { |
| 147 | return vc_manager_.get(); |
| 148 | } |
| 149 | |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 150 | bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; } |
| 151 | |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 152 | // Synchronously establish a channel to the GPU plugin if not previously |
| 153 | // established or if it has been lost (for example if the GPU plugin crashed). |
| 154 | // If there is a pending asynchronous request, it will be completed by the |
| 155 | // time this routine returns. |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 156 | GpuChannelHost* EstablishGpuChannelSync(content::CauseForGpuLaunch); |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 157 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 158 | // Get the GPU channel. Returns NULL if the channel is not established or |
| 159 | // has been lost. |
| 160 | GpuChannelHost* GetGpuChannel(); |
| 161 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 162 | // Returns a MessageLoopProxy instance corresponding to the message loop |
| 163 | // of the thread on which file operations should be run. Must be called |
| 164 | // on the renderer's main thread. |
| 165 | scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); |
| 166 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 167 | // Causes the idle handler to skip sending idle notifications |
| 168 | // on the two next scheduled calls, so idle notifications are |
| 169 | // not sent for at least one notification delay. |
| 170 | void PostponeIdleNotification(); |
| 171 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 172 | private: |
[email protected] | edc64de | 2011-11-17 20:07:38 | [diff] [blame] | 173 | virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 175 | void Init(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 176 | |
[email protected] | 4e2a25a | 2012-01-27 00:42:08 | [diff] [blame^] | 177 | void OnSetZoomLevelForCurrentURL(const std::string& host, double zoom_level); |
[email protected] | 56879f93 | 2010-12-13 21:05:37 | [diff] [blame] | 178 | void OnDOMStorageEvent(const DOMStorageMsg_Event_Params& params); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 179 | void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 180 | void OnCreateNewView(const ViewMsg_New_Params& params); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | void OnTransferBitmap(const SkBitmap& bitmap, int resource_id); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 182 | void OnPurgePluginListCache(bool reload_pages); |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 183 | void OnNetworkStateChanged(bool online); |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 184 | void OnGetAccessibilityTree(); |
[email protected] | b69934e | 2011-10-29 02:51:52 | [diff] [blame] | 185 | void OnTempCrashWithData(const GURL& data); |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 186 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 187 | void IdleHandlerInForegroundTab(); |
| 188 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 189 | // These objects live solely on the render thread. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 190 | scoped_ptr<AppCacheDispatcher> appcache_dispatcher_; |
[email protected] | 31bfae7 | 2011-12-16 02:04:38 | [diff] [blame] | 191 | scoped_ptr<IndexedDBDispatcher> main_thread_indexed_db_dispatcher_; |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 192 | scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_; |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 193 | scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_; |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 194 | |
[email protected] | e2b2d4a | 2009-10-24 03:32:59 | [diff] [blame] | 195 | // Used on the renderer and IPC threads. |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 196 | scoped_refptr<DBMessageFilter> db_message_filter_; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 197 | scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_; |
| 198 | scoped_refptr<AudioMessageFilter> audio_message_filter_; |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 199 | scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_; |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 200 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 201 | // Used on multiple threads. |
| 202 | scoped_refptr<VideoCaptureImplManager> vc_manager_; |
| 203 | |
[email protected] | 1d4dbde | 2011-04-01 20:40:35 | [diff] [blame] | 204 | // Used on multiple script execution context threads. |
| 205 | scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_; |
| 206 | |
[email protected] | 1a77126 | 2011-10-31 09:11:12 | [diff] [blame] | 207 | // Initialize COM when using plugins outside the sandbox (Windows only). |
| 208 | scoped_ptr<base::win::ScopedCOMInitializer> initialize_com_; |
| 209 | |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 210 | // If true, then a GetPlugins call is allowed to rescan the disk. |
| 211 | bool plugin_refresh_allowed_; |
| 212 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 213 | // The count of RenderWidgets running through this thread. |
| 214 | int widget_count_; |
| 215 | |
| 216 | // The count of hidden RenderWidgets running through this thread. |
| 217 | int hidden_widget_count_; |
| 218 | |
| 219 | // The current value of the idle notification timer delay. |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 220 | int64 idle_notification_delay_in_ms_; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 221 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 222 | // The number of idle handler calls that skip sending idle notifications. |
| 223 | int idle_notifications_to_skip_; |
| 224 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 225 | bool suspend_webkit_shared_timer_; |
| 226 | bool notify_webkit_of_modal_loop_; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 227 | |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 228 | // Timer that periodically calls IdleHandler. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 229 | base::RepeatingTimer<RenderThreadImpl> idle_timer_; |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 230 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 231 | // The channel from the renderer process to the GPU process. |
| 232 | scoped_refptr<GpuChannelHost> gpu_channel_; |
| 233 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 234 | // A lazily initiated thread on which file operations are run. |
| 235 | scoped_ptr<base::Thread> file_thread_; |
| 236 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 237 | // Map of registered v8 extensions. The key is the extension name. |
| 238 | std::set<std::string> v8_extensions_; |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 239 | |
[email protected] | 2db58cf9 | 2011-12-01 21:39:01 | [diff] [blame] | 240 | bool compositor_initialized_; |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 241 | scoped_ptr<CompositorThread> compositor_thread_; |
| 242 | |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 243 | ObserverList<content::RenderProcessObserver> observers_; |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 244 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 245 | DISALLOW_COPY_AND_ASSIGN(RenderThreadImpl); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 246 | }; |
| 247 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 248 | #endif // CONTENT_RENDERER_RENDER_THREAD_IMPL_H_ |