blob: a8e82f26bee6544c28bbffd6fcbbe70eb7f9a5a5 [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]1357c322010-12-30 22:18:5624#include "base/threading/thread_local.h"
[email protected]d293572a2013-05-23 18:50:4525#include "base/threading/thread_restrictions.h"
[email protected]58436a12012-03-21 17:10:2626#include "base/utf_string_conversions.h"
[email protected]7a4de7a62010-08-17 18:38:2427#include "base/values.h"
[email protected]e93e04e2011-03-14 00:27:1028#include "content/common/appcache/appcache_dispatcher.h"
[email protected]83ab4a282012-07-12 18:19:4529#include "content/common/child_histogram_message_filter.h"
[email protected]bdae9812011-10-15 00:33:0330#include "content/common/child_process_messages.h"
[email protected]37666cf2011-03-13 21:51:4231#include "content/common/database_messages.h"
32#include "content/common/db_message_filter.h"
[email protected]127dd582011-03-16 21:32:1033#include "content/common/dom_storage_messages.h"
[email protected]c29b7ff2013-03-06 03:51:0434#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]c26ad882012-02-07 06:41:2035#include "content/common/gpu/client/gpu_channel_host.h"
[email protected]202b54ff2011-04-22 21:36:3836#include "content/common/gpu/gpu_messages.h"
[email protected]359dfa32011-10-12 01:10:1537#include "content/common/resource_dispatcher.h"
[email protected]94dc971d2011-03-05 19:08:3238#include "content/common/resource_messages.h"
[email protected]778574e2011-03-21 22:03:5039#include "content/common/view_messages.h"
[email protected]1570ac52013-05-22 15:05:3640#include "content/common_child/indexed_db/indexed_db_dispatcher.h"
41#include "content/common_child/indexed_db/indexed_db_message_filter.h"
[email protected]872f3a92013-05-21 08:16:0842#include "content/common_child/npobject_util.h"
43#include "content/common_child/plugin_messages.h"
[email protected]08b1f75f2013-05-22 22:02:3844#include "content/common_child/web_database_observer_impl.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]f7eb0a392011-07-12 10:19:5160#include "content/renderer/media/audio_input_message_filter.h"
61#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:4162#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]d8cd8372012-03-09 10:49:5163#include "content/renderer/media/media_stream_center.h"
[email protected]6ee10bd2012-09-13 09:01:5364#include "content/renderer/media/media_stream_dependency_factory.h"
[email protected]af089972013-01-10 04:04:4065#include "content/renderer/media/peer_connection_tracker.h"
[email protected]80b161a2011-06-27 17:42:1166#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:3467#include "content/renderer/media/video_capture_message_filter.h"
[email protected]6941ac5c2013-02-07 03:59:5668#include "content/renderer/memory_benchmarking_extension.h"
[email protected]4761cf12012-09-12 10:37:5569#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3570#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0571#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:2872#include "content/renderer/render_view_impl.h"
[email protected]8d6cba42011-09-02 10:05:1973#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]a8228252013-05-14 11:10:0574#include "content/renderer/skia_benchmarking_extension.h"
[email protected]766a7082012-02-03 23:39:1575#include "grit/content_resources.h"
[email protected]46f36a492010-07-28 19:36:4176#include "ipc/ipc_channel_handle.h"
[email protected]1842fe22012-08-13 23:24:3577#include "ipc/ipc_forwarding_message_filter.h"
[email protected]cb6037d2009-11-16 22:55:1778#include "ipc/ipc_platform_file.h"
[email protected]563d665f2013-02-01 04:42:3979#include "media/base/audio_hardware_config.h"
[email protected]433df472012-03-07 20:33:3980#include "media/base/media.h"
[email protected]620161e2011-03-07 18:05:2681#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5482#include "net/base/net_util.h"
[email protected]5c30b5e02013-05-30 03:46:0883#include "third_party/WebKit/public/platform/WebString.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]c49201a2012-05-24 11:04:5796#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:3297#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:5098#include "v8/include/v8.h"
[email protected]d471190a2011-02-16 14:52:3099#include "webkit/glue/webkit_glue.h"
[email protected]2c62b562009-01-27 19:04:50100
[email protected]da00a2882009-03-09 17:51:19101#if defined(OS_WIN)
102#include <windows.h>
103#include <objbase.h>
[email protected]5f7e4512012-10-01 20:51:37104#include "base/win/scoped_com_initializer.h"
105#else
106// TODO(port)
107#include "base/memory/scoped_handle.h"
[email protected]872f3a92013-05-21 08:16:08108#include "content/common_child/np_channel_base.h"
[email protected]da00a2882009-03-09 17:51:19109#endif
110
[email protected]6217d392010-03-25 22:08:35111#if defined(OS_POSIX)
112#include "ipc/ipc_channel_posix.h"
113#endif
114
[email protected]950f9ce22012-12-27 00:25:07115#if defined(ENABLE_WEBRTC)
116#include "third_party/webrtc/system_wrappers/interface/event_tracer.h"
117#endif
118
[email protected]913d99a2013-05-31 07:16:07119#if defined(OS_ANDROID)
120#include "content/renderer/android/synchronous_compositor_factory.h"
121#endif
122
[email protected]d293572a2013-05-23 18:50:45123using base::ThreadRestrictions;
[email protected]b6cb3a842011-06-24 18:28:41124using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:01125using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:09126using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:00127using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:51128using WebKit::WebScriptController;
[email protected]58436a12012-03-21 17:10:26129using WebKit::WebSecurityPolicy;
[email protected]2c434b32009-03-19 06:27:47130using WebKit::WebString;
[email protected]50ae00ef2009-10-19 05:11:03131using WebKit::WebView;
[email protected]e9ff79c2012-10-19 21:31:26132
133namespace content {
initial.commit09911bf2008-07-26 23:55:29134
[email protected]42f1d7822009-07-23 18:17:55135namespace {
[email protected]da9ccfb2012-01-28 00:34:40136
137const int64 kInitialIdleHandlerDelayMs = 1000;
138const int64 kShortIdleHandlerDelayMs = 1000;
139const int64 kLongIdleHandlerDelayMs = 30*1000;
140const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03141
[email protected]f1a29a02011-10-06 23:08:44142// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16143// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40144base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49145 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54146
[email protected]e9ff79c2012-10-19 21:31:26147class RenderViewZoomer : public RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51148 public:
[email protected]367c5c1d2013-03-11 18:59:02149 RenderViewZoomer(const std::string& scheme,
150 const std::string& host,
151 double zoom_level) : scheme_(scheme),
152 host_(host),
153 zoom_level_(zoom_level) {
[email protected]40bd6582009-12-04 23:49:51154 }
155
[email protected]c3e35892013-02-12 02:08:01156 virtual bool Visit(RenderView* render_view) OVERRIDE {
[email protected]a2ef54c2011-10-10 16:20:31157 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41158 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25159
160 // Don't set zoom level for full-page plugin since they don't use the same
161 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41162 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25163 return true;
[email protected]367c5c1d2013-03-11 18:59:02164 GURL url(document.url());
165 // Empty scheme works as wildcard that matches any scheme,
166 if ((net::GetHostOrSpecFromURL(url) == host_) &&
167 (scheme_.empty() || scheme_ == url.scheme())) {
[email protected]40bd6582009-12-04 23:49:51168 webview->setZoomLevel(false, zoom_level_);
[email protected]367c5c1d2013-03-11 18:59:02169 }
[email protected]40bd6582009-12-04 23:49:51170 return true;
171 }
172
173 private:
[email protected]367c5c1d2013-03-11 18:59:02174 const std::string scheme_;
175 const std::string host_;
176 const double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51177
178 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
179};
[email protected]0478d0162010-08-28 08:29:40180
[email protected]b2d98762012-09-03 17:04:06181std::string HostToCustomHistogramSuffix(const std::string& host) {
182 if (host == "mail.google.com")
183 return ".gmail";
184 if (host == "docs.google.com" || host == "drive.google.com")
185 return ".docs";
186 if (host == "plus.google.com")
187 return ".plus";
[email protected]007b3f82013-04-09 08:46:45188 return std::string();
[email protected]b2d98762012-09-03 17:04:06189}
[email protected]42f1d7822009-07-23 18:17:55190
[email protected]b2d98762012-09-03 17:04:06191void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13192 const char *name, int min, int max, size_t buckets) {
193 if (min <= 0)
194 min = 1;
[email protected]b2d98762012-09-03 17:04:06195 std::string histogram_name;
196 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
197 if (render_thread_impl) { // Can be null in tests.
198 histogram_name = render_thread_impl->
199 histogram_customizer()->ConvertToCustomHistogramName(name);
200 } else {
201 histogram_name = std::string(name);
202 }
[email protected]de415552013-01-23 04:12:17203 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06204 histogram_name, min, max, buckets,
205 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13206 return histogram;
207}
208
[email protected]b2d98762012-09-03 17:04:06209void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13210 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
211 histogram->Add(sample);
212}
213
[email protected]950f9ce22012-12-27 00:25:07214#if defined(ENABLE_WEBRTC)
[email protected]d936677a2013-04-19 08:49:03215const unsigned char* GetCategoryGroupEnabled(const char* category_group) {
216 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group);
[email protected]da0f6952012-12-26 22:22:39217}
218
219void AddTraceEvent(char phase,
[email protected]d936677a2013-04-19 08:49:03220 const unsigned char* category_group_enabled,
[email protected]da0f6952012-12-26 22:22:39221 const char* name,
222 unsigned long long id,
223 int num_args,
224 const char** arg_names,
225 const unsigned char* arg_types,
226 const unsigned long long* arg_values,
227 unsigned char flags) {
[email protected]d936677a2013-04-19 08:49:03228 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id,
229 num_args, arg_names, arg_types, arg_values,
[email protected]7fceeab22013-05-03 15:40:47230 NULL, flags);
[email protected]da0f6952012-12-26 22:22:39231}
[email protected]950f9ce22012-12-27 00:25:07232#endif
[email protected]da0f6952012-12-26 22:22:39233
[email protected]b2d98762012-09-03 17:04:06234} // namespace
235
[email protected]fe476b02012-08-13 21:21:38236class RenderThreadImpl::GpuVDAContextLostCallback
237 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
238 public:
239 GpuVDAContextLostCallback() {}
240 virtual ~GpuVDAContextLostCallback() {}
241 virtual void onContextLost() {
242 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind(
243 &RenderThreadImpl::OnGpuVDAContextLoss));
244 }
245};
246
[email protected]00874dd2013-03-08 23:51:18247class RenderThreadImpl::RendererContextProviderCommandBuffer
248 : public ContextProviderCommandBuffer {
[email protected]e06e1122013-03-15 17:12:38249 public:
250 static scoped_refptr<RendererContextProviderCommandBuffer> Create() {
251 scoped_refptr<RendererContextProviderCommandBuffer> provider =
252 new RendererContextProviderCommandBuffer();
253 if (!provider->InitializeOnMainThread())
254 return NULL;
255 return provider;
256 }
257
[email protected]00874dd2013-03-08 23:51:18258 protected:
259 virtual ~RendererContextProviderCommandBuffer() {}
260
261 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]aa3174b2013-03-15 09:12:48262 CreateOffscreenContext3d() OVERRIDE {
[email protected]00874dd2013-03-08 23:51:18263 RenderThreadImpl* self = RenderThreadImpl::current();
264 DCHECK(self);
265 return self->CreateOffscreenContext3d().Pass();
266 }
267};
268
[email protected]b2d98762012-09-03 17:04:06269RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
270 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
271 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
272 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
273}
274
275RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
276
277void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
278 const std::string& host, size_t view_count) {
[email protected]9baee832012-12-10 11:07:15279 if (CommandLine::ForCurrentProcess()->HasSwitch(
280 switches::kDisableHistogramCustomizer)) {
281 return;
282 }
[email protected]b2d98762012-09-03 17:04:06283 // Check if all RenderViews are displaying a page from the same host. If there
284 // is only one RenderView, the common host is this view's host. If there are
285 // many, check if this one shares the common host of the other
286 // RenderViews. It's ok to not detect some cases where the RenderViews share a
287 // common host. This information is only used for producing custom histograms.
288 if (view_count == 1)
289 SetCommonHost(host);
290 else if (host != common_host_)
291 SetCommonHost(std::string());
292}
293
294std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
295 const char* histogram_name) const {
296 std::string name(histogram_name);
297 if (!common_host_histogram_suffix_.empty() &&
298 custom_histograms_.find(name) != custom_histograms_.end())
299 name += common_host_histogram_suffix_;
300 return name;
301}
302
303void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
304 const std::string& host) {
305 if (host != common_host_) {
306 common_host_ = host;
307 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
308 v8::V8::SetCreateHistogramFunction(CreateHistogram);
309 }
310}
311
[email protected]f1a29a02011-10-06 23:08:44312RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06313 return lazy_tls.Pointer()->Get();
314}
315
[email protected]42f1d7822009-07-23 18:17:55316// When we run plugins in process, we actually run them on the render thread,
317// which means that we need to make the render thread pump UI events.
[email protected]f1a29a02011-10-06 23:08:44318RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55319 Init();
320}
321
[email protected]f1a29a02011-10-06 23:08:44322RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55323 : ChildThread(channel_name) {
324 Init();
325}
[email protected]5fa1c542009-05-05 20:36:07326
[email protected]f1a29a02011-10-06 23:08:44327void RenderThreadImpl::Init() {
328 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33329
[email protected]c7e948b42012-07-12 09:20:20330 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
331 v8::V8::SetCreateHistogramFunction(CreateHistogram);
332 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
333
[email protected]d3f09092012-02-16 01:52:17334#if defined(OS_MACOSX) || defined(OS_ANDROID)
335 // On Mac and Android, the select popups are rendered by the browser.
[email protected]53c607c2011-03-21 23:19:04336 WebKit::WebView::setUseExternalPopupMenus(true);
337#endif
338
[email protected]94f9a0f682009-06-15 18:30:30339 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28340
[email protected]2c62b562009-01-27 19:04:50341#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34342 // If you are running plugins in this thread you need COM active but in
343 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28344 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12345 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50346#endif
initial.commit09911bf2008-07-26 23:55:29347
[email protected]06c694d2012-02-01 22:26:16348 // Register this object as the main thread.
349 ChildProcess::current()->set_main_thread(this);
350
[email protected]31f87132010-04-21 23:36:21351 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50352 suspend_webkit_shared_timer_ = true;
353 notify_webkit_of_modal_loop_ = true;
[email protected]bee16aab2009-08-26 15:55:03354 widget_count_ = 0;
355 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44356 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48357 idle_notifications_to_skip_ = 0;
[email protected]70dee7e2013-05-29 18:28:30358 layout_test_mode_ = false;
[email protected]8d86fce2009-02-26 23:37:55359
[email protected]dcc72db2013-01-02 00:44:18360 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
[email protected]1910fe82012-05-10 00:04:10361 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
[email protected]dcc72db2013-01-02 00:44:18362 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13363
[email protected]d8cd8372012-03-09 10:49:51364 media_stream_center_ = NULL;
365
[email protected]017022b2009-07-27 23:06:34366 db_message_filter_ = new DBMessageFilter();
367 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13368
[email protected]4761cf12012-09-12 10:37:55369#if defined(ENABLE_WEBRTC)
[email protected]d936677a2013-04-19 08:49:03370 webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent);
[email protected]af089972013-01-10 04:04:40371
372 peer_connection_tracker_.reset(new PeerConnectionTracker());
373 AddObserver(peer_connection_tracker_.get());
374
[email protected]e9ff79c2012-10-19 21:31:26375 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy());
[email protected]fc72bb12013-06-02 21:13:46376 AddFilter(p2p_socket_dispatcher_.get());
[email protected]4761cf12012-09-12 10:37:55377#endif // defined(ENABLE_WEBRTC)
[email protected]80b161a2011-06-27 17:42:11378 vc_manager_ = new VideoCaptureImplManager();
379 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46380
[email protected]e0a938702013-02-25 21:15:56381 audio_input_message_filter_ =
382 new AudioInputMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51383 AddFilter(audio_input_message_filter_.get());
384
[email protected]e0a938702013-02-25 21:15:56385 audio_message_filter_ = new AudioMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51386 AddFilter(audio_message_filter_.get());
387
[email protected]31bfae72011-12-16 02:04:38388 AddFilter(new IndexedDBMessageFilter);
389
[email protected]e9ff79c2012-10-19 21:31:26390 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24391
[email protected]302fe422012-06-11 14:49:11392 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01393 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking))
[email protected]e9ff79c2012-10-19 21:31:26394 RegisterExtension(GpuBenchmarkingExtension::Get());
[email protected]e54ab492012-06-12 19:40:01395
[email protected]a70ed8b32013-05-24 15:16:34396#if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID))
[email protected]6941ac5c2013-02-07 03:59:56397 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
398 RegisterExtension(MemoryBenchmarkingExtension::Get());
[email protected]a70ed8b32013-05-24 15:16:34399#endif // USE_TCMALLOC
[email protected]6941ac5c2013-02-07 03:59:56400
[email protected]a8228252013-05-14 11:10:05401 if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking)) {
402 LOG(WARNING) << "Enabling unsafe Skia benchmarking extension.";
403 RegisterExtension(SkiaBenchmarkingExtension::Get());
404 }
405
[email protected]fe476b02012-08-13 21:21:38406 context_lost_cb_.reset(new GpuVDAContextLostCallback());
407
[email protected]433df472012-03-07 20:33:39408 // Note that under Linux, the media library will normally already have
409 // been initialized by the Zygote before this instance became a Renderer.
[email protected]c42de732013-02-16 06:26:31410 base::FilePath media_path;
[email protected]e9ff79c2012-10-19 21:31:26411 PathService::Get(DIR_MEDIA_LIBS, &media_path);
[email protected]433df472012-03-07 20:33:39412 if (!media_path.empty())
413 media::InitializeMediaLibrary(media_path);
414
[email protected]f1a29a02011-10-06 23:08:44415 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29416}
417
[email protected]f1a29a02011-10-06 23:08:44418RenderThreadImpl::~RenderThreadImpl() {
[email protected]ce79d8512013-04-22 22:44:41419}
420
421void RenderThreadImpl::Shutdown() {
[email protected]1223d6ef2011-03-28 16:47:50422 FOR_EACH_OBSERVER(
423 RenderProcessObserver, observers_, OnRenderProcessShutdown());
424
[email protected]12cbfda32010-01-30 01:04:25425 // Wait for all databases to be closed.
[email protected]59383c782013-04-17 16:43:27426 if (web_database_observer_impl_)
[email protected]2b437e232010-04-02 01:30:08427 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25428
[email protected]8d86fce2009-02-26 23:37:55429 // Shutdown in reverse of the initialization order.
[email protected]fc72bb12013-06-02 21:13:46430 if (devtools_agent_message_filter_.get()) {
[email protected]b146d6d2012-09-11 10:20:05431 RemoveFilter(devtools_agent_message_filter_.get());
432 devtools_agent_message_filter_ = NULL;
433 }
[email protected]82622452011-07-22 09:57:20434
[email protected]f7eb0a392011-07-12 10:19:51435 RemoveFilter(audio_input_message_filter_.get());
436 audio_input_message_filter_ = NULL;
437
438 RemoveFilter(audio_message_filter_.get());
439 audio_message_filter_ = NULL;
440
[email protected]80b161a2011-06-27 17:42:11441 RemoveFilter(vc_manager_->video_capture_message_filter());
442
[email protected]017022b2009-07-27 23:06:34443 RemoveFilter(db_message_filter_.get());
444 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25445
[email protected]c6a7b862010-08-20 22:19:38446 // Shutdown the file thread if it's running.
[email protected]59383c782013-04-17 16:43:27447 if (file_thread_)
[email protected]c6a7b862010-08-20 22:19:38448 file_thread_->Stop();
449
[email protected]fc72bb12013-06-02 21:13:46450 if (compositor_output_surface_filter_.get()) {
[email protected]23d2b7e2012-08-14 00:34:09451 RemoveFilter(compositor_output_surface_filter_.get());
452 compositor_output_surface_filter_ = NULL;
453 }
[email protected]1842fe22012-08-13 23:24:35454
[email protected]79a92b52013-04-08 19:09:02455 compositor_thread_.reset();
[email protected]59383c782013-04-17 16:43:27456 if (input_handler_manager_) {
[email protected]ea5f70a2013-03-07 12:30:36457 RemoveFilter(input_handler_manager_->GetMessageFilter());
458 input_handler_manager_.reset();
[email protected]a9fb30aa2011-10-06 06:58:46459 }
460
[email protected]59383c782013-04-17 16:43:27461 if (webkit_platform_support_)
[email protected]9291ed12009-07-23 17:33:22462 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22463
[email protected]94f9a0f682009-06-15 18:30:30464 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30465
[email protected]8d86fce2009-02-26 23:37:55466 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50467#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29468 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50469 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50470#endif
[email protected]00874dd2013-03-08 23:51:18471
472 // Leak shared contexts on other threads, as we can not get to the correct
473 // thread to destroy them.
[email protected]fc72bb12013-06-02 21:13:46474 if (shared_contexts_compositor_thread_.get())
[email protected]00874dd2013-03-08 23:51:18475 shared_contexts_compositor_thread_->set_leak_on_destroy();
initial.commit09911bf2008-07-26 23:55:29476}
477
[email protected]f1a29a02011-10-06 23:08:44478bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14479 // Certain synchronous messages cannot always be processed synchronously by
480 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50481 // This could cause a complete hang of Chrome if a windowed plug-in is trying
482 // to communicate with the renderer thread since the browser's UI thread
483 // could be stuck (within a Windows API call) trying to synchronously
484 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14485 // thread while the browser is processing this request. This creates an
486 // opportunity for re-entrancy into WebKit, so we need to take care to disable
487 // callbacks, timers, and pending network loads that could trigger such
488 // callbacks.
[email protected]38b592902011-04-16 02:08:42489 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50490 if (msg->is_sync()) {
491 if (msg->is_caller_pumping_messages()) {
492 pumping_events = true;
493 } else {
[email protected]38b592902011-04-16 02:08:42494 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
495 msg->type() == ViewHostMsg_GetRawCookies::ID ||
496 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
[email protected]e9ff79c2012-10-19 21:31:26497 GetContentClient()->renderer()->
[email protected]38b592902011-04-16 02:08:42498 ShouldPumpEventsDuringCookieMessage()) {
499 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50500 }
501 }
[email protected]c1f50aa2010-02-18 03:46:57502 }
503
[email protected]80fc08c52010-03-09 07:43:50504 bool suspend_webkit_shared_timer = true; // default value
505 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57506
[email protected]80fc08c52010-03-09 07:43:50507 bool notify_webkit_of_modal_loop = true; // default value
508 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
509
[email protected]c48de1a2012-11-02 19:06:56510 int render_view_id = MSG_ROUTING_NONE;
[email protected]c1f50aa2010-02-18 03:46:57511
512 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50513 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19514 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57515
[email protected]39065d012010-07-09 11:22:46516 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57517 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57518
[email protected]bae061f72013-04-26 16:22:29519 RenderViewImpl* render_view =
520 RenderViewImpl::FromRoutingID(msg->routing_id());
521 if (render_view) {
522 render_view_id = msg->routing_id();
[email protected]c1f50aa2010-02-18 03:46:57523 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56524 new PluginMsg_SignalModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57525 }
526 }
527
528 bool rv = ChildThread::Send(msg);
529
530 if (pumping_events) {
[email protected]c48de1a2012-11-02 19:06:56531 if (render_view_id != MSG_ROUTING_NONE) {
[email protected]c1f50aa2010-02-18 03:46:57532 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56533 new PluginMsg_ResetModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57534 }
535
[email protected]39065d012010-07-09 11:22:46536 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57537 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57538
[email protected]80fc08c52010-03-09 07:43:50539 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19540 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57541 }
542
543 return rv;
544}
545
[email protected]9e7154122013-05-30 23:11:04546base::MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06547 return message_loop();
548}
549
[email protected]f1a29a02011-10-06 23:08:44550IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06551 return channel();
552}
553
[email protected]f1a29a02011-10-06 23:08:44554std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06555 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:02556 // --lang command line flag.
[email protected]526476902011-10-06 20:34:06557 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
558 const std::string& lang =
559 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:02560 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:06561 return lang;
562}
563
[email protected]07bb6332012-01-21 01:07:57564IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
565 return sync_message_filter();
566}
567
[email protected]96191d52012-05-17 01:37:11568scoped_refptr<base::MessageLoopProxy>
569 RenderThreadImpl::GetIOMessageLoopProxy() {
570 return ChildProcess::current()->io_message_loop_proxy();
571}
572
[email protected]c47317e2012-06-20 22:35:31573void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57574 widget_count_++;
575 return ChildThread::AddRoute(routing_id, listener);
576}
577
[email protected]f1a29a02011-10-06 23:08:44578void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57579 widget_count_--;
580 return ChildThread::RemoveRoute(routing_id);
581}
582
[email protected]77fc9b92011-10-15 16:20:37583int RenderThreadImpl::GenerateRoutingID() {
584 int routing_id = MSG_ROUTING_NONE;
585 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
586 return routing_id;
587}
588
[email protected]f1a29a02011-10-06 23:08:44589void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55590 channel()->AddFilter(filter);
591}
592
[email protected]f1a29a02011-10-06 23:08:44593void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55594 channel()->RemoveFilter(filter);
595}
596
[email protected]f1a29a02011-10-06 23:08:44597void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06598 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
599}
600
[email protected]e9ff79c2012-10-19 21:31:26601void RenderThreadImpl::AddObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06602 observers_.AddObserver(observer);
603}
604
[email protected]e9ff79c2012-10-19 21:31:26605void RenderThreadImpl::RemoveObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06606 observers_.RemoveObserver(observer);
607}
608
[email protected]359dfa32011-10-12 01:10:15609void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:26610 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:15611 resource_dispatcher()->set_delegate(delegate);
612}
613
[email protected]f1a29a02011-10-06 23:08:44614void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03615 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50616 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24617
[email protected]e9ff79c2012-10-19 21:31:26618 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24619 return;
620 }
621
622 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44623 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03624}
625
[email protected]f1a29a02011-10-06 23:08:44626void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08627 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03628 hidden_widget_count_--;
[email protected]e9ff79c2012-10-19 21:31:26629 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24630 return;
631 }
[email protected]bee16aab2009-08-26 15:55:03632
[email protected]1784b2f2011-11-24 10:53:48633 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39634}
635
[email protected]78b86f9a2013-05-03 23:33:40636static void AdjustRuntimeFeatureDefaultsForPlatform() {
637#if defined(OS_ANDROID) && !defined(GOOGLE_TV)
[email protected]5bf1223a52013-05-14 21:42:31638 WebRuntimeFeatures::enableWebKitMediaSource(false);
[email protected]16c242d2013-05-31 23:56:47639 WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
640 WebRuntimeFeatures::enableEncryptedMedia(false);
[email protected]78b86f9a2013-05-03 23:33:40641#endif
642
643#if defined(OS_ANDROID)
644 WebRuntimeFeatures::enableWebAudio(false);
[email protected]78b86f9a2013-05-03 23:33:40645 // Android does not support the Gamepad API.
646 WebRuntimeFeatures::enableGamepad(false);
647 // input[type=week] in Android is incomplete. crbug.com/135938
648 WebRuntimeFeatures::enableInputTypeWeek(false);
[email protected]09128282013-05-17 16:42:52649 // Android does not have support for PagePopup
650 WebRuntimeFeatures::enablePagePopup(false);
[email protected]0338ce792013-05-24 11:15:59651 // datalist on Android is not enabled
652 WebRuntimeFeatures::enableDataListElement(false);
[email protected]78b86f9a2013-05-03 23:33:40653#endif
654}
655
656static void AdjustRuntimeFeaturesFromArgs(const CommandLine& command_line) {
657 if (command_line.HasSwitch(switches::kDisableDatabases))
658 WebRuntimeFeatures::enableDatabase(false);
659
660 if (command_line.HasSwitch(switches::kDisableApplicationCache))
661 WebRuntimeFeatures::enableApplicationCache(false);
662
663 if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
664 WebRuntimeFeatures::enableNotifications(false);
665
666 if (command_line.HasSwitch(switches::kDisableLocalStorage))
667 WebRuntimeFeatures::enableLocalStorage(false);
668
669 if (command_line.HasSwitch(switches::kDisableSessionStorage))
670 WebRuntimeFeatures::enableSessionStorage(false);
671
672 if (command_line.HasSwitch(switches::kDisableGeolocation))
673 WebRuntimeFeatures::enableGeolocation(false);
674
[email protected]85dd7ca2013-05-30 23:53:00675#if defined(OS_ANDROID) && !defined(GOOGLE_TV)
676 if (command_line.HasSwitch(switches::kEnableWebKitMediaSource))
677 WebRuntimeFeatures::enableWebKitMediaSource(true);
678#else
[email protected]5bf1223a52013-05-14 21:42:31679 if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
680 WebRuntimeFeatures::enableWebKitMediaSource(false);
[email protected]78b86f9a2013-05-03 23:33:40681#endif
682
683#if defined(OS_ANDROID)
[email protected]3bd0aab2013-05-30 20:07:49684 if (command_line.HasSwitch(switches::kDisableWebRTC)) {
[email protected]78b86f9a2013-05-03 23:33:40685 WebRuntimeFeatures::enableMediaStream(false);
[email protected]78b86f9a2013-05-03 23:33:40686 WebRuntimeFeatures::enablePeerConnection(false);
[email protected]3bd0aab2013-05-30 20:07:49687 }
688
689 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
690 WebRuntimeFeatures::enableScriptedSpeech(false);
691
692 if (command_line.HasSwitch(switches::kEnableWebAudio))
693 WebRuntimeFeatures::enableWebAudio(true);
694#else
695 if (command_line.HasSwitch(switches::kDisableWebAudio))
696 WebRuntimeFeatures::enableWebAudio(false);
[email protected]78b86f9a2013-05-03 23:33:40697#endif
698
699 if (command_line.HasSwitch(switches::kDisableFullScreen))
[email protected]d2414bb2013-05-10 21:29:27700 WebRuntimeFeatures::enableFullscreen(false);
[email protected]78b86f9a2013-05-03 23:33:40701
[email protected]16c242d2013-05-31 23:56:47702 if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
703 WebRuntimeFeatures::enableEncryptedMedia(true);
704
705 if (command_line.HasSwitch(switches::kDisableLegacyEncryptedMedia))
706 WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
[email protected]78b86f9a2013-05-03 23:33:40707
[email protected]78b86f9a2013-05-03 23:33:40708 if (command_line.HasSwitch(switches::kEnableWebMIDI))
709 WebRuntimeFeatures::enableWebMIDI(true);
710
711 if (command_line.HasSwitch(switches::kEnableDeviceMotion))
712 WebRuntimeFeatures::enableDeviceMotion(true);
713
714 if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
715 WebRuntimeFeatures::enableDeviceOrientation(false);
716
717 if (command_line.HasSwitch(switches::kDisableSpeechInput))
718 WebRuntimeFeatures::enableSpeechInput(false);
719
720 if (command_line.HasSwitch(switches::kDisableFileSystem))
721 WebRuntimeFeatures::enableFileSystem(false);
722
723 if (command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI))
724 WebRuntimeFeatures::enableJavaScriptI18NAPI(false);
725
[email protected]78b86f9a2013-05-03 23:33:40726 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
727 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
728
729 if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
730 WebRuntimeFeatures::enableSpeechSynthesis(true);
[email protected]70dc60932013-06-04 03:33:49731
732 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
733 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
[email protected]78b86f9a2013-05-03 23:33:40734}
735
[email protected]f1a29a02011-10-06 23:08:44736void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]59383c782013-04-17 16:43:27737 if (webkit_platform_support_)
[email protected]d1b8fccc2011-08-03 01:20:13738 return;
739
[email protected]8d6cba42011-09-02 10:05:19740 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
741 WebKit::initialize(webkit_platform_support_.get());
[email protected]00fccb42012-12-11 00:09:59742 WebKit::setSharedWorkerRepository(
743 webkit_platform_support_.get()->sharedWorkerRepository());
[email protected]2a23d3f52013-01-08 01:20:24744 WebKit::setIDBFactory(
745 webkit_platform_support_.get()->idbFactory());
[email protected]d1b8fccc2011-08-03 01:20:13746
[email protected]cd7ce3be2012-09-10 05:19:41747 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]cd7ce3be2012-09-10 05:19:41748
[email protected]0f21e8582013-01-11 11:06:56749 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing);
[email protected]72787e392012-03-23 05:55:43750 if (enable) {
[email protected]913d99a2013-05-31 07:16:07751#if defined(OS_ANDROID)
752 if (SynchronousCompositorFactory* factory =
753 SynchronousCompositorFactory::GetInstance())
754 compositor_message_loop_proxy_ =
755 factory->GetCompositorMessageLoop();
756#endif
757 if (!compositor_message_loop_proxy_) {
[email protected]ea5f70a2013-03-07 12:30:36758 compositor_thread_.reset(new base::Thread("Compositor"));
759 compositor_thread_->Start();
[email protected]b38864d2013-05-24 14:42:36760#if defined(OS_ANDROID)
761 compositor_thread_->SetPriority(base::kThreadPriority_Display);
762#endif
[email protected]ea5f70a2013-03-07 12:30:36763 compositor_message_loop_proxy_ =
764 compositor_thread_->message_loop_proxy();
[email protected]d293572a2013-05-23 18:50:45765 compositor_message_loop_proxy_->PostTask(
766 FROM_HERE,
767 base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed),
768 false));
[email protected]ea5f70a2013-03-07 12:30:36769 }
770
[email protected]913d99a2013-05-31 07:16:07771 input_handler_manager_.reset(
772 new InputHandlerManager(this, compositor_message_loop_proxy_));
773 AddFilter(input_handler_manager_->GetMessageFilter());
[email protected]a458504b2012-07-23 19:57:06774 }
[email protected]a9fb30aa2011-10-06 06:58:46775
[email protected]ea5f70a2013-03-07 12:30:36776 scoped_refptr<base::MessageLoopProxy> output_surface_loop;
[email protected]7f1f63f2013-03-07 06:07:29777 if (enable)
[email protected]ea5f70a2013-03-07 12:30:36778 output_surface_loop = compositor_message_loop_proxy_;
[email protected]7f1f63f2013-03-07 06:07:29779 else
780 output_surface_loop = base::MessageLoopProxy::current();
[email protected]1842fe22012-08-13 23:24:35781
[email protected]7f1f63f2013-03-07 06:07:29782 compositor_output_surface_filter_ =
[email protected]fc72bb12013-06-02 21:13:46783 CompositorOutputSurface::CreateFilter(output_surface_loop.get());
[email protected]1842fe22012-08-13 23:24:35784 AddFilter(compositor_output_surface_filter_.get());
785
[email protected]d1b8fccc2011-08-03 01:20:13786 WebScriptController::enableV8SingleThreadMode();
787
[email protected]58436a12012-03-21 17:10:26788 RenderThreadImpl::RegisterSchemes();
789
[email protected]d1b8fccc2011-08-03 01:20:13790 webkit_glue::EnableWebCoreLogChannels(
791 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
792
[email protected]fa1c17e42012-03-06 22:29:54793 web_database_observer_impl_.reset(
794 new WebDatabaseObserverImpl(sync_message_filter()));
[email protected]d1b8fccc2011-08-03 01:20:13795 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
796
[email protected]d1bf64b2013-05-06 12:13:53797 WebRuntimeFeatures::enableStableFeatures(true);
[email protected]d1b8fccc2011-08-03 01:20:13798
[email protected]d1bf64b2013-05-06 12:13:53799 if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures))
800 WebRuntimeFeatures::enableExperimentalFeatures(true);
[email protected]4ae41b42012-12-06 21:59:03801
[email protected]78b86f9a2013-05-03 23:33:40802 AdjustRuntimeFeatureDefaultsForPlatform();
803 AdjustRuntimeFeaturesFromArgs(command_line);
[email protected]d3e7aea22013-01-09 08:47:53804
[email protected]205855d2013-04-24 01:42:18805 // Enabled by default for testing.
806 // TODO(urvang): Go back to using the command-line option after a few days.
[email protected]78b86f9a2013-05-03 23:33:40807 // https://code.google.com/p/chromium/issues/detail?id=234437
[email protected]205855d2013-04-24 01:42:18808 WebRuntimeFeatures::enableWebPInAcceptHeader(true);
[email protected]8027acd2013-04-18 08:35:15809
[email protected]78b86f9a2013-05-03 23:33:40810 if (!media::IsMediaLibraryInitialized()) {
811 WebRuntimeFeatures::enableMediaPlayer(false);
812 WebRuntimeFeatures::enableWebAudio(false);
813 }
[email protected]7a06d282013-05-03 04:39:33814
[email protected]d1b8fccc2011-08-03 01:20:13815 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48816
[email protected]b146d6d2012-09-11 10:20:05817 devtools_agent_message_filter_ = new DevToolsAgentFilter();
818 AddFilter(devtools_agent_message_filter_.get());
819
[email protected]e9ff79c2012-10-19 21:31:26820 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]1784b2f2011-11-24 10:53:48821 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]d1b8fccc2011-08-03 01:20:13822}
823
[email protected]58436a12012-03-21 17:10:26824void RenderThreadImpl::RegisterSchemes() {
825 // swappedout: pages should not be accessible, and should also
826 // be treated as empty documents that can commit synchronously.
827 WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme));
828 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme);
829 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme);
830}
831
[email protected]f1a29a02011-10-06 23:08:44832void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06833 Send(new ViewHostMsg_UserMetricsRecordAction(action));
834}
835
[email protected]fb79aa22012-12-13 01:12:13836scoped_ptr<base::SharedMemory>
[email protected]3f892832013-01-11 03:23:59837 RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
838 if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
839 return scoped_ptr<base::SharedMemory>();
840
[email protected]fb79aa22012-12-13 01:12:13841 base::SharedMemoryHandle handle;
842 bool success;
843 IPC::Message* message =
844 new ChildProcessHostMsg_SyncAllocateSharedMemory(size, &handle);
845
846 // Allow calling this from the compositor thread.
[email protected]dd32b1272013-05-04 14:17:11847 if (base::MessageLoop::current() == message_loop())
[email protected]fb79aa22012-12-13 01:12:13848 success = ChildThread::Send(message);
849 else
850 success = sync_message_filter()->Send(message);
851
852 if (!success)
853 return scoped_ptr<base::SharedMemory>();
854
855 if (!base::SharedMemory::IsHandleValid(handle))
856 return scoped_ptr<base::SharedMemory>();
857
858 return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false));
[email protected]00614a82011-10-07 22:39:31859}
860
[email protected]f1a29a02011-10-06 23:08:44861void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06862 WebScriptController::registerExtension(extension);
[email protected]526476902011-10-06 20:34:06863}
864
[email protected]6593ae12011-11-14 12:09:44865void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
866 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06867 idle_timer_.Stop();
868 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44869 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44870 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06871}
872
[email protected]f1a29a02011-10-06 23:08:44873void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48874 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:26875 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:48876 RunIdleHandlerWhenWidgetsHidden();
877 if (run_in_foreground_tab) {
878 IdleHandlerInForegroundTab();
879 return;
880 }
[email protected]237a14852012-04-28 02:56:38881
882 base::allocator::ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:06883
884 v8::V8::IdleNotification();
885
886 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44887 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06888 // delay = delay + 1 / (delay + 2)
889 // Using floor(delay) has a dampening effect such as:
890 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44891 // If the delay is in milliseconds, the above formula is equivalent to:
892 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
893 // which is equivalent to
894 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
895 // Note that idle_notification_delay_in_ms_ would be reset to
896 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
897 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
898 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06899
900 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
901}
902
[email protected]1784b2f2011-11-24 10:53:48903void RenderThreadImpl::IdleHandlerInForegroundTab() {
904 // Increase the delay in the same way as in IdleHandler,
905 // but make it periodic by reseting it once it is too big.
906 int64 new_delay_ms = idle_notification_delay_in_ms_ +
907 1000000 / (idle_notification_delay_in_ms_ + 2000);
908 if (new_delay_ms >= kLongIdleHandlerDelayMs)
909 new_delay_ms = kShortIdleHandlerDelayMs;
910
[email protected]1784b2f2011-11-24 10:53:48911 if (idle_notifications_to_skip_ > 0) {
912 idle_notifications_to_skip_--;
[email protected]7e967f82011-12-01 09:35:14913 } else {
[email protected]a47105c832011-12-07 17:24:30914 int cpu_usage = 0;
[email protected]7e967f82011-12-01 09:35:14915 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
[email protected]1393c4a2012-02-07 10:12:58916 // Idle notification hint roughly specifies the expected duration of the
917 // idle pause. We set it proportional to the idle timer delay.
918 int idle_hint = static_cast<int>(new_delay_ms / 10);
[email protected]d7e59252012-03-06 22:26:02919 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
[email protected]237a14852012-04-28 02:56:38920 base::allocator::ReleaseFreeMemory();
[email protected]d7e59252012-03-06 22:26:02921 if (v8::V8::IdleNotification(idle_hint)) {
922 // V8 finished collecting garbage.
923 new_delay_ms = kLongIdleHandlerDelayMs;
924 }
[email protected]1784b2f2011-11-24 10:53:48925 }
926 }
[email protected]1784b2f2011-11-24 10:53:48927 ScheduleIdleHandler(new_delay_ms);
928}
929
[email protected]6593ae12011-11-14 12:09:44930int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
931 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06932}
933
[email protected]6593ae12011-11-14 12:09:44934void RenderThreadImpl::SetIdleNotificationDelayInMs(
935 int64 idle_notification_delay_in_ms) {
936 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08937}
938
[email protected]a1a7ff32012-07-19 14:03:51939void RenderThreadImpl::ToggleWebKitSharedTimer(bool suspend) {
940 if (suspend_webkit_shared_timer_) {
941 EnsureWebKitInitialized();
942 if (suspend) {
943 webkit_platform_support_->SuspendSharedTimer();
944 } else {
945 webkit_platform_support_->ResumeSharedTimer();
946 }
947 }
948}
949
950void RenderThreadImpl::UpdateHistograms(int sequence_number) {
951 child_histogram_message_filter()->SendHistograms(sequence_number);
952}
953
[email protected]b02f5902012-12-19 07:33:00954bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
955 bool result = false;
956 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
957 return result;
958}
959
[email protected]1784b2f2011-11-24 10:53:48960void RenderThreadImpl::PostponeIdleNotification() {
961 idle_notifications_to_skip_ = 2;
962}
963
[email protected]fe476b02012-08-13 21:21:38964/* static */
965void RenderThreadImpl::OnGpuVDAContextLoss() {
966 RenderThreadImpl* self = RenderThreadImpl::current();
967 DCHECK(self);
[email protected]59383c782013-04-17 16:43:27968 if (!self->gpu_vda_context3d_)
[email protected]fe476b02012-08-13 21:21:38969 return;
[email protected]ea5f70a2013-03-07 12:30:36970 if (self->compositor_message_loop_proxy()) {
971 self->compositor_message_loop_proxy()->DeleteSoon(
[email protected]fe476b02012-08-13 21:21:38972 FROM_HERE, self->gpu_vda_context3d_.release());
973 } else {
974 self->gpu_vda_context3d_.reset();
[email protected]3b2afc32012-06-18 21:31:16975 }
[email protected]fe476b02012-08-13 21:21:38976}
977
978WebGraphicsContext3DCommandBufferImpl*
979RenderThreadImpl::GetGpuVDAContext3D() {
[email protected]59383c782013-04-17 16:43:27980 if (!gpu_vda_context3d_) {
[email protected]3b2afc32012-06-18 21:31:16981 gpu_vda_context3d_.reset(
982 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
[email protected]d1a9e062012-07-13 00:45:14983 this, WebKit::WebGraphicsContext3D::Attributes(),
984 GURL("chrome://gpu/RenderThreadImpl::GetGpuVDAContext3D")));
[email protected]59383c782013-04-17 16:43:27985 if (gpu_vda_context3d_)
[email protected]fde3e2f2012-08-14 06:51:37986 gpu_vda_context3d_->setContextLostCallback(context_lost_cb_.get());
[email protected]3b2afc32012-06-18 21:31:16987 }
[email protected]fe476b02012-08-13 21:21:38988 return gpu_vda_context3d_.get();
[email protected]3b2afc32012-06-18 21:31:16989}
990
[email protected]c29b7ff2013-03-06 03:51:04991scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
992RenderThreadImpl::CreateOffscreenContext3d() {
993 WebKit::WebGraphicsContext3D::Attributes attributes;
994 attributes.shareResources = true;
995 attributes.depth = false;
996 attributes.stencil = false;
997 attributes.antialias = false;
998 attributes.noAutomaticFlushes = true;
999
1000 return make_scoped_ptr(
1001 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
1002 this,
1003 attributes,
1004 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext3d")));
1005}
1006
[email protected]a45c46e2013-03-07 01:04:461007scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:041008RenderThreadImpl::OffscreenContextProviderForMainThread() {
[email protected]e06e1122013-03-15 17:12:381009 DCHECK(IsMainThread());
1010
[email protected]fc72bb12013-06-02 21:13:461011 if (!shared_contexts_main_thread_.get() ||
[email protected]e06e1122013-03-15 17:12:381012 shared_contexts_main_thread_->DestroyedOnMainThread()) {
1013 shared_contexts_main_thread_ =
1014 RendererContextProviderCommandBuffer::Create();
[email protected]fc72bb12013-06-02 21:13:461015 if (shared_contexts_main_thread_.get() &&
[email protected]e06e1122013-03-15 17:12:381016 !shared_contexts_main_thread_->BindToCurrentThread())
1017 shared_contexts_main_thread_ = NULL;
1018 }
[email protected]c29b7ff2013-03-06 03:51:041019 return shared_contexts_main_thread_;
1020}
1021
[email protected]a45c46e2013-03-07 01:04:461022scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:041023RenderThreadImpl::OffscreenContextProviderForCompositorThread() {
[email protected]e06e1122013-03-15 17:12:381024 DCHECK(IsMainThread());
1025
[email protected]fc72bb12013-06-02 21:13:461026 if (!shared_contexts_compositor_thread_.get() ||
[email protected]c29b7ff2013-03-06 03:51:041027 shared_contexts_compositor_thread_->DestroyedOnMainThread()) {
1028 shared_contexts_compositor_thread_ =
[email protected]e06e1122013-03-15 17:12:381029 RendererContextProviderCommandBuffer::Create();
[email protected]c29b7ff2013-03-06 03:51:041030 }
1031 return shared_contexts_compositor_thread_;
1032}
1033
[email protected]e9ff79c2012-10-19 21:31:261034AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]59383c782013-04-17 16:43:271035 if (!audio_renderer_mixer_manager_) {
[email protected]3958e972012-07-17 00:25:411036 audio_renderer_mixer_manager_.reset(new AudioRendererMixerManager(
[email protected]563d665f2013-02-01 04:42:391037 GetAudioHardwareConfig()));
[email protected]3958e972012-07-17 00:25:411038 }
1039
1040 return audio_renderer_mixer_manager_.get();
1041}
1042
[email protected]563d665f2013-02-01 04:42:391043media::AudioHardwareConfig* RenderThreadImpl::GetAudioHardwareConfig() {
1044 if (!audio_hardware_config_) {
[email protected]06ea4f7c2013-03-13 20:36:511045 media::AudioParameters input_params;
1046 media::AudioParameters output_params;
[email protected]563d665f2013-02-01 04:42:391047 Send(new ViewHostMsg_GetAudioHardwareConfig(
[email protected]06ea4f7c2013-03-13 20:36:511048 &input_params, &output_params));
[email protected]563d665f2013-02-01 04:42:391049
1050 audio_hardware_config_.reset(new media::AudioHardwareConfig(
[email protected]06ea4f7c2013-03-13 20:36:511051 input_params, output_params));
[email protected]563d665f2013-02-01 04:42:391052 audio_message_filter_->SetAudioHardwareConfig(audio_hardware_config_.get());
1053 }
1054
1055 return audio_hardware_config_.get();
1056}
1057
[email protected]4a7d6392011-09-19 20:55:081058#if defined(OS_WIN)
[email protected]feb32372012-11-21 01:14:561059void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font,
1060 const string16& str) {
1061 Send(new ViewHostMsg_PreCacheFontCharacters(log_font, str));
1062}
1063
[email protected]f1a29a02011-10-06 23:08:441064void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:061065 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:211066}
1067
[email protected]f1a29a02011-10-06 23:08:441068void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:061069 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:081070}
[email protected]526476902011-10-06 20:34:061071
[email protected]4a7d6392011-09-19 20:55:081072#endif // OS_WIN
1073
[email protected]988aacf2012-02-12 18:10:031074bool RenderThreadImpl::IsWebFrameValid(WebKit::WebFrame* web_frame) {
1075 if (!web_frame)
[email protected]4761cf12012-09-12 10:37:551076 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031077
1078 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
1079 if (!render_view)
[email protected]4761cf12012-09-12 10:37:551080 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031081
1082 return true;
1083}
1084
[email protected]b3e83de2012-02-07 03:33:281085bool RenderThreadImpl::IsMainThread() {
1086 return !!current();
1087}
1088
1089bool RenderThreadImpl::IsIOThread() {
[email protected]dd32b1272013-05-04 14:17:111090 return base::MessageLoop::current() ==
1091 ChildProcess::current()->io_message_loop();
[email protected]b3e83de2012-02-07 03:33:281092}
1093
[email protected]9e7154122013-05-30 23:11:041094base::MessageLoop* RenderThreadImpl::GetMainLoop() {
[email protected]b3e83de2012-02-07 03:33:281095 return message_loop();
1096}
[email protected]5b040e592012-02-10 02:56:101097
1098scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() {
[email protected]b3e83de2012-02-07 03:33:281099 return ChildProcess::current()->io_message_loop_proxy();
1100}
1101
1102base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() {
1103 return ChildProcess::current()->GetShutDownEvent();
1104}
1105
1106scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory(
[email protected]3f892832013-01-11 03:23:591107 size_t size) {
[email protected]fb79aa22012-12-13 01:12:131108 return scoped_ptr<base::SharedMemory>(
1109 HostAllocateSharedMemoryBuffer(size));
[email protected]b3e83de2012-02-07 03:33:281110}
1111
1112int32 RenderThreadImpl::CreateViewCommandBuffer(
1113 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) {
[email protected]d13f35d2012-05-18 02:28:151114 TRACE_EVENT1("gpu",
1115 "RenderThreadImpl::CreateViewCommandBuffer",
1116 "surface_id",
1117 surface_id);
1118
[email protected]b3e83de2012-02-07 03:33:281119 int32 route_id = MSG_ROUTING_NONE;
[email protected]8b10b332012-02-29 21:02:141120 IPC::Message* message = new GpuHostMsg_CreateViewCommandBuffer(
[email protected]b3e83de2012-02-07 03:33:281121 surface_id,
1122 init_params,
[email protected]8b10b332012-02-29 21:02:141123 &route_id);
1124
1125 // Allow calling this from the compositor thread.
[email protected]dd32b1272013-05-04 14:17:111126 if (base::MessageLoop::current() == message_loop())
[email protected]8b10b332012-02-29 21:02:141127 ChildThread::Send(message);
1128 else
1129 sync_message_filter()->Send(message);
1130
[email protected]b3e83de2012-02-07 03:33:281131 return route_id;
1132}
1133
[email protected]09d50362012-10-18 20:54:371134void RenderThreadImpl::CreateImage(
1135 gfx::PluginWindowHandle window,
1136 int32 image_id,
1137 const CreateImageCallback& callback) {
1138 NOTREACHED();
1139}
1140
1141void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) {
1142 NOTREACHED();
1143}
1144
[email protected]f1a29a02011-10-06 23:08:441145void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:061146 suspend_webkit_shared_timer_ = false;
1147}
1148
[email protected]f1a29a02011-10-06 23:08:441149void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:061150 notify_webkit_of_modal_loop_ = false;
1151}
1152
[email protected]367c5c1d2013-03-11 18:59:021153void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& scheme,
1154 const std::string& host,
[email protected]f1a29a02011-10-06 23:08:441155 double zoom_level) {
[email protected]367c5c1d2013-03-11 18:59:021156 RenderViewZoomer zoomer(scheme, host, zoom_level);
[email protected]e9ff79c2012-10-19 21:31:261157 RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:061158}
1159
[email protected]f1a29a02011-10-06 23:08:441160bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:501161 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
1162 RenderProcessObserver* observer;
1163 while ((observer = it.GetNext()) != NULL) {
1164 if (observer->OnControlMessageReceived(msg))
1165 return true;
1166 }
1167
[email protected]70c19a932010-05-14 12:59:111168 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101169 if (appcache_dispatcher_->OnMessageReceived(msg) ||
1170 dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281171 return true;
[email protected]1910fe82012-05-10 00:04:101172 }
[email protected]1edc16b82009-04-07 17:45:541173
[email protected]a95986a82010-12-24 06:19:281174 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:441175 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:541176 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
1177 OnSetZoomLevelForCurrentURL)
[email protected]8930d472009-02-21 08:05:281178 // TODO(port): removed from render_messages_internal.h;
1179 // is there a new non-windows message I should add here?
1180 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:451181 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:091182 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]b69934e2011-10-29 02:51:521183 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]44363382013-03-12 07:22:471184 IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended,
1185 OnSetWebKitSharedTimersSuspended)
[email protected]a95986a82010-12-24 06:19:281186 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281187 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281188 return handled;
initial.commit09911bf2008-07-26 23:55:291189}
1190
[email protected]f1a29a02011-10-06 23:08:441191void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:471192 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:331193 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]6cd7c6b2012-10-25 03:26:231194 RenderViewImpl::Create(
[email protected]6cd7c6b2012-10-25 03:26:231195 params.opener_route_id,
1196 params.renderer_preferences,
1197 params.web_preferences,
1198 new SharedRenderViewCounter(0),
1199 params.view_id,
[email protected]227692c52013-05-31 22:43:041200 params.main_frame_routing_id,
[email protected]6cd7c6b2012-10-25 03:26:231201 params.surface_id,
1202 params.session_storage_namespace_id,
1203 params.frame_name,
1204 false,
1205 params.swapped_out,
1206 params.next_page_id,
1207 params.screen_info,
[email protected]34bb3ac2013-03-08 02:41:281208 params.accessibility_mode,
1209 params.allow_partial_swap);
[email protected]7f874dec2009-02-06 01:48:271210}
[email protected]4274e582009-01-27 22:09:561211
[email protected]f1a29a02011-10-06 23:08:441212GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:261213 CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]d13f35d2012-05-18 02:28:151214 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1215
[email protected]fc72bb12013-06-02 21:13:461216 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:221217 // Do nothing if we already have a GPU channel or are already
1218 // establishing one.
[email protected]e09cee42010-11-09 01:50:081219 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
1220 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:041221 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:351222
1223 // Recreate the channel if it has been lost.
[email protected]894e8fc2012-02-24 13:29:501224 gpu_channel_ = NULL;
[email protected]6217d392010-03-25 22:08:351225 }
1226
[email protected]6217d392010-03-25 22:08:351227 // Ask the browser for the channel name.
[email protected]894e8fc2012-02-24 13:29:501228 int client_id = 0;
[email protected]b42a9f62011-06-08 20:36:041229 IPC::ChannelHandle channel_handle;
[email protected]d7b5cc72013-05-23 20:05:001230 gpu::GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:041231 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
[email protected]894e8fc2012-02-24 13:29:501232 &client_id,
[email protected]b42a9f62011-06-08 20:36:041233 &channel_handle,
[email protected]b42a9f62011-06-08 20:36:041234 &gpu_info)) ||
[email protected]8bc550e2012-02-07 11:05:561235#if defined(OS_POSIX)
1236 channel_handle.socket.fd == -1 ||
1237#endif
[email protected]cd0bd792012-04-14 00:52:161238 channel_handle.name.empty()) {
[email protected]b42a9f62011-06-08 20:36:041239 // Otherwise cancel the connection.
1240 gpu_channel_ = NULL;
1241 return NULL;
1242 }
[email protected]6217d392010-03-25 22:08:351243
[email protected]03dc8882012-03-08 23:46:291244 gpu_channel_ = new GpuChannelHost(this, 0, client_id);
[email protected]b42a9f62011-06-08 20:36:041245 gpu_channel_->set_gpu_info(gpu_info);
[email protected]e9ff79c2012-10-19 21:31:261246 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]b42a9f62011-06-08 20:36:041247
1248 // Connect to the GPU process if a channel name was received.
[email protected]cd0bd792012-04-14 00:52:161249 gpu_channel_->Connect(channel_handle);
[email protected]b42a9f62011-06-08 20:36:041250
[email protected]f9a2b2fe2010-07-15 21:13:231251 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:341252}
1253
[email protected]d8cd8372012-03-09 10:49:511254WebKit::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1255 WebKit::WebMediaStreamCenterClient* client) {
[email protected]d9da9582013-01-31 04:59:051256#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:161257 if (CommandLine::ForCurrentProcess()->HasSwitch(
1258 switches::kDisableWebRTC))
[email protected]d9da9582013-01-31 04:59:051259 return NULL;
1260#endif
1261
[email protected]d8cd8372012-03-09 10:49:511262#if defined(ENABLE_WEBRTC)
[email protected]68e5fee2013-02-18 10:04:221263 if (!media_stream_center_) {
1264 media_stream_center_ = GetContentClient()->renderer()
1265 ->OverrideCreateWebMediaStreamCenter(client);
1266 if (!media_stream_center_) {
1267 media_stream_center_ = new MediaStreamCenter(
1268 client, GetMediaStreamDependencyFactory());
1269 }
1270 }
[email protected]d8cd8372012-03-09 10:49:511271#endif
1272 return media_stream_center_;
1273}
1274
[email protected]6ee10bd2012-09-13 09:01:531275MediaStreamDependencyFactory*
1276RenderThreadImpl::GetMediaStreamDependencyFactory() {
1277#if defined(ENABLE_WEBRTC)
[email protected]59383c782013-04-17 16:43:271278 if (!media_stream_factory_) {
[email protected]6ee10bd2012-09-13 09:01:531279 media_stream_factory_.reset(new MediaStreamDependencyFactory(
[email protected]fc72bb12013-06-02 21:13:461280 vc_manager_.get(), p2p_socket_dispatcher_.get()));
[email protected]6ee10bd2012-09-13 09:01:531281 }
1282#endif
1283 return media_stream_factory_.get();
1284}
1285
[email protected]f1a29a02011-10-06 23:08:441286GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]fc72bb12013-06-02 21:13:461287 if (!gpu_channel_.get())
[email protected]6217d392010-03-25 22:08:351288 return NULL;
1289
[email protected]e09cee42010-11-09 01:50:081290 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:351291 return NULL;
1292
1293 return gpu_channel_.get();
1294}
1295
[email protected]f1a29a02011-10-06 23:08:441296void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591297 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271298 // The call below will cause a GetPlugins call with refresh=true, but at this
1299 // point we already know that the browser has refreshed its list, so disable
1300 // refresh temporarily to prevent each renderer process causing the list to be
1301 // regenerated.
[email protected]a70b4352012-07-31 22:34:531302 webkit_platform_support_->set_plugin_refresh_allowed(false);
[email protected]b78e168b2009-09-21 22:05:451303 WebKit::resetPluginCache(reload_pages);
[email protected]a70b4352012-07-31 22:34:531304 webkit_platform_support_->set_plugin_refresh_allowed(true);
[email protected]3b48dbc2012-01-06 16:34:171305
1306 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:271307}
[email protected]85c55dc2009-11-06 03:05:461308
[email protected]f1a29a02011-10-06 23:08:441309void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:091310 EnsureWebKitInitialized();
1311 WebNetworkStateNotifier::setOnLine(online);
1312}
1313
[email protected]b69934e2011-10-29 02:51:521314void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
[email protected]e9ff79c2012-10-19 21:31:261315 GetContentClient()->SetActiveURL(data);
[email protected]b69934e2011-10-29 02:51:521316 CHECK(false);
1317}
1318
[email protected]44363382013-03-12 07:22:471319void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) {
1320 ToggleWebKitSharedTimer(suspend);
1321}
1322
[email protected]c6a7b862010-08-20 22:19:381323scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:441324RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]dd32b1272013-05-04 14:17:111325 DCHECK(message_loop() == base::MessageLoop::current());
[email protected]59383c782013-04-17 16:43:271326 if (!file_thread_) {
[email protected]c6a7b862010-08-20 22:19:381327 file_thread_.reset(new base::Thread("Renderer::FILE"));
1328 file_thread_->Start();
1329 }
1330 return file_thread_->message_loop_proxy();
1331}
[email protected]e9ff79c2012-10-19 21:31:261332
[email protected]107c0532013-02-06 02:34:091333void RenderThreadImpl::SetFlingCurveParameters(
1334 const std::vector<float>& new_touchpad,
1335 const std::vector<float>& new_touchscreen) {
1336 webkit_platform_support_->SetFlingCurveParameters(new_touchpad,
1337 new_touchscreen);
1338
1339}
1340
[email protected]e9ff79c2012-10-19 21:31:261341} // namespace content