blob: 58cd3f73731723b0e25920bd595e6c0bcb7b2ceb [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]58436a12012-03-21 17:10:2625#include "base/utf_string_conversions.h"
[email protected]7a4de7a62010-08-17 18:38:2426#include "base/values.h"
[email protected]e93e04e2011-03-14 00:27:1027#include "content/common/appcache/appcache_dispatcher.h"
[email protected]83ab4a282012-07-12 18:19:4528#include "content/common/child_histogram_message_filter.h"
[email protected]bdae9812011-10-15 00:33:0329#include "content/common/child_process_messages.h"
[email protected]37666cf2011-03-13 21:51:4230#include "content/common/database_messages.h"
31#include "content/common/db_message_filter.h"
[email protected]127dd582011-03-16 21:32:1032#include "content/common/dom_storage_messages.h"
[email protected]c29b7ff2013-03-06 03:51:0433#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]c26ad882012-02-07 06:41:2034#include "content/common/gpu/client/gpu_channel_host.h"
[email protected]202b54ff2011-04-22 21:36:3835#include "content/common/gpu/gpu_messages.h"
[email protected]988aacf2012-02-12 18:10:0336#include "content/common/indexed_db/indexed_db_dispatcher.h"
37#include "content/common/indexed_db/indexed_db_message_filter.h"
[email protected]d3fd748b2011-09-20 17:39:1738#include "content/common/npobject_util.h"
[email protected]105303e2011-03-14 22:16:1039#include "content/common/plugin_messages.h"
[email protected]359dfa32011-10-12 01:10:1540#include "content/common/resource_dispatcher.h"
[email protected]94dc971d2011-03-05 19:08:3241#include "content/common/resource_messages.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
[email protected]e93e04e2011-03-14 00:27:1043#include "content/common/web_database_observer_impl.h"
[email protected]a458504b2012-07-23 19:57:0644#include "content/public/common/content_constants.h"
[email protected]433df472012-03-07 20:33:3945#include "content/public/common/content_paths.h"
[email protected]c08950d22011-10-13 22:20:2946#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3147#include "content/public/common/renderer_preferences.h"
[email protected]58436a12012-03-21 17:10:2648#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3449#include "content/public/renderer/content_renderer_client.h"
[email protected]64ffa0442011-10-03 22:08:3650#include "content/public/renderer/render_process_observer.h"
51#include "content/public/renderer/render_view_visitor.h"
[email protected]70019152012-12-19 11:44:1952#include "content/renderer/devtools/devtools_agent_filter.h"
[email protected]1910fe82012-05-10 00:04:1053#include "content/renderer/dom_storage/dom_storage_dispatcher.h"
54#include "content/renderer/dom_storage/webstoragearea_impl.h"
55#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]1842fe22012-08-13 23:24:3556#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]e54ab492012-06-12 19:40:0157#include "content/renderer/gpu/gpu_benchmarking_extension.h"
[email protected]ea5f70a2013-03-07 12:30:3658#include "content/renderer/gpu/input_handler_manager.h"
[email protected]f7eb0a392011-07-12 10:19:5159#include "content/renderer/media/audio_input_message_filter.h"
60#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:4161#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]d8cd8372012-03-09 10:49:5162#include "content/renderer/media/media_stream_center.h"
[email protected]6ee10bd2012-09-13 09:01:5363#include "content/renderer/media/media_stream_dependency_factory.h"
[email protected]af089972013-01-10 04:04:4064#include "content/renderer/media/peer_connection_tracker.h"
[email protected]80b161a2011-06-27 17:42:1165#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:3466#include "content/renderer/media/video_capture_message_filter.h"
[email protected]6941ac5c2013-02-07 03:59:5667#include "content/renderer/memory_benchmarking_extension.h"
[email protected]4761cf12012-09-12 10:37:5568#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3569#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0570#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:2871#include "content/renderer/render_view_impl.h"
[email protected]8d6cba42011-09-02 10:05:1972#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]766a7082012-02-03 23:39:1573#include "grit/content_resources.h"
[email protected]46f36a492010-07-28 19:36:4174#include "ipc/ipc_channel_handle.h"
[email protected]1842fe22012-08-13 23:24:3575#include "ipc/ipc_forwarding_message_filter.h"
[email protected]cb6037d2009-11-16 22:55:1776#include "ipc/ipc_platform_file.h"
[email protected]563d665f2013-02-01 04:42:3977#include "media/base/audio_hardware_config.h"
[email protected]433df472012-03-07 20:33:3978#include "media/base/media.h"
[email protected]47ebb0e2012-11-30 08:28:2979#include "media/base/media_switches.h"
[email protected]620161e2011-03-07 18:05:2680#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5481#include "net/base/net_util.h"
[email protected]cd7ce3be2012-09-10 05:19:4182#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
83#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSupport.h"
[email protected]1332623f12012-08-10 03:45:1384#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
[email protected]f8c648b2012-02-28 03:46:4585#include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h"
[email protected]8bd0fe62011-01-17 06:44:3786#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3788#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]2a23d3f52013-01-08 01:20:2489#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
[email protected]8bd0fe62011-01-17 06:44:3790#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]6eac57a2011-07-12 21:15:0991#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]4bd55a32011-07-28 13:28:3892#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
[email protected]8bd0fe62011-01-17 06:44:3793#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
[email protected]58436a12012-03-21 17:10:2695#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]00fccb42012-12-11 00:09:5996#include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerRepository.h"
[email protected]61a796c42012-05-17 21:28:2097#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]c49201a2012-05-24 11:04:5798#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:3299#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:50100#include "v8/include/v8.h"
[email protected]d471190a2011-02-16 14:52:30101#include "webkit/glue/webkit_glue.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"
110#include "content/common/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]b6cb3a842011-06-24 18:28:41121using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:01122using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:09123using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:00124using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:51125using WebKit::WebScriptController;
[email protected]58436a12012-03-21 17:10:26126using WebKit::WebSecurityPolicy;
[email protected]2c434b32009-03-19 06:27:47127using WebKit::WebString;
[email protected]50ae00ef2009-10-19 05:11:03128using WebKit::WebView;
[email protected]e9ff79c2012-10-19 21:31:26129
130namespace content {
initial.commit09911bf2008-07-26 23:55:29131
[email protected]42f1d7822009-07-23 18:17:55132namespace {
[email protected]da9ccfb2012-01-28 00:34:40133
134const int64 kInitialIdleHandlerDelayMs = 1000;
135const int64 kShortIdleHandlerDelayMs = 1000;
136const int64 kLongIdleHandlerDelayMs = 30*1000;
137const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03138
[email protected]f1a29a02011-10-06 23:08:44139// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16140// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40141base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49142 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54143
[email protected]e9ff79c2012-10-19 21:31:26144class RenderViewZoomer : public RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51145 public:
[email protected]367c5c1d2013-03-11 18:59:02146 RenderViewZoomer(const std::string& scheme,
147 const std::string& host,
148 double zoom_level) : scheme_(scheme),
149 host_(host),
150 zoom_level_(zoom_level) {
[email protected]40bd6582009-12-04 23:49:51151 }
152
[email protected]c3e35892013-02-12 02:08:01153 virtual bool Visit(RenderView* render_view) OVERRIDE {
[email protected]a2ef54c2011-10-10 16:20:31154 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41155 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25156
157 // Don't set zoom level for full-page plugin since they don't use the same
158 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41159 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25160 return true;
[email protected]367c5c1d2013-03-11 18:59:02161 GURL url(document.url());
162 // Empty scheme works as wildcard that matches any scheme,
163 if ((net::GetHostOrSpecFromURL(url) == host_) &&
164 (scheme_.empty() || scheme_ == url.scheme())) {
[email protected]40bd6582009-12-04 23:49:51165 webview->setZoomLevel(false, zoom_level_);
[email protected]367c5c1d2013-03-11 18:59:02166 }
[email protected]40bd6582009-12-04 23:49:51167 return true;
168 }
169
170 private:
[email protected]367c5c1d2013-03-11 18:59:02171 const std::string scheme_;
172 const std::string host_;
173 const double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51174
175 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
176};
[email protected]0478d0162010-08-28 08:29:40177
[email protected]b2d98762012-09-03 17:04:06178std::string HostToCustomHistogramSuffix(const std::string& host) {
179 if (host == "mail.google.com")
180 return ".gmail";
181 if (host == "docs.google.com" || host == "drive.google.com")
182 return ".docs";
183 if (host == "plus.google.com")
184 return ".plus";
185 return "";
186}
[email protected]42f1d7822009-07-23 18:17:55187
[email protected]b2d98762012-09-03 17:04:06188void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13189 const char *name, int min, int max, size_t buckets) {
190 if (min <= 0)
191 min = 1;
[email protected]b2d98762012-09-03 17:04:06192 std::string histogram_name;
193 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
194 if (render_thread_impl) { // Can be null in tests.
195 histogram_name = render_thread_impl->
196 histogram_customizer()->ConvertToCustomHistogramName(name);
197 } else {
198 histogram_name = std::string(name);
199 }
[email protected]de415552013-01-23 04:12:17200 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06201 histogram_name, min, max, buckets,
202 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13203 return histogram;
204}
205
[email protected]b2d98762012-09-03 17:04:06206void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13207 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
208 histogram->Add(sample);
209}
210
[email protected]950f9ce22012-12-27 00:25:07211#if defined(ENABLE_WEBRTC)
[email protected]da0f6952012-12-26 22:22:39212const unsigned char* GetCategoryEnabled(const char* name) {
213 return TRACE_EVENT_API_GET_CATEGORY_ENABLED(name);
214}
215
216void AddTraceEvent(char phase,
217 const unsigned char* category_enabled,
218 const char* name,
219 unsigned long long id,
220 int num_args,
221 const char** arg_names,
222 const unsigned char* arg_types,
223 const unsigned long long* arg_values,
224 unsigned char flags) {
225 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_enabled, name, id, num_args,
226 arg_names, arg_types, arg_values, flags);
227}
[email protected]950f9ce22012-12-27 00:25:07228#endif
[email protected]da0f6952012-12-26 22:22:39229
[email protected]b2d98762012-09-03 17:04:06230} // namespace
231
[email protected]fe476b02012-08-13 21:21:38232class RenderThreadImpl::GpuVDAContextLostCallback
233 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
234 public:
235 GpuVDAContextLostCallback() {}
236 virtual ~GpuVDAContextLostCallback() {}
237 virtual void onContextLost() {
238 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind(
239 &RenderThreadImpl::OnGpuVDAContextLoss));
240 }
241};
242
[email protected]00874dd2013-03-08 23:51:18243class RenderThreadImpl::RendererContextProviderCommandBuffer
244 : public ContextProviderCommandBuffer {
245 protected:
246 virtual ~RendererContextProviderCommandBuffer() {}
247
248 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
249 CreateOffscreenContext3d() {
250 RenderThreadImpl* self = RenderThreadImpl::current();
251 DCHECK(self);
252 return self->CreateOffscreenContext3d().Pass();
253 }
254};
255
[email protected]b2d98762012-09-03 17:04:06256RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
257 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
258 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
259 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
260}
261
262RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
263
264void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
265 const std::string& host, size_t view_count) {
[email protected]9baee832012-12-10 11:07:15266 if (CommandLine::ForCurrentProcess()->HasSwitch(
267 switches::kDisableHistogramCustomizer)) {
268 return;
269 }
[email protected]b2d98762012-09-03 17:04:06270 // Check if all RenderViews are displaying a page from the same host. If there
271 // is only one RenderView, the common host is this view's host. If there are
272 // many, check if this one shares the common host of the other
273 // RenderViews. It's ok to not detect some cases where the RenderViews share a
274 // common host. This information is only used for producing custom histograms.
275 if (view_count == 1)
276 SetCommonHost(host);
277 else if (host != common_host_)
278 SetCommonHost(std::string());
279}
280
281std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
282 const char* histogram_name) const {
283 std::string name(histogram_name);
284 if (!common_host_histogram_suffix_.empty() &&
285 custom_histograms_.find(name) != custom_histograms_.end())
286 name += common_host_histogram_suffix_;
287 return name;
288}
289
290void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
291 const std::string& host) {
292 if (host != common_host_) {
293 common_host_ = host;
294 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
295 v8::V8::SetCreateHistogramFunction(CreateHistogram);
296 }
297}
298
[email protected]f1a29a02011-10-06 23:08:44299RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06300 return lazy_tls.Pointer()->Get();
301}
302
[email protected]42f1d7822009-07-23 18:17:55303// When we run plugins in process, we actually run them on the render thread,
304// which means that we need to make the render thread pump UI events.
[email protected]f1a29a02011-10-06 23:08:44305RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55306 Init();
307}
308
[email protected]f1a29a02011-10-06 23:08:44309RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55310 : ChildThread(channel_name) {
311 Init();
312}
[email protected]5fa1c542009-05-05 20:36:07313
[email protected]f1a29a02011-10-06 23:08:44314void RenderThreadImpl::Init() {
315 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33316
[email protected]c7e948b42012-07-12 09:20:20317 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
318 v8::V8::SetCreateHistogramFunction(CreateHistogram);
319 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
320
[email protected]d3f09092012-02-16 01:52:17321#if defined(OS_MACOSX) || defined(OS_ANDROID)
322 // On Mac and Android, the select popups are rendered by the browser.
[email protected]53c607c2011-03-21 23:19:04323 WebKit::WebView::setUseExternalPopupMenus(true);
324#endif
325
[email protected]94f9a0f682009-06-15 18:30:30326 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28327
[email protected]2c62b562009-01-27 19:04:50328#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34329 // If you are running plugins in this thread you need COM active but in
330 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28331 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12332 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50333#endif
initial.commit09911bf2008-07-26 23:55:29334
[email protected]06c694d2012-02-01 22:26:16335 // Register this object as the main thread.
336 ChildProcess::current()->set_main_thread(this);
337
[email protected]31f87132010-04-21 23:36:21338 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50339 suspend_webkit_shared_timer_ = true;
340 notify_webkit_of_modal_loop_ = true;
[email protected]bee16aab2009-08-26 15:55:03341 widget_count_ = 0;
342 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44343 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48344 idle_notifications_to_skip_ = 0;
[email protected]e1176152013-03-06 09:16:44345 should_send_focus_ipcs_ = true;
[email protected]8be1c582013-03-06 00:55:03346 short_circuit_size_updates_ = false;
[email protected]8d86fce2009-02-26 23:37:55347
[email protected]dcc72db2013-01-02 00:44:18348 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
[email protected]1910fe82012-05-10 00:04:10349 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
[email protected]dcc72db2013-01-02 00:44:18350 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13351
[email protected]d8cd8372012-03-09 10:49:51352 media_stream_center_ = NULL;
353
[email protected]017022b2009-07-27 23:06:34354 db_message_filter_ = new DBMessageFilter();
355 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13356
[email protected]4761cf12012-09-12 10:37:55357#if defined(ENABLE_WEBRTC)
[email protected]da0f6952012-12-26 22:22:39358 webrtc::SetupEventTracer(&GetCategoryEnabled, &AddTraceEvent);
[email protected]af089972013-01-10 04:04:40359
360 peer_connection_tracker_.reset(new PeerConnectionTracker());
361 AddObserver(peer_connection_tracker_.get());
362
[email protected]e9ff79c2012-10-19 21:31:26363 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy());
[email protected]4761cf12012-09-12 10:37:55364 AddFilter(p2p_socket_dispatcher_);
365#endif // defined(ENABLE_WEBRTC)
[email protected]80b161a2011-06-27 17:42:11366 vc_manager_ = new VideoCaptureImplManager();
367 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46368
[email protected]e0a938702013-02-25 21:15:56369 audio_input_message_filter_ =
370 new AudioInputMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51371 AddFilter(audio_input_message_filter_.get());
372
[email protected]e0a938702013-02-25 21:15:56373 audio_message_filter_ = new AudioMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51374 AddFilter(audio_message_filter_.get());
375
[email protected]31bfae72011-12-16 02:04:38376 AddFilter(new IndexedDBMessageFilter);
377
[email protected]e9ff79c2012-10-19 21:31:26378 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24379
[email protected]302fe422012-06-11 14:49:11380 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01381 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking))
[email protected]e9ff79c2012-10-19 21:31:26382 RegisterExtension(GpuBenchmarkingExtension::Get());
[email protected]e54ab492012-06-12 19:40:01383
[email protected]6941ac5c2013-02-07 03:59:56384 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
385 RegisterExtension(MemoryBenchmarkingExtension::Get());
386
[email protected]fe476b02012-08-13 21:21:38387 context_lost_cb_.reset(new GpuVDAContextLostCallback());
388
[email protected]433df472012-03-07 20:33:39389 // Note that under Linux, the media library will normally already have
390 // been initialized by the Zygote before this instance became a Renderer.
[email protected]c42de732013-02-16 06:26:31391 base::FilePath media_path;
[email protected]e9ff79c2012-10-19 21:31:26392 PathService::Get(DIR_MEDIA_LIBS, &media_path);
[email protected]433df472012-03-07 20:33:39393 if (!media_path.empty())
394 media::InitializeMediaLibrary(media_path);
395
[email protected]f1a29a02011-10-06 23:08:44396 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29397}
398
[email protected]f1a29a02011-10-06 23:08:44399RenderThreadImpl::~RenderThreadImpl() {
[email protected]1223d6ef2011-03-28 16:47:50400 FOR_EACH_OBSERVER(
401 RenderProcessObserver, observers_, OnRenderProcessShutdown());
402
[email protected]12cbfda32010-01-30 01:04:25403 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08404 if (web_database_observer_impl_.get())
405 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25406
[email protected]8d86fce2009-02-26 23:37:55407 // Shutdown in reverse of the initialization order.
[email protected]b146d6d2012-09-11 10:20:05408 if (devtools_agent_message_filter_.get()) {
409 RemoveFilter(devtools_agent_message_filter_.get());
410 devtools_agent_message_filter_ = NULL;
411 }
[email protected]82622452011-07-22 09:57:20412
[email protected]f7eb0a392011-07-12 10:19:51413 RemoveFilter(audio_input_message_filter_.get());
414 audio_input_message_filter_ = NULL;
415
416 RemoveFilter(audio_message_filter_.get());
417 audio_message_filter_ = NULL;
418
[email protected]80b161a2011-06-27 17:42:11419 RemoveFilter(vc_manager_->video_capture_message_filter());
420
[email protected]017022b2009-07-27 23:06:34421 RemoveFilter(db_message_filter_.get());
422 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25423
[email protected]c6a7b862010-08-20 22:19:38424 // Shutdown the file thread if it's running.
425 if (file_thread_.get())
426 file_thread_->Stop();
427
[email protected]23d2b7e2012-08-14 00:34:09428 if (compositor_output_surface_filter_.get()) {
429 RemoveFilter(compositor_output_surface_filter_.get());
430 compositor_output_surface_filter_ = NULL;
431 }
[email protected]1842fe22012-08-13 23:24:35432
[email protected]ea5f70a2013-03-07 12:30:36433 if (input_handler_manager_.get()) {
434 RemoveFilter(input_handler_manager_->GetMessageFilter());
435 input_handler_manager_.reset();
[email protected]a9fb30aa2011-10-06 06:58:46436 }
437
[email protected]8d6cba42011-09-02 10:05:19438 if (webkit_platform_support_.get())
[email protected]9291ed12009-07-23 17:33:22439 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22440
[email protected]94f9a0f682009-06-15 18:30:30441 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30442
[email protected]8d86fce2009-02-26 23:37:55443 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50444#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29445 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50446 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50447#endif
[email protected]00874dd2013-03-08 23:51:18448
449 // Leak shared contexts on other threads, as we can not get to the correct
450 // thread to destroy them.
451 if (shared_contexts_compositor_thread_)
452 shared_contexts_compositor_thread_->set_leak_on_destroy();
initial.commit09911bf2008-07-26 23:55:29453}
454
[email protected]f1a29a02011-10-06 23:08:44455bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14456 // Certain synchronous messages cannot always be processed synchronously by
457 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50458 // This could cause a complete hang of Chrome if a windowed plug-in is trying
459 // to communicate with the renderer thread since the browser's UI thread
460 // could be stuck (within a Windows API call) trying to synchronously
461 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14462 // thread while the browser is processing this request. This creates an
463 // opportunity for re-entrancy into WebKit, so we need to take care to disable
464 // callbacks, timers, and pending network loads that could trigger such
465 // callbacks.
[email protected]38b592902011-04-16 02:08:42466 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50467 if (msg->is_sync()) {
468 if (msg->is_caller_pumping_messages()) {
469 pumping_events = true;
470 } else {
[email protected]38b592902011-04-16 02:08:42471 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
472 msg->type() == ViewHostMsg_GetRawCookies::ID ||
473 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
[email protected]e9ff79c2012-10-19 21:31:26474 GetContentClient()->renderer()->
[email protected]38b592902011-04-16 02:08:42475 ShouldPumpEventsDuringCookieMessage()) {
476 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50477 }
478 }
[email protected]c1f50aa2010-02-18 03:46:57479 }
480
[email protected]80fc08c52010-03-09 07:43:50481 bool suspend_webkit_shared_timer = true; // default value
482 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57483
[email protected]80fc08c52010-03-09 07:43:50484 bool notify_webkit_of_modal_loop = true; // default value
485 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
486
[email protected]c48de1a2012-11-02 19:06:56487 int render_view_id = MSG_ROUTING_NONE;
[email protected]c1f50aa2010-02-18 03:46:57488
489 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50490 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19491 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57492
[email protected]39065d012010-07-09 11:22:46493 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57494 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57495
[email protected]80fc08c52010-03-09 07:43:50496 RenderWidget* widget =
497 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
498 if (widget) {
[email protected]c48de1a2012-11-02 19:06:56499 render_view_id = widget->routing_id();
[email protected]c1f50aa2010-02-18 03:46:57500 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56501 new PluginMsg_SignalModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57502 }
503 }
504
505 bool rv = ChildThread::Send(msg);
506
507 if (pumping_events) {
[email protected]c48de1a2012-11-02 19:06:56508 if (render_view_id != MSG_ROUTING_NONE) {
[email protected]c1f50aa2010-02-18 03:46:57509 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56510 new PluginMsg_ResetModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57511 }
512
[email protected]39065d012010-07-09 11:22:46513 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57514 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57515
[email protected]80fc08c52010-03-09 07:43:50516 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19517 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57518 }
519
520 return rv;
521}
522
[email protected]f1a29a02011-10-06 23:08:44523MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06524 return message_loop();
525}
526
[email protected]f1a29a02011-10-06 23:08:44527IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06528 return channel();
529}
530
[email protected]f1a29a02011-10-06 23:08:44531std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06532 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:02533 // --lang command line flag.
[email protected]526476902011-10-06 20:34:06534 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
535 const std::string& lang =
536 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:02537 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:06538 return lang;
539}
540
[email protected]07bb6332012-01-21 01:07:57541IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
542 return sync_message_filter();
543}
544
[email protected]96191d52012-05-17 01:37:11545scoped_refptr<base::MessageLoopProxy>
546 RenderThreadImpl::GetIOMessageLoopProxy() {
547 return ChildProcess::current()->io_message_loop_proxy();
548}
549
[email protected]c47317e2012-06-20 22:35:31550void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57551 widget_count_++;
552 return ChildThread::AddRoute(routing_id, listener);
553}
554
[email protected]f1a29a02011-10-06 23:08:44555void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57556 widget_count_--;
557 return ChildThread::RemoveRoute(routing_id);
558}
559
[email protected]77fc9b92011-10-15 16:20:37560int RenderThreadImpl::GenerateRoutingID() {
561 int routing_id = MSG_ROUTING_NONE;
562 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
563 return routing_id;
564}
565
[email protected]f1a29a02011-10-06 23:08:44566void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55567 channel()->AddFilter(filter);
568}
569
[email protected]f1a29a02011-10-06 23:08:44570void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55571 channel()->RemoveFilter(filter);
572}
573
[email protected]f1a29a02011-10-06 23:08:44574void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06575 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
576}
577
[email protected]e9ff79c2012-10-19 21:31:26578void RenderThreadImpl::AddObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06579 observers_.AddObserver(observer);
580}
581
[email protected]e9ff79c2012-10-19 21:31:26582void RenderThreadImpl::RemoveObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06583 observers_.RemoveObserver(observer);
584}
585
[email protected]359dfa32011-10-12 01:10:15586void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:26587 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:15588 resource_dispatcher()->set_delegate(delegate);
589}
590
[email protected]f1a29a02011-10-06 23:08:44591void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03592 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50593 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24594
[email protected]e9ff79c2012-10-19 21:31:26595 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24596 return;
597 }
598
599 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44600 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03601}
602
[email protected]f1a29a02011-10-06 23:08:44603void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08604 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03605 hidden_widget_count_--;
[email protected]e9ff79c2012-10-19 21:31:26606 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24607 return;
608 }
[email protected]bee16aab2009-08-26 15:55:03609
[email protected]1784b2f2011-11-24 10:53:48610 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39611}
612
[email protected]f1a29a02011-10-06 23:08:44613void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]8d6cba42011-09-02 10:05:19614 if (webkit_platform_support_.get())
[email protected]d1b8fccc2011-08-03 01:20:13615 return;
616
[email protected]8d6cba42011-09-02 10:05:19617 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
618 WebKit::initialize(webkit_platform_support_.get());
[email protected]00fccb42012-12-11 00:09:59619 WebKit::setSharedWorkerRepository(
620 webkit_platform_support_.get()->sharedWorkerRepository());
[email protected]2a23d3f52013-01-08 01:20:24621 WebKit::setIDBFactory(
622 webkit_platform_support_.get()->idbFactory());
[email protected]d1b8fccc2011-08-03 01:20:13623
[email protected]cd7ce3be2012-09-10 05:19:41624 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]cd7ce3be2012-09-10 05:19:41625
[email protected]0f21e8582013-01-11 11:06:56626 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing);
[email protected]72787e392012-03-23 05:55:43627 if (enable) {
[email protected]ea5f70a2013-03-07 12:30:36628 MessageLoop* override_loop =
629 GetContentClient()->renderer()->OverrideCompositorMessageLoop();
630 if (override_loop) {
631 compositor_message_loop_proxy_ = override_loop->message_loop_proxy();
632 } else {
633 compositor_thread_.reset(new base::Thread("Compositor"));
634 compositor_thread_->Start();
635 compositor_message_loop_proxy_ =
636 compositor_thread_->message_loop_proxy();
637 }
638
639 input_handler_manager_.reset(
640 new InputHandlerManager(this, compositor_message_loop_proxy_));
641 AddFilter(input_handler_manager_->GetMessageFilter());
[email protected]a458504b2012-07-23 19:57:06642 }
[email protected]a9fb30aa2011-10-06 06:58:46643
[email protected]ea5f70a2013-03-07 12:30:36644 scoped_refptr<base::MessageLoopProxy> output_surface_loop;
[email protected]7f1f63f2013-03-07 06:07:29645 if (enable)
[email protected]ea5f70a2013-03-07 12:30:36646 output_surface_loop = compositor_message_loop_proxy_;
[email protected]7f1f63f2013-03-07 06:07:29647 else
648 output_surface_loop = base::MessageLoopProxy::current();
[email protected]1842fe22012-08-13 23:24:35649
[email protected]7f1f63f2013-03-07 06:07:29650 compositor_output_surface_filter_ =
651 CompositorOutputSurface::CreateFilter(output_surface_loop);
[email protected]1842fe22012-08-13 23:24:35652 AddFilter(compositor_output_surface_filter_.get());
653
[email protected]d1b8fccc2011-08-03 01:20:13654 WebScriptController::enableV8SingleThreadMode();
655
[email protected]58436a12012-03-21 17:10:26656 RenderThreadImpl::RegisterSchemes();
657
[email protected]d1b8fccc2011-08-03 01:20:13658 webkit_glue::EnableWebCoreLogChannels(
659 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
660
[email protected]fa1c17e42012-03-06 22:29:54661 web_database_observer_impl_.reset(
662 new WebDatabaseObserverImpl(sync_message_filter()));
[email protected]d1b8fccc2011-08-03 01:20:13663 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
664
665 WebRuntimeFeatures::enableSockets(
666 !command_line.HasSwitch(switches::kDisableWebSockets));
667
668 WebRuntimeFeatures::enableDatabase(
669 !command_line.HasSwitch(switches::kDisableDatabases));
670
671 WebRuntimeFeatures::enableDataTransferItems(
672 !command_line.HasSwitch(switches::kDisableDataTransferItems));
673
674 WebRuntimeFeatures::enableApplicationCache(
675 !command_line.HasSwitch(switches::kDisableApplicationCache));
676
677 WebRuntimeFeatures::enableNotifications(
678 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
679
680 WebRuntimeFeatures::enableLocalStorage(
681 !command_line.HasSwitch(switches::kDisableLocalStorage));
682 WebRuntimeFeatures::enableSessionStorage(
683 !command_line.HasSwitch(switches::kDisableSessionStorage));
684
[email protected]b3796c82012-01-19 08:34:33685 WebRuntimeFeatures::enableIndexedDatabase(true);
[email protected]d1b8fccc2011-08-03 01:20:13686
687 WebRuntimeFeatures::enableGeolocation(
688 !command_line.HasSwitch(switches::kDisableGeolocation));
689
[email protected]6aa03b32011-10-27 21:44:44690 WebKit::WebRuntimeFeatures::enableMediaSource(
[email protected]da43c082012-09-07 18:56:11691 !command_line.HasSwitch(switches::kDisableMediaSource));
[email protected]6aa03b32011-10-27 21:44:44692
[email protected]433df472012-03-07 20:33:39693 WebRuntimeFeatures::enableMediaPlayer(
694 media::IsMediaLibraryInitialized());
695
[email protected]d9da9582013-01-31 04:59:05696#if defined(OS_ANDROID)
697 WebKit::WebRuntimeFeatures::enableMediaStream(
698 command_line.HasSwitch(switches::kEnableWebRTC));
699 WebKit::WebRuntimeFeatures::enablePeerConnection(
700 command_line.HasSwitch(switches::kEnableWebRTC));
701#else
[email protected]7082fb942012-05-16 23:44:59702 WebKit::WebRuntimeFeatures::enableMediaStream(true);
[email protected]cdb609e72012-08-30 10:49:58703 WebKit::WebRuntimeFeatures::enablePeerConnection(true);
[email protected]d9da9582013-01-31 04:59:05704#endif
[email protected]8ea05a12012-05-02 09:17:47705
[email protected]efdc0282011-08-26 00:36:12706 WebKit::WebRuntimeFeatures::enableFullScreenAPI(
[email protected]5e5671a2011-09-08 02:12:21707 !command_line.HasSwitch(switches::kDisableFullScreen));
[email protected]efdc0282011-08-26 00:36:12708
[email protected]9f5b7822012-04-18 23:39:03709 WebKit::WebRuntimeFeatures::enableEncryptedMedia(
[email protected]36d98412013-01-31 20:28:53710 !command_line.HasSwitch(switches::kDisableEncryptedMedia));
[email protected]9f5b7822012-04-18 23:39:03711
[email protected]634a3bd2012-07-26 04:49:01712#if defined(OS_ANDROID)
713 WebRuntimeFeatures::enableWebAudio(
714 command_line.HasSwitch(switches::kEnableWebAudio) &&
715 media::IsMediaLibraryInitialized());
716#else
[email protected]d1b8fccc2011-08-03 01:20:13717 WebRuntimeFeatures::enableWebAudio(
[email protected]6a1f9cf2012-05-24 21:23:45718 !command_line.HasSwitch(switches::kDisableWebAudio) &&
719 media::IsMediaLibraryInitialized());
[email protected]634a3bd2012-07-26 04:49:01720#endif
[email protected]d1b8fccc2011-08-03 01:20:13721
[email protected]d1b8fccc2011-08-03 01:20:13722 WebRuntimeFeatures::enableDeviceMotion(
723 command_line.HasSwitch(switches::kEnableDeviceMotion));
724
725 WebRuntimeFeatures::enableDeviceOrientation(
726 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
727
728 WebRuntimeFeatures::enableSpeechInput(
729 !command_line.HasSwitch(switches::kDisableSpeechInput));
730
[email protected]0cc3e8022013-01-16 11:41:24731#if defined(OS_ANDROID)
732 // Web Speech API Speech recognition is not implemented on Android yet.
733 WebRuntimeFeatures::enableScriptedSpeech(false);
734#else
[email protected]14f843ea2012-12-01 20:26:29735 WebRuntimeFeatures::enableScriptedSpeech(true);
[email protected]0cc3e8022013-01-16 11:41:24736#endif
[email protected]9b7b57d2012-03-21 13:17:48737
[email protected]d1b8fccc2011-08-03 01:20:13738 WebRuntimeFeatures::enableFileSystem(
739 !command_line.HasSwitch(switches::kDisableFileSystem));
740
741 WebRuntimeFeatures::enableJavaScriptI18NAPI(
742 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI));
743
[email protected]d7a35b72012-05-17 15:59:57744 WebRuntimeFeatures::enableGamepad(true);
[email protected]0205fbf2011-11-30 21:51:36745
[email protected]d1b8fccc2011-08-03 01:20:13746 WebRuntimeFeatures::enableQuota(true);
747
[email protected]739d08d32012-10-12 07:38:14748 WebRuntimeFeatures::enableShadowDOM(true);
[email protected]d2edc6702012-01-30 09:13:16749
[email protected]d9a64602012-12-21 07:28:05750 if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures)) {
751 WebRuntimeFeatures::enableStyleScoped(true);
[email protected]0374ada2013-03-01 02:58:42752 WebRuntimeFeatures::enableCustomDOMElements(true);
[email protected]d9a64602012-12-21 07:28:05753 WebRuntimeFeatures::enableCSSExclusions(true);
754 WebRuntimeFeatures::enableExperimentalContentSecurityPolicyFeatures(true);
755 WebRuntimeFeatures::enableCSSRegions(true);
756 WebRuntimeFeatures::enableDialogElement(true);
757 }
[email protected]4ae41b42012-12-06 21:59:03758
[email protected]d3e7aea22013-01-09 08:47:53759 WebRuntimeFeatures::enableSeamlessIFrames(
760 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures));
761
[email protected]d1b8fccc2011-08-03 01:20:13762 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48763
[email protected]b146d6d2012-09-11 10:20:05764 devtools_agent_message_filter_ = new DevToolsAgentFilter();
765 AddFilter(devtools_agent_message_filter_.get());
766
[email protected]e9ff79c2012-10-19 21:31:26767 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]1784b2f2011-11-24 10:53:48768 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]d1b8fccc2011-08-03 01:20:13769}
770
[email protected]58436a12012-03-21 17:10:26771void RenderThreadImpl::RegisterSchemes() {
772 // swappedout: pages should not be accessible, and should also
773 // be treated as empty documents that can commit synchronously.
774 WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme));
775 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme);
776 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme);
777}
778
[email protected]f1a29a02011-10-06 23:08:44779void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06780 Send(new ViewHostMsg_UserMetricsRecordAction(action));
781}
782
[email protected]fb79aa22012-12-13 01:12:13783scoped_ptr<base::SharedMemory>
[email protected]3f892832013-01-11 03:23:59784 RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
785 if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
786 return scoped_ptr<base::SharedMemory>();
787
[email protected]fb79aa22012-12-13 01:12:13788 base::SharedMemoryHandle handle;
789 bool success;
790 IPC::Message* message =
791 new ChildProcessHostMsg_SyncAllocateSharedMemory(size, &handle);
792
793 // Allow calling this from the compositor thread.
794 if (MessageLoop::current() == message_loop())
795 success = ChildThread::Send(message);
796 else
797 success = sync_message_filter()->Send(message);
798
799 if (!success)
800 return scoped_ptr<base::SharedMemory>();
801
802 if (!base::SharedMemory::IsHandleValid(handle))
803 return scoped_ptr<base::SharedMemory>();
804
805 return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false));
[email protected]00614a82011-10-07 22:39:31806}
807
[email protected]f1a29a02011-10-06 23:08:44808void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06809 WebScriptController::registerExtension(extension);
[email protected]526476902011-10-06 20:34:06810}
811
[email protected]6593ae12011-11-14 12:09:44812void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
813 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06814 idle_timer_.Stop();
815 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44816 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44817 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06818}
819
[email protected]f1a29a02011-10-06 23:08:44820void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48821 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:26822 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:48823 RunIdleHandlerWhenWidgetsHidden();
824 if (run_in_foreground_tab) {
825 IdleHandlerInForegroundTab();
826 return;
827 }
[email protected]237a14852012-04-28 02:56:38828
829 base::allocator::ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:06830
831 v8::V8::IdleNotification();
832
833 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44834 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06835 // delay = delay + 1 / (delay + 2)
836 // Using floor(delay) has a dampening effect such as:
837 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44838 // If the delay is in milliseconds, the above formula is equivalent to:
839 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
840 // which is equivalent to
841 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
842 // Note that idle_notification_delay_in_ms_ would be reset to
843 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
844 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
845 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06846
847 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
848}
849
[email protected]1784b2f2011-11-24 10:53:48850void RenderThreadImpl::IdleHandlerInForegroundTab() {
851 // Increase the delay in the same way as in IdleHandler,
852 // but make it periodic by reseting it once it is too big.
853 int64 new_delay_ms = idle_notification_delay_in_ms_ +
854 1000000 / (idle_notification_delay_in_ms_ + 2000);
855 if (new_delay_ms >= kLongIdleHandlerDelayMs)
856 new_delay_ms = kShortIdleHandlerDelayMs;
857
[email protected]1784b2f2011-11-24 10:53:48858 if (idle_notifications_to_skip_ > 0) {
859 idle_notifications_to_skip_--;
[email protected]7e967f82011-12-01 09:35:14860 } else {
[email protected]a47105c832011-12-07 17:24:30861 int cpu_usage = 0;
[email protected]7e967f82011-12-01 09:35:14862 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
[email protected]1393c4a2012-02-07 10:12:58863 // Idle notification hint roughly specifies the expected duration of the
864 // idle pause. We set it proportional to the idle timer delay.
865 int idle_hint = static_cast<int>(new_delay_ms / 10);
[email protected]d7e59252012-03-06 22:26:02866 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
[email protected]237a14852012-04-28 02:56:38867 base::allocator::ReleaseFreeMemory();
[email protected]d7e59252012-03-06 22:26:02868 if (v8::V8::IdleNotification(idle_hint)) {
869 // V8 finished collecting garbage.
870 new_delay_ms = kLongIdleHandlerDelayMs;
871 }
[email protected]1784b2f2011-11-24 10:53:48872 }
873 }
[email protected]1784b2f2011-11-24 10:53:48874 ScheduleIdleHandler(new_delay_ms);
875}
876
[email protected]6593ae12011-11-14 12:09:44877int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
878 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06879}
880
[email protected]6593ae12011-11-14 12:09:44881void RenderThreadImpl::SetIdleNotificationDelayInMs(
882 int64 idle_notification_delay_in_ms) {
883 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08884}
885
[email protected]a1a7ff32012-07-19 14:03:51886void RenderThreadImpl::ToggleWebKitSharedTimer(bool suspend) {
887 if (suspend_webkit_shared_timer_) {
888 EnsureWebKitInitialized();
889 if (suspend) {
890 webkit_platform_support_->SuspendSharedTimer();
891 } else {
892 webkit_platform_support_->ResumeSharedTimer();
893 }
894 }
895}
896
897void RenderThreadImpl::UpdateHistograms(int sequence_number) {
898 child_histogram_message_filter()->SendHistograms(sequence_number);
899}
900
[email protected]b02f5902012-12-19 07:33:00901bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
902 bool result = false;
903 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
904 return result;
905}
906
[email protected]1784b2f2011-11-24 10:53:48907void RenderThreadImpl::PostponeIdleNotification() {
908 idle_notifications_to_skip_ = 2;
909}
910
[email protected]fe476b02012-08-13 21:21:38911/* static */
912void RenderThreadImpl::OnGpuVDAContextLoss() {
913 RenderThreadImpl* self = RenderThreadImpl::current();
914 DCHECK(self);
915 if (!self->gpu_vda_context3d_.get())
916 return;
[email protected]ea5f70a2013-03-07 12:30:36917 if (self->compositor_message_loop_proxy()) {
918 self->compositor_message_loop_proxy()->DeleteSoon(
[email protected]fe476b02012-08-13 21:21:38919 FROM_HERE, self->gpu_vda_context3d_.release());
920 } else {
921 self->gpu_vda_context3d_.reset();
[email protected]3b2afc32012-06-18 21:31:16922 }
[email protected]fe476b02012-08-13 21:21:38923}
924
925WebGraphicsContext3DCommandBufferImpl*
926RenderThreadImpl::GetGpuVDAContext3D() {
[email protected]3b2afc32012-06-18 21:31:16927 if (!gpu_vda_context3d_.get()) {
928 gpu_vda_context3d_.reset(
929 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
[email protected]d1a9e062012-07-13 00:45:14930 this, WebKit::WebGraphicsContext3D::Attributes(),
931 GURL("chrome://gpu/RenderThreadImpl::GetGpuVDAContext3D")));
[email protected]fde3e2f2012-08-14 06:51:37932 if (gpu_vda_context3d_.get())
933 gpu_vda_context3d_->setContextLostCallback(context_lost_cb_.get());
[email protected]3b2afc32012-06-18 21:31:16934 }
[email protected]fe476b02012-08-13 21:21:38935 return gpu_vda_context3d_.get();
[email protected]3b2afc32012-06-18 21:31:16936}
937
[email protected]c29b7ff2013-03-06 03:51:04938scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
939RenderThreadImpl::CreateOffscreenContext3d() {
940 WebKit::WebGraphicsContext3D::Attributes attributes;
941 attributes.shareResources = true;
942 attributes.depth = false;
943 attributes.stencil = false;
944 attributes.antialias = false;
945 attributes.noAutomaticFlushes = true;
946
947 return make_scoped_ptr(
948 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
949 this,
950 attributes,
951 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext3d")));
952}
953
[email protected]a45c46e2013-03-07 01:04:46954scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:04955RenderThreadImpl::OffscreenContextProviderForMainThread() {
956 if (!shared_contexts_main_thread_ ||
957 shared_contexts_main_thread_->DestroyedOnMainThread())
958 shared_contexts_main_thread_ = new RendererContextProviderCommandBuffer;
959 return shared_contexts_main_thread_;
960}
961
[email protected]a45c46e2013-03-07 01:04:46962scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:04963RenderThreadImpl::OffscreenContextProviderForCompositorThread() {
964 if (!shared_contexts_compositor_thread_ ||
965 shared_contexts_compositor_thread_->DestroyedOnMainThread()) {
966 shared_contexts_compositor_thread_ =
967 new RendererContextProviderCommandBuffer;
968 }
969 return shared_contexts_compositor_thread_;
970}
971
[email protected]e9ff79c2012-10-19 21:31:26972AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]3958e972012-07-17 00:25:41973 if (!audio_renderer_mixer_manager_.get()) {
974 audio_renderer_mixer_manager_.reset(new AudioRendererMixerManager(
[email protected]563d665f2013-02-01 04:42:39975 GetAudioHardwareConfig()));
[email protected]3958e972012-07-17 00:25:41976 }
977
978 return audio_renderer_mixer_manager_.get();
979}
980
[email protected]563d665f2013-02-01 04:42:39981media::AudioHardwareConfig* RenderThreadImpl::GetAudioHardwareConfig() {
982 if (!audio_hardware_config_) {
983 int output_buffer_size;
984 int output_sample_rate;
985 int input_sample_rate;
986 media::ChannelLayout input_channel_layout;
987
988 Send(new ViewHostMsg_GetAudioHardwareConfig(
989 &output_buffer_size, &output_sample_rate,
990 &input_sample_rate, &input_channel_layout));
991
992 audio_hardware_config_.reset(new media::AudioHardwareConfig(
993 output_buffer_size, output_sample_rate, input_sample_rate,
994 input_channel_layout));
995 audio_message_filter_->SetAudioHardwareConfig(audio_hardware_config_.get());
996 }
997
998 return audio_hardware_config_.get();
999}
1000
[email protected]4a7d6392011-09-19 20:55:081001#if defined(OS_WIN)
[email protected]feb32372012-11-21 01:14:561002void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font,
1003 const string16& str) {
1004 Send(new ViewHostMsg_PreCacheFontCharacters(log_font, str));
1005}
1006
[email protected]f1a29a02011-10-06 23:08:441007void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:061008 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:211009}
1010
[email protected]f1a29a02011-10-06 23:08:441011void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:061012 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:081013}
[email protected]526476902011-10-06 20:34:061014
[email protected]4a7d6392011-09-19 20:55:081015#endif // OS_WIN
1016
[email protected]988aacf2012-02-12 18:10:031017bool RenderThreadImpl::IsWebFrameValid(WebKit::WebFrame* web_frame) {
1018 if (!web_frame)
[email protected]4761cf12012-09-12 10:37:551019 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031020
1021 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
1022 if (!render_view)
[email protected]4761cf12012-09-12 10:37:551023 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031024
1025 return true;
1026}
1027
[email protected]b3e83de2012-02-07 03:33:281028bool RenderThreadImpl::IsMainThread() {
1029 return !!current();
1030}
1031
1032bool RenderThreadImpl::IsIOThread() {
1033 return MessageLoop::current() == ChildProcess::current()->io_message_loop();
1034}
1035
1036MessageLoop* RenderThreadImpl::GetMainLoop() {
1037 return message_loop();
1038}
[email protected]5b040e592012-02-10 02:56:101039
1040scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() {
[email protected]b3e83de2012-02-07 03:33:281041 return ChildProcess::current()->io_message_loop_proxy();
1042}
1043
1044base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() {
1045 return ChildProcess::current()->GetShutDownEvent();
1046}
1047
1048scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory(
[email protected]3f892832013-01-11 03:23:591049 size_t size) {
[email protected]fb79aa22012-12-13 01:12:131050 return scoped_ptr<base::SharedMemory>(
1051 HostAllocateSharedMemoryBuffer(size));
[email protected]b3e83de2012-02-07 03:33:281052}
1053
1054int32 RenderThreadImpl::CreateViewCommandBuffer(
1055 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) {
[email protected]d13f35d2012-05-18 02:28:151056 TRACE_EVENT1("gpu",
1057 "RenderThreadImpl::CreateViewCommandBuffer",
1058 "surface_id",
1059 surface_id);
1060
[email protected]b3e83de2012-02-07 03:33:281061 int32 route_id = MSG_ROUTING_NONE;
[email protected]8b10b332012-02-29 21:02:141062 IPC::Message* message = new GpuHostMsg_CreateViewCommandBuffer(
[email protected]b3e83de2012-02-07 03:33:281063 surface_id,
1064 init_params,
[email protected]8b10b332012-02-29 21:02:141065 &route_id);
1066
1067 // Allow calling this from the compositor thread.
1068 if (MessageLoop::current() == message_loop())
1069 ChildThread::Send(message);
1070 else
1071 sync_message_filter()->Send(message);
1072
[email protected]b3e83de2012-02-07 03:33:281073 return route_id;
1074}
1075
[email protected]09d50362012-10-18 20:54:371076void RenderThreadImpl::CreateImage(
1077 gfx::PluginWindowHandle window,
1078 int32 image_id,
1079 const CreateImageCallback& callback) {
1080 NOTREACHED();
1081}
1082
1083void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) {
1084 NOTREACHED();
1085}
1086
[email protected]f1a29a02011-10-06 23:08:441087void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:061088 suspend_webkit_shared_timer_ = false;
1089}
1090
[email protected]f1a29a02011-10-06 23:08:441091void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:061092 notify_webkit_of_modal_loop_ = false;
1093}
1094
[email protected]367c5c1d2013-03-11 18:59:021095void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& scheme,
1096 const std::string& host,
[email protected]f1a29a02011-10-06 23:08:441097 double zoom_level) {
[email protected]367c5c1d2013-03-11 18:59:021098 RenderViewZoomer zoomer(scheme, host, zoom_level);
[email protected]e9ff79c2012-10-19 21:31:261099 RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:061100}
1101
[email protected]f1a29a02011-10-06 23:08:441102bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:501103 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
1104 RenderProcessObserver* observer;
1105 while ((observer = it.GetNext()) != NULL) {
1106 if (observer->OnControlMessageReceived(msg))
1107 return true;
1108 }
1109
[email protected]70c19a932010-05-14 12:59:111110 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101111 if (appcache_dispatcher_->OnMessageReceived(msg) ||
1112 dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281113 return true;
[email protected]1910fe82012-05-10 00:04:101114 }
[email protected]1edc16b82009-04-07 17:45:541115
[email protected]a95986a82010-12-24 06:19:281116 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:441117 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:541118 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
1119 OnSetZoomLevelForCurrentURL)
[email protected]8930d472009-02-21 08:05:281120 // TODO(port): removed from render_messages_internal.h;
1121 // is there a new non-windows message I should add here?
1122 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:451123 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:091124 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]b69934e2011-10-29 02:51:521125 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]44363382013-03-12 07:22:471126 IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended,
1127 OnSetWebKitSharedTimersSuspended)
[email protected]a95986a82010-12-24 06:19:281128 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281129 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281130 return handled;
initial.commit09911bf2008-07-26 23:55:291131}
1132
[email protected]f1a29a02011-10-06 23:08:441133void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:471134 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:331135 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]6cd7c6b2012-10-25 03:26:231136 RenderViewImpl::Create(
[email protected]6cd7c6b2012-10-25 03:26:231137 params.opener_route_id,
1138 params.renderer_preferences,
1139 params.web_preferences,
1140 new SharedRenderViewCounter(0),
1141 params.view_id,
1142 params.surface_id,
1143 params.session_storage_namespace_id,
1144 params.frame_name,
1145 false,
1146 params.swapped_out,
1147 params.next_page_id,
1148 params.screen_info,
[email protected]34bb3ac2013-03-08 02:41:281149 params.accessibility_mode,
1150 params.allow_partial_swap);
[email protected]7f874dec2009-02-06 01:48:271151}
[email protected]4274e582009-01-27 22:09:561152
[email protected]f1a29a02011-10-06 23:08:441153GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:261154 CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]d13f35d2012-05-18 02:28:151155 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1156
[email protected]6217d392010-03-25 22:08:351157 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:221158 // Do nothing if we already have a GPU channel or are already
1159 // establishing one.
[email protected]e09cee42010-11-09 01:50:081160 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
1161 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:041162 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:351163
1164 // Recreate the channel if it has been lost.
[email protected]894e8fc2012-02-24 13:29:501165 gpu_channel_ = NULL;
[email protected]6217d392010-03-25 22:08:351166 }
1167
[email protected]6217d392010-03-25 22:08:351168 // Ask the browser for the channel name.
[email protected]894e8fc2012-02-24 13:29:501169 int client_id = 0;
[email protected]b42a9f62011-06-08 20:36:041170 IPC::ChannelHandle channel_handle;
[email protected]e9ff79c2012-10-19 21:31:261171 GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:041172 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
[email protected]894e8fc2012-02-24 13:29:501173 &client_id,
[email protected]b42a9f62011-06-08 20:36:041174 &channel_handle,
[email protected]b42a9f62011-06-08 20:36:041175 &gpu_info)) ||
[email protected]8bc550e2012-02-07 11:05:561176#if defined(OS_POSIX)
1177 channel_handle.socket.fd == -1 ||
1178#endif
[email protected]cd0bd792012-04-14 00:52:161179 channel_handle.name.empty()) {
[email protected]b42a9f62011-06-08 20:36:041180 // Otherwise cancel the connection.
1181 gpu_channel_ = NULL;
1182 return NULL;
1183 }
[email protected]6217d392010-03-25 22:08:351184
[email protected]03dc8882012-03-08 23:46:291185 gpu_channel_ = new GpuChannelHost(this, 0, client_id);
[email protected]b42a9f62011-06-08 20:36:041186 gpu_channel_->set_gpu_info(gpu_info);
[email protected]e9ff79c2012-10-19 21:31:261187 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]b42a9f62011-06-08 20:36:041188
1189 // Connect to the GPU process if a channel name was received.
[email protected]cd0bd792012-04-14 00:52:161190 gpu_channel_->Connect(channel_handle);
[email protected]b42a9f62011-06-08 20:36:041191
[email protected]f9a2b2fe2010-07-15 21:13:231192 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:341193}
1194
[email protected]d8cd8372012-03-09 10:49:511195WebKit::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1196 WebKit::WebMediaStreamCenterClient* client) {
[email protected]d9da9582013-01-31 04:59:051197#if defined(OS_ANDROID)
1198 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1199 switches::kEnableWebRTC))
1200 return NULL;
1201#endif
1202
[email protected]d8cd8372012-03-09 10:49:511203#if defined(ENABLE_WEBRTC)
[email protected]68e5fee2013-02-18 10:04:221204 if (!media_stream_center_) {
1205 media_stream_center_ = GetContentClient()->renderer()
1206 ->OverrideCreateWebMediaStreamCenter(client);
1207 if (!media_stream_center_) {
1208 media_stream_center_ = new MediaStreamCenter(
1209 client, GetMediaStreamDependencyFactory());
1210 }
1211 }
[email protected]d8cd8372012-03-09 10:49:511212#endif
1213 return media_stream_center_;
1214}
1215
[email protected]6ee10bd2012-09-13 09:01:531216MediaStreamDependencyFactory*
1217RenderThreadImpl::GetMediaStreamDependencyFactory() {
1218#if defined(ENABLE_WEBRTC)
1219 if (!media_stream_factory_.get()) {
1220 media_stream_factory_.reset(new MediaStreamDependencyFactory(
1221 vc_manager_, p2p_socket_dispatcher_));
1222 }
1223#endif
1224 return media_stream_factory_.get();
1225}
1226
[email protected]f1a29a02011-10-06 23:08:441227GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]6217d392010-03-25 22:08:351228 if (!gpu_channel_.get())
1229 return NULL;
1230
[email protected]e09cee42010-11-09 01:50:081231 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:351232 return NULL;
1233
1234 return gpu_channel_.get();
1235}
1236
[email protected]f1a29a02011-10-06 23:08:441237void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591238 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271239 // The call below will cause a GetPlugins call with refresh=true, but at this
1240 // point we already know that the browser has refreshed its list, so disable
1241 // refresh temporarily to prevent each renderer process causing the list to be
1242 // regenerated.
[email protected]a70b4352012-07-31 22:34:531243 webkit_platform_support_->set_plugin_refresh_allowed(false);
[email protected]b78e168b2009-09-21 22:05:451244 WebKit::resetPluginCache(reload_pages);
[email protected]a70b4352012-07-31 22:34:531245 webkit_platform_support_->set_plugin_refresh_allowed(true);
[email protected]3b48dbc2012-01-06 16:34:171246
1247 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:271248}
[email protected]85c55dc2009-11-06 03:05:461249
[email protected]f1a29a02011-10-06 23:08:441250void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:091251 EnsureWebKitInitialized();
1252 WebNetworkStateNotifier::setOnLine(online);
1253}
1254
[email protected]b69934e2011-10-29 02:51:521255void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
[email protected]e9ff79c2012-10-19 21:31:261256 GetContentClient()->SetActiveURL(data);
[email protected]b69934e2011-10-29 02:51:521257 CHECK(false);
1258}
1259
[email protected]44363382013-03-12 07:22:471260void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) {
1261 ToggleWebKitSharedTimer(suspend);
1262}
1263
[email protected]c6a7b862010-08-20 22:19:381264scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:441265RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]c6a7b862010-08-20 22:19:381266 DCHECK(message_loop() == MessageLoop::current());
1267 if (!file_thread_.get()) {
1268 file_thread_.reset(new base::Thread("Renderer::FILE"));
1269 file_thread_->Start();
1270 }
1271 return file_thread_->message_loop_proxy();
1272}
[email protected]e9ff79c2012-10-19 21:31:261273
[email protected]107c0532013-02-06 02:34:091274void RenderThreadImpl::SetFlingCurveParameters(
1275 const std::vector<float>& new_touchpad,
1276 const std::vector<float>& new_touchscreen) {
1277 webkit_platform_support_->SetFlingCurveParameters(new_touchpad,
1278 new_touchscreen);
1279
1280}
1281
[email protected]e9ff79c2012-10-19 21:31:261282} // namespace content