blob: 51d742e6558d3780ae1440c28f4ce07667bbdf6e [file] [log] [blame]
[email protected]f85f0702010-01-30 09:31:011// Copyright (c) 2010 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]1d97d2e2008-12-18 23:39:025#ifndef CHROME_RENDERER_RENDER_THREAD_H_
6#define CHROME_RENDERER_RENDER_THREAD_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]c8865962009-12-16 07:47:398#include <set>
[email protected]b68d5ed2009-04-16 02:41:289#include <string>
[email protected]1bc83062009-02-06 00:16:3710#include <vector>
11
[email protected]010ea08a2009-10-11 20:21:3212#include "app/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/shared_memory.h"
[email protected]85c55dc2009-11-06 03:05:4614#include "base/string16.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/task.h"
[email protected]71d6d852009-12-07 22:12:3616#include "base/time.h"
17#include "base/timer.h"
[email protected]037fce02009-01-22 01:42:1518#include "build/build_config.h"
[email protected]8930d472009-02-21 08:05:2819#include "chrome/common/child_thread.h"
[email protected]b9ab10c2009-08-07 18:09:5520#include "chrome/common/css_colors.h"
[email protected]4e6419c2010-01-15 04:50:3421#include "chrome/common/dom_storage_common.h"
[email protected]55e57d42009-02-25 06:10:1722#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]3e90d4a2009-07-03 17:38:3923#include "chrome/renderer/visitedlink_slave.h"
[email protected]cb6037d2009-11-16 22:55:1724#include "ipc/ipc_platform_file.h"
initial.commit09911bf2008-07-26 23:55:2925
[email protected]1edc16b82009-04-07 17:45:5426class AppCacheDispatcher;
[email protected]dd9241932010-02-24 19:23:1327class CookieMessageFilter;
[email protected]017022b2009-07-27 23:06:3428class DBMessageFilter;
[email protected]a8624712009-04-17 00:51:3529class DevToolsAgentFilter;
[email protected]39008c02009-02-11 23:59:2530class FilePath;
[email protected]dfcb62a2009-06-17 19:32:4331class ListValue;
[email protected]b7c7bcf2009-10-03 07:07:3432class NullableString16;
[email protected]39008c02009-02-11 23:59:2533class RenderDnsMaster;
[email protected]55e57d42009-02-25 06:10:1734class RendererHistogram;
[email protected]e2b2d4a2009-10-24 03:32:5935class RendererWebDatabaseObserver;
[email protected]8d86fce2009-02-26 23:37:5536class RendererWebKitClientImpl;
[email protected]85c55dc2009-11-06 03:05:4637class SpellCheck;
[email protected]39008c02009-02-11 23:59:2538class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4039class UserScriptSlave;
[email protected]cccf90932009-08-23 17:56:2540class URLPattern;
41
[email protected]f85f0702010-01-30 09:31:0142struct ContentSettings;
[email protected]9b6f40e2009-06-11 15:54:2643struct RendererPreferences;
[email protected]c61cc652009-11-04 05:44:4044struct ViewMsg_DOMStorageEvent_Params;
[email protected]4e6419c2010-01-15 04:50:3445struct ViewMsg_New_Params;
[email protected]39008c02009-02-11 23:59:2546struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2947
[email protected]b7c7bcf2009-10-03 07:07:3448namespace WebKit {
49class WebStorageEventDispatcher;
50}
51
[email protected]81a34412009-01-05 19:17:2452// The RenderThreadBase is the minimal interface that a RenderView/Widget
53// expects from a render thread. The interface basically abstracts a way to send
54// and receive messages.
[email protected]00c39612010-03-06 02:53:2855//
56// TODO(brettw) this should be refactored like RenderProcess/RenderProcessImpl:
57// This class should be named RenderThread and the implementation below should
58// be RenderThreadImpl. The ::current() getter on the impl should then be moved
59// here so we can provide another implementation of RenderThread for tests
60// without having to check for NULL all the time.
[email protected]8930d472009-02-21 08:05:2861class RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4462 public:
63 virtual ~RenderThreadBase() {}
64
[email protected]8930d472009-02-21 08:05:2865 virtual bool Send(IPC::Message* msg) = 0;
66
[email protected]8085dbc82008-09-26 22:53:4467 // Called to add or remove a listener for a particular message routing ID.
68 // These methods normally get delegated to a MessageRouter.
69 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
70 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2471
72 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
73 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]bee16aab2009-08-26 15:55:0374
75 // Called by a RenderWidget when it is hidden or restored.
76 virtual void WidgetHidden() = 0;
77 virtual void WidgetRestored() = 0;
[email protected]8085dbc82008-09-26 22:53:4478};
79
initial.commit09911bf2008-07-26 23:55:2980// The RenderThread class represents a background thread where RenderView
81// instances live. The RenderThread supports an API that is used by its
82// consumer to talk indirectly to the RenderViews and supporting objects.
83// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:3484// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2985//
86// Most of the communication occurs in the form of IPC messages. They are
87// routed to the RenderThread according to the routing IDs of the messages.
88// The routing IDs correspond to RenderView instances.
[email protected]8930d472009-02-21 08:05:2889class RenderThread : public RenderThreadBase,
90 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2991 public:
[email protected]8930d472009-02-21 08:05:2892 // Grabs the IPC channel name from the command line.
93 RenderThread();
94 // Constructor that's used when running in single process mode.
[email protected]11f4857282009-11-13 19:56:1795 explicit RenderThread(const std::string& channel_name);
[email protected]8085dbc82008-09-26 22:53:4496 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2997
[email protected]8930d472009-02-21 08:05:2898 // Returns the one render thread for this process. Note that this should only
99 // be accessed when running on the render thread itself
[email protected]00c39612010-03-06 02:53:28100 //
101 // TODO(brettw) this should be on the abstract base class instead of here,
102 // and return the base class' interface instead. Currently this causes
103 // problems with testing. See the comment above RenderThreadBase above.
[email protected]8930d472009-02-21 08:05:28104 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:29105
[email protected]c1f50aa2010-02-18 03:46:57106 // Returns the routing ID of the RenderWidget containing the current script
107 // execution context (corresponding to WebFrame::frameForCurrentContext).
108 static int32 RoutingIDForCurrentContext();
109
[email protected]45776222009-07-15 20:21:58110 // Overridden from RenderThreadBase.
[email protected]c1f50aa2010-02-18 03:46:57111 virtual bool Send(IPC::Message* msg);
112 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
113 virtual void RemoveRoute(int32 routing_id);
[email protected]81a34412009-01-05 19:17:24114 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
115 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
[email protected]bee16aab2009-08-26 15:55:03116 virtual void WidgetHidden();
117 virtual void WidgetRestored();
118
[email protected]c1f50aa2010-02-18 03:46:57119 // These methods modify how the next message is sent. Normally, when sending
120 // a synchronous message that runs a nested message loop, we need to suspend
121 // callbacks into WebKit. This involves disabling timers and deferring
122 // resource loads. However, there are exceptions when we need to customize
123 // the behavior.
124 void DoNotSuspendWebKitSharedTimer();
125 void DoNotNotifyWebKitOfModalLoop();
126
[email protected]8d86fce2009-02-26 23:37:55127 VisitedLinkSlave* visited_link_slave() const {
128 return visited_link_slave_.get();
129 }
initial.commit09911bf2008-07-26 23:55:29130
[email protected]8d86fce2009-02-26 23:37:55131 UserScriptSlave* user_script_slave() const {
132 return user_script_slave_.get();
133 }
[email protected]1e0f70402008-10-16 23:57:47134
[email protected]f430b5712009-08-21 21:46:31135 AppCacheDispatcher* appcache_dispatcher() const {
136 return appcache_dispatcher_.get();
137 }
138
[email protected]85c55dc2009-11-06 03:05:46139 SpellCheck* spellchecker() const {
140 return spellchecker_.get();
141 }
[email protected]85c55dc2009-11-06 03:05:46142
[email protected]b547fd42009-04-23 23:16:27143 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
144
[email protected]71d6d852009-12-07 22:12:36145 bool is_extension_process() const { return is_extension_process_; }
146
initial.commit09911bf2008-07-26 23:55:29147 // Do DNS prefetch resolution of a hostname.
148 void Resolve(const char* name, size_t length);
149
[email protected]55e57d42009-02-25 06:10:17150 // Send all the Histogram data to browser.
[email protected]c9a3ef82009-05-28 22:02:46151 void SendHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17152
initial.commit09911bf2008-07-26 23:55:29153 // Invokes InformHostOfCacheStats after a short delay. Used to move this
154 // bookkeeping operation off the critical latency path.
155 void InformHostOfCacheStatsLater();
156
[email protected]c40acc32010-01-14 01:02:53157 // Sends a message to the browser to close all connections.
158 void CloseCurrentConnections();
[email protected]b07f29092009-06-05 07:33:21159
160 // Sends a message to the browser to enable or disable the disk cache.
161 void SetCacheMode(bool enabled);
162
[email protected]c8865962009-12-16 07:47:39163 // Update the list of active extensions that will be reported when we crash.
164 void UpdateActiveExtensions();
165
[email protected]8930d472009-02-21 08:05:28166 private:
167 virtual void OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29168
[email protected]42f1d7822009-07-23 18:17:55169 void Init();
initial.commit09911bf2008-07-26 23:55:29170
[email protected]176aa482008-11-14 03:25:15171 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]3e90d4a2009-07-03 17:38:39172 void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints);
173 void OnResetVisitedLinks();
[email protected]40bd6582009-12-04 23:49:51174 void OnSetZoomLevelForCurrentHost(const std::string& host, int zoom_level);
[email protected]f85f0702010-01-30 09:31:01175 void OnSetContentSettingsForCurrentHost(
176 const std::string& host, const ContentSettings& content_settings);
[email protected]55a35692010-02-11 23:25:21177 void OnUpdateUserScripts(base::SharedMemoryHandle table,
178 bool only_inject_incognito);
[email protected]703e807a2009-03-28 19:56:51179 void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
[email protected]45776222009-07-15 20:21:58180 void OnPageActionsUpdated(const std::string& extension_id,
[email protected]b7c7bcf2009-10-03 07:07:34181 const std::vector<std::string>& page_actions);
[email protected]c61cc652009-11-04 05:44:40182 void OnDOMStorageEvent(const ViewMsg_DOMStorageEvent_Params& params);
[email protected]75e126b932009-09-28 19:38:49183 void OnExtensionSetAPIPermissions(
184 const std::string& extension_id,
185 const std::vector<std::string>& permissions);
186 void OnExtensionSetHostPermissions(
187 const GURL& extension_url,
188 const std::vector<URLPattern>& permissions);
[email protected]db7331a2010-02-25 22:10:50189 void OnExtensionSetIncognitoEnabled(
190 const std::string& extension_id,
191 bool enabled);
initial.commit09911bf2008-07-26 23:55:29192 void OnSetNextPageID(int32 next_page_id);
[email protected]b9ab10c2009-08-07 18:09:55193 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]4e6419c2010-01-15 04:50:34194 void OnCreateNewView(const ViewMsg_New_Params& params);
initial.commit09911bf2008-07-26 23:55:29195 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
196 void OnSetCacheCapacities(size_t min_dead_capacity,
197 size_t max_dead_capacity,
198 size_t capacity);
199 void OnGetCacheResourceStats();
200
[email protected]55e57d42009-02-25 06:10:17201 // Send all histograms to browser.
[email protected]c9a3ef82009-05-28 22:02:46202 void OnGetRendererHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17203
[email protected]d41041092009-10-08 06:56:57204 // Send tcmalloc info to browser.
205 void OnGetRendererTcmalloc();
[email protected]38b48a82009-11-11 01:51:32206 void OnGetV8HeapStats();
[email protected]d41041092009-10-08 06:56:57207
[email protected]dfcb62a2009-06-17 19:32:43208 void OnExtensionMessageInvoke(const std::string& function_name,
209 const ListValue& args);
[email protected]fede6ca12009-10-08 18:24:26210 void OnPurgeMemory();
[email protected]b78e168b2009-09-21 22:05:45211 void OnPurgePluginListCache(bool reload_pages);
[email protected]75e5a872009-04-02 23:56:11212
[email protected]cb6037d2009-11-16 22:55:17213 void OnInitSpellChecker(IPC::PlatformFileForTransit bdict_file,
[email protected]85c55dc2009-11-06 03:05:46214 const std::vector<std::string>& custom_words,
215 const std::string& language,
216 bool auto_spell_correct);
217 void OnSpellCheckWordAdded(const std::string& word);
218 void OnSpellCheckEnableAutoSpellCorrect(bool enable);
[email protected]85c55dc2009-11-06 03:05:46219
initial.commit09911bf2008-07-26 23:55:29220 // Gather usage statistics from the in-memory cache and inform our host.
221 // These functions should be call periodically so that the host can make
222 // decisions about how to allocation resources using current information.
223 void InformHostOfCacheStats();
224
[email protected]90a3fbb12009-02-28 01:13:47225 // We initialize WebKit as late as possible.
226 void EnsureWebKitInitialized();
227
[email protected]bee16aab2009-08-26 15:55:03228 // A task we invoke periodically to assist with idle cleanup.
229 void IdleHandler();
230
[email protected]71d6d852009-12-07 22:12:36231 // Schedule a call to IdleHandler with the given initial delay.
232 void ScheduleIdleHandler(double initial_delay_s);
233
initial.commit09911bf2008-07-26 23:55:29234 // These objects live solely on the render thread.
[email protected]bee16aab2009-08-26 15:55:03235 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_;
[email protected]42f1d7822009-07-23 18:17:55236 scoped_ptr<VisitedLinkSlave> visited_link_slave_;
237 scoped_ptr<UserScriptSlave> user_script_slave_;
238 scoped_ptr<RenderDnsMaster> dns_master_;
[email protected]f430b5712009-08-21 21:46:31239 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22240 scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_;
[email protected]42f1d7822009-07-23 18:17:55241 scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
242 scoped_ptr<RendererWebKitClientImpl> webkit_client_;
[email protected]b7c7bcf2009-10-03 07:07:34243 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
[email protected]e2b2d4a2009-10-24 03:32:59244 scoped_ptr<RendererWebDatabaseObserver> renderer_web_database_observer_;
[email protected]85c55dc2009-11-06 03:05:46245 scoped_ptr<SpellCheck> spellchecker_;
[email protected]9291ed12009-07-23 17:33:22246
[email protected]e2b2d4a2009-10-24 03:32:59247 // Used on the renderer and IPC threads.
[email protected]017022b2009-07-27 23:06:34248 scoped_refptr<DBMessageFilter> db_message_filter_;
[email protected]dd9241932010-02-24 19:23:13249 scoped_refptr<CookieMessageFilter> cookie_message_filter_;
[email protected]017022b2009-07-27 23:06:34250
[email protected]5fa1c542009-05-05 20:36:07251#if defined(OS_POSIX)
252 scoped_refptr<IPC::ChannelProxy::MessageFilter>
253 suicide_on_channel_error_filter_;
254#endif
255
[email protected]b547fd42009-04-23 23:16:27256 // If true, then a GetPlugins call is allowed to rescan the disk.
257 bool plugin_refresh_allowed_;
258
[email protected]bee16aab2009-08-26 15:55:03259 // Is there a pending task for doing CacheStats.
260 bool cache_stats_task_pending_;
261
262 // The count of RenderWidgets running through this thread.
263 int widget_count_;
264
265 // The count of hidden RenderWidgets running through this thread.
266 int hidden_widget_count_;
267
268 // The current value of the idle notification timer delay.
269 double idle_notification_delay_in_s_;
270
[email protected]71d6d852009-12-07 22:12:36271 // True if this renderer is running extensions.
272 bool is_extension_process_;
273
[email protected]80fc08c52010-03-09 07:43:50274 bool suspend_webkit_shared_timer_;
275 bool notify_webkit_of_modal_loop_;
[email protected]c1f50aa2010-02-18 03:46:57276 bool did_notify_webkit_of_modal_loop_;
277
[email protected]71d6d852009-12-07 22:12:36278 // Timer that periodically calls IdleHandler.
279 base::RepeatingTimer<RenderThread> idle_timer_;
280
281 // Same as above, but on a longer timer and will run even if the process is
282 // not idle, to ensure that IdleHandle gets called eventually.
283 base::RepeatingTimer<RenderThread> forced_idle_timer_;
284
[email protected]1bc83062009-02-06 00:16:37285 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29286};
287
[email protected]1d97d2e2008-12-18 23:39:02288#endif // CHROME_RENDERER_RENDER_THREAD_H_