blob: 50f010a7531975500f5ea51ea08351ed0223d070 [file] [log] [blame]
[email protected]7785b17f2011-03-23 01:20:281// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f1a29a02011-10-06 23:08:445#include "content/renderer/render_thread_impl.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]da00a2882009-03-09 17:51:197#include <algorithm>
[email protected]61a9b2d82010-02-26 00:31:088#include <limits>
[email protected]75e126b932009-09-28 19:38:499#include <map>
[email protected]da00a2882009-03-09 17:51:1910#include <vector>
11
[email protected]06533c0b2009-03-05 21:39:1112#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5013#include "base/debug/trace_event.h"
[email protected]94f9a0f682009-06-15 18:30:3014#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0315#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/field_trial.h"
[email protected]6cf19311f2011-04-14 23:06:0217#include "base/metrics/histogram.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/stats_table.h"
[email protected]d41041092009-10-08 06:56:5719#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2920#include "base/shared_memory.h"
[email protected]46f36a492010-07-28 19:36:4121#include "base/task.h"
[email protected]1357c322010-12-30 22:18:5622#include "base/threading/thread_local.h"
[email protected]7a4de7a62010-08-17 18:38:2423#include "base/values.h"
[email protected]1a771262011-10-31 09:11:1224#include "base/win/scoped_com_initializer.h"
[email protected]e93e04e2011-03-14 00:27:1025#include "content/common/appcache/appcache_dispatcher.h"
[email protected]bdae9812011-10-15 00:33:0326#include "content/common/child_process_messages.h"
[email protected]37666cf2011-03-13 21:51:4227#include "content/common/database_messages.h"
28#include "content/common/db_message_filter.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/dom_storage_messages.h"
[email protected]202b54ff2011-04-22 21:36:3830#include "content/common/gpu/gpu_messages.h"
[email protected]d3fd748b2011-09-20 17:39:1731#include "content/common/npobject_util.h"
[email protected]105303e2011-03-14 22:16:1032#include "content/common/plugin_messages.h"
[email protected]359dfa32011-10-12 01:10:1533#include "content/common/resource_dispatcher.h"
[email protected]94dc971d2011-03-05 19:08:3234#include "content/common/resource_messages.h"
[email protected]778574e2011-03-21 22:03:5035#include "content/common/view_messages.h"
[email protected]e93e04e2011-03-14 00:27:1036#include "content/common/web_database_observer_impl.h"
[email protected]c08950d22011-10-13 22:20:2937#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3138#include "content/public/common/renderer_preferences.h"
[email protected]d344114c2011-10-01 01:24:3439#include "content/public/renderer/content_renderer_client.h"
[email protected]64ffa0442011-10-03 22:08:3640#include "content/public/renderer/render_process_observer.h"
41#include "content/public/renderer/render_view_visitor.h"
[email protected]82622452011-07-22 09:57:2042#include "content/renderer/devtools_agent_filter.h"
[email protected]a9fb30aa2011-10-06 06:58:4643#include "content/renderer/gpu/compositor_thread.h"
[email protected]a03a2222011-05-25 21:26:4044#include "content/renderer/gpu/gpu_channel_host.h"
[email protected]230b7ef2011-03-16 22:30:1945#include "content/renderer/indexed_db_dispatcher.h"
[email protected]f7eb0a392011-07-12 10:19:5146#include "content/renderer/media/audio_input_message_filter.h"
47#include "content/renderer/media/audio_message_filter.h"
[email protected]80b161a2011-06-27 17:42:1148#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:3449#include "content/renderer/media/video_capture_message_filter.h"
[email protected]6f516082011-03-17 19:15:3550#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0551#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:2852#include "content/renderer/render_view_impl.h"
[email protected]acb94722011-03-18 01:33:3453#include "content/renderer/renderer_webidbfactory_impl.h"
[email protected]8d6cba42011-09-02 10:05:1954#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]46f36a492010-07-28 19:36:4155#include "ipc/ipc_channel_handle.h"
[email protected]cb6037d2009-11-16 22:55:1756#include "ipc/ipc_platform_file.h"
[email protected]620161e2011-03-07 18:05:2657#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5458#include "net/base/net_util.h"
[email protected]1b1f3eb2009-12-01 13:48:0459#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
[email protected]8bd0fe62011-01-17 06:44:3760#include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h"
[email protected]028217e2011-11-19 00:19:0861#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
[email protected]8bd0fe62011-01-17 06:44:3762#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
63#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3764#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
65#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]6eac57a2011-07-12 21:15:0966#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]4bd55a32011-07-28 13:28:3867#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
[email protected]8bd0fe62011-01-17 06:44:3768#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
69#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
[email protected]8bd0fe62011-01-17 06:44:3770#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
71#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
72#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]18ad6772011-09-20 21:51:3273#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:5074#include "v8/include/v8.h"
[email protected]06533c0b2009-03-05 21:39:1175#include "webkit/extensions/v8/playback_extension.h"
[email protected]d471190a2011-02-16 14:52:3076#include "webkit/glue/webkit_glue.h"
[email protected]2c62b562009-01-27 19:04:5077
[email protected]94dc971d2011-03-05 19:08:3278// TODO(port)
[email protected]bdae9812011-10-15 00:33:0379#if !defined(OS_WIN)
[email protected]3b63f8f42011-03-28 01:54:1580#include "base/memory/scoped_handle.h"
[email protected]099587b72011-09-20 00:40:5081#include "content/common/np_channel_base.h"
[email protected]94dc971d2011-03-05 19:08:3282#endif
83
[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]6217d392010-03-25 22:08:3589#if defined(OS_POSIX)
90#include "ipc/ipc_channel_posix.h"
91#endif
92
[email protected]b6cb3a842011-06-24 18:28:4193using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:0194using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:0995using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:0096using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:5197using WebKit::WebScriptController;
[email protected]2c434b32009-03-19 06:27:4798using WebKit::WebString;
[email protected]b7c7bcf2009-10-03 07:07:3499using WebKit::WebStorageEventDispatcher;
[email protected]50ae00ef2009-10-19 05:11:03100using WebKit::WebView;
[email protected]64ffa0442011-10-03 22:08:36101using content::RenderProcessObserver;
initial.commit09911bf2008-07-26 23:55:29102
[email protected]42f1d7822009-07-23 18:17:55103namespace {
[email protected]6593ae12011-11-14 12:09:44104static const int64 kInitialIdleHandlerDelayMs = 1000;
[email protected]1784b2f2011-11-24 10:53:48105static const int64 kShortIdleHandlerDelayMs = 1000;
106static const int64 kLongIdleHandlerDelayMs = 30*1000;
107static const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03108
[email protected]f1a29a02011-10-06 23:08:44109// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16110// incorrectly from the wrong thread.
[email protected]6de0fd1d2011-11-15 13:31:49111static base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
112 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54113
[email protected]64ffa0442011-10-03 22:08:36114class RenderViewZoomer : public content::RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51115 public:
[email protected]b75b8292010-10-01 07:28:25116 RenderViewZoomer(const GURL& url, double zoom_level)
[email protected]9d797f32010-04-23 07:17:54117 : zoom_level_(zoom_level) {
118 host_ = net::GetHostOrSpecFromURL(url);
[email protected]40bd6582009-12-04 23:49:51119 }
120
[email protected]a2ef54c2011-10-10 16:20:31121 virtual bool Visit(content::RenderView* render_view) {
122 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41123 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25124
125 // Don't set zoom level for full-page plugin since they don't use the same
126 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41127 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25128 return true;
129
[email protected]b6cb3a842011-06-24 18:28:41130 if (net::GetHostOrSpecFromURL(GURL(document.url())) == host_)
[email protected]40bd6582009-12-04 23:49:51131 webview->setZoomLevel(false, zoom_level_);
132 return true;
133 }
134
135 private:
136 std::string host_;
[email protected]b75b8292010-10-01 07:28:25137 double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51138
139 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
140};
[email protected]0478d0162010-08-28 08:29:40141
[email protected]42f1d7822009-07-23 18:17:55142} // namespace
143
[email protected]d1b8fccc2011-08-03 01:20:13144static void* CreateHistogram(
145 const char *name, int min, int max, size_t buckets) {
146 if (min <= 0)
147 min = 1;
148 base::Histogram* histogram = base::Histogram::FactoryGet(
149 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag);
150 return histogram;
151}
152
153static void AddHistogramSample(void* hist, int sample) {
154 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
155 histogram->Add(sample);
156}
157
[email protected]f1a29a02011-10-06 23:08:44158RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06159 return lazy_tls.Pointer()->Get();
160}
161
[email protected]42f1d7822009-07-23 18:17:55162// When we run plugins in process, we actually run them on the render thread,
163// which means that we need to make the render thread pump UI events.
[email protected]f1a29a02011-10-06 23:08:44164RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55165 Init();
166}
167
[email protected]f1a29a02011-10-06 23:08:44168RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55169 : ChildThread(channel_name) {
170 Init();
171}
[email protected]5fa1c542009-05-05 20:36:07172
[email protected]f1a29a02011-10-06 23:08:44173void RenderThreadImpl::Init() {
174 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33175
[email protected]53c607c2011-03-21 23:19:04176#if defined(OS_MACOSX)
177 // On Mac, the select popups are rendered by the browser.
178 WebKit::WebView::setUseExternalPopupMenus(true);
179#endif
180
[email protected]94f9a0f682009-06-15 18:30:30181 lazy_tls.Pointer()->Set(this);
[email protected]2c62b562009-01-27 19:04:50182#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34183 // If you are running plugins in this thread you need COM active but in
184 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28185 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12186 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50187#endif
initial.commit09911bf2008-07-26 23:55:29188
[email protected]31f87132010-04-21 23:36:21189 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50190 suspend_webkit_shared_timer_ = true;
191 notify_webkit_of_modal_loop_ = true;
[email protected]42f1d7822009-07-23 18:17:55192 plugin_refresh_allowed_ = true;
[email protected]bee16aab2009-08-26 15:55:03193 widget_count_ = 0;
194 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44195 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48196 idle_notifications_to_skip_ = 0;
197 base::ProcessHandle handle = base::GetCurrentProcessHandle();
198#if defined(OS_MACOSX)
199 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle,
200 NULL));
201#else
202 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle));
203#endif
204 process_metrics_->GetCPUUsage(); // Initialize CPU usage counters.
[email protected]f1a29a02011-10-06 23:08:44205 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this));
[email protected]8d86fce2009-02-26 23:37:55206
[email protected]526476902011-10-06 20:34:06207 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
[email protected]70c19a932010-05-14 12:59:11208 indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13209
[email protected]017022b2009-07-27 23:06:34210 db_message_filter_ = new DBMessageFilter();
211 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13212
[email protected]80b161a2011-06-27 17:42:11213 vc_manager_ = new VideoCaptureImplManager();
214 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46215
[email protected]f7eb0a392011-07-12 10:19:51216 audio_input_message_filter_ = new AudioInputMessageFilter();
217 AddFilter(audio_input_message_filter_.get());
218
219 audio_message_filter_ = new AudioMessageFilter();
220 AddFilter(audio_message_filter_.get());
221
[email protected]82622452011-07-22 09:57:20222 devtools_agent_message_filter_ = new DevToolsAgentFilter();
223 AddFilter(devtools_agent_message_filter_.get());
224
[email protected]8d97ade2011-04-14 18:17:08225 content::GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24226
[email protected]f1a29a02011-10-06 23:08:44227 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29228}
229
[email protected]f1a29a02011-10-06 23:08:44230RenderThreadImpl::~RenderThreadImpl() {
[email protected]1223d6ef2011-03-28 16:47:50231 FOR_EACH_OBSERVER(
232 RenderProcessObserver, observers_, OnRenderProcessShutdown());
233
[email protected]12cbfda32010-01-30 01:04:25234 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08235 if (web_database_observer_impl_.get())
236 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25237
[email protected]8d86fce2009-02-26 23:37:55238 // Shutdown in reverse of the initialization order.
[email protected]82622452011-07-22 09:57:20239 RemoveFilter(devtools_agent_message_filter_.get());
240 devtools_agent_message_filter_ = NULL;
241
[email protected]f7eb0a392011-07-12 10:19:51242 RemoveFilter(audio_input_message_filter_.get());
243 audio_input_message_filter_ = NULL;
244
245 RemoveFilter(audio_message_filter_.get());
246 audio_message_filter_ = NULL;
247
[email protected]80b161a2011-06-27 17:42:11248 RemoveFilter(vc_manager_->video_capture_message_filter());
249
[email protected]017022b2009-07-27 23:06:34250 RemoveFilter(db_message_filter_.get());
251 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25252
[email protected]c6a7b862010-08-20 22:19:38253 // Shutdown the file thread if it's running.
254 if (file_thread_.get())
255 file_thread_->Stop();
256
[email protected]028217e2011-11-19 00:19:08257#ifdef WEBCOMPOSITOR_HAS_INITIALIZE
258 WebKit::WebCompositor::shutdown();
259#endif
[email protected]a9fb30aa2011-10-06 06:58:46260 if (compositor_thread_.get()) {
261 RemoveFilter(compositor_thread_->GetMessageFilter());
262 compositor_thread_.reset();
263 }
264
[email protected]8d6cba42011-09-02 10:05:19265 if (webkit_platform_support_.get())
[email protected]9291ed12009-07-23 17:33:22266 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22267
[email protected]94f9a0f682009-06-15 18:30:30268 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30269
[email protected]8d86fce2009-02-26 23:37:55270 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50271#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29272 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50273 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50274#endif
initial.commit09911bf2008-07-26 23:55:29275}
276
[email protected]f1a29a02011-10-06 23:08:44277bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14278 // Certain synchronous messages cannot always be processed synchronously by
279 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50280 // This could cause a complete hang of Chrome if a windowed plug-in is trying
281 // to communicate with the renderer thread since the browser's UI thread
282 // could be stuck (within a Windows API call) trying to synchronously
283 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14284 // thread while the browser is processing this request. This creates an
285 // opportunity for re-entrancy into WebKit, so we need to take care to disable
286 // callbacks, timers, and pending network loads that could trigger such
287 // callbacks.
[email protected]38b592902011-04-16 02:08:42288 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50289 if (msg->is_sync()) {
290 if (msg->is_caller_pumping_messages()) {
291 pumping_events = true;
292 } else {
[email protected]38b592902011-04-16 02:08:42293 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
294 msg->type() == ViewHostMsg_GetRawCookies::ID ||
295 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
296 content::GetContentClient()->renderer()->
297 ShouldPumpEventsDuringCookieMessage()) {
298 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50299 }
300 }
[email protected]c1f50aa2010-02-18 03:46:57301 }
302
[email protected]80fc08c52010-03-09 07:43:50303 bool suspend_webkit_shared_timer = true; // default value
304 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57305
[email protected]80fc08c52010-03-09 07:43:50306 bool notify_webkit_of_modal_loop = true; // default value
307 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
308
309 gfx::NativeViewId host_window = 0;
[email protected]c1f50aa2010-02-18 03:46:57310
311 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50312 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19313 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57314
[email protected]39065d012010-07-09 11:22:46315 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57316 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57317
[email protected]80fc08c52010-03-09 07:43:50318 RenderWidget* widget =
319 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
320 if (widget) {
321 host_window = widget->host_window();
[email protected]c1f50aa2010-02-18 03:46:57322 PluginChannelHost::Broadcast(
323 new PluginMsg_SignalModalDialogEvent(host_window));
324 }
325 }
326
327 bool rv = ChildThread::Send(msg);
328
329 if (pumping_events) {
330 if (host_window) {
331 PluginChannelHost::Broadcast(
332 new PluginMsg_ResetModalDialogEvent(host_window));
333 }
334
[email protected]39065d012010-07-09 11:22:46335 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57336 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57337
[email protected]80fc08c52010-03-09 07:43:50338 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19339 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57340 }
341
342 return rv;
343}
344
[email protected]f1a29a02011-10-06 23:08:44345MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06346 return message_loop();
347}
348
[email protected]f1a29a02011-10-06 23:08:44349IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06350 return channel();
351}
352
[email protected]f1a29a02011-10-06 23:08:44353std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06354 // The browser process should have passed the locale to the renderer via the
355 // --lang command line flag. In single process mode, this will return the
356 // wrong value. TODO(tc): Fix this for single process mode.
357 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
358 const std::string& lang =
359 parsed_command_line.GetSwitchValueASCII(switches::kLang);
360 DCHECK(!lang.empty() ||
361 (!parsed_command_line.HasSwitch(switches::kRendererProcess) &&
362 !parsed_command_line.HasSwitch(switches::kPluginProcess)));
363 return lang;
364}
365
[email protected]f1a29a02011-10-06 23:08:44366void RenderThreadImpl::AddRoute(int32 routing_id,
367 IPC::Channel::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57368 widget_count_++;
369 return ChildThread::AddRoute(routing_id, listener);
370}
371
[email protected]f1a29a02011-10-06 23:08:44372void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57373 widget_count_--;
374 return ChildThread::RemoveRoute(routing_id);
375}
376
[email protected]77fc9b92011-10-15 16:20:37377int RenderThreadImpl::GenerateRoutingID() {
378 int routing_id = MSG_ROUTING_NONE;
379 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
380 return routing_id;
381}
382
[email protected]f1a29a02011-10-06 23:08:44383void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55384 channel()->AddFilter(filter);
385}
386
[email protected]f1a29a02011-10-06 23:08:44387void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55388 channel()->RemoveFilter(filter);
389}
390
[email protected]f1a29a02011-10-06 23:08:44391void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06392 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
393}
394
[email protected]f1a29a02011-10-06 23:08:44395void RenderThreadImpl::AddObserver(content::RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06396 observers_.AddObserver(observer);
397}
398
[email protected]f1a29a02011-10-06 23:08:44399void RenderThreadImpl::RemoveObserver(
400 content::RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06401 observers_.RemoveObserver(observer);
402}
403
[email protected]359dfa32011-10-12 01:10:15404void RenderThreadImpl::SetResourceDispatcherDelegate(
405 content::ResourceDispatcherDelegate* delegate) {
406 resource_dispatcher()->set_delegate(delegate);
407}
408
[email protected]f1a29a02011-10-06 23:08:44409void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03410 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50411 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24412
413 if (!content::GetContentClient()->renderer()->
414 RunIdleHandlerWhenWidgetsHidden()) {
415 return;
416 }
417
418 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44419 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03420}
421
[email protected]f1a29a02011-10-06 23:08:44422void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08423 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03424 hidden_widget_count_--;
[email protected]6779aa12011-03-29 17:32:24425 if (!content::GetContentClient()->renderer()->
426 RunIdleHandlerWhenWidgetsHidden()) {
427 return;
428 }
[email protected]bee16aab2009-08-26 15:55:03429
[email protected]1784b2f2011-11-24 10:53:48430 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39431}
432
[email protected]f1a29a02011-10-06 23:08:44433void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]8d6cba42011-09-02 10:05:19434 if (webkit_platform_support_.get())
[email protected]d1b8fccc2011-08-03 01:20:13435 return;
436
437 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
438 v8::V8::SetCreateHistogramFunction(CreateHistogram);
439 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
440
[email protected]8d6cba42011-09-02 10:05:19441 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
442 WebKit::initialize(webkit_platform_support_.get());
[email protected]d1b8fccc2011-08-03 01:20:13443
[email protected]f3150172011-10-22 02:28:45444 if (CommandLine::ForCurrentProcess()->HasSwitch(
445 switches::kEnableThreadedCompositing)) {
446 compositor_thread_.reset(new CompositorThread(this));
447 AddFilter(compositor_thread_->GetMessageFilter());
[email protected]028217e2011-11-19 00:19:08448#ifdef WEBCOMPOSITOR_HAS_INITIALIZE
449 WebKit::WebCompositor::initialize(compositor_thread_->GetWebThread());
450#else
451 WebKit::WebCompositor::setThread(compositor_thread_->GetWebThread());
452#endif
453 } else {
454#ifdef WEBCOMPOSITOR_HAS_INITIALIZE
455 WebKit::WebCompositor::initialize(NULL);
456#endif
[email protected]f3150172011-10-22 02:28:45457 }
[email protected]a9fb30aa2011-10-06 06:58:46458
[email protected]d1b8fccc2011-08-03 01:20:13459 WebScriptController::enableV8SingleThreadMode();
460
461 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
462
463 webkit_glue::EnableWebCoreLogChannels(
464 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
465
[email protected]d1b8fccc2011-08-03 01:20:13466 if (command_line.HasSwitch(switches::kPlaybackMode) ||
467 command_line.HasSwitch(switches::kRecordMode) ||
468 command_line.HasSwitch(switches::kNoJsRandomness)) {
469 RegisterExtension(extensions_v8::PlaybackExtension::Get());
470 }
471
[email protected]526476902011-10-06 20:34:06472 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(Get()));
[email protected]d1b8fccc2011-08-03 01:20:13473 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
474
475 WebRuntimeFeatures::enableSockets(
476 !command_line.HasSwitch(switches::kDisableWebSockets));
477
478 WebRuntimeFeatures::enableDatabase(
479 !command_line.HasSwitch(switches::kDisableDatabases));
480
481 WebRuntimeFeatures::enableDataTransferItems(
482 !command_line.HasSwitch(switches::kDisableDataTransferItems));
483
484 WebRuntimeFeatures::enableApplicationCache(
485 !command_line.HasSwitch(switches::kDisableApplicationCache));
486
487 WebRuntimeFeatures::enableNotifications(
488 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
489
490 WebRuntimeFeatures::enableLocalStorage(
491 !command_line.HasSwitch(switches::kDisableLocalStorage));
492 WebRuntimeFeatures::enableSessionStorage(
493 !command_line.HasSwitch(switches::kDisableSessionStorage));
494
495 WebRuntimeFeatures::enableIndexedDatabase(
496 !command_line.HasSwitch(switches::kDisableIndexedDatabase));
497
498 WebRuntimeFeatures::enableGeolocation(
499 !command_line.HasSwitch(switches::kDisableGeolocation));
500
[email protected]6aa03b32011-10-27 21:44:44501 WebKit::WebRuntimeFeatures::enableMediaSource(
502 command_line.HasSwitch(switches::kEnableMediaSource));
503
[email protected]d1b8fccc2011-08-03 01:20:13504 WebKit::WebRuntimeFeatures::enableMediaStream(
505 command_line.HasSwitch(switches::kEnableMediaStream));
506
[email protected]efdc0282011-08-26 00:36:12507 WebKit::WebRuntimeFeatures::enableFullScreenAPI(
[email protected]5e5671a2011-09-08 02:12:21508 !command_line.HasSwitch(switches::kDisableFullScreen));
[email protected]efdc0282011-08-26 00:36:12509
[email protected]e4e68dbb2011-11-18 01:50:22510 WebKit::WebRuntimeFeatures::enablePointerLock(
511 command_line.HasSwitch(switches::kEnablePointerLock));
512
[email protected]f5da41d2011-10-08 17:40:07513 WebKit::WebRuntimeFeatures::enableVideoTrack(
514 command_line.HasSwitch(switches::kEnableVideoTrack));
515
[email protected]d1b8fccc2011-08-03 01:20:13516#if defined(OS_CHROMEOS)
517 // TODO(crogers): enable once Web Audio has been tested and optimized.
518 WebRuntimeFeatures::enableWebAudio(false);
519#else
520 WebRuntimeFeatures::enableWebAudio(
521 !command_line.HasSwitch(switches::kDisableWebAudio));
522#endif
523
524 WebRuntimeFeatures::enablePushState(true);
525
[email protected]d1b8fccc2011-08-03 01:20:13526 WebRuntimeFeatures::enableTouch(false);
[email protected]d1b8fccc2011-08-03 01:20:13527
528 WebRuntimeFeatures::enableDeviceMotion(
529 command_line.HasSwitch(switches::kEnableDeviceMotion));
530
531 WebRuntimeFeatures::enableDeviceOrientation(
532 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
533
534 WebRuntimeFeatures::enableSpeechInput(
535 !command_line.HasSwitch(switches::kDisableSpeechInput));
536
537 WebRuntimeFeatures::enableFileSystem(
538 !command_line.HasSwitch(switches::kDisableFileSystem));
539
540 WebRuntimeFeatures::enableJavaScriptI18NAPI(
541 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI));
542
543 WebRuntimeFeatures::enableQuota(true);
544
545 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48546
547 if (content::GetContentClient()->renderer()->
548 RunIdleHandlerWhenWidgetsHidden()) {
549 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
550 }
[email protected]d1b8fccc2011-08-03 01:20:13551}
552
[email protected]f1a29a02011-10-06 23:08:44553void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06554 Send(new ViewHostMsg_UserMetricsRecordAction(action));
555}
556
[email protected]00614a82011-10-07 22:39:31557base::SharedMemoryHandle RenderThreadImpl::HostAllocateSharedMemoryBuffer(
[email protected]bdae9812011-10-15 00:33:03558 uint32 buffer_size) {
[email protected]00614a82011-10-07 22:39:31559 base::SharedMemoryHandle mem_handle;
[email protected]bdae9812011-10-15 00:33:03560 Send(new ChildProcessHostMsg_SyncAllocateSharedMemory(
561 buffer_size, &mem_handle));
[email protected]00614a82011-10-07 22:39:31562 return mem_handle;
563}
564
[email protected]f1a29a02011-10-06 23:08:44565void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06566 WebScriptController::registerExtension(extension);
567 v8_extensions_.insert(extension->name());
568}
569
[email protected]f1a29a02011-10-06 23:08:44570bool RenderThreadImpl::IsRegisteredExtension(
[email protected]526476902011-10-06 20:34:06571 const std::string& v8_extension_name) const {
572 return v8_extensions_.find(v8_extension_name) != v8_extensions_.end();
573}
574
[email protected]6593ae12011-11-14 12:09:44575void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
576 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06577 idle_timer_.Stop();
578 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44579 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44580 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06581}
582
[email protected]f1a29a02011-10-06 23:08:44583void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48584 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
585 content::GetContentClient()->renderer()->
586 RunIdleHandlerWhenWidgetsHidden();
587 if (run_in_foreground_tab) {
588 IdleHandlerInForegroundTab();
589 return;
590 }
591#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
[email protected]526476902011-10-06 20:34:06592 MallocExtension::instance()->ReleaseFreeMemory();
593#endif
594
595 v8::V8::IdleNotification();
596
597 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44598 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06599 // delay = delay + 1 / (delay + 2)
600 // Using floor(delay) has a dampening effect such as:
601 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44602 // If the delay is in milliseconds, the above formula is equivalent to:
603 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
604 // which is equivalent to
605 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
606 // Note that idle_notification_delay_in_ms_ would be reset to
607 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
608 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
609 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06610
611 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
612}
613
[email protected]1784b2f2011-11-24 10:53:48614void RenderThreadImpl::IdleHandlerInForegroundTab() {
615 // Increase the delay in the same way as in IdleHandler,
616 // but make it periodic by reseting it once it is too big.
617 int64 new_delay_ms = idle_notification_delay_in_ms_ +
618 1000000 / (idle_notification_delay_in_ms_ + 2000);
619 if (new_delay_ms >= kLongIdleHandlerDelayMs)
620 new_delay_ms = kShortIdleHandlerDelayMs;
621
622 // Sample the CPU usage on each timer event, so that it is more accurate.
623 double cpu_usage = process_metrics_->GetCPUUsage();
624
625 if (idle_notifications_to_skip_ > 0) {
626 idle_notifications_to_skip_--;
627 } else if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
628 if (v8::V8::IdleNotification()) {
629 // V8 finished collecting garbage.
630 new_delay_ms = kLongIdleHandlerDelayMs;
631 }
632 }
633
634 ScheduleIdleHandler(new_delay_ms);
635}
636
[email protected]6593ae12011-11-14 12:09:44637int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
638 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06639}
640
[email protected]6593ae12011-11-14 12:09:44641void RenderThreadImpl::SetIdleNotificationDelayInMs(
642 int64 idle_notification_delay_in_ms) {
643 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08644}
645
[email protected]1784b2f2011-11-24 10:53:48646void RenderThreadImpl::PostponeIdleNotification() {
647 idle_notifications_to_skip_ = 2;
648}
649
[email protected]4a7d6392011-09-19 20:55:08650#if defined(OS_WIN)
[email protected]f1a29a02011-10-06 23:08:44651void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:06652 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:21653}
654
[email protected]f1a29a02011-10-06 23:08:44655void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:06656 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:08657}
[email protected]526476902011-10-06 20:34:06658
[email protected]4a7d6392011-09-19 20:55:08659#endif // OS_WIN
660
[email protected]f1a29a02011-10-06 23:08:44661int32 RenderThreadImpl::RoutingIDForCurrentContext() {
[email protected]526476902011-10-06 20:34:06662 int32 routing_id = MSG_ROUTING_CONTROL;
663 if (v8::Context::InContext()) {
664 WebFrame* frame = WebFrame::frameForCurrentContext();
665 if (frame) {
[email protected]310ebd6302011-10-10 19:06:28666 RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view());
[email protected]526476902011-10-06 20:34:06667 if (view)
668 routing_id = view->routing_id();
669 }
670 } else {
671 DLOG(WARNING) << "Not called within a script context!";
672 }
673 return routing_id;
674}
675
[email protected]f1a29a02011-10-06 23:08:44676void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:06677 suspend_webkit_shared_timer_ = false;
678}
679
[email protected]f1a29a02011-10-06 23:08:44680void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:06681 notify_webkit_of_modal_loop_ = false;
682}
683
[email protected]f1a29a02011-10-06 23:08:44684void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const GURL& url,
685 double zoom_level) {
[email protected]526476902011-10-06 20:34:06686 RenderViewZoomer zoomer(url, zoom_level);
[email protected]310ebd6302011-10-10 19:06:28687 content::RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:06688}
689
[email protected]f1a29a02011-10-06 23:08:44690void RenderThreadImpl::OnDOMStorageEvent(
[email protected]526476902011-10-06 20:34:06691 const DOMStorageMsg_Event_Params& params) {
[email protected]0654cc82011-11-17 09:20:59692 if (!dom_storage_event_dispatcher_.get()) {
693 EnsureWebKitInitialized();
[email protected]526476902011-10-06 20:34:06694 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
[email protected]0654cc82011-11-17 09:20:59695 }
[email protected]526476902011-10-06 20:34:06696 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key,
697 params.old_value, params.new_value, params.origin, params.url,
698 params.storage_type == DOM_STORAGE_LOCAL);
699}
700
[email protected]f1a29a02011-10-06 23:08:44701bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:50702 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
703 RenderProcessObserver* observer;
704 while ((observer = it.GetNext()) != NULL) {
705 if (observer->OnControlMessageReceived(msg))
706 return true;
707 }
708
[email protected]70c19a932010-05-14 12:59:11709 // Some messages are handled by delegates.
[email protected]f430b5712009-08-21 21:46:31710 if (appcache_dispatcher_->OnMessageReceived(msg))
[email protected]a95986a82010-12-24 06:19:28711 return true;
[email protected]70c19a932010-05-14 12:59:11712 if (indexed_db_dispatcher_->OnMessageReceived(msg))
[email protected]a95986a82010-12-24 06:19:28713 return true;
[email protected]1edc16b82009-04-07 17:45:54714
[email protected]a95986a82010-12-24 06:19:28715 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:44716 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:54717 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
718 OnSetZoomLevelForCurrentURL)
[email protected]8930d472009-02-21 08:05:28719 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
[email protected]b9ab10c2009-08-07 18:09:55720 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
[email protected]8930d472009-02-21 08:05:28721 // TODO(port): removed from render_messages_internal.h;
722 // is there a new non-windows message I should add here?
723 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:45724 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:09725 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]3e267192011-03-25 01:55:45726 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent)
[email protected]b69934e2011-10-29 02:51:52727 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]a95986a82010-12-24 06:19:28728 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:28729 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28730 return handled;
initial.commit09911bf2008-07-26 23:55:29731}
732
[email protected]f1a29a02011-10-06 23:08:44733void RenderThreadImpl::OnSetNextPageID(int32 next_page_id) {
[email protected]ae195eca72011-11-17 21:18:38734 // This is called at process initialization time or when this process is
735 // being re-used for a new RenderView. It is ok if another RenderView
736 // has identical page_ids or inflates next_page_id_ just before this arrives,
737 // as long as we ensure next_page_id_ is at least this large.
[email protected]310ebd6302011-10-10 19:06:28738 RenderViewImpl::SetNextPageID(next_page_id);
initial.commit09911bf2008-07-26 23:55:29739}
740
[email protected]b9ab10c2009-08-07 18:09:55741// Called when to register CSS Color name->system color mappings.
742// We update the colors one by one and then tell WebKit to refresh all render
743// views.
[email protected]f1a29a02011-10-06 23:08:44744void RenderThreadImpl::OnSetCSSColors(
[email protected]b9ab10c2009-08-07 18:09:55745 const std::vector<CSSColors::CSSColorMapping>& colors) {
[email protected]f5e4b9bf2009-10-08 00:59:59746 EnsureWebKitInitialized();
[email protected]b9ab10c2009-08-07 18:09:55747 size_t num_colors = colors.size();
748 scoped_array<WebKit::WebColorName> color_names(
749 new WebKit::WebColorName[num_colors]);
750 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]);
751 size_t i = 0;
752 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it =
753 colors.begin();
754 it != colors.end();
755 ++it, ++i) {
756 color_names[i] = it->first;
757 web_colors[i] = it->second;
758 }
759 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors);
760}
761
[email protected]f1a29a02011-10-06 23:08:44762void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:47763 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:33764 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]310ebd6302011-10-10 19:06:28765 RenderViewImpl::Create(
[email protected]8ab04652010-06-12 02:47:26766 params.parent_window,
767 MSG_ROUTING_NONE,
768 params.renderer_preferences,
769 params.web_preferences,
770 new SharedRenderViewCounter(0),
771 params.view_id,
772 params.session_storage_namespace_id,
773 params.frame_name);
[email protected]7f874dec2009-02-06 01:48:27774}
[email protected]4274e582009-01-27 22:09:56775
[email protected]f1a29a02011-10-06 23:08:44776GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]7f3a2cf2011-04-06 00:10:50777 content::CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]6217d392010-03-25 22:08:35778 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:22779 // Do nothing if we already have a GPU channel or are already
780 // establishing one.
[email protected]e09cee42010-11-09 01:50:08781 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
782 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:04783 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:35784
785 // Recreate the channel if it has been lost.
[email protected]e09cee42010-11-09 01:50:08786 if (gpu_channel_->state() == GpuChannelHost::kLost)
[email protected]6217d392010-03-25 22:08:35787 gpu_channel_ = NULL;
788 }
789
790 if (!gpu_channel_.get())
791 gpu_channel_ = new GpuChannelHost;
792
793 // Ask the browser for the channel name.
[email protected]b42a9f62011-06-08 20:36:04794 IPC::ChannelHandle channel_handle;
795 base::ProcessHandle renderer_process_for_gpu;
[email protected]a80f5ece2011-10-20 23:56:55796 content::GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:04797 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
798 &channel_handle,
799 &renderer_process_for_gpu,
800 &gpu_info)) ||
801 channel_handle.name.empty() ||
802 renderer_process_for_gpu == base::kNullProcessHandle) {
803 // Otherwise cancel the connection.
804 gpu_channel_ = NULL;
805 return NULL;
806 }
[email protected]6217d392010-03-25 22:08:35807
[email protected]b42a9f62011-06-08 20:36:04808 gpu_channel_->set_gpu_info(gpu_info);
809 content::GetContentClient()->SetGpuInfo(gpu_info);
810
811 // Connect to the GPU process if a channel name was received.
812 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu);
813
[email protected]f9a2b2fe2010-07-15 21:13:23814 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:34815}
816
[email protected]f1a29a02011-10-06 23:08:44817GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]6217d392010-03-25 22:08:35818 if (!gpu_channel_.get())
819 return NULL;
820
[email protected]e09cee42010-11-09 01:50:08821 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:35822 return NULL;
823
824 return gpu_channel_.get();
825}
826
[email protected]f1a29a02011-10-06 23:08:44827void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:59828 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:27829 // The call below will cause a GetPlugins call with refresh=true, but at this
830 // point we already know that the browser has refreshed its list, so disable
831 // refresh temporarily to prevent each renderer process causing the list to be
832 // regenerated.
833 plugin_refresh_allowed_ = false;
[email protected]b78e168b2009-09-21 22:05:45834 WebKit::resetPluginCache(reload_pages);
[email protected]b547fd42009-04-23 23:16:27835 plugin_refresh_allowed_ = true;
836}
[email protected]85c55dc2009-11-06 03:05:46837
[email protected]f1a29a02011-10-06 23:08:44838void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:09839 EnsureWebKitInitialized();
840 WebNetworkStateNotifier::setOnLine(online);
841}
842
[email protected]b69934e2011-10-29 02:51:52843void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
844 content::GetContentClient()->SetActiveURL(data);
845 CHECK(false);
846}
847
[email protected]c6a7b862010-08-20 22:19:38848scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:44849RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]c6a7b862010-08-20 22:19:38850 DCHECK(message_loop() == MessageLoop::current());
851 if (!file_thread_.get()) {
852 file_thread_.reset(new base::Thread("Renderer::FILE"));
853 file_thread_->Start();
854 }
855 return file_thread_->message_loop_proxy();
856}