blob: 5bb608c5964d0eada08d090b355c764e219ace47 [file] [log] [blame]
[email protected]d3d6325d2012-01-03 21:17:361// Copyright (c) 2012 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]237a14852012-04-28 02:56:3812#include "base/allocator/allocator_extension.h"
[email protected]06533c0b2009-03-05 21:39:1113#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5014#include "base/debug/trace_event.h"
[email protected]94f9a0f682009-06-15 18:30:3015#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0316#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/field_trial.h"
[email protected]6cf19311f2011-04-14 23:06:0218#include "base/metrics/histogram.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/stats_table.h"
[email protected]433df472012-03-07 20:33:3920#include "base/path_service.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/shared_memory.h"
[email protected]feb32372012-11-21 01:14:5622#include "base/string16.h"
[email protected]8c380582011-12-02 03:16:1023#include "base/string_number_conversions.h" // Temporary
[email protected]74ebfb12013-06-07 20:48:0024#include "base/strings/utf_string_conversions.h"
[email protected]1357c322010-12-30 22:18:5625#include "base/threading/thread_local.h"
[email protected]d293572a2013-05-23 18:50:4526#include "base/threading/thread_restrictions.h"
[email protected]7a4de7a62010-08-17 18:38:2427#include "base/values.h"
[email protected]10208ea2013-06-06 20:08:0328#include "content/child/child_histogram_message_filter.h"
[email protected]c7199a6e2013-06-04 12:56:0129#include "content/child/indexed_db/indexed_db_dispatcher.h"
30#include "content/child/indexed_db/indexed_db_message_filter.h"
31#include "content/child/npobject_util.h"
32#include "content/child/plugin_messages.h"
[email protected]10208ea2013-06-06 20:08:0333#include "content/child/resource_dispatcher.h"
[email protected]c7199a6e2013-06-04 12:56:0134#include "content/child/web_database_observer_impl.h"
[email protected]e93e04e2011-03-14 00:27:1035#include "content/common/appcache/appcache_dispatcher.h"
[email protected]bdae9812011-10-15 00:33:0336#include "content/common/child_process_messages.h"
[email protected]37666cf2011-03-13 21:51:4237#include "content/common/database_messages.h"
38#include "content/common/db_message_filter.h"
[email protected]127dd582011-03-16 21:32:1039#include "content/common/dom_storage_messages.h"
[email protected]c29b7ff2013-03-06 03:51:0440#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]c26ad882012-02-07 06:41:2041#include "content/common/gpu/client/gpu_channel_host.h"
[email protected]202b54ff2011-04-22 21:36:3842#include "content/common/gpu/gpu_messages.h"
[email protected]94dc971d2011-03-05 19:08:3243#include "content/common/resource_messages.h"
[email protected]778574e2011-03-21 22:03:5044#include "content/common/view_messages.h"
[email protected]a458504b2012-07-23 19:57:0645#include "content/public/common/content_constants.h"
[email protected]433df472012-03-07 20:33:3946#include "content/public/common/content_paths.h"
[email protected]c08950d22011-10-13 22:20:2947#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3148#include "content/public/common/renderer_preferences.h"
[email protected]58436a12012-03-21 17:10:2649#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3450#include "content/public/renderer/content_renderer_client.h"
[email protected]64ffa0442011-10-03 22:08:3651#include "content/public/renderer/render_process_observer.h"
52#include "content/public/renderer/render_view_visitor.h"
[email protected]70019152012-12-19 11:44:1953#include "content/renderer/devtools/devtools_agent_filter.h"
[email protected]1910fe82012-05-10 00:04:1054#include "content/renderer/dom_storage/dom_storage_dispatcher.h"
55#include "content/renderer/dom_storage/webstoragearea_impl.h"
56#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]1842fe22012-08-13 23:24:3557#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]e54ab492012-06-12 19:40:0158#include "content/renderer/gpu/gpu_benchmarking_extension.h"
[email protected]ea5f70a2013-03-07 12:30:3659#include "content/renderer/gpu/input_handler_manager.h"
[email protected]b0255682013-06-07 21:24:0860#include "content/renderer/gpu/input_event_filter.h"
[email protected]f7eb0a392011-07-12 10:19:5161#include "content/renderer/media/audio_input_message_filter.h"
62#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:4163#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]d8cd8372012-03-09 10:49:5164#include "content/renderer/media/media_stream_center.h"
[email protected]6ee10bd2012-09-13 09:01:5365#include "content/renderer/media/media_stream_dependency_factory.h"
[email protected]af089972013-01-10 04:04:4066#include "content/renderer/media/peer_connection_tracker.h"
[email protected]80b161a2011-06-27 17:42:1167#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:3468#include "content/renderer/media/video_capture_message_filter.h"
[email protected]6941ac5c2013-02-07 03:59:5669#include "content/renderer/memory_benchmarking_extension.h"
[email protected]4761cf12012-09-12 10:37:5570#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3571#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0572#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:2873#include "content/renderer/render_view_impl.h"
[email protected]8d6cba42011-09-02 10:05:1974#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]a8228252013-05-14 11:10:0575#include "content/renderer/skia_benchmarking_extension.h"
[email protected]766a7082012-02-03 23:39:1576#include "grit/content_resources.h"
[email protected]46f36a492010-07-28 19:36:4177#include "ipc/ipc_channel_handle.h"
[email protected]1842fe22012-08-13 23:24:3578#include "ipc/ipc_forwarding_message_filter.h"
[email protected]cb6037d2009-11-16 22:55:1779#include "ipc/ipc_platform_file.h"
[email protected]563d665f2013-02-01 04:42:3980#include "media/base/audio_hardware_config.h"
[email protected]433df472012-03-07 20:33:3981#include "media/base/media.h"
[email protected]620161e2011-03-07 18:05:2682#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5483#include "net/base/net_util.h"
[email protected]f8c648b2012-02-28 03:46:4584#include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h"
[email protected]8bd0fe62011-01-17 06:44:3785#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3787#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]6eac57a2011-07-12 21:15:0989#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]4bd55a32011-07-28 13:28:3890#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
[email protected]8bd0fe62011-01-17 06:44:3791#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
[email protected]58436a12012-03-21 17:10:2693#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]00fccb42012-12-11 00:09:5994#include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerRepository.h"
[email protected]61a796c42012-05-17 21:28:2095#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]c7199a6e2013-06-04 12:56:0196#include "third_party/WebKit/public/platform/WebString.h"
[email protected]c49201a2012-05-24 11:04:5797#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:3298#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:5099#include "v8/include/v8.h"
[email protected]d471190a2011-02-16 14:52:30100#include "webkit/glue/webkit_glue.h"
[email protected]d5b2fdf2013-06-05 09:36:55101#include "webkit/renderer/appcache/appcache_frontend_impl.h"
[email protected]2c62b562009-01-27 19:04:50102
[email protected]da00a2882009-03-09 17:51:19103#if defined(OS_WIN)
104#include <windows.h>
105#include <objbase.h>
[email protected]5f7e4512012-10-01 20:51:37106#include "base/win/scoped_com_initializer.h"
107#else
108// TODO(port)
109#include "base/memory/scoped_handle.h"
[email protected]c7199a6e2013-06-04 12:56:01110#include "content/child/np_channel_base.h"
[email protected]da00a2882009-03-09 17:51:19111#endif
112
[email protected]6217d392010-03-25 22:08:35113#if defined(OS_POSIX)
114#include "ipc/ipc_channel_posix.h"
115#endif
116
[email protected]950f9ce22012-12-27 00:25:07117#if defined(ENABLE_WEBRTC)
118#include "third_party/webrtc/system_wrappers/interface/event_tracer.h"
119#endif
120
[email protected]913d99a2013-05-31 07:16:07121#if defined(OS_ANDROID)
[email protected]9a1af192013-06-06 03:09:59122#include <cpu-features.h>
[email protected]913d99a2013-05-31 07:16:07123#include "content/renderer/android/synchronous_compositor_factory.h"
124#endif
125
[email protected]d293572a2013-05-23 18:50:45126using base::ThreadRestrictions;
[email protected]b6cb3a842011-06-24 18:28:41127using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:01128using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:09129using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:00130using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:51131using WebKit::WebScriptController;
[email protected]58436a12012-03-21 17:10:26132using WebKit::WebSecurityPolicy;
[email protected]2c434b32009-03-19 06:27:47133using WebKit::WebString;
[email protected]50ae00ef2009-10-19 05:11:03134using WebKit::WebView;
[email protected]e9ff79c2012-10-19 21:31:26135
136namespace content {
initial.commit09911bf2008-07-26 23:55:29137
[email protected]42f1d7822009-07-23 18:17:55138namespace {
[email protected]da9ccfb2012-01-28 00:34:40139
140const int64 kInitialIdleHandlerDelayMs = 1000;
141const int64 kShortIdleHandlerDelayMs = 1000;
142const int64 kLongIdleHandlerDelayMs = 30*1000;
143const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03144
[email protected]f1a29a02011-10-06 23:08:44145// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16146// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40147base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49148 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54149
[email protected]e9ff79c2012-10-19 21:31:26150class RenderViewZoomer : public RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51151 public:
[email protected]367c5c1d2013-03-11 18:59:02152 RenderViewZoomer(const std::string& scheme,
153 const std::string& host,
154 double zoom_level) : scheme_(scheme),
155 host_(host),
156 zoom_level_(zoom_level) {
[email protected]40bd6582009-12-04 23:49:51157 }
158
[email protected]c3e35892013-02-12 02:08:01159 virtual bool Visit(RenderView* render_view) OVERRIDE {
[email protected]a2ef54c2011-10-10 16:20:31160 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41161 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25162
163 // Don't set zoom level for full-page plugin since they don't use the same
164 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41165 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25166 return true;
[email protected]367c5c1d2013-03-11 18:59:02167 GURL url(document.url());
168 // Empty scheme works as wildcard that matches any scheme,
169 if ((net::GetHostOrSpecFromURL(url) == host_) &&
170 (scheme_.empty() || scheme_ == url.scheme())) {
[email protected]40bd6582009-12-04 23:49:51171 webview->setZoomLevel(false, zoom_level_);
[email protected]367c5c1d2013-03-11 18:59:02172 }
[email protected]40bd6582009-12-04 23:49:51173 return true;
174 }
175
176 private:
[email protected]367c5c1d2013-03-11 18:59:02177 const std::string scheme_;
178 const std::string host_;
179 const double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51180
181 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
182};
[email protected]0478d0162010-08-28 08:29:40183
[email protected]b2d98762012-09-03 17:04:06184std::string HostToCustomHistogramSuffix(const std::string& host) {
185 if (host == "mail.google.com")
186 return ".gmail";
187 if (host == "docs.google.com" || host == "drive.google.com")
188 return ".docs";
189 if (host == "plus.google.com")
190 return ".plus";
[email protected]007b3f82013-04-09 08:46:45191 return std::string();
[email protected]b2d98762012-09-03 17:04:06192}
[email protected]42f1d7822009-07-23 18:17:55193
[email protected]b2d98762012-09-03 17:04:06194void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13195 const char *name, int min, int max, size_t buckets) {
196 if (min <= 0)
197 min = 1;
[email protected]b2d98762012-09-03 17:04:06198 std::string histogram_name;
199 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
200 if (render_thread_impl) { // Can be null in tests.
201 histogram_name = render_thread_impl->
202 histogram_customizer()->ConvertToCustomHistogramName(name);
203 } else {
204 histogram_name = std::string(name);
205 }
[email protected]de415552013-01-23 04:12:17206 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06207 histogram_name, min, max, buckets,
208 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13209 return histogram;
210}
211
[email protected]b2d98762012-09-03 17:04:06212void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13213 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
214 histogram->Add(sample);
215}
216
[email protected]950f9ce22012-12-27 00:25:07217#if defined(ENABLE_WEBRTC)
[email protected]d936677a2013-04-19 08:49:03218const unsigned char* GetCategoryGroupEnabled(const char* category_group) {
219 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group);
[email protected]da0f6952012-12-26 22:22:39220}
221
222void AddTraceEvent(char phase,
[email protected]d936677a2013-04-19 08:49:03223 const unsigned char* category_group_enabled,
[email protected]da0f6952012-12-26 22:22:39224 const char* name,
225 unsigned long long id,
226 int num_args,
227 const char** arg_names,
228 const unsigned char* arg_types,
229 const unsigned long long* arg_values,
230 unsigned char flags) {
[email protected]d936677a2013-04-19 08:49:03231 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id,
232 num_args, arg_names, arg_types, arg_values,
[email protected]7fceeab22013-05-03 15:40:47233 NULL, flags);
[email protected]da0f6952012-12-26 22:22:39234}
[email protected]950f9ce22012-12-27 00:25:07235#endif
[email protected]da0f6952012-12-26 22:22:39236
[email protected]b2d98762012-09-03 17:04:06237} // namespace
238
[email protected]fe476b02012-08-13 21:21:38239class RenderThreadImpl::GpuVDAContextLostCallback
240 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
241 public:
242 GpuVDAContextLostCallback() {}
243 virtual ~GpuVDAContextLostCallback() {}
244 virtual void onContextLost() {
245 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind(
246 &RenderThreadImpl::OnGpuVDAContextLoss));
247 }
248};
249
[email protected]00874dd2013-03-08 23:51:18250class RenderThreadImpl::RendererContextProviderCommandBuffer
251 : public ContextProviderCommandBuffer {
[email protected]e06e1122013-03-15 17:12:38252 public:
253 static scoped_refptr<RendererContextProviderCommandBuffer> Create() {
254 scoped_refptr<RendererContextProviderCommandBuffer> provider =
255 new RendererContextProviderCommandBuffer();
256 if (!provider->InitializeOnMainThread())
257 return NULL;
258 return provider;
259 }
260
[email protected]00874dd2013-03-08 23:51:18261 protected:
262 virtual ~RendererContextProviderCommandBuffer() {}
263
264 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]aa3174b2013-03-15 09:12:48265 CreateOffscreenContext3d() OVERRIDE {
[email protected]00874dd2013-03-08 23:51:18266 RenderThreadImpl* self = RenderThreadImpl::current();
267 DCHECK(self);
268 return self->CreateOffscreenContext3d().Pass();
269 }
270};
271
[email protected]b2d98762012-09-03 17:04:06272RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
273 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
274 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
275 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
276}
277
278RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
279
280void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
281 const std::string& host, size_t view_count) {
[email protected]9baee832012-12-10 11:07:15282 if (CommandLine::ForCurrentProcess()->HasSwitch(
283 switches::kDisableHistogramCustomizer)) {
284 return;
285 }
[email protected]b2d98762012-09-03 17:04:06286 // Check if all RenderViews are displaying a page from the same host. If there
287 // is only one RenderView, the common host is this view's host. If there are
288 // many, check if this one shares the common host of the other
289 // RenderViews. It's ok to not detect some cases where the RenderViews share a
290 // common host. This information is only used for producing custom histograms.
291 if (view_count == 1)
292 SetCommonHost(host);
293 else if (host != common_host_)
294 SetCommonHost(std::string());
295}
296
297std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
298 const char* histogram_name) const {
299 std::string name(histogram_name);
300 if (!common_host_histogram_suffix_.empty() &&
301 custom_histograms_.find(name) != custom_histograms_.end())
302 name += common_host_histogram_suffix_;
303 return name;
304}
305
306void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
307 const std::string& host) {
308 if (host != common_host_) {
309 common_host_ = host;
310 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
311 v8::V8::SetCreateHistogramFunction(CreateHistogram);
312 }
313}
314
[email protected]f1a29a02011-10-06 23:08:44315RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06316 return lazy_tls.Pointer()->Get();
317}
318
[email protected]42f1d7822009-07-23 18:17:55319// When we run plugins in process, we actually run them on the render thread,
320// which means that we need to make the render thread pump UI events.
[email protected]f1a29a02011-10-06 23:08:44321RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55322 Init();
323}
324
[email protected]f1a29a02011-10-06 23:08:44325RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55326 : ChildThread(channel_name) {
327 Init();
328}
[email protected]5fa1c542009-05-05 20:36:07329
[email protected]f1a29a02011-10-06 23:08:44330void RenderThreadImpl::Init() {
331 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33332
[email protected]c7e948b42012-07-12 09:20:20333 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
334 v8::V8::SetCreateHistogramFunction(CreateHistogram);
335 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
336
[email protected]d3f09092012-02-16 01:52:17337#if defined(OS_MACOSX) || defined(OS_ANDROID)
338 // On Mac and Android, the select popups are rendered by the browser.
[email protected]53c607c2011-03-21 23:19:04339 WebKit::WebView::setUseExternalPopupMenus(true);
340#endif
341
[email protected]94f9a0f682009-06-15 18:30:30342 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28343
[email protected]2c62b562009-01-27 19:04:50344#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34345 // If you are running plugins in this thread you need COM active but in
346 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28347 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12348 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50349#endif
initial.commit09911bf2008-07-26 23:55:29350
[email protected]06c694d2012-02-01 22:26:16351 // Register this object as the main thread.
352 ChildProcess::current()->set_main_thread(this);
353
[email protected]31f87132010-04-21 23:36:21354 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50355 suspend_webkit_shared_timer_ = true;
356 notify_webkit_of_modal_loop_ = true;
[email protected]bee16aab2009-08-26 15:55:03357 widget_count_ = 0;
358 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44359 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48360 idle_notifications_to_skip_ = 0;
[email protected]70dee7e2013-05-29 18:28:30361 layout_test_mode_ = false;
[email protected]8d86fce2009-02-26 23:37:55362
[email protected]d5b2fdf2013-06-05 09:36:55363 appcache_dispatcher_.reset(
364 new AppCacheDispatcher(Get(), new appcache::AppCacheFrontendImpl()));
[email protected]1910fe82012-05-10 00:04:10365 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
[email protected]dcc72db2013-01-02 00:44:18366 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13367
[email protected]d8cd8372012-03-09 10:49:51368 media_stream_center_ = NULL;
369
[email protected]017022b2009-07-27 23:06:34370 db_message_filter_ = new DBMessageFilter();
371 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13372
[email protected]4761cf12012-09-12 10:37:55373#if defined(ENABLE_WEBRTC)
[email protected]d936677a2013-04-19 08:49:03374 webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent);
[email protected]af089972013-01-10 04:04:40375
376 peer_connection_tracker_.reset(new PeerConnectionTracker());
377 AddObserver(peer_connection_tracker_.get());
378
[email protected]e9ff79c2012-10-19 21:31:26379 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy());
[email protected]fc72bb12013-06-02 21:13:46380 AddFilter(p2p_socket_dispatcher_.get());
[email protected]4761cf12012-09-12 10:37:55381#endif // defined(ENABLE_WEBRTC)
[email protected]80b161a2011-06-27 17:42:11382 vc_manager_ = new VideoCaptureImplManager();
383 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46384
[email protected]e0a938702013-02-25 21:15:56385 audio_input_message_filter_ =
386 new AudioInputMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51387 AddFilter(audio_input_message_filter_.get());
388
[email protected]e0a938702013-02-25 21:15:56389 audio_message_filter_ = new AudioMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51390 AddFilter(audio_message_filter_.get());
391
[email protected]31bfae72011-12-16 02:04:38392 AddFilter(new IndexedDBMessageFilter);
393
[email protected]e9ff79c2012-10-19 21:31:26394 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24395
[email protected]302fe422012-06-11 14:49:11396 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01397 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking))
[email protected]e9ff79c2012-10-19 21:31:26398 RegisterExtension(GpuBenchmarkingExtension::Get());
[email protected]e54ab492012-06-12 19:40:01399
[email protected]a70ed8b32013-05-24 15:16:34400#if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID))
[email protected]6941ac5c2013-02-07 03:59:56401 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
402 RegisterExtension(MemoryBenchmarkingExtension::Get());
[email protected]a70ed8b32013-05-24 15:16:34403#endif // USE_TCMALLOC
[email protected]6941ac5c2013-02-07 03:59:56404
[email protected]a8228252013-05-14 11:10:05405 if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking)) {
406 LOG(WARNING) << "Enabling unsafe Skia benchmarking extension.";
407 RegisterExtension(SkiaBenchmarkingExtension::Get());
408 }
409
[email protected]fe476b02012-08-13 21:21:38410 context_lost_cb_.reset(new GpuVDAContextLostCallback());
411
[email protected]433df472012-03-07 20:33:39412 // Note that under Linux, the media library will normally already have
413 // been initialized by the Zygote before this instance became a Renderer.
[email protected]c42de732013-02-16 06:26:31414 base::FilePath media_path;
[email protected]e9ff79c2012-10-19 21:31:26415 PathService::Get(DIR_MEDIA_LIBS, &media_path);
[email protected]433df472012-03-07 20:33:39416 if (!media_path.empty())
417 media::InitializeMediaLibrary(media_path);
418
[email protected]f1a29a02011-10-06 23:08:44419 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29420}
421
[email protected]f1a29a02011-10-06 23:08:44422RenderThreadImpl::~RenderThreadImpl() {
[email protected]ce79d8512013-04-22 22:44:41423}
424
425void RenderThreadImpl::Shutdown() {
[email protected]1223d6ef2011-03-28 16:47:50426 FOR_EACH_OBSERVER(
427 RenderProcessObserver, observers_, OnRenderProcessShutdown());
428
[email protected]12cbfda32010-01-30 01:04:25429 // Wait for all databases to be closed.
[email protected]59383c782013-04-17 16:43:27430 if (web_database_observer_impl_)
[email protected]2b437e232010-04-02 01:30:08431 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25432
[email protected]8d86fce2009-02-26 23:37:55433 // Shutdown in reverse of the initialization order.
[email protected]fc72bb12013-06-02 21:13:46434 if (devtools_agent_message_filter_.get()) {
[email protected]b146d6d2012-09-11 10:20:05435 RemoveFilter(devtools_agent_message_filter_.get());
436 devtools_agent_message_filter_ = NULL;
437 }
[email protected]82622452011-07-22 09:57:20438
[email protected]f7eb0a392011-07-12 10:19:51439 RemoveFilter(audio_input_message_filter_.get());
440 audio_input_message_filter_ = NULL;
441
442 RemoveFilter(audio_message_filter_.get());
443 audio_message_filter_ = NULL;
444
[email protected]80b161a2011-06-27 17:42:11445 RemoveFilter(vc_manager_->video_capture_message_filter());
446
[email protected]017022b2009-07-27 23:06:34447 RemoveFilter(db_message_filter_.get());
448 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25449
[email protected]c6a7b862010-08-20 22:19:38450 // Shutdown the file thread if it's running.
[email protected]59383c782013-04-17 16:43:27451 if (file_thread_)
[email protected]c6a7b862010-08-20 22:19:38452 file_thread_->Stop();
453
[email protected]fc72bb12013-06-02 21:13:46454 if (compositor_output_surface_filter_.get()) {
[email protected]23d2b7e2012-08-14 00:34:09455 RemoveFilter(compositor_output_surface_filter_.get());
456 compositor_output_surface_filter_ = NULL;
457 }
[email protected]1842fe22012-08-13 23:24:35458
[email protected]79a92b52013-04-08 19:09:02459 compositor_thread_.reset();
[email protected]b0255682013-06-07 21:24:08460 input_handler_manager_.reset();
461 if (input_event_filter_) {
462 RemoveFilter(input_event_filter_.get());
463 input_event_filter_ = NULL;
[email protected]a9fb30aa2011-10-06 06:58:46464 }
465
[email protected]59383c782013-04-17 16:43:27466 if (webkit_platform_support_)
[email protected]9291ed12009-07-23 17:33:22467 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22468
[email protected]94f9a0f682009-06-15 18:30:30469 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30470
[email protected]8d86fce2009-02-26 23:37:55471 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50472#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29473 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50474 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50475#endif
[email protected]00874dd2013-03-08 23:51:18476
477 // Leak shared contexts on other threads, as we can not get to the correct
478 // thread to destroy them.
[email protected]fc72bb12013-06-02 21:13:46479 if (shared_contexts_compositor_thread_.get())
[email protected]00874dd2013-03-08 23:51:18480 shared_contexts_compositor_thread_->set_leak_on_destroy();
initial.commit09911bf2008-07-26 23:55:29481}
482
[email protected]f1a29a02011-10-06 23:08:44483bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14484 // Certain synchronous messages cannot always be processed synchronously by
485 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50486 // This could cause a complete hang of Chrome if a windowed plug-in is trying
487 // to communicate with the renderer thread since the browser's UI thread
488 // could be stuck (within a Windows API call) trying to synchronously
489 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14490 // thread while the browser is processing this request. This creates an
491 // opportunity for re-entrancy into WebKit, so we need to take care to disable
492 // callbacks, timers, and pending network loads that could trigger such
493 // callbacks.
[email protected]38b592902011-04-16 02:08:42494 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50495 if (msg->is_sync()) {
496 if (msg->is_caller_pumping_messages()) {
497 pumping_events = true;
498 } else {
[email protected]38b592902011-04-16 02:08:42499 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
500 msg->type() == ViewHostMsg_GetRawCookies::ID ||
501 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
[email protected]e9ff79c2012-10-19 21:31:26502 GetContentClient()->renderer()->
[email protected]38b592902011-04-16 02:08:42503 ShouldPumpEventsDuringCookieMessage()) {
504 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50505 }
506 }
[email protected]c1f50aa2010-02-18 03:46:57507 }
508
[email protected]80fc08c52010-03-09 07:43:50509 bool suspend_webkit_shared_timer = true; // default value
510 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57511
[email protected]80fc08c52010-03-09 07:43:50512 bool notify_webkit_of_modal_loop = true; // default value
513 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
514
[email protected]c48de1a2012-11-02 19:06:56515 int render_view_id = MSG_ROUTING_NONE;
[email protected]c1f50aa2010-02-18 03:46:57516
517 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50518 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19519 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57520
[email protected]39065d012010-07-09 11:22:46521 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57522 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57523
[email protected]bae061f72013-04-26 16:22:29524 RenderViewImpl* render_view =
525 RenderViewImpl::FromRoutingID(msg->routing_id());
526 if (render_view) {
527 render_view_id = msg->routing_id();
[email protected]c1f50aa2010-02-18 03:46:57528 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56529 new PluginMsg_SignalModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57530 }
531 }
532
533 bool rv = ChildThread::Send(msg);
534
535 if (pumping_events) {
[email protected]c48de1a2012-11-02 19:06:56536 if (render_view_id != MSG_ROUTING_NONE) {
[email protected]c1f50aa2010-02-18 03:46:57537 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56538 new PluginMsg_ResetModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57539 }
540
[email protected]39065d012010-07-09 11:22:46541 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57542 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57543
[email protected]80fc08c52010-03-09 07:43:50544 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19545 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57546 }
547
548 return rv;
549}
550
[email protected]9e7154122013-05-30 23:11:04551base::MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06552 return message_loop();
553}
554
[email protected]f1a29a02011-10-06 23:08:44555IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06556 return channel();
557}
558
[email protected]f1a29a02011-10-06 23:08:44559std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06560 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:02561 // --lang command line flag.
[email protected]526476902011-10-06 20:34:06562 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
563 const std::string& lang =
564 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:02565 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:06566 return lang;
567}
568
[email protected]07bb6332012-01-21 01:07:57569IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
570 return sync_message_filter();
571}
572
[email protected]96191d52012-05-17 01:37:11573scoped_refptr<base::MessageLoopProxy>
574 RenderThreadImpl::GetIOMessageLoopProxy() {
575 return ChildProcess::current()->io_message_loop_proxy();
576}
577
[email protected]c47317e2012-06-20 22:35:31578void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57579 widget_count_++;
580 return ChildThread::AddRoute(routing_id, listener);
581}
582
[email protected]f1a29a02011-10-06 23:08:44583void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57584 widget_count_--;
585 return ChildThread::RemoveRoute(routing_id);
586}
587
[email protected]77fc9b92011-10-15 16:20:37588int RenderThreadImpl::GenerateRoutingID() {
589 int routing_id = MSG_ROUTING_NONE;
590 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
591 return routing_id;
592}
593
[email protected]f1a29a02011-10-06 23:08:44594void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55595 channel()->AddFilter(filter);
596}
597
[email protected]f1a29a02011-10-06 23:08:44598void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55599 channel()->RemoveFilter(filter);
600}
601
[email protected]f1a29a02011-10-06 23:08:44602void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06603 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
604}
605
[email protected]e9ff79c2012-10-19 21:31:26606void RenderThreadImpl::AddObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06607 observers_.AddObserver(observer);
608}
609
[email protected]e9ff79c2012-10-19 21:31:26610void RenderThreadImpl::RemoveObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06611 observers_.RemoveObserver(observer);
612}
613
[email protected]359dfa32011-10-12 01:10:15614void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:26615 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:15616 resource_dispatcher()->set_delegate(delegate);
617}
618
[email protected]f1a29a02011-10-06 23:08:44619void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03620 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50621 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24622
[email protected]e9ff79c2012-10-19 21:31:26623 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24624 return;
625 }
626
627 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44628 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03629}
630
[email protected]f1a29a02011-10-06 23:08:44631void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08632 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03633 hidden_widget_count_--;
[email protected]e9ff79c2012-10-19 21:31:26634 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24635 return;
636 }
[email protected]bee16aab2009-08-26 15:55:03637
[email protected]1784b2f2011-11-24 10:53:48638 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39639}
640
[email protected]78b86f9a2013-05-03 23:33:40641static void AdjustRuntimeFeatureDefaultsForPlatform() {
642#if defined(OS_ANDROID) && !defined(GOOGLE_TV)
[email protected]5bf1223a52013-05-14 21:42:31643 WebRuntimeFeatures::enableWebKitMediaSource(false);
[email protected]16c242d2013-05-31 23:56:47644 WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
645 WebRuntimeFeatures::enableEncryptedMedia(false);
[email protected]78b86f9a2013-05-03 23:33:40646#endif
647
648#if defined(OS_ANDROID)
649 WebRuntimeFeatures::enableWebAudio(false);
[email protected]78b86f9a2013-05-03 23:33:40650 // Android does not support the Gamepad API.
651 WebRuntimeFeatures::enableGamepad(false);
652 // input[type=week] in Android is incomplete. crbug.com/135938
653 WebRuntimeFeatures::enableInputTypeWeek(false);
[email protected]09128282013-05-17 16:42:52654 // Android does not have support for PagePopup
655 WebRuntimeFeatures::enablePagePopup(false);
[email protected]0338ce792013-05-24 11:15:59656 // datalist on Android is not enabled
657 WebRuntimeFeatures::enableDataListElement(false);
[email protected]78b86f9a2013-05-03 23:33:40658#endif
659}
660
661static void AdjustRuntimeFeaturesFromArgs(const CommandLine& command_line) {
662 if (command_line.HasSwitch(switches::kDisableDatabases))
663 WebRuntimeFeatures::enableDatabase(false);
664
665 if (command_line.HasSwitch(switches::kDisableApplicationCache))
666 WebRuntimeFeatures::enableApplicationCache(false);
667
668 if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
669 WebRuntimeFeatures::enableNotifications(false);
670
671 if (command_line.HasSwitch(switches::kDisableLocalStorage))
672 WebRuntimeFeatures::enableLocalStorage(false);
673
674 if (command_line.HasSwitch(switches::kDisableSessionStorage))
675 WebRuntimeFeatures::enableSessionStorage(false);
676
677 if (command_line.HasSwitch(switches::kDisableGeolocation))
678 WebRuntimeFeatures::enableGeolocation(false);
679
[email protected]85dd7ca2013-05-30 23:53:00680#if defined(OS_ANDROID) && !defined(GOOGLE_TV)
681 if (command_line.HasSwitch(switches::kEnableWebKitMediaSource))
682 WebRuntimeFeatures::enableWebKitMediaSource(true);
683#else
[email protected]5bf1223a52013-05-14 21:42:31684 if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
685 WebRuntimeFeatures::enableWebKitMediaSource(false);
[email protected]78b86f9a2013-05-03 23:33:40686#endif
687
688#if defined(OS_ANDROID)
[email protected]3bd0aab2013-05-30 20:07:49689 if (command_line.HasSwitch(switches::kDisableWebRTC)) {
[email protected]78b86f9a2013-05-03 23:33:40690 WebRuntimeFeatures::enableMediaStream(false);
[email protected]78b86f9a2013-05-03 23:33:40691 WebRuntimeFeatures::enablePeerConnection(false);
[email protected]3bd0aab2013-05-30 20:07:49692 }
693
694 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
695 WebRuntimeFeatures::enableScriptedSpeech(false);
696
[email protected]9a1af192013-06-06 03:09:59697 if (command_line.HasSwitch(switches::kEnableWebAudio)) {
698 bool enable_webaudio = true;
699#if defined(ARCH_CPU_ARMEL)
700 enable_webaudio =
701 ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
702#endif
703 WebRuntimeFeatures::enableWebAudio(enable_webaudio);
704 }
[email protected]3bd0aab2013-05-30 20:07:49705#else
706 if (command_line.HasSwitch(switches::kDisableWebAudio))
707 WebRuntimeFeatures::enableWebAudio(false);
[email protected]78b86f9a2013-05-03 23:33:40708#endif
709
710 if (command_line.HasSwitch(switches::kDisableFullScreen))
[email protected]d2414bb2013-05-10 21:29:27711 WebRuntimeFeatures::enableFullscreen(false);
[email protected]78b86f9a2013-05-03 23:33:40712
[email protected]16c242d2013-05-31 23:56:47713 if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
714 WebRuntimeFeatures::enableEncryptedMedia(true);
715
716 if (command_line.HasSwitch(switches::kDisableLegacyEncryptedMedia))
717 WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
[email protected]78b86f9a2013-05-03 23:33:40718
[email protected]78b86f9a2013-05-03 23:33:40719 if (command_line.HasSwitch(switches::kEnableWebMIDI))
720 WebRuntimeFeatures::enableWebMIDI(true);
721
722 if (command_line.HasSwitch(switches::kEnableDeviceMotion))
723 WebRuntimeFeatures::enableDeviceMotion(true);
724
725 if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
726 WebRuntimeFeatures::enableDeviceOrientation(false);
727
728 if (command_line.HasSwitch(switches::kDisableSpeechInput))
729 WebRuntimeFeatures::enableSpeechInput(false);
730
731 if (command_line.HasSwitch(switches::kDisableFileSystem))
732 WebRuntimeFeatures::enableFileSystem(false);
733
734 if (command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI))
735 WebRuntimeFeatures::enableJavaScriptI18NAPI(false);
736
[email protected]78b86f9a2013-05-03 23:33:40737 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
738 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
739
740 if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
741 WebRuntimeFeatures::enableSpeechSynthesis(true);
[email protected]70dc60932013-06-04 03:33:49742
743 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
744 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
[email protected]78b86f9a2013-05-03 23:33:40745}
746
[email protected]f1a29a02011-10-06 23:08:44747void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]59383c782013-04-17 16:43:27748 if (webkit_platform_support_)
[email protected]d1b8fccc2011-08-03 01:20:13749 return;
750
[email protected]8d6cba42011-09-02 10:05:19751 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
752 WebKit::initialize(webkit_platform_support_.get());
[email protected]00fccb42012-12-11 00:09:59753 WebKit::setSharedWorkerRepository(
754 webkit_platform_support_.get()->sharedWorkerRepository());
[email protected]d1b8fccc2011-08-03 01:20:13755
[email protected]cd7ce3be2012-09-10 05:19:41756 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]cd7ce3be2012-09-10 05:19:41757
[email protected]0f21e8582013-01-11 11:06:56758 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing);
[email protected]72787e392012-03-23 05:55:43759 if (enable) {
[email protected]913d99a2013-05-31 07:16:07760#if defined(OS_ANDROID)
761 if (SynchronousCompositorFactory* factory =
762 SynchronousCompositorFactory::GetInstance())
763 compositor_message_loop_proxy_ =
764 factory->GetCompositorMessageLoop();
765#endif
766 if (!compositor_message_loop_proxy_) {
[email protected]ea5f70a2013-03-07 12:30:36767 compositor_thread_.reset(new base::Thread("Compositor"));
768 compositor_thread_->Start();
[email protected]b38864d2013-05-24 14:42:36769#if defined(OS_ANDROID)
770 compositor_thread_->SetPriority(base::kThreadPriority_Display);
771#endif
[email protected]ea5f70a2013-03-07 12:30:36772 compositor_message_loop_proxy_ =
773 compositor_thread_->message_loop_proxy();
[email protected]d293572a2013-05-23 18:50:45774 compositor_message_loop_proxy_->PostTask(
775 FROM_HERE,
776 base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed),
777 false));
[email protected]ea5f70a2013-03-07 12:30:36778 }
779
[email protected]b0255682013-06-07 21:24:08780 InputHandlerManagerClient* input_handler_manager_client = NULL;
781#if defined(OS_ANDROID)
782 if (SynchronousCompositorFactory* factory =
783 SynchronousCompositorFactory::GetInstance()) {
784 input_handler_manager_client = factory->GetInputHandlerManagerClient();
785 }
786#endif
787 if (!input_handler_manager_client) {
788 input_event_filter_ =
789 new InputEventFilter(this, compositor_message_loop_proxy_);
790 AddFilter(input_event_filter_.get());
791 input_handler_manager_client = input_event_filter_.get();
792 }
[email protected]913d99a2013-05-31 07:16:07793 input_handler_manager_.reset(
[email protected]b0255682013-06-07 21:24:08794 new InputHandlerManager(compositor_message_loop_proxy_,
795 input_handler_manager_client));
[email protected]a458504b2012-07-23 19:57:06796 }
[email protected]a9fb30aa2011-10-06 06:58:46797
[email protected]ea5f70a2013-03-07 12:30:36798 scoped_refptr<base::MessageLoopProxy> output_surface_loop;
[email protected]7f1f63f2013-03-07 06:07:29799 if (enable)
[email protected]ea5f70a2013-03-07 12:30:36800 output_surface_loop = compositor_message_loop_proxy_;
[email protected]7f1f63f2013-03-07 06:07:29801 else
802 output_surface_loop = base::MessageLoopProxy::current();
[email protected]1842fe22012-08-13 23:24:35803
[email protected]7f1f63f2013-03-07 06:07:29804 compositor_output_surface_filter_ =
[email protected]fc72bb12013-06-02 21:13:46805 CompositorOutputSurface::CreateFilter(output_surface_loop.get());
[email protected]1842fe22012-08-13 23:24:35806 AddFilter(compositor_output_surface_filter_.get());
807
[email protected]d1b8fccc2011-08-03 01:20:13808 WebScriptController::enableV8SingleThreadMode();
809
[email protected]58436a12012-03-21 17:10:26810 RenderThreadImpl::RegisterSchemes();
811
[email protected]d1b8fccc2011-08-03 01:20:13812 webkit_glue::EnableWebCoreLogChannels(
813 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
814
[email protected]fa1c17e42012-03-06 22:29:54815 web_database_observer_impl_.reset(
816 new WebDatabaseObserverImpl(sync_message_filter()));
[email protected]d1b8fccc2011-08-03 01:20:13817 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
818
[email protected]d1bf64b2013-05-06 12:13:53819 WebRuntimeFeatures::enableStableFeatures(true);
[email protected]d1b8fccc2011-08-03 01:20:13820
[email protected]d1bf64b2013-05-06 12:13:53821 if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures))
822 WebRuntimeFeatures::enableExperimentalFeatures(true);
[email protected]4ae41b42012-12-06 21:59:03823
[email protected]78b86f9a2013-05-03 23:33:40824 AdjustRuntimeFeatureDefaultsForPlatform();
825 AdjustRuntimeFeaturesFromArgs(command_line);
[email protected]d3e7aea22013-01-09 08:47:53826
[email protected]205855d2013-04-24 01:42:18827 // Enabled by default for testing.
828 // TODO(urvang): Go back to using the command-line option after a few days.
[email protected]78b86f9a2013-05-03 23:33:40829 // https://code.google.com/p/chromium/issues/detail?id=234437
[email protected]205855d2013-04-24 01:42:18830 WebRuntimeFeatures::enableWebPInAcceptHeader(true);
[email protected]8027acd2013-04-18 08:35:15831
[email protected]78b86f9a2013-05-03 23:33:40832 if (!media::IsMediaLibraryInitialized()) {
833 WebRuntimeFeatures::enableMediaPlayer(false);
834 WebRuntimeFeatures::enableWebAudio(false);
835 }
[email protected]7a06d282013-05-03 04:39:33836
[email protected]d1b8fccc2011-08-03 01:20:13837 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48838
[email protected]b146d6d2012-09-11 10:20:05839 devtools_agent_message_filter_ = new DevToolsAgentFilter();
840 AddFilter(devtools_agent_message_filter_.get());
841
[email protected]e9ff79c2012-10-19 21:31:26842 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]1784b2f2011-11-24 10:53:48843 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]d1b8fccc2011-08-03 01:20:13844}
845
[email protected]58436a12012-03-21 17:10:26846void RenderThreadImpl::RegisterSchemes() {
847 // swappedout: pages should not be accessible, and should also
848 // be treated as empty documents that can commit synchronously.
849 WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme));
850 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme);
851 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme);
852}
853
[email protected]f1a29a02011-10-06 23:08:44854void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06855 Send(new ViewHostMsg_UserMetricsRecordAction(action));
856}
857
[email protected]fb79aa22012-12-13 01:12:13858scoped_ptr<base::SharedMemory>
[email protected]3f892832013-01-11 03:23:59859 RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
860 if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
861 return scoped_ptr<base::SharedMemory>();
862
[email protected]fb79aa22012-12-13 01:12:13863 base::SharedMemoryHandle handle;
864 bool success;
865 IPC::Message* message =
866 new ChildProcessHostMsg_SyncAllocateSharedMemory(size, &handle);
867
868 // Allow calling this from the compositor thread.
[email protected]dd32b1272013-05-04 14:17:11869 if (base::MessageLoop::current() == message_loop())
[email protected]fb79aa22012-12-13 01:12:13870 success = ChildThread::Send(message);
871 else
872 success = sync_message_filter()->Send(message);
873
874 if (!success)
875 return scoped_ptr<base::SharedMemory>();
876
877 if (!base::SharedMemory::IsHandleValid(handle))
878 return scoped_ptr<base::SharedMemory>();
879
880 return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false));
[email protected]00614a82011-10-07 22:39:31881}
882
[email protected]f1a29a02011-10-06 23:08:44883void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06884 WebScriptController::registerExtension(extension);
[email protected]526476902011-10-06 20:34:06885}
886
[email protected]6593ae12011-11-14 12:09:44887void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
888 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06889 idle_timer_.Stop();
890 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44891 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44892 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06893}
894
[email protected]f1a29a02011-10-06 23:08:44895void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48896 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:26897 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:48898 RunIdleHandlerWhenWidgetsHidden();
899 if (run_in_foreground_tab) {
900 IdleHandlerInForegroundTab();
901 return;
902 }
[email protected]237a14852012-04-28 02:56:38903
904 base::allocator::ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:06905
906 v8::V8::IdleNotification();
907
908 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44909 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06910 // delay = delay + 1 / (delay + 2)
911 // Using floor(delay) has a dampening effect such as:
912 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44913 // If the delay is in milliseconds, the above formula is equivalent to:
914 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
915 // which is equivalent to
916 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
917 // Note that idle_notification_delay_in_ms_ would be reset to
918 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
919 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
920 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06921
922 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
923}
924
[email protected]1784b2f2011-11-24 10:53:48925void RenderThreadImpl::IdleHandlerInForegroundTab() {
926 // Increase the delay in the same way as in IdleHandler,
927 // but make it periodic by reseting it once it is too big.
928 int64 new_delay_ms = idle_notification_delay_in_ms_ +
929 1000000 / (idle_notification_delay_in_ms_ + 2000);
930 if (new_delay_ms >= kLongIdleHandlerDelayMs)
931 new_delay_ms = kShortIdleHandlerDelayMs;
932
[email protected]1784b2f2011-11-24 10:53:48933 if (idle_notifications_to_skip_ > 0) {
934 idle_notifications_to_skip_--;
[email protected]7e967f82011-12-01 09:35:14935 } else {
[email protected]a47105c832011-12-07 17:24:30936 int cpu_usage = 0;
[email protected]7e967f82011-12-01 09:35:14937 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
[email protected]1393c4a2012-02-07 10:12:58938 // Idle notification hint roughly specifies the expected duration of the
939 // idle pause. We set it proportional to the idle timer delay.
940 int idle_hint = static_cast<int>(new_delay_ms / 10);
[email protected]d7e59252012-03-06 22:26:02941 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
[email protected]237a14852012-04-28 02:56:38942 base::allocator::ReleaseFreeMemory();
[email protected]d7e59252012-03-06 22:26:02943 if (v8::V8::IdleNotification(idle_hint)) {
944 // V8 finished collecting garbage.
945 new_delay_ms = kLongIdleHandlerDelayMs;
946 }
[email protected]1784b2f2011-11-24 10:53:48947 }
948 }
[email protected]1784b2f2011-11-24 10:53:48949 ScheduleIdleHandler(new_delay_ms);
950}
951
[email protected]6593ae12011-11-14 12:09:44952int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
953 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06954}
955
[email protected]6593ae12011-11-14 12:09:44956void RenderThreadImpl::SetIdleNotificationDelayInMs(
957 int64 idle_notification_delay_in_ms) {
958 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08959}
960
[email protected]a1a7ff32012-07-19 14:03:51961void RenderThreadImpl::ToggleWebKitSharedTimer(bool suspend) {
962 if (suspend_webkit_shared_timer_) {
963 EnsureWebKitInitialized();
964 if (suspend) {
965 webkit_platform_support_->SuspendSharedTimer();
966 } else {
967 webkit_platform_support_->ResumeSharedTimer();
968 }
969 }
970}
971
972void RenderThreadImpl::UpdateHistograms(int sequence_number) {
973 child_histogram_message_filter()->SendHistograms(sequence_number);
974}
975
[email protected]b02f5902012-12-19 07:33:00976bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
977 bool result = false;
978 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
979 return result;
980}
981
[email protected]1784b2f2011-11-24 10:53:48982void RenderThreadImpl::PostponeIdleNotification() {
983 idle_notifications_to_skip_ = 2;
984}
985
[email protected]fe476b02012-08-13 21:21:38986/* static */
987void RenderThreadImpl::OnGpuVDAContextLoss() {
988 RenderThreadImpl* self = RenderThreadImpl::current();
989 DCHECK(self);
[email protected]59383c782013-04-17 16:43:27990 if (!self->gpu_vda_context3d_)
[email protected]fe476b02012-08-13 21:21:38991 return;
[email protected]ea5f70a2013-03-07 12:30:36992 if (self->compositor_message_loop_proxy()) {
993 self->compositor_message_loop_proxy()->DeleteSoon(
[email protected]fe476b02012-08-13 21:21:38994 FROM_HERE, self->gpu_vda_context3d_.release());
995 } else {
996 self->gpu_vda_context3d_.reset();
[email protected]3b2afc32012-06-18 21:31:16997 }
[email protected]fe476b02012-08-13 21:21:38998}
999
1000WebGraphicsContext3DCommandBufferImpl*
1001RenderThreadImpl::GetGpuVDAContext3D() {
[email protected]59383c782013-04-17 16:43:271002 if (!gpu_vda_context3d_) {
[email protected]3b2afc32012-06-18 21:31:161003 gpu_vda_context3d_.reset(
1004 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
[email protected]d1a9e062012-07-13 00:45:141005 this, WebKit::WebGraphicsContext3D::Attributes(),
1006 GURL("chrome://gpu/RenderThreadImpl::GetGpuVDAContext3D")));
[email protected]59383c782013-04-17 16:43:271007 if (gpu_vda_context3d_)
[email protected]fde3e2f2012-08-14 06:51:371008 gpu_vda_context3d_->setContextLostCallback(context_lost_cb_.get());
[email protected]3b2afc32012-06-18 21:31:161009 }
[email protected]fe476b02012-08-13 21:21:381010 return gpu_vda_context3d_.get();
[email protected]3b2afc32012-06-18 21:31:161011}
1012
[email protected]c29b7ff2013-03-06 03:51:041013scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
1014RenderThreadImpl::CreateOffscreenContext3d() {
1015 WebKit::WebGraphicsContext3D::Attributes attributes;
1016 attributes.shareResources = true;
1017 attributes.depth = false;
1018 attributes.stencil = false;
1019 attributes.antialias = false;
1020 attributes.noAutomaticFlushes = true;
1021
1022 return make_scoped_ptr(
1023 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
1024 this,
1025 attributes,
1026 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext3d")));
1027}
1028
[email protected]a45c46e2013-03-07 01:04:461029scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:041030RenderThreadImpl::OffscreenContextProviderForMainThread() {
[email protected]e06e1122013-03-15 17:12:381031 DCHECK(IsMainThread());
1032
[email protected]fc72bb12013-06-02 21:13:461033 if (!shared_contexts_main_thread_.get() ||
[email protected]e06e1122013-03-15 17:12:381034 shared_contexts_main_thread_->DestroyedOnMainThread()) {
1035 shared_contexts_main_thread_ =
1036 RendererContextProviderCommandBuffer::Create();
[email protected]fc72bb12013-06-02 21:13:461037 if (shared_contexts_main_thread_.get() &&
[email protected]e06e1122013-03-15 17:12:381038 !shared_contexts_main_thread_->BindToCurrentThread())
1039 shared_contexts_main_thread_ = NULL;
1040 }
[email protected]c29b7ff2013-03-06 03:51:041041 return shared_contexts_main_thread_;
1042}
1043
[email protected]a45c46e2013-03-07 01:04:461044scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:041045RenderThreadImpl::OffscreenContextProviderForCompositorThread() {
[email protected]e06e1122013-03-15 17:12:381046 DCHECK(IsMainThread());
1047
[email protected]fc72bb12013-06-02 21:13:461048 if (!shared_contexts_compositor_thread_.get() ||
[email protected]c29b7ff2013-03-06 03:51:041049 shared_contexts_compositor_thread_->DestroyedOnMainThread()) {
1050 shared_contexts_compositor_thread_ =
[email protected]e06e1122013-03-15 17:12:381051 RendererContextProviderCommandBuffer::Create();
[email protected]c29b7ff2013-03-06 03:51:041052 }
1053 return shared_contexts_compositor_thread_;
1054}
1055
[email protected]e9ff79c2012-10-19 21:31:261056AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]59383c782013-04-17 16:43:271057 if (!audio_renderer_mixer_manager_) {
[email protected]3958e972012-07-17 00:25:411058 audio_renderer_mixer_manager_.reset(new AudioRendererMixerManager(
[email protected]563d665f2013-02-01 04:42:391059 GetAudioHardwareConfig()));
[email protected]3958e972012-07-17 00:25:411060 }
1061
1062 return audio_renderer_mixer_manager_.get();
1063}
1064
[email protected]563d665f2013-02-01 04:42:391065media::AudioHardwareConfig* RenderThreadImpl::GetAudioHardwareConfig() {
1066 if (!audio_hardware_config_) {
[email protected]06ea4f7c2013-03-13 20:36:511067 media::AudioParameters input_params;
1068 media::AudioParameters output_params;
[email protected]563d665f2013-02-01 04:42:391069 Send(new ViewHostMsg_GetAudioHardwareConfig(
[email protected]06ea4f7c2013-03-13 20:36:511070 &input_params, &output_params));
[email protected]563d665f2013-02-01 04:42:391071
1072 audio_hardware_config_.reset(new media::AudioHardwareConfig(
[email protected]06ea4f7c2013-03-13 20:36:511073 input_params, output_params));
[email protected]563d665f2013-02-01 04:42:391074 audio_message_filter_->SetAudioHardwareConfig(audio_hardware_config_.get());
1075 }
1076
1077 return audio_hardware_config_.get();
1078}
1079
[email protected]4a7d6392011-09-19 20:55:081080#if defined(OS_WIN)
[email protected]feb32372012-11-21 01:14:561081void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font,
1082 const string16& str) {
1083 Send(new ViewHostMsg_PreCacheFontCharacters(log_font, str));
1084}
1085
[email protected]f1a29a02011-10-06 23:08:441086void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:061087 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:211088}
1089
[email protected]f1a29a02011-10-06 23:08:441090void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:061091 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:081092}
[email protected]526476902011-10-06 20:34:061093
[email protected]4a7d6392011-09-19 20:55:081094#endif // OS_WIN
1095
[email protected]988aacf2012-02-12 18:10:031096bool RenderThreadImpl::IsWebFrameValid(WebKit::WebFrame* web_frame) {
1097 if (!web_frame)
[email protected]4761cf12012-09-12 10:37:551098 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031099
1100 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
1101 if (!render_view)
[email protected]4761cf12012-09-12 10:37:551102 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031103
1104 return true;
1105}
1106
[email protected]b3e83de2012-02-07 03:33:281107bool RenderThreadImpl::IsMainThread() {
1108 return !!current();
1109}
1110
1111bool RenderThreadImpl::IsIOThread() {
[email protected]dd32b1272013-05-04 14:17:111112 return base::MessageLoop::current() ==
1113 ChildProcess::current()->io_message_loop();
[email protected]b3e83de2012-02-07 03:33:281114}
1115
[email protected]9e7154122013-05-30 23:11:041116base::MessageLoop* RenderThreadImpl::GetMainLoop() {
[email protected]b3e83de2012-02-07 03:33:281117 return message_loop();
1118}
[email protected]5b040e592012-02-10 02:56:101119
1120scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() {
[email protected]b3e83de2012-02-07 03:33:281121 return ChildProcess::current()->io_message_loop_proxy();
1122}
1123
1124base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() {
1125 return ChildProcess::current()->GetShutDownEvent();
1126}
1127
1128scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory(
[email protected]3f892832013-01-11 03:23:591129 size_t size) {
[email protected]fb79aa22012-12-13 01:12:131130 return scoped_ptr<base::SharedMemory>(
1131 HostAllocateSharedMemoryBuffer(size));
[email protected]b3e83de2012-02-07 03:33:281132}
1133
1134int32 RenderThreadImpl::CreateViewCommandBuffer(
1135 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) {
[email protected]d13f35d2012-05-18 02:28:151136 TRACE_EVENT1("gpu",
1137 "RenderThreadImpl::CreateViewCommandBuffer",
1138 "surface_id",
1139 surface_id);
1140
[email protected]b3e83de2012-02-07 03:33:281141 int32 route_id = MSG_ROUTING_NONE;
[email protected]8b10b332012-02-29 21:02:141142 IPC::Message* message = new GpuHostMsg_CreateViewCommandBuffer(
[email protected]b3e83de2012-02-07 03:33:281143 surface_id,
1144 init_params,
[email protected]8b10b332012-02-29 21:02:141145 &route_id);
1146
1147 // Allow calling this from the compositor thread.
[email protected]dd32b1272013-05-04 14:17:111148 if (base::MessageLoop::current() == message_loop())
[email protected]8b10b332012-02-29 21:02:141149 ChildThread::Send(message);
1150 else
1151 sync_message_filter()->Send(message);
1152
[email protected]b3e83de2012-02-07 03:33:281153 return route_id;
1154}
1155
[email protected]09d50362012-10-18 20:54:371156void RenderThreadImpl::CreateImage(
1157 gfx::PluginWindowHandle window,
1158 int32 image_id,
1159 const CreateImageCallback& callback) {
1160 NOTREACHED();
1161}
1162
1163void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) {
1164 NOTREACHED();
1165}
1166
[email protected]f1a29a02011-10-06 23:08:441167void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:061168 suspend_webkit_shared_timer_ = false;
1169}
1170
[email protected]f1a29a02011-10-06 23:08:441171void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:061172 notify_webkit_of_modal_loop_ = false;
1173}
1174
[email protected]367c5c1d2013-03-11 18:59:021175void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& scheme,
1176 const std::string& host,
[email protected]f1a29a02011-10-06 23:08:441177 double zoom_level) {
[email protected]367c5c1d2013-03-11 18:59:021178 RenderViewZoomer zoomer(scheme, host, zoom_level);
[email protected]e9ff79c2012-10-19 21:31:261179 RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:061180}
1181
[email protected]f1a29a02011-10-06 23:08:441182bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:501183 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
1184 RenderProcessObserver* observer;
1185 while ((observer = it.GetNext()) != NULL) {
1186 if (observer->OnControlMessageReceived(msg))
1187 return true;
1188 }
1189
[email protected]70c19a932010-05-14 12:59:111190 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101191 if (appcache_dispatcher_->OnMessageReceived(msg) ||
1192 dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281193 return true;
[email protected]1910fe82012-05-10 00:04:101194 }
[email protected]1edc16b82009-04-07 17:45:541195
[email protected]a95986a82010-12-24 06:19:281196 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:441197 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:541198 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
1199 OnSetZoomLevelForCurrentURL)
[email protected]8930d472009-02-21 08:05:281200 // TODO(port): removed from render_messages_internal.h;
1201 // is there a new non-windows message I should add here?
1202 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:451203 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:091204 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]b69934e2011-10-29 02:51:521205 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]44363382013-03-12 07:22:471206 IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended,
1207 OnSetWebKitSharedTimersSuspended)
[email protected]a95986a82010-12-24 06:19:281208 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281209 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281210 return handled;
initial.commit09911bf2008-07-26 23:55:291211}
1212
[email protected]f1a29a02011-10-06 23:08:441213void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:471214 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:331215 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]6cd7c6b2012-10-25 03:26:231216 RenderViewImpl::Create(
[email protected]6cd7c6b2012-10-25 03:26:231217 params.opener_route_id,
1218 params.renderer_preferences,
1219 params.web_preferences,
1220 new SharedRenderViewCounter(0),
1221 params.view_id,
[email protected]227692c52013-05-31 22:43:041222 params.main_frame_routing_id,
[email protected]6cd7c6b2012-10-25 03:26:231223 params.surface_id,
1224 params.session_storage_namespace_id,
1225 params.frame_name,
1226 false,
1227 params.swapped_out,
1228 params.next_page_id,
1229 params.screen_info,
[email protected]34bb3ac2013-03-08 02:41:281230 params.accessibility_mode,
1231 params.allow_partial_swap);
[email protected]7f874dec2009-02-06 01:48:271232}
[email protected]4274e582009-01-27 22:09:561233
[email protected]f1a29a02011-10-06 23:08:441234GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:261235 CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]d13f35d2012-05-18 02:28:151236 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1237
[email protected]fc72bb12013-06-02 21:13:461238 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:221239 // Do nothing if we already have a GPU channel or are already
1240 // establishing one.
[email protected]e09cee42010-11-09 01:50:081241 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
1242 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:041243 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:351244
1245 // Recreate the channel if it has been lost.
[email protected]894e8fc2012-02-24 13:29:501246 gpu_channel_ = NULL;
[email protected]6217d392010-03-25 22:08:351247 }
1248
[email protected]6217d392010-03-25 22:08:351249 // Ask the browser for the channel name.
[email protected]894e8fc2012-02-24 13:29:501250 int client_id = 0;
[email protected]b42a9f62011-06-08 20:36:041251 IPC::ChannelHandle channel_handle;
[email protected]d7b5cc72013-05-23 20:05:001252 gpu::GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:041253 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
[email protected]894e8fc2012-02-24 13:29:501254 &client_id,
[email protected]b42a9f62011-06-08 20:36:041255 &channel_handle,
[email protected]b42a9f62011-06-08 20:36:041256 &gpu_info)) ||
[email protected]8bc550e2012-02-07 11:05:561257#if defined(OS_POSIX)
1258 channel_handle.socket.fd == -1 ||
1259#endif
[email protected]cd0bd792012-04-14 00:52:161260 channel_handle.name.empty()) {
[email protected]b42a9f62011-06-08 20:36:041261 // Otherwise cancel the connection.
1262 gpu_channel_ = NULL;
1263 return NULL;
1264 }
[email protected]6217d392010-03-25 22:08:351265
[email protected]03dc8882012-03-08 23:46:291266 gpu_channel_ = new GpuChannelHost(this, 0, client_id);
[email protected]b42a9f62011-06-08 20:36:041267 gpu_channel_->set_gpu_info(gpu_info);
[email protected]e9ff79c2012-10-19 21:31:261268 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]b42a9f62011-06-08 20:36:041269
1270 // Connect to the GPU process if a channel name was received.
[email protected]cd0bd792012-04-14 00:52:161271 gpu_channel_->Connect(channel_handle);
[email protected]b42a9f62011-06-08 20:36:041272
[email protected]f9a2b2fe2010-07-15 21:13:231273 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:341274}
1275
[email protected]d8cd8372012-03-09 10:49:511276WebKit::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1277 WebKit::WebMediaStreamCenterClient* client) {
[email protected]d9da9582013-01-31 04:59:051278#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:161279 if (CommandLine::ForCurrentProcess()->HasSwitch(
1280 switches::kDisableWebRTC))
[email protected]d9da9582013-01-31 04:59:051281 return NULL;
1282#endif
1283
[email protected]d8cd8372012-03-09 10:49:511284#if defined(ENABLE_WEBRTC)
[email protected]68e5fee2013-02-18 10:04:221285 if (!media_stream_center_) {
1286 media_stream_center_ = GetContentClient()->renderer()
1287 ->OverrideCreateWebMediaStreamCenter(client);
1288 if (!media_stream_center_) {
1289 media_stream_center_ = new MediaStreamCenter(
1290 client, GetMediaStreamDependencyFactory());
1291 }
1292 }
[email protected]d8cd8372012-03-09 10:49:511293#endif
1294 return media_stream_center_;
1295}
1296
[email protected]6ee10bd2012-09-13 09:01:531297MediaStreamDependencyFactory*
1298RenderThreadImpl::GetMediaStreamDependencyFactory() {
1299#if defined(ENABLE_WEBRTC)
[email protected]59383c782013-04-17 16:43:271300 if (!media_stream_factory_) {
[email protected]6ee10bd2012-09-13 09:01:531301 media_stream_factory_.reset(new MediaStreamDependencyFactory(
[email protected]fc72bb12013-06-02 21:13:461302 vc_manager_.get(), p2p_socket_dispatcher_.get()));
[email protected]6ee10bd2012-09-13 09:01:531303 }
1304#endif
1305 return media_stream_factory_.get();
1306}
1307
[email protected]f1a29a02011-10-06 23:08:441308GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]fc72bb12013-06-02 21:13:461309 if (!gpu_channel_.get())
[email protected]6217d392010-03-25 22:08:351310 return NULL;
1311
[email protected]e09cee42010-11-09 01:50:081312 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:351313 return NULL;
1314
1315 return gpu_channel_.get();
1316}
1317
[email protected]f1a29a02011-10-06 23:08:441318void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591319 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271320 // The call below will cause a GetPlugins call with refresh=true, but at this
1321 // point we already know that the browser has refreshed its list, so disable
1322 // refresh temporarily to prevent each renderer process causing the list to be
1323 // regenerated.
[email protected]a70b4352012-07-31 22:34:531324 webkit_platform_support_->set_plugin_refresh_allowed(false);
[email protected]b78e168b2009-09-21 22:05:451325 WebKit::resetPluginCache(reload_pages);
[email protected]a70b4352012-07-31 22:34:531326 webkit_platform_support_->set_plugin_refresh_allowed(true);
[email protected]3b48dbc2012-01-06 16:34:171327
1328 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:271329}
[email protected]85c55dc2009-11-06 03:05:461330
[email protected]f1a29a02011-10-06 23:08:441331void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:091332 EnsureWebKitInitialized();
1333 WebNetworkStateNotifier::setOnLine(online);
1334}
1335
[email protected]b69934e2011-10-29 02:51:521336void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
[email protected]e9ff79c2012-10-19 21:31:261337 GetContentClient()->SetActiveURL(data);
[email protected]b69934e2011-10-29 02:51:521338 CHECK(false);
1339}
1340
[email protected]44363382013-03-12 07:22:471341void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) {
1342 ToggleWebKitSharedTimer(suspend);
1343}
1344
[email protected]c6a7b862010-08-20 22:19:381345scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:441346RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]dd32b1272013-05-04 14:17:111347 DCHECK(message_loop() == base::MessageLoop::current());
[email protected]59383c782013-04-17 16:43:271348 if (!file_thread_) {
[email protected]c6a7b862010-08-20 22:19:381349 file_thread_.reset(new base::Thread("Renderer::FILE"));
1350 file_thread_->Start();
1351 }
1352 return file_thread_->message_loop_proxy();
1353}
[email protected]e9ff79c2012-10-19 21:31:261354
[email protected]c1330c82013-06-06 02:23:251355scoped_refptr<base::MessageLoopProxy>
1356RenderThreadImpl::GetMediaThreadMessageLoopProxy() {
1357 DCHECK(message_loop() == base::MessageLoop::current());
1358 if (!media_thread_) {
1359 media_thread_.reset(new base::Thread("Media"));
1360 media_thread_->Start();
1361 }
1362 return media_thread_->message_loop_proxy();
1363}
1364
[email protected]107c0532013-02-06 02:34:091365void RenderThreadImpl::SetFlingCurveParameters(
1366 const std::vector<float>& new_touchpad,
1367 const std::vector<float>& new_touchscreen) {
1368 webkit_platform_support_->SetFlingCurveParameters(new_touchpad,
1369 new_touchscreen);
1370
1371}
1372
[email protected]e9ff79c2012-10-19 21:31:261373} // namespace content