blob: 7ad062eb7c29e212be8f1bb29aab1017254eb94a [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]dd9241932010-02-24 19:23:1345#include "chrome/renderer/cookie_message_filter.h"
[email protected]a8624712009-04-17 00:51:3546#include "chrome/renderer/devtools_agent_filter.h"
[email protected]ad1f9bd2009-07-30 20:23:1547#include "chrome/renderer/extension_groups.h"
[email protected]a40caa972009-04-08 18:35:3448#include "chrome/renderer/extensions/event_bindings.h"
[email protected]309d7a282009-03-24 09:18:2749#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]be77f0a2009-08-25 08:31:1750#include "chrome/renderer/extensions/js_only_v8_extensions.h"
[email protected]0aa477bd2009-03-23 22:21:4351#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]3c8e3702009-05-01 16:27:4252#include "chrome/renderer/external_extension.h"
[email protected]0bc46552009-04-07 21:56:4253#include "chrome/renderer/loadtimes_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2954#include "chrome/renderer/net/render_dns_master.h"
[email protected]c1f50aa2010-02-18 03:46:5755#include "chrome/renderer/plugin_channel_host.h"
[email protected]00c39612010-03-06 02:53:2856#include "chrome/renderer/render_process_impl.h"
initial.commit09911bf2008-07-26 23:55:2957#include "chrome/renderer/render_view.h"
[email protected]40bd6582009-12-04 23:49:5158#include "chrome/renderer/render_view_visitor.h"
[email protected]8d86fce2009-02-26 23:37:5559#include "chrome/renderer/renderer_webkitclient_impl.h"
[email protected]e2b2d4a2009-10-24 03:32:5960#include "chrome/renderer/renderer_web_database_observer.h"
[email protected]85c55dc2009-11-06 03:05:4661#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3562#include "chrome/renderer/user_script_slave.h"
[email protected]d55aaa132009-09-28 21:08:0463#include "ipc/ipc_message.h"
[email protected]cb6037d2009-11-16 22:55:1764#include "ipc/ipc_platform_file.h"
[email protected]1b1f3eb2009-12-01 13:48:0465#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
[email protected]418ed5ab2009-11-12 01:14:4966#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
67#include "third_party/WebKit/WebKit/chromium/public/WebColor.h"
68#include "third_party/WebKit/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h"
69#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
70#include "third_party/WebKit/WebKit/chromium/public/WebFontCache.h"
[email protected]40bd6582009-12-04 23:49:5171#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
[email protected]418ed5ab2009-11-12 01:14:4972#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
73#include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h"
74#include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h"
76#include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h"
77#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
[email protected]b07f29092009-06-05 07:33:2178#include "webkit/extensions/v8/benchmarking_extension.h"
[email protected]06533c0b2009-03-05 21:39:1179#include "webkit/extensions/v8/gears_extension.h"
80#include "webkit/extensions/v8/interval_extension.h"
81#include "webkit/extensions/v8/playback_extension.h"
[email protected]2c62b562009-01-27 19:04:5082
[email protected]da00a2882009-03-09 17:51:1983#if defined(OS_WIN)
84#include <windows.h>
85#include <objbase.h>
86#endif
87
[email protected]fe819f52009-12-15 07:58:1188#if defined(OS_MACOSX)
89#include "chrome/app/breakpad_mac.h"
90#endif
91
[email protected]2c434b32009-03-19 06:27:4792using WebKit::WebCache;
[email protected]fede6ca12009-10-08 18:24:2693using WebKit::WebCrossOriginPreflightResultCache;
94using WebKit::WebFontCache;
[email protected]f85f0702010-01-30 09:31:0195using WebKit::WebFrame;
[email protected]adf00bc2009-11-02 18:35:0096using WebKit::WebRuntimeFeatures;
[email protected]204758c2009-10-22 03:56:3097using WebKit::WebSecurityPolicy;
[email protected]98d7127b2009-10-23 18:26:5198using WebKit::WebScriptController;
[email protected]2c434b32009-03-19 06:27:4799using WebKit::WebString;
[email protected]b7c7bcf2009-10-03 07:07:34100using WebKit::WebStorageEventDispatcher;
[email protected]50ae00ef2009-10-19 05:11:03101using WebKit::WebView;
initial.commit09911bf2008-07-26 23:55:29102
[email protected]42f1d7822009-07-23 18:17:55103namespace {
[email protected]2c434b32009-03-19 06:27:47104static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
[email protected]bee16aab2009-08-26 15:55:03105static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
[email protected]71d6d852009-12-07 22:12:36106static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
107static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
[email protected]bee16aab2009-08-26 15:55:03108
[email protected]94f9a0f682009-06-15 18:30:30109static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls(
110 base::LINKER_INITIALIZED);
[email protected]1edc16b82009-04-07 17:45:54111
[email protected]5fa1c542009-05-05 20:36:07112#if defined(OS_POSIX)
113class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter {
114 void OnChannelError() {
115 // On POSIX, at least, one can install an unload handler which loops
116 // forever and leave behind a renderer process which eats 100% CPU forever.
117 //
118 // This is because the terminate signals (ViewMsg_ShouldClose and the error
119 // from the IPC channel) are routed to the main message loop but never
120 // processed (because that message loop is stuck in V8).
121 //
122 // One could make the browser SIGKILL the renderers, but that leaves open a
123 // large window where a browser failure (or a user, manually terminating
124 // the browser because "it's stuck") will leave behind a process eating all
125 // the CPU.
126 //
127 // So, we install a filter on the channel so that we can process this event
128 // here and kill the process.
[email protected]fe819f52009-12-15 07:58:11129
130#if defined(OS_MACOSX)
131 // TODO(viettrungluu): crbug.com/28547: The following is needed, as a
132 // stopgap, to avoid leaking due to not releasing Breakpad properly.
133 // TODO(viettrungluu): Investigate why this is being called.
134 if (IsCrashReporterEnabled()) {
135 LOG(INFO) << "Cleaning up Breakpad.";
136 DestructCrashReporter();
137 } else {
138 LOG(INFO) << "Breakpad not enabled; no clean-up needed.";
139 }
140#endif // OS_MACOSX
141
[email protected]5fa1c542009-05-05 20:36:07142 _exit(0);
143 }
144};
145#endif
[email protected]40bd6582009-12-04 23:49:51146
[email protected]f85f0702010-01-30 09:31:01147class RenderViewContentSettingsSetter : public RenderViewVisitor {
148 public:
149 RenderViewContentSettingsSetter(const std::string& host,
150 const ContentSettings& content_settings)
151 : host_(host),
152 content_settings_(content_settings) {
153 }
154
155 virtual bool Visit(RenderView* render_view) {
[email protected]433819d2010-01-30 20:20:01156 if (GURL(render_view->webview()->mainFrame()->url()).host() == host_)
157 render_view->SetContentSettings(content_settings_);
[email protected]f85f0702010-01-30 09:31:01158 return true;
159 }
160
161 private:
162 std::string host_;
163 ContentSettings content_settings_;
164
165 DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter);
166};
167
[email protected]40bd6582009-12-04 23:49:51168class RenderViewZoomer : public RenderViewVisitor {
169 public:
170 RenderViewZoomer(const std::string& host, int zoom_level)
171 : host_(host),
172 zoom_level_(zoom_level) {
173 }
174
175 virtual bool Visit(RenderView* render_view) {
176 WebView* webview = render_view->webview(); // Guaranteed non-NULL.
177 if (GURL(webview->mainFrame()->url()).host() == host_)
178 webview->setZoomLevel(false, zoom_level_);
179 return true;
180 }
181
182 private:
183 std::string host_;
184 int zoom_level_;
185
186 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
187};
[email protected]42f1d7822009-07-23 18:17:55188} // namespace
189
190// When we run plugins in process, we actually run them on the render thread,
191// which means that we need to make the render thread pump UI events.
192RenderThread::RenderThread() {
193 Init();
194}
195
196RenderThread::RenderThread(const std::string& channel_name)
197 : ChildThread(channel_name) {
198 Init();
199}
[email protected]5fa1c542009-05-05 20:36:07200
initial.commit09911bf2008-07-26 23:55:29201void RenderThread::Init() {
[email protected]94f9a0f682009-06-15 18:30:30202 lazy_tls.Pointer()->Set(this);
[email protected]2c62b562009-01-27 19:04:50203#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34204 // If you are running plugins in this thread you need COM active but in
205 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28206 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34207 CoInitialize(0);
[email protected]2c62b562009-01-27 19:04:50208#endif
initial.commit09911bf2008-07-26 23:55:29209
[email protected]71d6d852009-12-07 22:12:36210 std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
211 switches::kProcessType);
212 is_extension_process_ = type_str == switches::kExtensionProcess;
[email protected]80fc08c52010-03-09 07:43:50213 suspend_webkit_shared_timer_ = true;
214 notify_webkit_of_modal_loop_ = true;
[email protected]c1f50aa2010-02-18 03:46:57215 did_notify_webkit_of_modal_loop_ = false;
[email protected]42f1d7822009-07-23 18:17:55216 plugin_refresh_allowed_ = true;
[email protected]bee16aab2009-08-26 15:55:03217 cache_stats_task_pending_ = false;
218 widget_count_ = 0;
219 hidden_widget_count_ = 0;
[email protected]71d6d852009-12-07 22:12:36220 idle_notification_delay_in_s_ = is_extension_process_ ?
221 kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS;
[email protected]bee16aab2009-08-26 15:55:03222 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this));
[email protected]8d86fce2009-02-26 23:37:55223
[email protected]8d86fce2009-02-26 23:37:55224 visited_link_slave_.reset(new VisitedLinkSlave());
225 user_script_slave_.reset(new UserScriptSlave());
226 dns_master_.reset(new RenderDnsMaster());
227 histogram_snapshots_.reset(new RendererHistogramSnapshots());
[email protected]f430b5712009-08-21 21:46:31228 appcache_dispatcher_.reset(new AppCacheDispatcher(this));
[email protected]dd9241932010-02-24 19:23:13229 spellchecker_.reset(new SpellCheck());
230
[email protected]a8624712009-04-17 00:51:35231 devtools_agent_filter_ = new DevToolsAgentFilter();
232 AddFilter(devtools_agent_filter_.get());
[email protected]dd9241932010-02-24 19:23:13233
[email protected]017022b2009-07-27 23:06:34234 db_message_filter_ = new DBMessageFilter();
235 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13236
237 cookie_message_filter_ = new CookieMessageFilter();
238 AddFilter(cookie_message_filter_.get());
[email protected]5fa1c542009-05-05 20:36:07239
240#if defined(OS_POSIX)
241 suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter;
242 AddFilter(suicide_on_channel_error_filter_.get());
243#endif
initial.commit09911bf2008-07-26 23:55:29244}
245
[email protected]42f1d7822009-07-23 18:17:55246RenderThread::~RenderThread() {
[email protected]12cbfda32010-01-30 01:04:25247 // Wait for all databases to be closed.
248 if (renderer_web_database_observer_.get())
249 renderer_web_database_observer_->WaitForAllDatabasesToClose();
250
[email protected]8d86fce2009-02-26 23:37:55251 // Shutdown in reverse of the initialization order.
[email protected]a8624712009-04-17 00:51:35252 RemoveFilter(devtools_agent_filter_.get());
[email protected]017022b2009-07-27 23:06:34253 RemoveFilter(db_message_filter_.get());
254 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25255
[email protected]42f1d7822009-07-23 18:17:55256 if (webkit_client_.get())
[email protected]9291ed12009-07-23 17:33:22257 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22258
[email protected]94f9a0f682009-06-15 18:30:30259 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30260
[email protected]8d86fce2009-02-26 23:37:55261 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50262#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29263 // Clean up plugin channels before this thread goes away.
264 PluginChannelBase::CleanupChannels();
[email protected]bdef78b52009-04-16 19:31:34265 // Don't call COM if the renderer is in the sandbox.
[email protected]00c39612010-03-06 02:53:28266 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34267 CoUninitialize();
[email protected]2c62b562009-01-27 19:04:50268#endif
initial.commit09911bf2008-07-26 23:55:29269}
270
[email protected]42f1d7822009-07-23 18:17:55271RenderThread* RenderThread::current() {
272 return lazy_tls.Pointer()->Get();
273}
274
[email protected]c1f50aa2010-02-18 03:46:57275int32 RenderThread::RoutingIDForCurrentContext() {
276 int32 routing_id = MSG_ROUTING_CONTROL;
277 if (v8::Context::InContext()) {
[email protected]d5ddf9a2010-03-04 00:48:29278 WebFrame* frame = WebFrame::frameForCurrentContext();
279 if (frame) {
280 RenderView* view = RenderView::FromWebView(frame->view());
281 if (view)
282 routing_id = view->routing_id();
283 }
[email protected]c1f50aa2010-02-18 03:46:57284 } else {
285 DLOG(WARNING) << "Not called within a script context!";
286 }
287 return routing_id;
288}
289
290bool RenderThread::Send(IPC::Message* msg) {
[email protected]80fc08c52010-03-09 07:43:50291 // Certain synchronous messages can result in an app-modal cookie prompt.
292 // This could cause a complete hang of Chrome if a windowed plug-in is trying
293 // to communicate with the renderer thread since the browser's UI thread
294 // could be stuck (within a Windows API call) trying to synchronously
295 // communicate with the plug-in. The remedy is to pump messages on this
296 // thread while the cookie prompt is showing. This creates an opportunity
297 // for re-entrancy into WebKit, so we need to take care to disable callbacks,
298 // timers, and pending network loads that could trigger such callbacks.
[email protected]c1f50aa2010-02-18 03:46:57299
[email protected]80fc08c52010-03-09 07:43:50300 bool pumping_events = false, may_show_cookie_prompt = false;
301 if (msg->is_sync()) {
302 if (msg->is_caller_pumping_messages()) {
303 pumping_events = true;
304 } else {
305 switch (msg->type()) {
306 case ViewHostMsg_GetCookies::ID:
307 case ViewHostMsg_GetRawCookies::ID:
308 case ViewHostMsg_DOMStorageSetItem::ID:
309 case ViewHostMsg_SyncLoad::ID:
310 may_show_cookie_prompt = true;
311 pumping_events = true;
312 break;
313 }
314 }
[email protected]c1f50aa2010-02-18 03:46:57315 }
316
[email protected]80fc08c52010-03-09 07:43:50317 bool suspend_webkit_shared_timer = true; // default value
318 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57319
[email protected]80fc08c52010-03-09 07:43:50320 bool notify_webkit_of_modal_loop = true; // default value
321 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
322
323 gfx::NativeViewId host_window = 0;
[email protected]c1f50aa2010-02-18 03:46:57324
325 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50326 // See ViewMsg_SignalCookiePromptEvent.
327 if (may_show_cookie_prompt) {
328 static_cast<IPC::SyncMessage*>(msg)->set_pump_messages_event(
329 cookie_message_filter_->pump_messages_event());
330 }
331
332 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57333 webkit_client_->SuspendSharedTimer();
334
335 // WebKit does not like nested calls to willEnterModalLoop.
336 // TODO(darin): Fix WebKit to allow nesting.
[email protected]80fc08c52010-03-09 07:43:50337 if (notify_webkit_of_modal_loop && !did_notify_webkit_of_modal_loop_) {
[email protected]c1f50aa2010-02-18 03:46:57338 WebView::willEnterModalLoop();
339 did_notify_webkit_of_modal_loop_ = true;
340 }
341
[email protected]80fc08c52010-03-09 07:43:50342 RenderWidget* widget =
343 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
344 if (widget) {
345 host_window = widget->host_window();
[email protected]c1f50aa2010-02-18 03:46:57346 PluginChannelHost::Broadcast(
347 new PluginMsg_SignalModalDialogEvent(host_window));
348 }
349 }
350
351 bool rv = ChildThread::Send(msg);
352
353 if (pumping_events) {
354 if (host_window) {
355 PluginChannelHost::Broadcast(
356 new PluginMsg_ResetModalDialogEvent(host_window));
357 }
358
[email protected]80fc08c52010-03-09 07:43:50359 if (notify_webkit_of_modal_loop && did_notify_webkit_of_modal_loop_) {
[email protected]c1f50aa2010-02-18 03:46:57360 WebView::didExitModalLoop();
361 did_notify_webkit_of_modal_loop_ = false;
362 }
363
[email protected]80fc08c52010-03-09 07:43:50364 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57365 webkit_client_->ResumeSharedTimer();
[email protected]80fc08c52010-03-09 07:43:50366
367 // We may end up nesting calls to Send, so we defer the reset until we
368 // return to the top-most message loop.
369 if (may_show_cookie_prompt &&
370 cookie_message_filter_->pump_messages_event()->IsSignaled()) {
371 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
372 NewRunnableMethod(cookie_message_filter_.get(),
373 &CookieMessageFilter::ResetPumpMessagesEvent));
374 }
[email protected]c1f50aa2010-02-18 03:46:57375 }
376
377 return rv;
378}
379
380void RenderThread::AddRoute(int32 routing_id,
381 IPC::Channel::Listener* listener) {
382 widget_count_++;
383 return ChildThread::AddRoute(routing_id, listener);
384}
385
386void RenderThread::RemoveRoute(int32 routing_id) {
387 widget_count_--;
388 return ChildThread::RemoveRoute(routing_id);
389}
390
[email protected]42f1d7822009-07-23 18:17:55391void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
392 channel()->AddFilter(filter);
393}
394
395void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
396 channel()->RemoveFilter(filter);
397}
398
[email protected]bee16aab2009-08-26 15:55:03399void RenderThread::WidgetHidden() {
400 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50401 hidden_widget_count_++;
[email protected]71d6d852009-12-07 22:12:36402 if (!is_extension_process() &&
403 widget_count_ && hidden_widget_count_ == widget_count_)
404 ScheduleIdleHandler(kInitialIdleHandlerDelayS);
[email protected]bee16aab2009-08-26 15:55:03405}
406
407void RenderThread::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08408 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03409 hidden_widget_count_--;
[email protected]71d6d852009-12-07 22:12:36410 if (!is_extension_process())
411 idle_timer_.Stop();
[email protected]bee16aab2009-08-26 15:55:03412}
413
[email protected]c1f50aa2010-02-18 03:46:57414void RenderThread::DoNotSuspendWebKitSharedTimer() {
[email protected]80fc08c52010-03-09 07:43:50415 suspend_webkit_shared_timer_ = false;
[email protected]c1f50aa2010-02-18 03:46:57416}
417
418void RenderThread::DoNotNotifyWebKitOfModalLoop() {
[email protected]80fc08c52010-03-09 07:43:50419 notify_webkit_of_modal_loop_ = false;
[email protected]c1f50aa2010-02-18 03:46:57420}
421
[email protected]42f1d7822009-07-23 18:17:55422void RenderThread::Resolve(const char* name, size_t length) {
423 return dns_master_->Resolve(name, length);
424}
425
426void RenderThread::SendHistograms(int sequence_number) {
427 return histogram_snapshots_->SendHistograms(sequence_number);
428}
429
[email protected]176aa482008-11-14 03:25:15430void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) {
[email protected]5fe733de2009-02-11 18:59:20431 DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle";
initial.commit09911bf2008-07-26 23:55:29432 visited_link_slave_->Init(table);
433}
434
[email protected]3e90d4a2009-07-03 17:38:39435void RenderThread::OnAddVisitedLinks(
436 const VisitedLinkSlave::Fingerprints& fingerprints) {
437 for (size_t i = 0; i < fingerprints.size(); ++i)
[email protected]50ae00ef2009-10-19 05:11:03438 WebView::updateVisitedLinkState(fingerprints[i]);
[email protected]3e90d4a2009-07-03 17:38:39439}
440
441void RenderThread::OnResetVisitedLinks() {
[email protected]50ae00ef2009-10-19 05:11:03442 WebView::resetVisitedLinkState();
[email protected]3e90d4a2009-07-03 17:38:39443}
444
[email protected]f85f0702010-01-30 09:31:01445void RenderThread::OnSetContentSettingsForCurrentHost(
446 const std::string& host,
447 const ContentSettings& content_settings) {
448 RenderViewContentSettingsSetter setter(host, content_settings);
449 RenderView::ForEach(&setter);
450}
451
[email protected]40bd6582009-12-04 23:49:51452void RenderThread::OnSetZoomLevelForCurrentHost(const std::string& host,
453 int zoom_level) {
454 RenderViewZoomer zoomer(host, zoom_level);
455 RenderView::ForEach(&zoomer);
456}
457
[email protected]0938d3c2009-01-09 20:37:35458void RenderThread::OnUpdateUserScripts(
[email protected]55a35692010-02-11 23:25:21459 base::SharedMemoryHandle scripts, bool only_inject_incognito) {
[email protected]5fe733de2009-02-11 18:59:20460 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle";
[email protected]55a35692010-02-11 23:25:21461 user_script_slave_->UpdateScripts(scripts, only_inject_incognito);
[email protected]c8865962009-12-16 07:47:39462 UpdateActiveExtensions();
[email protected]1e0f70402008-10-16 23:57:47463}
464
[email protected]703e807a2009-03-28 19:56:51465void RenderThread::OnSetExtensionFunctionNames(
466 const std::vector<std::string>& names) {
[email protected]a1a0df02009-04-09 08:18:04467 ExtensionProcessBindings::SetFunctionNames(names);
[email protected]703e807a2009-03-28 19:56:51468}
469
[email protected]45776222009-07-15 20:21:58470void RenderThread::OnPageActionsUpdated(
471 const std::string& extension_id,
472 const std::vector<std::string>& page_actions) {
473 ExtensionProcessBindings::SetPageActions(extension_id, page_actions);
474}
475
[email protected]cccf90932009-08-23 17:56:25476void RenderThread::OnExtensionSetAPIPermissions(
[email protected]35506352009-08-07 18:58:19477 const std::string& extension_id,
478 const std::vector<std::string>& permissions) {
[email protected]cccf90932009-08-23 17:56:25479 ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions);
[email protected]71d6d852009-12-07 22:12:36480
481 // This is called when starting a new extension page, so start the idle
482 // handler ticking.
[email protected]71d6d852009-12-07 22:12:36483 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]c8865962009-12-16 07:47:39484
485 UpdateActiveExtensions();
[email protected]cccf90932009-08-23 17:56:25486}
487
488void RenderThread::OnExtensionSetHostPermissions(
489 const GURL& extension_url, const std::vector<URLPattern>& permissions) {
490 ExtensionProcessBindings::SetHostPermissions(extension_url, permissions);
[email protected]35506352009-08-07 18:58:19491}
492
[email protected]db7331a2010-02-25 22:10:50493void RenderThread::OnExtensionSetIncognitoEnabled(
494 const std::string& extension_id, bool enabled) {
495 ExtensionProcessBindings::SetIncognitoEnabled(extension_id, enabled);
496}
497
[email protected]c61cc652009-11-04 05:44:40498void RenderThread::OnDOMStorageEvent(
499 const ViewMsg_DOMStorageEvent_Params& params) {
500 if (!dom_storage_event_dispatcher_.get())
[email protected]b7c7bcf2009-10-03 07:07:34501 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
[email protected]c61cc652009-11-04 05:44:40502 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key_,
[email protected]ee2be5b32009-11-05 09:13:12503 params.old_value_, params.new_value_, params.origin_, params.url_,
[email protected]c61cc652009-11-04 05:44:40504 params.storage_type_ == DOM_STORAGE_LOCAL);
[email protected]b7c7bcf2009-10-03 07:07:34505}
506
[email protected]8930d472009-02-21 08:05:28507void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1edc16b82009-04-07 17:45:54508 // App cache messages are handled by a delegate.
[email protected]f430b5712009-08-21 21:46:31509 if (appcache_dispatcher_->OnMessageReceived(msg))
[email protected]1edc16b82009-04-07 17:45:54510 return;
511
[email protected]8930d472009-02-21 08:05:28512 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
513 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
[email protected]3e90d4a2009-07-03 17:38:39514 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks)
515 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks)
[email protected]f85f0702010-01-30 09:31:01516 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentHost,
517 OnSetContentSettingsForCurrentHost)
[email protected]40bd6582009-12-04 23:49:51518 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentHost,
519 OnSetZoomLevelForCurrentHost)
[email protected]8930d472009-02-21 08:05:28520 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
[email protected]b9ab10c2009-08-07 18:09:55521 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
[email protected]8930d472009-02-21 08:05:28522 // TODO(port): removed from render_messages_internal.h;
523 // is there a new non-windows message I should add here?
524 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
525 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
[email protected]55e57d42009-02-25 06:10:17526 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms,
[email protected]c9a3ef82009-05-28 22:02:46527 OnGetRendererHistograms)
[email protected]d41041092009-10-08 06:56:57528#if defined(USE_TCMALLOC)
529 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc,
530 OnGetRendererTcmalloc)
531#endif
[email protected]38b48a82009-11-11 01:51:32532 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats)
[email protected]8930d472009-02-21 08:05:28533 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
534 OnGetCacheResourceStats)
[email protected]2f2243e2009-05-26 02:27:02535 IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts,
[email protected]8930d472009-02-21 08:05:28536 OnUpdateUserScripts)
[email protected]b68d5ed2009-04-16 02:41:28537 // TODO(rafaelw): create an ExtensionDispatcher that handles extension
538 // messages seperates their handling from the RenderThread.
[email protected]dfcb62a2009-06-17 19:32:43539 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
540 OnExtensionMessageInvoke)
[email protected]703e807a2009-03-28 19:56:51541 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
542 OnSetExtensionFunctionNames)
[email protected]fede6ca12009-10-08 18:24:26543 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory)
[email protected]b547fd42009-04-23 23:16:27544 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
545 OnPurgePluginListCache)
[email protected]45776222009-07-15 20:21:58546 IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions,
547 OnPageActionsUpdated)
[email protected]cccf90932009-08-23 17:56:25548 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions,
549 OnExtensionSetAPIPermissions)
550 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions,
551 OnExtensionSetHostPermissions)
[email protected]db7331a2010-02-25 22:10:50552 IPC_MESSAGE_HANDLER(ViewMsg_Extension_ExtensionSetIncognitoEnabled,
553 OnExtensionSetIncognitoEnabled)
[email protected]b7c7bcf2009-10-03 07:07:34554 IPC_MESSAGE_HANDLER(ViewMsg_DOMStorageEvent,
555 OnDOMStorageEvent)
[email protected]d55aaa132009-09-28 21:08:04556#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]12636df2009-09-28 22:32:21557 IPC_MESSAGE_HANDLER(ViewMsg_SetIPCLoggingEnabled,
[email protected]d55aaa132009-09-28 21:08:04558 OnSetIPCLoggingEnabled)
559#endif
[email protected]85c55dc2009-11-06 03:05:46560 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_Init,
561 OnInitSpellChecker)
562 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_WordAdded,
563 OnSpellCheckWordAdded)
564 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_EnableAutoSpellCorrect,
565 OnSpellCheckEnableAutoSpellCorrect)
[email protected]8930d472009-02-21 08:05:28566 IPC_END_MESSAGE_MAP()
initial.commit09911bf2008-07-26 23:55:29567}
568
569void RenderThread::OnSetNextPageID(int32 next_page_id) {
570 // This should only be called at process initialization time, so we shouldn't
571 // have to worry about thread-safety.
572 RenderView::SetNextPageID(next_page_id);
573}
574
[email protected]b9ab10c2009-08-07 18:09:55575// Called when to register CSS Color name->system color mappings.
576// We update the colors one by one and then tell WebKit to refresh all render
577// views.
578void RenderThread::OnSetCSSColors(
579 const std::vector<CSSColors::CSSColorMapping>& colors) {
[email protected]f5e4b9bf2009-10-08 00:59:59580 EnsureWebKitInitialized();
[email protected]b9ab10c2009-08-07 18:09:55581 size_t num_colors = colors.size();
582 scoped_array<WebKit::WebColorName> color_names(
583 new WebKit::WebColorName[num_colors]);
584 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]);
585 size_t i = 0;
586 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it =
587 colors.begin();
588 it != colors.end();
589 ++it, ++i) {
590 color_names[i] = it->first;
591 web_colors[i] = it->second;
592 }
593 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors);
594}
595
[email protected]4e6419c2010-01-15 04:50:34596void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:47597 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:33598 // When bringing in render_view, also bring in webkit's glue and jsbindings.
initial.commit09911bf2008-07-26 23:55:29599 RenderView::Create(
[email protected]4e6419c2010-01-15 04:50:34600 this, params.parent_window, MSG_ROUTING_NONE, params.renderer_preferences,
601 params.web_preferences, new SharedRenderViewCounter(0), params.view_id,
602 params.session_storage_namespace_id);
[email protected]7f874dec2009-02-06 01:48:27603}
[email protected]4274e582009-01-27 22:09:56604
initial.commit09911bf2008-07-26 23:55:29605void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity,
606 size_t max_dead_capacity,
607 size_t capacity) {
[email protected]90a3fbb12009-02-28 01:13:47608 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47609 WebCache::setCapacities(
610 min_dead_capacity, max_dead_capacity, capacity);
initial.commit09911bf2008-07-26 23:55:29611}
612
613void RenderThread::OnGetCacheResourceStats() {
[email protected]90a3fbb12009-02-28 01:13:47614 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47615 WebCache::ResourceTypeStats stats;
616 WebCache::getResourceTypeStats(&stats);
initial.commit09911bf2008-07-26 23:55:29617 Send(new ViewHostMsg_ResourceTypeStats(stats));
618}
619
[email protected]c9a3ef82009-05-28 22:02:46620void RenderThread::OnGetRendererHistograms(int sequence_number) {
621 SendHistograms(sequence_number);
[email protected]55e57d42009-02-25 06:10:17622}
623
[email protected]d41041092009-10-08 06:56:57624#if defined(USE_TCMALLOC)
625void RenderThread::OnGetRendererTcmalloc() {
626 std::string result;
627 char buffer[1024 * 32];
[email protected]a4dc33f2009-10-20 15:09:55628 base::ProcessId pid = base::GetCurrentProcId();
[email protected]d41041092009-10-08 06:56:57629 MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
630 result.append(buffer);
631 Send(new ViewHostMsg_RendererTcmalloc(pid, result));
632}
633#endif
634
[email protected]38b48a82009-11-11 01:51:32635void RenderThread::OnGetV8HeapStats() {
636 v8::HeapStatistics heap_stats;
637 v8::V8::GetHeapStatistics(&heap_stats);
638 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(),
639 heap_stats.used_heap_size()));
640}
641
initial.commit09911bf2008-07-26 23:55:29642void RenderThread::InformHostOfCacheStats() {
[email protected]90a3fbb12009-02-28 01:13:47643 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47644 WebCache::UsageStats stats;
645 WebCache::getUsageStats(&stats);
initial.commit09911bf2008-07-26 23:55:29646 Send(new ViewHostMsg_UpdatedCacheStats(stats));
[email protected]bee16aab2009-08-26 15:55:03647 cache_stats_task_pending_ = false;
initial.commit09911bf2008-07-26 23:55:29648}
649
650void RenderThread::InformHostOfCacheStatsLater() {
651 // Rate limit informing the host of our cache stats.
[email protected]bee16aab2009-08-26 15:55:03652 if (cache_stats_task_pending_)
initial.commit09911bf2008-07-26 23:55:29653 return;
654
[email protected]bee16aab2009-08-26 15:55:03655 cache_stats_task_pending_ = true;
initial.commit09911bf2008-07-26 23:55:29656 MessageLoop::current()->PostDelayedTask(FROM_HERE,
[email protected]bee16aab2009-08-26 15:55:03657 task_factory_->NewRunnableMethod(
initial.commit09911bf2008-07-26 23:55:29658 &RenderThread::InformHostOfCacheStats),
659 kCacheStatsDelayMS);
660}
[email protected]90a3fbb12009-02-28 01:13:47661
[email protected]c40acc32010-01-14 01:02:53662void RenderThread::CloseCurrentConnections() {
663 Send(new ViewHostMsg_CloseCurrentConnections());
[email protected]b07f29092009-06-05 07:33:21664}
665
666void RenderThread::SetCacheMode(bool enabled) {
667 Send(new ViewHostMsg_SetCacheMode(enabled));
668}
669
[email protected]c8865962009-12-16 07:47:39670void RenderThread::UpdateActiveExtensions() {
671 // In single-process mode, the browser process reports the active extensions.
672 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
673 return;
674
675 std::set<std::string> active_extensions;
676 user_script_slave_->GetActiveExtensions(&active_extensions);
677 ExtensionProcessBindings::GetActiveExtensions(&active_extensions);
678 child_process_logging::SetActiveExtensions(active_extensions);
679}
680
[email protected]3df0c202009-03-31 23:51:26681static void* CreateHistogram(
682 const char *name, int min, int max, size_t buckets) {
[email protected]e8829a192009-12-06 00:09:37683 if (min <= 0)
684 min = 1;
[email protected]2753b392009-12-28 06:59:52685 scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
686 name, min, max, buckets, Histogram::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:37687 // We'll end up leaking these histograms, unless there is some code hiding in
688 // there to do the dec-ref.
[email protected]2753b392009-12-28 06:59:52689 // TODO(jar): Handle reference counting in webkit glue.
[email protected]e8829a192009-12-06 00:09:37690 histogram->AddRef();
691 return histogram.get();
[email protected]3df0c202009-03-31 23:51:26692}
693
694static void AddHistogramSample(void* hist, int sample) {
695 Histogram* histogram = static_cast<Histogram *>(hist);
696 histogram->Add(sample);
697}
698
[email protected]90a3fbb12009-02-28 01:13:47699void RenderThread::EnsureWebKitInitialized() {
700 if (webkit_client_.get())
701 return;
[email protected]da00a2882009-03-09 17:51:19702
[email protected]71d6d852009-12-07 22:12:36703 // For extensions, we want to ensure we call the IdleHandler every so often,
704 // even if the extension keeps up activity.
705 if (is_extension_process()) {
706 forced_idle_timer_.Start(
707 base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS),
708 this, &RenderThread::IdleHandler);
709 }
710
[email protected]da00a2882009-03-09 17:51:19711 v8::V8::SetCounterFunction(StatsTable::FindLocation);
[email protected]3df0c202009-03-31 23:51:26712 v8::V8::SetCreateHistogramFunction(CreateHistogram);
713 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
[email protected]da00a2882009-03-09 17:51:19714
[email protected]90a3fbb12009-02-28 01:13:47715 webkit_client_.reset(new RendererWebKitClientImpl);
716 WebKit::initialize(webkit_client_.get());
[email protected]8881eca82009-03-12 18:20:44717
[email protected]98d7127b2009-10-23 18:26:51718 WebScriptController::enableV8SingleThreadMode();
[email protected]4ea00e82009-07-30 22:59:34719
[email protected]60e448982009-05-06 04:21:16720 // chrome: pages should not be accessible by normal content, and should
[email protected]8881eca82009-03-12 18:20:44721 // also be unable to script anything but themselves (to help limit the damage
[email protected]60e448982009-05-06 04:21:16722 // that a corrupt chrome: page could cause).
[email protected]2c434b32009-03-19 06:27:47723 WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme));
[email protected]204758c2009-10-22 03:56:30724 WebSecurityPolicy::registerURLSchemeAsLocal(chrome_ui_scheme);
725 WebSecurityPolicy::registerURLSchemeAsNoAccess(chrome_ui_scheme);
[email protected]da00a2882009-03-09 17:51:19726
[email protected]d53d8492009-07-14 01:51:32727 // print: pages should be not accessible by normal context.
728 WebString print_ui_scheme(ASCIIToUTF16(chrome::kPrintScheme));
[email protected]204758c2009-10-22 03:56:30729 WebSecurityPolicy::registerURLSchemeAsLocal(print_ui_scheme);
730 WebSecurityPolicy::registerURLSchemeAsNoAccess(print_ui_scheme);
[email protected]d53d8492009-07-14 01:51:32731
[email protected]6cf8b1a22009-05-26 23:36:00732#if defined(OS_WIN)
733 // We don't yet support Gears on non-Windows, so don't tell pages that we do.
[email protected]98d7127b2009-10-23 18:26:51734 WebScriptController::registerExtension(extensions_v8::GearsExtension::Get());
[email protected]6cf8b1a22009-05-26 23:36:00735#endif
[email protected]98d7127b2009-10-23 18:26:51736 WebScriptController::registerExtension(
737 extensions_v8::IntervalExtension::Get());
738 WebScriptController::registerExtension(
739 extensions_v8::LoadTimesExtension::Get());
740 WebScriptController::registerExtension(
741 extensions_v8::ExternalExtension::Get());
[email protected]309d7a282009-03-24 09:18:27742
[email protected]ad1f9bd2009-07-30 20:23:15743 const WebKit::WebString kExtensionScheme =
744 WebKit::WebString::fromUTF8(chrome::kExtensionScheme);
745
[email protected]98d7127b2009-10-23 18:26:51746 WebScriptController::registerExtension(
747 ExtensionProcessBindings::Get(), kExtensionScheme);
[email protected]ad1f9bd2009-07-30 20:23:15748
[email protected]98d7127b2009-10-23 18:26:51749 WebScriptController::registerExtension(
750 BaseJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
751 WebScriptController::registerExtension(
752 BaseJsV8Extension::Get(), kExtensionScheme);
753 WebScriptController::registerExtension(
754 JsonSchemaJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
755 WebScriptController::registerExtension(JsonSchemaJsV8Extension::Get(),
756 kExtensionScheme);
757 WebScriptController::registerExtension(
758 EventBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
759 WebScriptController::registerExtension(EventBindings::Get(),
760 kExtensionScheme);
761 WebScriptController::registerExtension(
762 RendererExtensionBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
763 WebScriptController::registerExtension(
764 RendererExtensionBindings::Get(), kExtensionScheme);
765 WebScriptController::registerExtension(
766 ExtensionApiTestV8Extension::Get(), kExtensionScheme);
767 WebScriptController::registerExtension(
768 ExtensionApiTestV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS);
[email protected]a1a0df02009-04-09 08:18:04769
[email protected]e2b2d4a2009-10-24 03:32:59770 renderer_web_database_observer_.reset(new RendererWebDatabaseObserver(this));
771 WebKit::WebDatabase::setObserver(renderer_web_database_observer_.get());
772
[email protected]06533c0b2009-03-05 21:39:11773 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1a0df02009-04-09 08:18:04774
[email protected]98d7127b2009-10-23 18:26:51775 if (command_line.HasSwitch(switches::kEnableBenchmarking)) {
776 WebScriptController::registerExtension(
777 extensions_v8::BenchmarkingExtension::Get());
778 }
[email protected]b07f29092009-06-05 07:33:21779
[email protected]06533c0b2009-03-05 21:39:11780 if (command_line.HasSwitch(switches::kPlaybackMode) ||
[email protected]ca12c842009-04-14 22:20:18781 command_line.HasSwitch(switches::kRecordMode) ||
782 command_line.HasSwitch(switches::kNoJsRandomness)) {
[email protected]98d7127b2009-10-23 18:26:51783 WebScriptController::registerExtension(
784 extensions_v8::PlaybackExtension::Get());
[email protected]06533c0b2009-03-05 21:39:11785 }
[email protected]2cb82332009-03-18 17:24:55786
[email protected]b1b13212009-10-30 06:42:01787 WebRuntimeFeatures::enableMediaPlayer(
[email protected]00c39612010-03-06 02:53:28788 RenderProcess::current()->HasInitializedMediaLibrary());
[email protected]3553c6cc2009-10-20 05:51:55789
[email protected]b1b13212009-10-30 06:42:01790 WebRuntimeFeatures::enableSockets(
[email protected]cdf24782009-11-05 09:32:47791 !command_line.HasSwitch(switches::kDisableWebSockets));
[email protected]0afb9932009-10-24 00:37:58792
[email protected]b1b13212009-10-30 06:42:01793 WebRuntimeFeatures::enableDatabase(
[email protected]90a7ad522009-11-20 22:42:53794 !command_line.HasSwitch(switches::kDisableDatabases));
[email protected]bfa69d492009-10-31 03:27:19795
[email protected]13bc0d822009-11-07 01:17:14796 WebRuntimeFeatures::enableApplicationCache(
[email protected]425c270642010-01-26 20:42:37797 !command_line.HasSwitch(switches::kDisableApplicationCache));
[email protected]13bc0d822009-11-07 01:17:14798
[email protected]bfa69d492009-10-31 03:27:19799 WebRuntimeFeatures::enableNotifications(
[email protected]380f1862009-11-14 02:48:01800 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
[email protected]7ee66e62009-11-05 09:16:30801
802 WebRuntimeFeatures::enableLocalStorage(
[email protected]5cf18362009-11-06 18:45:01803 !command_line.HasSwitch(switches::kDisableLocalStorage));
[email protected]7ee66e62009-11-05 09:16:30804 WebRuntimeFeatures::enableSessionStorage(
[email protected]03567802010-02-24 11:48:53805 !command_line.HasSwitch(switches::kDisableSessionStorage));
[email protected]2236bd1f2010-01-20 15:17:08806
[email protected]582fab732010-02-02 02:50:28807 WebRuntimeFeatures::enableIndexedDatabase(
808 command_line.HasSwitch(switches::kEnableIndexedDatabase));
809
[email protected]2236bd1f2010-01-20 15:17:08810 WebRuntimeFeatures::enableGeolocation(
811 command_line.HasSwitch(switches::kEnableGeolocation));
[email protected]7a716c82010-03-03 10:33:44812
813 WebRuntimeFeatures::enableWebGL(
814 command_line.HasSwitch(switches::kEnableExperimentalWebGL));
[email protected]90a3fbb12009-02-28 01:13:47815}
[email protected]75e5a872009-04-02 23:56:11816
[email protected]bee16aab2009-08-26 15:55:03817void RenderThread::IdleHandler() {
[email protected]61a9b2d82010-02-26 00:31:08818#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]e94afbb92009-10-01 00:25:41819 MallocExtension::instance()->ReleaseFreeMemory();
[email protected]05001182009-09-15 23:34:22820#endif
[email protected]bee16aab2009-08-26 15:55:03821
[email protected]f5e4b9bf2009-10-08 00:59:59822 LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this;
823 v8::V8::IdleNotification();
[email protected]05001182009-09-15 23:34:22824
825 // Schedule next invocation.
826 // Dampen the delay using the algorithm:
827 // delay = delay + 1 / (delay + 2)
828 // Using floor(delay) has a dampening effect such as:
829 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
830 // Note that idle_notification_delay_in_s_ would be reset to
831 // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden.
[email protected]71d6d852009-12-07 22:12:36832 ScheduleIdleHandler(idle_notification_delay_in_s_ +
833 1.0 / (idle_notification_delay_in_s_ + 2.0));
834 if (is_extension_process()) {
835 // Dampen the forced delay as well if the extension stays idle for long
836 // periods of time.
837 int64 forced_delay_s =
838 std::max(static_cast<int64>(idle_notification_delay_in_s_),
839 kMaxExtensionIdleHandlerDelayS);
840 forced_idle_timer_.Stop();
841 forced_idle_timer_.Start(
842 base::TimeDelta::FromSeconds(forced_delay_s),
843 this, &RenderThread::IdleHandler);
844 }
845}
[email protected]05001182009-09-15 23:34:22846
[email protected]71d6d852009-12-07 22:12:36847void RenderThread::ScheduleIdleHandler(double initial_delay_s) {
848 idle_notification_delay_in_s_ = initial_delay_s;
849 idle_timer_.Stop();
850 idle_timer_.Start(
851 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)),
852 this, &RenderThread::IdleHandler);
[email protected]bee16aab2009-08-26 15:55:03853}
854
[email protected]dfcb62a2009-06-17 19:32:43855void RenderThread::OnExtensionMessageInvoke(const std::string& function_name,
856 const ListValue& args) {
[email protected]7120f132009-07-20 21:05:37857 RendererExtensionBindings::Invoke(function_name, args, NULL);
[email protected]71d6d852009-12-07 22:12:36858
859 // Reset the idle handler each time there's any activity like event or message
860 // dispatch, for which Invoke is the chokepoint.
861 if (is_extension_process())
862 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]b68d5ed2009-04-16 02:41:28863}
[email protected]b547fd42009-04-23 23:16:27864
[email protected]fede6ca12009-10-08 18:24:26865void RenderThread::OnPurgeMemory() {
[email protected]85c55dc2009-11-06 03:05:46866 spellchecker_.reset(new SpellCheck());
[email protected]85c55dc2009-11-06 03:05:46867
[email protected]fede6ca12009-10-08 18:24:26868 EnsureWebKitInitialized();
869
870 // Clear the object cache (as much as possible; some live objects cannot be
871 // freed).
872 WebCache::clear();
873
874 // Clear the font/glyph cache.
875 WebFontCache::clear();
876
877 // Clear the Cross-Origin Preflight cache.
878 WebCrossOriginPreflightResultCache::clear();
879
[email protected]adf00bc2009-11-02 18:35:00880 // Release all freeable memory from the SQLite process-global page cache (a
881 // low-level object which backs the Connection-specific page caches).
[email protected]4a3dab22009-11-11 17:36:50882 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
883 }
[email protected]adf00bc2009-11-02 18:35:00884
[email protected]fede6ca12009-10-08 18:24:26885 // Repeatedly call the V8 idle notification until it returns true ("nothing
886 // more to free"). Note that it makes more sense to do this than to implement
887 // a new "delete everything" pass because object references make it difficult
888 // to free everything possible in just one pass.
[email protected]4a3dab22009-11-11 17:36:50889 while (!v8::V8::IdleNotification()) {
890 }
[email protected]fede6ca12009-10-08 18:24:26891
[email protected]61a9b2d82010-02-26 00:31:08892#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]fede6ca12009-10-08 18:24:26893 // Tell tcmalloc to release any free pages it's still holding.
894 MallocExtension::instance()->ReleaseFreeMemory();
895#endif
896}
897
[email protected]b78e168b2009-09-21 22:05:45898void RenderThread::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:59899 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:27900 // The call below will cause a GetPlugins call with refresh=true, but at this
901 // point we already know that the browser has refreshed its list, so disable
902 // refresh temporarily to prevent each renderer process causing the list to be
903 // regenerated.
904 plugin_refresh_allowed_ = false;
[email protected]b78e168b2009-09-21 22:05:45905 WebKit::resetPluginCache(reload_pages);
[email protected]b547fd42009-04-23 23:16:27906 plugin_refresh_allowed_ = true;
907}
[email protected]85c55dc2009-11-06 03:05:46908
[email protected]85c55dc2009-11-06 03:05:46909void RenderThread::OnInitSpellChecker(
[email protected]cb6037d2009-11-16 22:55:17910 IPC::PlatformFileForTransit bdict_file,
[email protected]85c55dc2009-11-06 03:05:46911 const std::vector<std::string>& custom_words,
912 const std::string& language,
913 bool auto_spell_correct) {
[email protected]cb6037d2009-11-16 22:55:17914 spellchecker_->Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file),
915 custom_words, language);
[email protected]85c55dc2009-11-06 03:05:46916 spellchecker_->EnableAutoSpellCorrect(auto_spell_correct);
917}
918
919void RenderThread::OnSpellCheckWordAdded(const std::string& word) {
920 spellchecker_->WordAdded(word);
921}
922
923void RenderThread::OnSpellCheckEnableAutoSpellCorrect(bool enable) {
924 spellchecker_->EnableAutoSpellCorrect(enable);
925}