blob: aff8fa63a4179b8c77b9580ab3fc6417165410b9 [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
initial.commit09911bf2008-07-26 23:55:295#include "chrome/renderer/render_thread.h"
6
[email protected]38b48a82009-11-11 01:51:327#include <v8.h>
8
[email protected]da00a2882009-03-09 17:51:199#include <algorithm>
[email protected]61a9b2d82010-02-26 00:31:0810#include <limits>
[email protected]75e126b932009-09-28 19:38:4911#include <map>
[email protected]da00a2882009-03-09 17:51:1912#include <vector>
13
[email protected]adf00bc2009-11-02 18:35:0014#if defined(USE_SYSTEM_SQLITE)
15#include <sqlite3.h>
16#else
17#include "third_party/sqlite/preprocessed/sqlite3.h"
18#endif
19
[email protected]06533c0b2009-03-05 21:39:1120#include "base/command_line.h"
[email protected]94f9a0f682009-06-15 18:30:3021#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0322#include "base/logging.h"
[email protected]b7c7bcf2009-10-03 07:07:3423#include "base/nullable_string16.h"
[email protected]d41041092009-10-08 06:56:5724#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2925#include "base/shared_memory.h"
[email protected]da00a2882009-03-09 17:51:1926#include "base/stats_table.h"
[email protected]b7c7bcf2009-10-03 07:07:3427#include "base/string_util.h"
[email protected]94f9a0f682009-06-15 18:30:3028#include "base/thread_local.h"
[email protected]f430b5712009-08-21 21:46:3129#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]c8865962009-12-16 07:47:3930#include "chrome/common/child_process_logging.h"
[email protected]06533c0b2009-03-05 21:39:1131#include "chrome/common/chrome_switches.h"
[email protected]017022b2009-07-27 23:06:3432#include "chrome/common/db_message_filter.h"
[email protected]c1f50aa2010-02-18 03:46:5733#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2934#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2635#include "chrome/common/renderer_preferences.h"
[email protected]90a3fbb12009-02-28 01:13:4736#include "chrome/common/url_constants.h"
[email protected]8930d472009-02-21 08:05:2837#include "chrome/plugin/npobject_util.h"
[email protected]2c62b562009-01-27 19:04:5038// TODO(port)
39#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/plugin/plugin_channel.h"
[email protected]2c62b562009-01-27 19:04:5041#else
[email protected]2c62b562009-01-27 19:04:5042#include "base/scoped_handle.h"
43#include "chrome/plugin/plugin_channel_base.h"
[email protected]2c62b562009-01-27 19:04:5044#endif
[email protected]a9602de2010-03-18 23:43:1145#include "chrome/renderer/automation/dom_automation_v8_extension.h"
[email protected]dd9241932010-02-24 19:23:1346#include "chrome/renderer/cookie_message_filter.h"
[email protected]a8624712009-04-17 00:51:3547#include "chrome/renderer/devtools_agent_filter.h"
[email protected]ad1f9bd2009-07-30 20:23:1548#include "chrome/renderer/extension_groups.h"
[email protected]a40caa972009-04-08 18:35:3449#include "chrome/renderer/extensions/event_bindings.h"
[email protected]309d7a282009-03-24 09:18:2750#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]be77f0a2009-08-25 08:31:1751#include "chrome/renderer/extensions/js_only_v8_extensions.h"
[email protected]0aa477bd2009-03-23 22:21:4352#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]3c8e3702009-05-01 16:27:4253#include "chrome/renderer/external_extension.h"
[email protected]0bc46552009-04-07 21:56:4254#include "chrome/renderer/loadtimes_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2955#include "chrome/renderer/net/render_dns_master.h"
[email protected]c1f50aa2010-02-18 03:46:5756#include "chrome/renderer/plugin_channel_host.h"
[email protected]00c39612010-03-06 02:53:2857#include "chrome/renderer/render_process_impl.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/renderer/render_view.h"
[email protected]40bd6582009-12-04 23:49:5159#include "chrome/renderer/render_view_visitor.h"
[email protected]8d86fce2009-02-26 23:37:5560#include "chrome/renderer/renderer_webkitclient_impl.h"
[email protected]e2b2d4a2009-10-24 03:32:5961#include "chrome/renderer/renderer_web_database_observer.h"
[email protected]85c55dc2009-11-06 03:05:4662#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3563#include "chrome/renderer/user_script_slave.h"
[email protected]d55aaa132009-09-28 21:08:0464#include "ipc/ipc_message.h"
[email protected]cb6037d2009-11-16 22:55:1765#include "ipc/ipc_platform_file.h"
[email protected]1b1f3eb2009-12-01 13:48:0466#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
[email protected]418ed5ab2009-11-12 01:14:4967#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
68#include "third_party/WebKit/WebKit/chromium/public/WebColor.h"
69#include "third_party/WebKit/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h"
70#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
71#include "third_party/WebKit/WebKit/chromium/public/WebFontCache.h"
[email protected]40bd6582009-12-04 23:49:5172#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
[email protected]418ed5ab2009-11-12 01:14:4973#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
74#include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h"
76#include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h"
77#include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h"
78#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
[email protected]b07f29092009-06-05 07:33:2179#include "webkit/extensions/v8/benchmarking_extension.h"
[email protected]06533c0b2009-03-05 21:39:1180#include "webkit/extensions/v8/gears_extension.h"
81#include "webkit/extensions/v8/interval_extension.h"
82#include "webkit/extensions/v8/playback_extension.h"
[email protected]2c62b562009-01-27 19:04:5083
[email protected]da00a2882009-03-09 17:51:1984#if defined(OS_WIN)
85#include <windows.h>
86#include <objbase.h>
87#endif
88
[email protected]fe819f52009-12-15 07:58:1189#if defined(OS_MACOSX)
90#include "chrome/app/breakpad_mac.h"
91#endif
92
[email protected]6217d392010-03-25 22:08:3593#if defined(OS_POSIX)
94#include "ipc/ipc_channel_posix.h"
95#endif
96
[email protected]2c434b32009-03-19 06:27:4797using WebKit::WebCache;
[email protected]fede6ca12009-10-08 18:24:2698using WebKit::WebCrossOriginPreflightResultCache;
99using WebKit::WebFontCache;
[email protected]f85f0702010-01-30 09:31:01100using WebKit::WebFrame;
[email protected]adf00bc2009-11-02 18:35:00101using WebKit::WebRuntimeFeatures;
[email protected]204758c2009-10-22 03:56:30102using WebKit::WebSecurityPolicy;
[email protected]98d7127b2009-10-23 18:26:51103using WebKit::WebScriptController;
[email protected]2c434b32009-03-19 06:27:47104using WebKit::WebString;
[email protected]b7c7bcf2009-10-03 07:07:34105using WebKit::WebStorageEventDispatcher;
[email protected]50ae00ef2009-10-19 05:11:03106using WebKit::WebView;
initial.commit09911bf2008-07-26 23:55:29107
[email protected]42f1d7822009-07-23 18:17:55108namespace {
[email protected]2c434b32009-03-19 06:27:47109static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
[email protected]bee16aab2009-08-26 15:55:03110static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
[email protected]71d6d852009-12-07 22:12:36111static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
112static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
[email protected]bee16aab2009-08-26 15:55:03113
[email protected]94f9a0f682009-06-15 18:30:30114static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls(
115 base::LINKER_INITIALIZED);
[email protected]1edc16b82009-04-07 17:45:54116
[email protected]5fa1c542009-05-05 20:36:07117#if defined(OS_POSIX)
118class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter {
119 void OnChannelError() {
120 // On POSIX, at least, one can install an unload handler which loops
121 // forever and leave behind a renderer process which eats 100% CPU forever.
122 //
123 // This is because the terminate signals (ViewMsg_ShouldClose and the error
124 // from the IPC channel) are routed to the main message loop but never
125 // processed (because that message loop is stuck in V8).
126 //
127 // One could make the browser SIGKILL the renderers, but that leaves open a
128 // large window where a browser failure (or a user, manually terminating
129 // the browser because "it's stuck") will leave behind a process eating all
130 // the CPU.
131 //
132 // So, we install a filter on the channel so that we can process this event
133 // here and kill the process.
[email protected]fe819f52009-12-15 07:58:11134
135#if defined(OS_MACOSX)
136 // TODO(viettrungluu): crbug.com/28547: The following is needed, as a
137 // stopgap, to avoid leaking due to not releasing Breakpad properly.
138 // TODO(viettrungluu): Investigate why this is being called.
139 if (IsCrashReporterEnabled()) {
140 LOG(INFO) << "Cleaning up Breakpad.";
141 DestructCrashReporter();
142 } else {
143 LOG(INFO) << "Breakpad not enabled; no clean-up needed.";
144 }
145#endif // OS_MACOSX
146
[email protected]5fa1c542009-05-05 20:36:07147 _exit(0);
148 }
149};
150#endif
[email protected]40bd6582009-12-04 23:49:51151
[email protected]f85f0702010-01-30 09:31:01152class RenderViewContentSettingsSetter : public RenderViewVisitor {
153 public:
154 RenderViewContentSettingsSetter(const std::string& host,
155 const ContentSettings& content_settings)
156 : host_(host),
157 content_settings_(content_settings) {
158 }
159
160 virtual bool Visit(RenderView* render_view) {
[email protected]433819d2010-01-30 20:20:01161 if (GURL(render_view->webview()->mainFrame()->url()).host() == host_)
162 render_view->SetContentSettings(content_settings_);
[email protected]f85f0702010-01-30 09:31:01163 return true;
164 }
165
166 private:
167 std::string host_;
168 ContentSettings content_settings_;
169
170 DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter);
171};
172
[email protected]40bd6582009-12-04 23:49:51173class RenderViewZoomer : public RenderViewVisitor {
174 public:
175 RenderViewZoomer(const std::string& host, int zoom_level)
176 : host_(host),
177 zoom_level_(zoom_level) {
178 }
179
180 virtual bool Visit(RenderView* render_view) {
181 WebView* webview = render_view->webview(); // Guaranteed non-NULL.
182 if (GURL(webview->mainFrame()->url()).host() == host_)
183 webview->setZoomLevel(false, zoom_level_);
184 return true;
185 }
186
187 private:
188 std::string host_;
189 int zoom_level_;
190
191 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
192};
[email protected]42f1d7822009-07-23 18:17:55193} // namespace
194
195// When we run plugins in process, we actually run them on the render thread,
196// which means that we need to make the render thread pump UI events.
197RenderThread::RenderThread() {
198 Init();
199}
200
201RenderThread::RenderThread(const std::string& channel_name)
202 : ChildThread(channel_name) {
203 Init();
204}
[email protected]5fa1c542009-05-05 20:36:07205
initial.commit09911bf2008-07-26 23:55:29206void RenderThread::Init() {
[email protected]94f9a0f682009-06-15 18:30:30207 lazy_tls.Pointer()->Set(this);
[email protected]2c62b562009-01-27 19:04:50208#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34209 // If you are running plugins in this thread you need COM active but in
210 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28211 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34212 CoInitialize(0);
[email protected]2c62b562009-01-27 19:04:50213#endif
initial.commit09911bf2008-07-26 23:55:29214
[email protected]71d6d852009-12-07 22:12:36215 std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
216 switches::kProcessType);
217 is_extension_process_ = type_str == switches::kExtensionProcess;
[email protected]b2a74ca2010-03-12 17:57:09218 is_incognito_process_ = false;
[email protected]80fc08c52010-03-09 07:43:50219 suspend_webkit_shared_timer_ = true;
220 notify_webkit_of_modal_loop_ = true;
[email protected]c1f50aa2010-02-18 03:46:57221 did_notify_webkit_of_modal_loop_ = false;
[email protected]42f1d7822009-07-23 18:17:55222 plugin_refresh_allowed_ = true;
[email protected]bee16aab2009-08-26 15:55:03223 cache_stats_task_pending_ = false;
224 widget_count_ = 0;
225 hidden_widget_count_ = 0;
[email protected]71d6d852009-12-07 22:12:36226 idle_notification_delay_in_s_ = is_extension_process_ ?
227 kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS;
[email protected]bee16aab2009-08-26 15:55:03228 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this));
[email protected]8d86fce2009-02-26 23:37:55229
[email protected]8d86fce2009-02-26 23:37:55230 visited_link_slave_.reset(new VisitedLinkSlave());
231 user_script_slave_.reset(new UserScriptSlave());
232 dns_master_.reset(new RenderDnsMaster());
233 histogram_snapshots_.reset(new RendererHistogramSnapshots());
[email protected]f430b5712009-08-21 21:46:31234 appcache_dispatcher_.reset(new AppCacheDispatcher(this));
[email protected]dd9241932010-02-24 19:23:13235 spellchecker_.reset(new SpellCheck());
236
[email protected]a8624712009-04-17 00:51:35237 devtools_agent_filter_ = new DevToolsAgentFilter();
238 AddFilter(devtools_agent_filter_.get());
[email protected]dd9241932010-02-24 19:23:13239
[email protected]017022b2009-07-27 23:06:34240 db_message_filter_ = new DBMessageFilter();
241 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13242
243 cookie_message_filter_ = new CookieMessageFilter();
244 AddFilter(cookie_message_filter_.get());
[email protected]5fa1c542009-05-05 20:36:07245
246#if defined(OS_POSIX)
247 suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter;
248 AddFilter(suicide_on_channel_error_filter_.get());
249#endif
initial.commit09911bf2008-07-26 23:55:29250}
251
[email protected]42f1d7822009-07-23 18:17:55252RenderThread::~RenderThread() {
[email protected]12cbfda32010-01-30 01:04:25253 // Wait for all databases to be closed.
254 if (renderer_web_database_observer_.get())
255 renderer_web_database_observer_->WaitForAllDatabasesToClose();
256
[email protected]8d86fce2009-02-26 23:37:55257 // Shutdown in reverse of the initialization order.
[email protected]a8624712009-04-17 00:51:35258 RemoveFilter(devtools_agent_filter_.get());
[email protected]017022b2009-07-27 23:06:34259 RemoveFilter(db_message_filter_.get());
260 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25261
[email protected]42f1d7822009-07-23 18:17:55262 if (webkit_client_.get())
[email protected]9291ed12009-07-23 17:33:22263 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22264
[email protected]94f9a0f682009-06-15 18:30:30265 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30266
[email protected]8d86fce2009-02-26 23:37:55267 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50268#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29269 // Clean up plugin channels before this thread goes away.
270 PluginChannelBase::CleanupChannels();
[email protected]bdef78b52009-04-16 19:31:34271 // Don't call COM if the renderer is in the sandbox.
[email protected]00c39612010-03-06 02:53:28272 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34273 CoUninitialize();
[email protected]2c62b562009-01-27 19:04:50274#endif
initial.commit09911bf2008-07-26 23:55:29275}
276
[email protected]42f1d7822009-07-23 18:17:55277RenderThread* RenderThread::current() {
278 return lazy_tls.Pointer()->Get();
279}
280
[email protected]c1f50aa2010-02-18 03:46:57281int32 RenderThread::RoutingIDForCurrentContext() {
282 int32 routing_id = MSG_ROUTING_CONTROL;
283 if (v8::Context::InContext()) {
[email protected]d5ddf9a2010-03-04 00:48:29284 WebFrame* frame = WebFrame::frameForCurrentContext();
285 if (frame) {
286 RenderView* view = RenderView::FromWebView(frame->view());
287 if (view)
288 routing_id = view->routing_id();
289 }
[email protected]c1f50aa2010-02-18 03:46:57290 } else {
291 DLOG(WARNING) << "Not called within a script context!";
292 }
293 return routing_id;
294}
295
296bool RenderThread::Send(IPC::Message* msg) {
[email protected]80fc08c52010-03-09 07:43:50297 // Certain synchronous messages can result in an app-modal cookie prompt.
298 // This could cause a complete hang of Chrome if a windowed plug-in is trying
299 // to communicate with the renderer thread since the browser's UI thread
300 // could be stuck (within a Windows API call) trying to synchronously
301 // communicate with the plug-in. The remedy is to pump messages on this
302 // thread while the cookie prompt is showing. This creates an opportunity
303 // for re-entrancy into WebKit, so we need to take care to disable callbacks,
304 // timers, and pending network loads that could trigger such callbacks.
[email protected]c1f50aa2010-02-18 03:46:57305
[email protected]80fc08c52010-03-09 07:43:50306 bool pumping_events = false, may_show_cookie_prompt = false;
307 if (msg->is_sync()) {
308 if (msg->is_caller_pumping_messages()) {
309 pumping_events = true;
310 } else {
311 switch (msg->type()) {
312 case ViewHostMsg_GetCookies::ID:
313 case ViewHostMsg_GetRawCookies::ID:
314 case ViewHostMsg_DOMStorageSetItem::ID:
315 case ViewHostMsg_SyncLoad::ID:
316 may_show_cookie_prompt = true;
317 pumping_events = true;
318 break;
319 }
320 }
[email protected]c1f50aa2010-02-18 03:46:57321 }
322
[email protected]80fc08c52010-03-09 07:43:50323 bool suspend_webkit_shared_timer = true; // default value
324 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57325
[email protected]80fc08c52010-03-09 07:43:50326 bool notify_webkit_of_modal_loop = true; // default value
327 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
328
329 gfx::NativeViewId host_window = 0;
[email protected]c1f50aa2010-02-18 03:46:57330
331 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50332 // See ViewMsg_SignalCookiePromptEvent.
333 if (may_show_cookie_prompt) {
334 static_cast<IPC::SyncMessage*>(msg)->set_pump_messages_event(
335 cookie_message_filter_->pump_messages_event());
336 }
337
338 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57339 webkit_client_->SuspendSharedTimer();
340
341 // WebKit does not like nested calls to willEnterModalLoop.
342 // TODO(darin): Fix WebKit to allow nesting.
[email protected]80fc08c52010-03-09 07:43:50343 if (notify_webkit_of_modal_loop && !did_notify_webkit_of_modal_loop_) {
[email protected]c1f50aa2010-02-18 03:46:57344 WebView::willEnterModalLoop();
345 did_notify_webkit_of_modal_loop_ = true;
346 }
347
[email protected]80fc08c52010-03-09 07:43:50348 RenderWidget* widget =
349 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
350 if (widget) {
351 host_window = widget->host_window();
[email protected]c1f50aa2010-02-18 03:46:57352 PluginChannelHost::Broadcast(
353 new PluginMsg_SignalModalDialogEvent(host_window));
354 }
355 }
356
357 bool rv = ChildThread::Send(msg);
358
359 if (pumping_events) {
360 if (host_window) {
361 PluginChannelHost::Broadcast(
362 new PluginMsg_ResetModalDialogEvent(host_window));
363 }
364
[email protected]80fc08c52010-03-09 07:43:50365 if (notify_webkit_of_modal_loop && did_notify_webkit_of_modal_loop_) {
[email protected]c1f50aa2010-02-18 03:46:57366 WebView::didExitModalLoop();
367 did_notify_webkit_of_modal_loop_ = false;
368 }
369
[email protected]80fc08c52010-03-09 07:43:50370 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57371 webkit_client_->ResumeSharedTimer();
[email protected]80fc08c52010-03-09 07:43:50372
373 // We may end up nesting calls to Send, so we defer the reset until we
374 // return to the top-most message loop.
375 if (may_show_cookie_prompt &&
376 cookie_message_filter_->pump_messages_event()->IsSignaled()) {
377 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
378 NewRunnableMethod(cookie_message_filter_.get(),
379 &CookieMessageFilter::ResetPumpMessagesEvent));
380 }
[email protected]c1f50aa2010-02-18 03:46:57381 }
382
383 return rv;
384}
385
386void RenderThread::AddRoute(int32 routing_id,
387 IPC::Channel::Listener* listener) {
388 widget_count_++;
389 return ChildThread::AddRoute(routing_id, listener);
390}
391
392void RenderThread::RemoveRoute(int32 routing_id) {
393 widget_count_--;
394 return ChildThread::RemoveRoute(routing_id);
395}
396
[email protected]42f1d7822009-07-23 18:17:55397void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
398 channel()->AddFilter(filter);
399}
400
401void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
402 channel()->RemoveFilter(filter);
403}
404
[email protected]bee16aab2009-08-26 15:55:03405void RenderThread::WidgetHidden() {
406 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50407 hidden_widget_count_++;
[email protected]71d6d852009-12-07 22:12:36408 if (!is_extension_process() &&
409 widget_count_ && hidden_widget_count_ == widget_count_)
410 ScheduleIdleHandler(kInitialIdleHandlerDelayS);
[email protected]bee16aab2009-08-26 15:55:03411}
412
413void RenderThread::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08414 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03415 hidden_widget_count_--;
[email protected]71d6d852009-12-07 22:12:36416 if (!is_extension_process())
417 idle_timer_.Stop();
[email protected]bee16aab2009-08-26 15:55:03418}
419
[email protected]c1f50aa2010-02-18 03:46:57420void RenderThread::DoNotSuspendWebKitSharedTimer() {
[email protected]80fc08c52010-03-09 07:43:50421 suspend_webkit_shared_timer_ = false;
[email protected]c1f50aa2010-02-18 03:46:57422}
423
424void RenderThread::DoNotNotifyWebKitOfModalLoop() {
[email protected]80fc08c52010-03-09 07:43:50425 notify_webkit_of_modal_loop_ = false;
[email protected]c1f50aa2010-02-18 03:46:57426}
427
[email protected]42f1d7822009-07-23 18:17:55428void RenderThread::Resolve(const char* name, size_t length) {
429 return dns_master_->Resolve(name, length);
430}
431
432void RenderThread::SendHistograms(int sequence_number) {
433 return histogram_snapshots_->SendHistograms(sequence_number);
434}
435
[email protected]176aa482008-11-14 03:25:15436void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) {
[email protected]5fe733de2009-02-11 18:59:20437 DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle";
initial.commit09911bf2008-07-26 23:55:29438 visited_link_slave_->Init(table);
439}
440
[email protected]3e90d4a2009-07-03 17:38:39441void RenderThread::OnAddVisitedLinks(
442 const VisitedLinkSlave::Fingerprints& fingerprints) {
443 for (size_t i = 0; i < fingerprints.size(); ++i)
[email protected]50ae00ef2009-10-19 05:11:03444 WebView::updateVisitedLinkState(fingerprints[i]);
[email protected]3e90d4a2009-07-03 17:38:39445}
446
447void RenderThread::OnResetVisitedLinks() {
[email protected]50ae00ef2009-10-19 05:11:03448 WebView::resetVisitedLinkState();
[email protected]3e90d4a2009-07-03 17:38:39449}
450
[email protected]f85f0702010-01-30 09:31:01451void RenderThread::OnSetContentSettingsForCurrentHost(
452 const std::string& host,
453 const ContentSettings& content_settings) {
454 RenderViewContentSettingsSetter setter(host, content_settings);
455 RenderView::ForEach(&setter);
456}
457
[email protected]40bd6582009-12-04 23:49:51458void RenderThread::OnSetZoomLevelForCurrentHost(const std::string& host,
459 int zoom_level) {
460 RenderViewZoomer zoomer(host, zoom_level);
461 RenderView::ForEach(&zoomer);
462}
463
[email protected]b2a74ca2010-03-12 17:57:09464void RenderThread::OnUpdateUserScripts(base::SharedMemoryHandle scripts) {
[email protected]5fe733de2009-02-11 18:59:20465 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle";
[email protected]b2a74ca2010-03-12 17:57:09466 user_script_slave_->UpdateScripts(scripts);
[email protected]c8865962009-12-16 07:47:39467 UpdateActiveExtensions();
[email protected]1e0f70402008-10-16 23:57:47468}
469
[email protected]703e807a2009-03-28 19:56:51470void RenderThread::OnSetExtensionFunctionNames(
471 const std::vector<std::string>& names) {
[email protected]a1a0df02009-04-09 08:18:04472 ExtensionProcessBindings::SetFunctionNames(names);
[email protected]703e807a2009-03-28 19:56:51473}
474
[email protected]45776222009-07-15 20:21:58475void RenderThread::OnPageActionsUpdated(
476 const std::string& extension_id,
477 const std::vector<std::string>& page_actions) {
478 ExtensionProcessBindings::SetPageActions(extension_id, page_actions);
479}
480
[email protected]cccf90932009-08-23 17:56:25481void RenderThread::OnExtensionSetAPIPermissions(
[email protected]35506352009-08-07 18:58:19482 const std::string& extension_id,
483 const std::vector<std::string>& permissions) {
[email protected]cccf90932009-08-23 17:56:25484 ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions);
[email protected]71d6d852009-12-07 22:12:36485
486 // This is called when starting a new extension page, so start the idle
487 // handler ticking.
[email protected]71d6d852009-12-07 22:12:36488 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]c8865962009-12-16 07:47:39489
490 UpdateActiveExtensions();
[email protected]cccf90932009-08-23 17:56:25491}
492
493void RenderThread::OnExtensionSetHostPermissions(
494 const GURL& extension_url, const std::vector<URLPattern>& permissions) {
495 ExtensionProcessBindings::SetHostPermissions(extension_url, permissions);
[email protected]35506352009-08-07 18:58:19496}
497
[email protected]db7331a2010-02-25 22:10:50498void RenderThread::OnExtensionSetIncognitoEnabled(
499 const std::string& extension_id, bool enabled) {
500 ExtensionProcessBindings::SetIncognitoEnabled(extension_id, enabled);
501}
502
[email protected]c61cc652009-11-04 05:44:40503void RenderThread::OnDOMStorageEvent(
504 const ViewMsg_DOMStorageEvent_Params& params) {
505 if (!dom_storage_event_dispatcher_.get())
[email protected]b7c7bcf2009-10-03 07:07:34506 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
[email protected]c61cc652009-11-04 05:44:40507 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key_,
[email protected]ee2be5b32009-11-05 09:13:12508 params.old_value_, params.new_value_, params.origin_, params.url_,
[email protected]c61cc652009-11-04 05:44:40509 params.storage_type_ == DOM_STORAGE_LOCAL);
[email protected]b7c7bcf2009-10-03 07:07:34510}
511
[email protected]8930d472009-02-21 08:05:28512void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1edc16b82009-04-07 17:45:54513 // App cache messages are handled by a delegate.
[email protected]f430b5712009-08-21 21:46:31514 if (appcache_dispatcher_->OnMessageReceived(msg))
[email protected]1edc16b82009-04-07 17:45:54515 return;
516
[email protected]8930d472009-02-21 08:05:28517 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
518 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
[email protected]3e90d4a2009-07-03 17:38:39519 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks)
520 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks)
[email protected]f85f0702010-01-30 09:31:01521 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentHost,
522 OnSetContentSettingsForCurrentHost)
[email protected]40bd6582009-12-04 23:49:51523 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentHost,
524 OnSetZoomLevelForCurrentHost)
[email protected]b2a74ca2010-03-12 17:57:09525 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess)
[email protected]8930d472009-02-21 08:05:28526 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
[email protected]b9ab10c2009-08-07 18:09:55527 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
[email protected]8930d472009-02-21 08:05:28528 // TODO(port): removed from render_messages_internal.h;
529 // is there a new non-windows message I should add here?
530 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
531 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
[email protected]55e57d42009-02-25 06:10:17532 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms,
[email protected]c9a3ef82009-05-28 22:02:46533 OnGetRendererHistograms)
[email protected]d41041092009-10-08 06:56:57534#if defined(USE_TCMALLOC)
535 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc,
536 OnGetRendererTcmalloc)
537#endif
[email protected]38b48a82009-11-11 01:51:32538 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats)
[email protected]8930d472009-02-21 08:05:28539 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
540 OnGetCacheResourceStats)
[email protected]2f2243e2009-05-26 02:27:02541 IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts,
[email protected]8930d472009-02-21 08:05:28542 OnUpdateUserScripts)
[email protected]b68d5ed2009-04-16 02:41:28543 // TODO(rafaelw): create an ExtensionDispatcher that handles extension
544 // messages seperates their handling from the RenderThread.
[email protected]dfcb62a2009-06-17 19:32:43545 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
546 OnExtensionMessageInvoke)
[email protected]703e807a2009-03-28 19:56:51547 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
548 OnSetExtensionFunctionNames)
[email protected]fede6ca12009-10-08 18:24:26549 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory)
[email protected]b547fd42009-04-23 23:16:27550 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
551 OnPurgePluginListCache)
[email protected]45776222009-07-15 20:21:58552 IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions,
553 OnPageActionsUpdated)
[email protected]cccf90932009-08-23 17:56:25554 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions,
555 OnExtensionSetAPIPermissions)
556 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions,
557 OnExtensionSetHostPermissions)
[email protected]db7331a2010-02-25 22:10:50558 IPC_MESSAGE_HANDLER(ViewMsg_Extension_ExtensionSetIncognitoEnabled,
559 OnExtensionSetIncognitoEnabled)
[email protected]b7c7bcf2009-10-03 07:07:34560 IPC_MESSAGE_HANDLER(ViewMsg_DOMStorageEvent,
561 OnDOMStorageEvent)
[email protected]d55aaa132009-09-28 21:08:04562#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]12636df2009-09-28 22:32:21563 IPC_MESSAGE_HANDLER(ViewMsg_SetIPCLoggingEnabled,
[email protected]d55aaa132009-09-28 21:08:04564 OnSetIPCLoggingEnabled)
565#endif
[email protected]85c55dc2009-11-06 03:05:46566 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_Init,
567 OnInitSpellChecker)
568 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_WordAdded,
569 OnSpellCheckWordAdded)
570 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_EnableAutoSpellCorrect,
571 OnSpellCheckEnableAutoSpellCorrect)
[email protected]6217d392010-03-25 22:08:35572 IPC_MESSAGE_HANDLER(ViewMsg_GpuChannelEstablished, OnGpuChannelEstablished)
[email protected]8930d472009-02-21 08:05:28573 IPC_END_MESSAGE_MAP()
initial.commit09911bf2008-07-26 23:55:29574}
575
576void RenderThread::OnSetNextPageID(int32 next_page_id) {
577 // This should only be called at process initialization time, so we shouldn't
578 // have to worry about thread-safety.
579 RenderView::SetNextPageID(next_page_id);
580}
581
[email protected]b9ab10c2009-08-07 18:09:55582// Called when to register CSS Color name->system color mappings.
583// We update the colors one by one and then tell WebKit to refresh all render
584// views.
585void RenderThread::OnSetCSSColors(
586 const std::vector<CSSColors::CSSColorMapping>& colors) {
[email protected]f5e4b9bf2009-10-08 00:59:59587 EnsureWebKitInitialized();
[email protected]b9ab10c2009-08-07 18:09:55588 size_t num_colors = colors.size();
589 scoped_array<WebKit::WebColorName> color_names(
590 new WebKit::WebColorName[num_colors]);
591 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]);
592 size_t i = 0;
593 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it =
594 colors.begin();
595 it != colors.end();
596 ++it, ++i) {
597 color_names[i] = it->first;
598 web_colors[i] = it->second;
599 }
600 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors);
601}
602
[email protected]4e6419c2010-01-15 04:50:34603void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:47604 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:33605 // When bringing in render_view, also bring in webkit's glue and jsbindings.
initial.commit09911bf2008-07-26 23:55:29606 RenderView::Create(
[email protected]4e6419c2010-01-15 04:50:34607 this, params.parent_window, MSG_ROUTING_NONE, params.renderer_preferences,
608 params.web_preferences, new SharedRenderViewCounter(0), params.view_id,
609 params.session_storage_namespace_id);
[email protected]7f874dec2009-02-06 01:48:27610}
[email protected]4274e582009-01-27 22:09:56611
initial.commit09911bf2008-07-26 23:55:29612void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity,
613 size_t max_dead_capacity,
614 size_t capacity) {
[email protected]90a3fbb12009-02-28 01:13:47615 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47616 WebCache::setCapacities(
617 min_dead_capacity, max_dead_capacity, capacity);
initial.commit09911bf2008-07-26 23:55:29618}
619
620void RenderThread::OnGetCacheResourceStats() {
[email protected]90a3fbb12009-02-28 01:13:47621 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47622 WebCache::ResourceTypeStats stats;
623 WebCache::getResourceTypeStats(&stats);
initial.commit09911bf2008-07-26 23:55:29624 Send(new ViewHostMsg_ResourceTypeStats(stats));
625}
626
[email protected]c9a3ef82009-05-28 22:02:46627void RenderThread::OnGetRendererHistograms(int sequence_number) {
628 SendHistograms(sequence_number);
[email protected]55e57d42009-02-25 06:10:17629}
630
[email protected]d41041092009-10-08 06:56:57631#if defined(USE_TCMALLOC)
632void RenderThread::OnGetRendererTcmalloc() {
633 std::string result;
634 char buffer[1024 * 32];
[email protected]a4dc33f2009-10-20 15:09:55635 base::ProcessId pid = base::GetCurrentProcId();
[email protected]d41041092009-10-08 06:56:57636 MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
637 result.append(buffer);
638 Send(new ViewHostMsg_RendererTcmalloc(pid, result));
639}
640#endif
641
[email protected]38b48a82009-11-11 01:51:32642void RenderThread::OnGetV8HeapStats() {
643 v8::HeapStatistics heap_stats;
644 v8::V8::GetHeapStatistics(&heap_stats);
645 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(),
646 heap_stats.used_heap_size()));
647}
648
initial.commit09911bf2008-07-26 23:55:29649void RenderThread::InformHostOfCacheStats() {
[email protected]90a3fbb12009-02-28 01:13:47650 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47651 WebCache::UsageStats stats;
652 WebCache::getUsageStats(&stats);
initial.commit09911bf2008-07-26 23:55:29653 Send(new ViewHostMsg_UpdatedCacheStats(stats));
[email protected]bee16aab2009-08-26 15:55:03654 cache_stats_task_pending_ = false;
initial.commit09911bf2008-07-26 23:55:29655}
656
657void RenderThread::InformHostOfCacheStatsLater() {
658 // Rate limit informing the host of our cache stats.
[email protected]bee16aab2009-08-26 15:55:03659 if (cache_stats_task_pending_)
initial.commit09911bf2008-07-26 23:55:29660 return;
661
[email protected]bee16aab2009-08-26 15:55:03662 cache_stats_task_pending_ = true;
initial.commit09911bf2008-07-26 23:55:29663 MessageLoop::current()->PostDelayedTask(FROM_HERE,
[email protected]bee16aab2009-08-26 15:55:03664 task_factory_->NewRunnableMethod(
initial.commit09911bf2008-07-26 23:55:29665 &RenderThread::InformHostOfCacheStats),
666 kCacheStatsDelayMS);
667}
[email protected]90a3fbb12009-02-28 01:13:47668
[email protected]c40acc32010-01-14 01:02:53669void RenderThread::CloseCurrentConnections() {
670 Send(new ViewHostMsg_CloseCurrentConnections());
[email protected]b07f29092009-06-05 07:33:21671}
672
673void RenderThread::SetCacheMode(bool enabled) {
674 Send(new ViewHostMsg_SetCacheMode(enabled));
675}
676
[email protected]c8865962009-12-16 07:47:39677void RenderThread::UpdateActiveExtensions() {
678 // In single-process mode, the browser process reports the active extensions.
679 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
680 return;
681
682 std::set<std::string> active_extensions;
683 user_script_slave_->GetActiveExtensions(&active_extensions);
684 ExtensionProcessBindings::GetActiveExtensions(&active_extensions);
685 child_process_logging::SetActiveExtensions(active_extensions);
686}
687
[email protected]6217d392010-03-25 22:08:35688void RenderThread::EstablishGpuChannel() {
689 if (gpu_channel_.get()) {
690 // Do nothing if we are already establishing GPU channel.
691 if (gpu_channel_->state() == GpuChannelHost::UNCONNECTED)
692 return;
693
694 // Recreate the channel if it has been lost.
695 if (gpu_channel_->state() == GpuChannelHost::LOST)
696 gpu_channel_ = NULL;
697 }
698
699 if (!gpu_channel_.get())
700 gpu_channel_ = new GpuChannelHost;
701
702 // Ask the browser for the channel name.
703 Send(new ViewHostMsg_EstablishGpuChannel());
704}
705
[email protected]3bf4d532010-03-27 00:23:34706GpuChannelHost* RenderThread::EstablishGpuChannelSync() {
707 EstablishGpuChannel();
708 Send(new ViewHostMsg_SynchronizeGpu());
709 // TODO(kbr): the GPU channel is still in the unconnected state at this point.
710 // Need to figure out whether it is really safe to return it.
711 return gpu_channel_.get();
712}
713
[email protected]6217d392010-03-25 22:08:35714GpuChannelHost* RenderThread::GetGpuChannel() {
715 if (!gpu_channel_.get())
716 return NULL;
717
718 if (gpu_channel_->state() != GpuChannelHost::CONNECTED)
719 return NULL;
720
721 return gpu_channel_.get();
722}
723
[email protected]3df0c202009-03-31 23:51:26724static void* CreateHistogram(
725 const char *name, int min, int max, size_t buckets) {
[email protected]e8829a192009-12-06 00:09:37726 if (min <= 0)
727 min = 1;
[email protected]2753b392009-12-28 06:59:52728 scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
729 name, min, max, buckets, Histogram::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:37730 // We'll end up leaking these histograms, unless there is some code hiding in
731 // there to do the dec-ref.
[email protected]2753b392009-12-28 06:59:52732 // TODO(jar): Handle reference counting in webkit glue.
[email protected]e8829a192009-12-06 00:09:37733 histogram->AddRef();
734 return histogram.get();
[email protected]3df0c202009-03-31 23:51:26735}
736
737static void AddHistogramSample(void* hist, int sample) {
738 Histogram* histogram = static_cast<Histogram *>(hist);
739 histogram->Add(sample);
740}
741
[email protected]90a3fbb12009-02-28 01:13:47742void RenderThread::EnsureWebKitInitialized() {
743 if (webkit_client_.get())
744 return;
[email protected]da00a2882009-03-09 17:51:19745
[email protected]71d6d852009-12-07 22:12:36746 // For extensions, we want to ensure we call the IdleHandler every so often,
747 // even if the extension keeps up activity.
748 if (is_extension_process()) {
749 forced_idle_timer_.Start(
750 base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS),
751 this, &RenderThread::IdleHandler);
752 }
753
[email protected]da00a2882009-03-09 17:51:19754 v8::V8::SetCounterFunction(StatsTable::FindLocation);
[email protected]3df0c202009-03-31 23:51:26755 v8::V8::SetCreateHistogramFunction(CreateHistogram);
756 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
[email protected]da00a2882009-03-09 17:51:19757
[email protected]90a3fbb12009-02-28 01:13:47758 webkit_client_.reset(new RendererWebKitClientImpl);
759 WebKit::initialize(webkit_client_.get());
[email protected]8881eca82009-03-12 18:20:44760
[email protected]98d7127b2009-10-23 18:26:51761 WebScriptController::enableV8SingleThreadMode();
[email protected]4ea00e82009-07-30 22:59:34762
[email protected]60e448982009-05-06 04:21:16763 // chrome: pages should not be accessible by normal content, and should
[email protected]8881eca82009-03-12 18:20:44764 // also be unable to script anything but themselves (to help limit the damage
[email protected]60e448982009-05-06 04:21:16765 // that a corrupt chrome: page could cause).
[email protected]2c434b32009-03-19 06:27:47766 WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme));
[email protected]204758c2009-10-22 03:56:30767 WebSecurityPolicy::registerURLSchemeAsLocal(chrome_ui_scheme);
768 WebSecurityPolicy::registerURLSchemeAsNoAccess(chrome_ui_scheme);
[email protected]da00a2882009-03-09 17:51:19769
[email protected]37e5a9a2010-03-13 09:42:39770 // chrome-extension: resources shouldn't trigger mixed content warnings.
771 WebString extension_scheme(ASCIIToUTF16(chrome::kExtensionScheme));
772 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme);
773
[email protected]d53d8492009-07-14 01:51:32774 // print: pages should be not accessible by normal context.
775 WebString print_ui_scheme(ASCIIToUTF16(chrome::kPrintScheme));
[email protected]204758c2009-10-22 03:56:30776 WebSecurityPolicy::registerURLSchemeAsLocal(print_ui_scheme);
777 WebSecurityPolicy::registerURLSchemeAsNoAccess(print_ui_scheme);
[email protected]d53d8492009-07-14 01:51:32778
[email protected]6cf8b1a22009-05-26 23:36:00779#if defined(OS_WIN)
780 // We don't yet support Gears on non-Windows, so don't tell pages that we do.
[email protected]98d7127b2009-10-23 18:26:51781 WebScriptController::registerExtension(extensions_v8::GearsExtension::Get());
[email protected]6cf8b1a22009-05-26 23:36:00782#endif
[email protected]98d7127b2009-10-23 18:26:51783 WebScriptController::registerExtension(
784 extensions_v8::IntervalExtension::Get());
785 WebScriptController::registerExtension(
786 extensions_v8::LoadTimesExtension::Get());
787 WebScriptController::registerExtension(
788 extensions_v8::ExternalExtension::Get());
[email protected]309d7a282009-03-24 09:18:27789
[email protected]ad1f9bd2009-07-30 20:23:15790 const WebKit::WebString kExtensionScheme =
791 WebKit::WebString::fromUTF8(chrome::kExtensionScheme);
792
[email protected]98d7127b2009-10-23 18:26:51793 WebScriptController::registerExtension(
794 ExtensionProcessBindings::Get(), kExtensionScheme);
[email protected]ad1f9bd2009-07-30 20:23:15795
[email protected]98d7127b2009-10-23 18:26:51796 WebScriptController::registerExtension(
797 BaseJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
798 WebScriptController::registerExtension(
799 BaseJsV8Extension::Get(), kExtensionScheme);
800 WebScriptController::registerExtension(
801 JsonSchemaJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
802 WebScriptController::registerExtension(JsonSchemaJsV8Extension::Get(),
803 kExtensionScheme);
804 WebScriptController::registerExtension(
805 EventBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
806 WebScriptController::registerExtension(EventBindings::Get(),
807 kExtensionScheme);
808 WebScriptController::registerExtension(
809 RendererExtensionBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
810 WebScriptController::registerExtension(
811 RendererExtensionBindings::Get(), kExtensionScheme);
812 WebScriptController::registerExtension(
813 ExtensionApiTestV8Extension::Get(), kExtensionScheme);
814 WebScriptController::registerExtension(
815 ExtensionApiTestV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
[email protected]a1a0df02009-04-09 08:18:04816
[email protected]e2b2d4a2009-10-24 03:32:59817 renderer_web_database_observer_.reset(new RendererWebDatabaseObserver(this));
818 WebKit::WebDatabase::setObserver(renderer_web_database_observer_.get());
819
[email protected]06533c0b2009-03-05 21:39:11820 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1a0df02009-04-09 08:18:04821
[email protected]98d7127b2009-10-23 18:26:51822 if (command_line.HasSwitch(switches::kEnableBenchmarking)) {
823 WebScriptController::registerExtension(
824 extensions_v8::BenchmarkingExtension::Get());
825 }
[email protected]b07f29092009-06-05 07:33:21826
[email protected]06533c0b2009-03-05 21:39:11827 if (command_line.HasSwitch(switches::kPlaybackMode) ||
[email protected]ca12c842009-04-14 22:20:18828 command_line.HasSwitch(switches::kRecordMode) ||
829 command_line.HasSwitch(switches::kNoJsRandomness)) {
[email protected]98d7127b2009-10-23 18:26:51830 WebScriptController::registerExtension(
831 extensions_v8::PlaybackExtension::Get());
[email protected]06533c0b2009-03-05 21:39:11832 }
[email protected]2cb82332009-03-18 17:24:55833
[email protected]a9602de2010-03-18 23:43:11834 if (command_line.HasSwitch(switches::kDomAutomationController)) {
835 WebScriptController::registerExtension(DomAutomationV8Extension::Get());
836 }
837
[email protected]b1b13212009-10-30 06:42:01838 WebRuntimeFeatures::enableMediaPlayer(
[email protected]00c39612010-03-06 02:53:28839 RenderProcess::current()->HasInitializedMediaLibrary());
[email protected]3553c6cc2009-10-20 05:51:55840
[email protected]b1b13212009-10-30 06:42:01841 WebRuntimeFeatures::enableSockets(
[email protected]cdf24782009-11-05 09:32:47842 !command_line.HasSwitch(switches::kDisableWebSockets));
[email protected]0afb9932009-10-24 00:37:58843
[email protected]b1b13212009-10-30 06:42:01844 WebRuntimeFeatures::enableDatabase(
[email protected]90a7ad522009-11-20 22:42:53845 !command_line.HasSwitch(switches::kDisableDatabases));
[email protected]bfa69d492009-10-31 03:27:19846
[email protected]13bc0d822009-11-07 01:17:14847 WebRuntimeFeatures::enableApplicationCache(
[email protected]425c270642010-01-26 20:42:37848 !command_line.HasSwitch(switches::kDisableApplicationCache));
[email protected]13bc0d822009-11-07 01:17:14849
[email protected]bfa69d492009-10-31 03:27:19850 WebRuntimeFeatures::enableNotifications(
[email protected]380f1862009-11-14 02:48:01851 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
[email protected]7ee66e62009-11-05 09:16:30852
853 WebRuntimeFeatures::enableLocalStorage(
[email protected]5cf18362009-11-06 18:45:01854 !command_line.HasSwitch(switches::kDisableLocalStorage));
[email protected]7ee66e62009-11-05 09:16:30855 WebRuntimeFeatures::enableSessionStorage(
[email protected]03567802010-02-24 11:48:53856 !command_line.HasSwitch(switches::kDisableSessionStorage));
[email protected]2236bd1f2010-01-20 15:17:08857
[email protected]582fab732010-02-02 02:50:28858 WebRuntimeFeatures::enableIndexedDatabase(
859 command_line.HasSwitch(switches::kEnableIndexedDatabase));
860
[email protected]2236bd1f2010-01-20 15:17:08861 WebRuntimeFeatures::enableGeolocation(
862 command_line.HasSwitch(switches::kEnableGeolocation));
[email protected]7a716c82010-03-03 10:33:44863
864 WebRuntimeFeatures::enableWebGL(
865 command_line.HasSwitch(switches::kEnableExperimentalWebGL));
[email protected]ccbe04e2010-03-17 17:58:43866
867 WebRuntimeFeatures::enablePushState(true);
[email protected]90a3fbb12009-02-28 01:13:47868}
[email protected]75e5a872009-04-02 23:56:11869
[email protected]bee16aab2009-08-26 15:55:03870void RenderThread::IdleHandler() {
[email protected]61a9b2d82010-02-26 00:31:08871#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]e94afbb92009-10-01 00:25:41872 MallocExtension::instance()->ReleaseFreeMemory();
[email protected]05001182009-09-15 23:34:22873#endif
[email protected]bee16aab2009-08-26 15:55:03874
[email protected]f5e4b9bf2009-10-08 00:59:59875 LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this;
876 v8::V8::IdleNotification();
[email protected]05001182009-09-15 23:34:22877
878 // Schedule next invocation.
879 // Dampen the delay using the algorithm:
880 // delay = delay + 1 / (delay + 2)
881 // Using floor(delay) has a dampening effect such as:
882 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
883 // Note that idle_notification_delay_in_s_ would be reset to
884 // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden.
[email protected]71d6d852009-12-07 22:12:36885 ScheduleIdleHandler(idle_notification_delay_in_s_ +
886 1.0 / (idle_notification_delay_in_s_ + 2.0));
887 if (is_extension_process()) {
888 // Dampen the forced delay as well if the extension stays idle for long
889 // periods of time.
890 int64 forced_delay_s =
891 std::max(static_cast<int64>(idle_notification_delay_in_s_),
892 kMaxExtensionIdleHandlerDelayS);
893 forced_idle_timer_.Stop();
894 forced_idle_timer_.Start(
895 base::TimeDelta::FromSeconds(forced_delay_s),
896 this, &RenderThread::IdleHandler);
897 }
898}
[email protected]05001182009-09-15 23:34:22899
[email protected]71d6d852009-12-07 22:12:36900void RenderThread::ScheduleIdleHandler(double initial_delay_s) {
901 idle_notification_delay_in_s_ = initial_delay_s;
902 idle_timer_.Stop();
903 idle_timer_.Start(
904 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)),
905 this, &RenderThread::IdleHandler);
[email protected]bee16aab2009-08-26 15:55:03906}
907
[email protected]dfcb62a2009-06-17 19:32:43908void RenderThread::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:49909 const ListValue& args,
910 bool requires_incognito_access) {
911 RendererExtensionBindings::Invoke(function_name, args, NULL, requires_incognito_access);
[email protected]71d6d852009-12-07 22:12:36912
913 // Reset the idle handler each time there's any activity like event or message
914 // dispatch, for which Invoke is the chokepoint.
915 if (is_extension_process())
916 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]b68d5ed2009-04-16 02:41:28917}
[email protected]b547fd42009-04-23 23:16:27918
[email protected]fede6ca12009-10-08 18:24:26919void RenderThread::OnPurgeMemory() {
[email protected]85c55dc2009-11-06 03:05:46920 spellchecker_.reset(new SpellCheck());
[email protected]85c55dc2009-11-06 03:05:46921
[email protected]fede6ca12009-10-08 18:24:26922 EnsureWebKitInitialized();
923
924 // Clear the object cache (as much as possible; some live objects cannot be
925 // freed).
926 WebCache::clear();
927
928 // Clear the font/glyph cache.
929 WebFontCache::clear();
930
931 // Clear the Cross-Origin Preflight cache.
932 WebCrossOriginPreflightResultCache::clear();
933
[email protected]adf00bc2009-11-02 18:35:00934 // Release all freeable memory from the SQLite process-global page cache (a
935 // low-level object which backs the Connection-specific page caches).
[email protected]4a3dab22009-11-11 17:36:50936 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
937 }
[email protected]adf00bc2009-11-02 18:35:00938
[email protected]fede6ca12009-10-08 18:24:26939 // Repeatedly call the V8 idle notification until it returns true ("nothing
940 // more to free"). Note that it makes more sense to do this than to implement
941 // a new "delete everything" pass because object references make it difficult
942 // to free everything possible in just one pass.
[email protected]4a3dab22009-11-11 17:36:50943 while (!v8::V8::IdleNotification()) {
944 }
[email protected]fede6ca12009-10-08 18:24:26945
[email protected]61a9b2d82010-02-26 00:31:08946#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]fede6ca12009-10-08 18:24:26947 // Tell tcmalloc to release any free pages it's still holding.
948 MallocExtension::instance()->ReleaseFreeMemory();
949#endif
950}
951
[email protected]b78e168b2009-09-21 22:05:45952void RenderThread::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:59953 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:27954 // The call below will cause a GetPlugins call with refresh=true, but at this
955 // point we already know that the browser has refreshed its list, so disable
956 // refresh temporarily to prevent each renderer process causing the list to be
957 // regenerated.
958 plugin_refresh_allowed_ = false;
[email protected]b78e168b2009-09-21 22:05:45959 WebKit::resetPluginCache(reload_pages);
[email protected]b547fd42009-04-23 23:16:27960 plugin_refresh_allowed_ = true;
961}
[email protected]85c55dc2009-11-06 03:05:46962
[email protected]85c55dc2009-11-06 03:05:46963void RenderThread::OnInitSpellChecker(
[email protected]cb6037d2009-11-16 22:55:17964 IPC::PlatformFileForTransit bdict_file,
[email protected]85c55dc2009-11-06 03:05:46965 const std::vector<std::string>& custom_words,
966 const std::string& language,
967 bool auto_spell_correct) {
[email protected]cb6037d2009-11-16 22:55:17968 spellchecker_->Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file),
969 custom_words, language);
[email protected]85c55dc2009-11-06 03:05:46970 spellchecker_->EnableAutoSpellCorrect(auto_spell_correct);
971}
972
973void RenderThread::OnSpellCheckWordAdded(const std::string& word) {
974 spellchecker_->WordAdded(word);
975}
976
977void RenderThread::OnSpellCheckEnableAutoSpellCorrect(bool enable) {
978 spellchecker_->EnableAutoSpellCorrect(enable);
979}
[email protected]b2a74ca2010-03-12 17:57:09980
981void RenderThread::OnSetIsIncognitoProcess(bool is_incognito_process) {
982 is_incognito_process_ = is_incognito_process;
983}
[email protected]6217d392010-03-25 22:08:35984
985void RenderThread::OnGpuChannelEstablished(
986 const IPC::ChannelHandle& channel_handle) {
987#if defined(OS_POSIX)
988 // If we received a ChannelHandle, register it now.
989 if (channel_handle.socket.fd >= 0)
990 IPC::AddChannelSocket(channel_handle.name, channel_handle.socket.fd);
991#endif
992
993 if (channel_handle.name.size() != 0) {
994 // Connect to the GPU process if a channel name was received.
995 gpu_channel_->Connect(channel_handle.name);
996 } else {
997 // Otherwise cancel the connection.
998 gpu_channel_ = NULL;
999 }
1000}