blob: 975e13ec35cacd44864906732b0242d882a1e803 [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]c26ad882012-02-07 06:41:2033#include "content/common/gpu/client/gpu_channel_host.h"
[email protected]202b54ff2011-04-22 21:36:3834#include "content/common/gpu/gpu_messages.h"
[email protected]988aacf2012-02-12 18:10:0335#include "content/common/indexed_db/indexed_db_dispatcher.h"
36#include "content/common/indexed_db/indexed_db_message_filter.h"
[email protected]d3fd748b2011-09-20 17:39:1737#include "content/common/npobject_util.h"
[email protected]105303e2011-03-14 22:16:1038#include "content/common/plugin_messages.h"
[email protected]359dfa32011-10-12 01:10:1539#include "content/common/resource_dispatcher.h"
[email protected]94dc971d2011-03-05 19:08:3240#include "content/common/resource_messages.h"
[email protected]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]e93e04e2011-03-14 00:27:1042#include "content/common/web_database_observer_impl.h"
[email protected]a458504b2012-07-23 19:57:0643#include "content/public/common/content_constants.h"
[email protected]433df472012-03-07 20:33:3944#include "content/public/common/content_paths.h"
[email protected]c08950d22011-10-13 22:20:2945#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3146#include "content/public/common/renderer_preferences.h"
[email protected]58436a12012-03-21 17:10:2647#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3448#include "content/public/renderer/content_renderer_client.h"
[email protected]64ffa0442011-10-03 22:08:3649#include "content/public/renderer/render_process_observer.h"
50#include "content/public/renderer/render_view_visitor.h"
[email protected]70019152012-12-19 11:44:1951#include "content/renderer/devtools/devtools_agent_filter.h"
[email protected]1910fe82012-05-10 00:04:1052#include "content/renderer/dom_storage/dom_storage_dispatcher.h"
53#include "content/renderer/dom_storage/webstoragearea_impl.h"
54#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]a9fb30aa2011-10-06 06:58:4655#include "content/renderer/gpu/compositor_thread.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]f7eb0a392011-07-12 10:19:5158#include "content/renderer/media/audio_input_message_filter.h"
59#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:4160#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]d8cd8372012-03-09 10:49:5161#include "content/renderer/media/media_stream_center.h"
[email protected]6ee10bd2012-09-13 09:01:5362#include "content/renderer/media/media_stream_dependency_factory.h"
[email protected]af089972013-01-10 04:04:4063#include "content/renderer/media/peer_connection_tracker.h"
[email protected]80b161a2011-06-27 17:42:1164#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:3465#include "content/renderer/media/video_capture_message_filter.h"
[email protected]6941ac5c2013-02-07 03:59:5666#include "content/renderer/memory_benchmarking_extension.h"
[email protected]4761cf12012-09-12 10:37:5567#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3568#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0569#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:2870#include "content/renderer/render_view_impl.h"
[email protected]8d6cba42011-09-02 10:05:1971#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]766a7082012-02-03 23:39:1572#include "grit/content_resources.h"
[email protected]46f36a492010-07-28 19:36:4173#include "ipc/ipc_channel_handle.h"
[email protected]1842fe22012-08-13 23:24:3574#include "ipc/ipc_forwarding_message_filter.h"
[email protected]cb6037d2009-11-16 22:55:1775#include "ipc/ipc_platform_file.h"
[email protected]563d665f2013-02-01 04:42:3976#include "media/base/audio_hardware_config.h"
[email protected]433df472012-03-07 20:33:3977#include "media/base/media.h"
[email protected]47ebb0e2012-11-30 08:28:2978#include "media/base/media_switches.h"
[email protected]620161e2011-03-07 18:05:2679#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5480#include "net/base/net_util.h"
[email protected]cd7ce3be2012-09-10 05:19:4181#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
82#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSupport.h"
[email protected]1332623f12012-08-10 03:45:1383#include "third_party/WebKit/Source/Platform/chromium/public/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"
[email protected]2a23d3f52013-01-08 01:20:2488#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
[email protected]8bd0fe62011-01-17 06:44:3789#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]6eac57a2011-07-12 21:15:0990#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]4bd55a32011-07-28 13:28:3891#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
[email protected]8bd0fe62011-01-17 06:44:3792#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
[email protected]58436a12012-03-21 17:10:2694#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]00fccb42012-12-11 00:09:5995#include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerRepository.h"
[email protected]61a796c42012-05-17 21:28:2096#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]c49201a2012-05-24 11:04:5797#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:3298#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:5099#include "v8/include/v8.h"
[email protected]d471190a2011-02-16 14:52:30100#include "webkit/glue/webkit_glue.h"
[email protected]2c62b562009-01-27 19:04:50101
[email protected]da00a2882009-03-09 17:51:19102#if defined(OS_WIN)
103#include <windows.h>
104#include <objbase.h>
[email protected]5f7e4512012-10-01 20:51:37105#include "base/win/scoped_com_initializer.h"
106#else
107// TODO(port)
108#include "base/memory/scoped_handle.h"
109#include "content/common/np_channel_base.h"
[email protected]da00a2882009-03-09 17:51:19110#endif
111
[email protected]6217d392010-03-25 22:08:35112#if defined(OS_POSIX)
113#include "ipc/ipc_channel_posix.h"
114#endif
115
[email protected]950f9ce22012-12-27 00:25:07116#if defined(ENABLE_WEBRTC)
117#include "third_party/webrtc/system_wrappers/interface/event_tracer.h"
118#endif
119
[email protected]b6cb3a842011-06-24 18:28:41120using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:01121using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:09122using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:00123using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:51124using WebKit::WebScriptController;
[email protected]58436a12012-03-21 17:10:26125using WebKit::WebSecurityPolicy;
[email protected]2c434b32009-03-19 06:27:47126using WebKit::WebString;
[email protected]50ae00ef2009-10-19 05:11:03127using WebKit::WebView;
[email protected]e9ff79c2012-10-19 21:31:26128
129namespace content {
initial.commit09911bf2008-07-26 23:55:29130
[email protected]42f1d7822009-07-23 18:17:55131namespace {
[email protected]da9ccfb2012-01-28 00:34:40132
133const int64 kInitialIdleHandlerDelayMs = 1000;
134const int64 kShortIdleHandlerDelayMs = 1000;
135const int64 kLongIdleHandlerDelayMs = 30*1000;
136const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03137
[email protected]f1a29a02011-10-06 23:08:44138// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16139// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40140base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49141 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54142
[email protected]e9ff79c2012-10-19 21:31:26143class RenderViewZoomer : public RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51144 public:
[email protected]4e2a25a2012-01-27 00:42:08145 RenderViewZoomer(const std::string& host, double zoom_level)
146 : host_(host), zoom_level_(zoom_level) {
[email protected]40bd6582009-12-04 23:49:51147 }
148
[email protected]e9ff79c2012-10-19 21:31:26149 virtual bool Visit(RenderView* render_view) {
[email protected]a2ef54c2011-10-10 16:20:31150 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41151 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25152
153 // Don't set zoom level for full-page plugin since they don't use the same
154 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41155 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25156 return true;
157
[email protected]b6cb3a842011-06-24 18:28:41158 if (net::GetHostOrSpecFromURL(GURL(document.url())) == host_)
[email protected]40bd6582009-12-04 23:49:51159 webview->setZoomLevel(false, zoom_level_);
160 return true;
161 }
162
163 private:
164 std::string host_;
[email protected]b75b8292010-10-01 07:28:25165 double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51166
167 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
168};
[email protected]0478d0162010-08-28 08:29:40169
[email protected]b2d98762012-09-03 17:04:06170std::string HostToCustomHistogramSuffix(const std::string& host) {
171 if (host == "mail.google.com")
172 return ".gmail";
173 if (host == "docs.google.com" || host == "drive.google.com")
174 return ".docs";
175 if (host == "plus.google.com")
176 return ".plus";
177 return "";
178}
[email protected]42f1d7822009-07-23 18:17:55179
[email protected]b2d98762012-09-03 17:04:06180void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13181 const char *name, int min, int max, size_t buckets) {
182 if (min <= 0)
183 min = 1;
[email protected]b2d98762012-09-03 17:04:06184 std::string histogram_name;
185 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
186 if (render_thread_impl) { // Can be null in tests.
187 histogram_name = render_thread_impl->
188 histogram_customizer()->ConvertToCustomHistogramName(name);
189 } else {
190 histogram_name = std::string(name);
191 }
[email protected]de415552013-01-23 04:12:17192 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06193 histogram_name, min, max, buckets,
194 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13195 return histogram;
196}
197
[email protected]b2d98762012-09-03 17:04:06198void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13199 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
200 histogram->Add(sample);
201}
202
[email protected]950f9ce22012-12-27 00:25:07203#if defined(ENABLE_WEBRTC)
[email protected]da0f6952012-12-26 22:22:39204const unsigned char* GetCategoryEnabled(const char* name) {
205 return TRACE_EVENT_API_GET_CATEGORY_ENABLED(name);
206}
207
208void AddTraceEvent(char phase,
209 const unsigned char* category_enabled,
210 const char* name,
211 unsigned long long id,
212 int num_args,
213 const char** arg_names,
214 const unsigned char* arg_types,
215 const unsigned long long* arg_values,
216 unsigned char flags) {
217 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_enabled, name, id, num_args,
218 arg_names, arg_types, arg_values, flags);
219}
[email protected]950f9ce22012-12-27 00:25:07220#endif
[email protected]da0f6952012-12-26 22:22:39221
[email protected]b2d98762012-09-03 17:04:06222} // namespace
223
[email protected]fe476b02012-08-13 21:21:38224class RenderThreadImpl::GpuVDAContextLostCallback
225 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
226 public:
227 GpuVDAContextLostCallback() {}
228 virtual ~GpuVDAContextLostCallback() {}
229 virtual void onContextLost() {
230 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind(
231 &RenderThreadImpl::OnGpuVDAContextLoss));
232 }
233};
234
[email protected]b2d98762012-09-03 17:04:06235RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
236 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
237 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
238 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
239}
240
241RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
242
243void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
244 const std::string& host, size_t view_count) {
[email protected]9baee832012-12-10 11:07:15245 if (CommandLine::ForCurrentProcess()->HasSwitch(
246 switches::kDisableHistogramCustomizer)) {
247 return;
248 }
[email protected]b2d98762012-09-03 17:04:06249 // Check if all RenderViews are displaying a page from the same host. If there
250 // is only one RenderView, the common host is this view's host. If there are
251 // many, check if this one shares the common host of the other
252 // RenderViews. It's ok to not detect some cases where the RenderViews share a
253 // common host. This information is only used for producing custom histograms.
254 if (view_count == 1)
255 SetCommonHost(host);
256 else if (host != common_host_)
257 SetCommonHost(std::string());
258}
259
260std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
261 const char* histogram_name) const {
262 std::string name(histogram_name);
263 if (!common_host_histogram_suffix_.empty() &&
264 custom_histograms_.find(name) != custom_histograms_.end())
265 name += common_host_histogram_suffix_;
266 return name;
267}
268
269void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
270 const std::string& host) {
271 if (host != common_host_) {
272 common_host_ = host;
273 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
274 v8::V8::SetCreateHistogramFunction(CreateHistogram);
275 }
276}
277
[email protected]f1a29a02011-10-06 23:08:44278RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06279 return lazy_tls.Pointer()->Get();
280}
281
[email protected]42f1d7822009-07-23 18:17:55282// When we run plugins in process, we actually run them on the render thread,
283// which means that we need to make the render thread pump UI events.
[email protected]f1a29a02011-10-06 23:08:44284RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55285 Init();
286}
287
[email protected]f1a29a02011-10-06 23:08:44288RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55289 : ChildThread(channel_name) {
290 Init();
291}
[email protected]5fa1c542009-05-05 20:36:07292
[email protected]f1a29a02011-10-06 23:08:44293void RenderThreadImpl::Init() {
294 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33295
[email protected]c7e948b42012-07-12 09:20:20296 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
297 v8::V8::SetCreateHistogramFunction(CreateHistogram);
298 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
299
[email protected]d3f09092012-02-16 01:52:17300#if defined(OS_MACOSX) || defined(OS_ANDROID)
301 // On Mac and Android, the select popups are rendered by the browser.
[email protected]53c607c2011-03-21 23:19:04302 WebKit::WebView::setUseExternalPopupMenus(true);
303#endif
304
[email protected]94f9a0f682009-06-15 18:30:30305 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28306
[email protected]2c62b562009-01-27 19:04:50307#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34308 // If you are running plugins in this thread you need COM active but in
309 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28310 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12311 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50312#endif
initial.commit09911bf2008-07-26 23:55:29313
[email protected]06c694d2012-02-01 22:26:16314 // Register this object as the main thread.
315 ChildProcess::current()->set_main_thread(this);
316
[email protected]31f87132010-04-21 23:36:21317 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50318 suspend_webkit_shared_timer_ = true;
319 notify_webkit_of_modal_loop_ = true;
[email protected]bee16aab2009-08-26 15:55:03320 widget_count_ = 0;
321 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44322 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48323 idle_notifications_to_skip_ = 0;
[email protected]2db58cf92011-12-01 21:39:01324 compositor_initialized_ = false;
[email protected]8d86fce2009-02-26 23:37:55325
[email protected]dcc72db2013-01-02 00:44:18326 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
[email protected]1910fe82012-05-10 00:04:10327 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
[email protected]dcc72db2013-01-02 00:44:18328 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13329
[email protected]d8cd8372012-03-09 10:49:51330 media_stream_center_ = NULL;
331
[email protected]017022b2009-07-27 23:06:34332 db_message_filter_ = new DBMessageFilter();
333 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13334
[email protected]4761cf12012-09-12 10:37:55335#if defined(ENABLE_WEBRTC)
[email protected]da0f6952012-12-26 22:22:39336 webrtc::SetupEventTracer(&GetCategoryEnabled, &AddTraceEvent);
[email protected]af089972013-01-10 04:04:40337
338 peer_connection_tracker_.reset(new PeerConnectionTracker());
339 AddObserver(peer_connection_tracker_.get());
340
[email protected]e9ff79c2012-10-19 21:31:26341 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy());
[email protected]4761cf12012-09-12 10:37:55342 AddFilter(p2p_socket_dispatcher_);
343#endif // defined(ENABLE_WEBRTC)
[email protected]80b161a2011-06-27 17:42:11344 vc_manager_ = new VideoCaptureImplManager();
345 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46346
[email protected]f7eb0a392011-07-12 10:19:51347 audio_input_message_filter_ = new AudioInputMessageFilter();
348 AddFilter(audio_input_message_filter_.get());
349
350 audio_message_filter_ = new AudioMessageFilter();
351 AddFilter(audio_message_filter_.get());
352
[email protected]31bfae72011-12-16 02:04:38353 AddFilter(new IndexedDBMessageFilter);
354
[email protected]e9ff79c2012-10-19 21:31:26355 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24356
[email protected]302fe422012-06-11 14:49:11357 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01358 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking))
[email protected]e9ff79c2012-10-19 21:31:26359 RegisterExtension(GpuBenchmarkingExtension::Get());
[email protected]e54ab492012-06-12 19:40:01360
[email protected]6941ac5c2013-02-07 03:59:56361 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
362 RegisterExtension(MemoryBenchmarkingExtension::Get());
363
[email protected]fe476b02012-08-13 21:21:38364 context_lost_cb_.reset(new GpuVDAContextLostCallback());
365
[email protected]433df472012-03-07 20:33:39366 // Note that under Linux, the media library will normally already have
367 // been initialized by the Zygote before this instance became a Renderer.
368 FilePath media_path;
[email protected]e9ff79c2012-10-19 21:31:26369 PathService::Get(DIR_MEDIA_LIBS, &media_path);
[email protected]433df472012-03-07 20:33:39370 if (!media_path.empty())
371 media::InitializeMediaLibrary(media_path);
372
[email protected]f1a29a02011-10-06 23:08:44373 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29374}
375
[email protected]f1a29a02011-10-06 23:08:44376RenderThreadImpl::~RenderThreadImpl() {
[email protected]1223d6ef2011-03-28 16:47:50377 FOR_EACH_OBSERVER(
378 RenderProcessObserver, observers_, OnRenderProcessShutdown());
379
[email protected]12cbfda32010-01-30 01:04:25380 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08381 if (web_database_observer_impl_.get())
382 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25383
[email protected]8d86fce2009-02-26 23:37:55384 // Shutdown in reverse of the initialization order.
[email protected]b146d6d2012-09-11 10:20:05385 if (devtools_agent_message_filter_.get()) {
386 RemoveFilter(devtools_agent_message_filter_.get());
387 devtools_agent_message_filter_ = NULL;
388 }
[email protected]82622452011-07-22 09:57:20389
[email protected]f7eb0a392011-07-12 10:19:51390 RemoveFilter(audio_input_message_filter_.get());
391 audio_input_message_filter_ = NULL;
392
393 RemoveFilter(audio_message_filter_.get());
394 audio_message_filter_ = NULL;
395
[email protected]80b161a2011-06-27 17:42:11396 RemoveFilter(vc_manager_->video_capture_message_filter());
397
[email protected]017022b2009-07-27 23:06:34398 RemoveFilter(db_message_filter_.get());
399 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25400
[email protected]c6a7b862010-08-20 22:19:38401 // Shutdown the file thread if it's running.
402 if (file_thread_.get())
403 file_thread_->Stop();
404
[email protected]23d2b7e2012-08-14 00:34:09405 if (compositor_output_surface_filter_.get()) {
406 RemoveFilter(compositor_output_surface_filter_.get());
407 compositor_output_surface_filter_ = NULL;
408 }
[email protected]1842fe22012-08-13 23:24:35409
[email protected]2db58cf92011-12-01 21:39:01410 if (compositor_initialized_) {
[email protected]cd7ce3be2012-09-10 05:19:41411 WebKit::Platform::current()->compositorSupport()->shutdown();
[email protected]2db58cf92011-12-01 21:39:01412 compositor_initialized_ = false;
413 }
[email protected]a9fb30aa2011-10-06 06:58:46414 if (compositor_thread_.get()) {
415 RemoveFilter(compositor_thread_->GetMessageFilter());
416 compositor_thread_.reset();
417 }
418
[email protected]8d6cba42011-09-02 10:05:19419 if (webkit_platform_support_.get())
[email protected]9291ed12009-07-23 17:33:22420 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22421
[email protected]94f9a0f682009-06-15 18:30:30422 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30423
[email protected]8d86fce2009-02-26 23:37:55424 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50425#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29426 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50427 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50428#endif
initial.commit09911bf2008-07-26 23:55:29429}
430
[email protected]f1a29a02011-10-06 23:08:44431bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14432 // Certain synchronous messages cannot always be processed synchronously by
433 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50434 // This could cause a complete hang of Chrome if a windowed plug-in is trying
435 // to communicate with the renderer thread since the browser's UI thread
436 // could be stuck (within a Windows API call) trying to synchronously
437 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14438 // thread while the browser is processing this request. This creates an
439 // opportunity for re-entrancy into WebKit, so we need to take care to disable
440 // callbacks, timers, and pending network loads that could trigger such
441 // callbacks.
[email protected]38b592902011-04-16 02:08:42442 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50443 if (msg->is_sync()) {
444 if (msg->is_caller_pumping_messages()) {
445 pumping_events = true;
446 } else {
[email protected]38b592902011-04-16 02:08:42447 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
448 msg->type() == ViewHostMsg_GetRawCookies::ID ||
449 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
[email protected]e9ff79c2012-10-19 21:31:26450 GetContentClient()->renderer()->
[email protected]38b592902011-04-16 02:08:42451 ShouldPumpEventsDuringCookieMessage()) {
452 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50453 }
454 }
[email protected]c1f50aa2010-02-18 03:46:57455 }
456
[email protected]80fc08c52010-03-09 07:43:50457 bool suspend_webkit_shared_timer = true; // default value
458 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57459
[email protected]80fc08c52010-03-09 07:43:50460 bool notify_webkit_of_modal_loop = true; // default value
461 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
462
[email protected]c48de1a2012-11-02 19:06:56463 int render_view_id = MSG_ROUTING_NONE;
[email protected]c1f50aa2010-02-18 03:46:57464
465 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50466 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19467 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57468
[email protected]39065d012010-07-09 11:22:46469 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57470 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57471
[email protected]80fc08c52010-03-09 07:43:50472 RenderWidget* widget =
473 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
474 if (widget) {
[email protected]c48de1a2012-11-02 19:06:56475 render_view_id = widget->routing_id();
[email protected]c1f50aa2010-02-18 03:46:57476 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56477 new PluginMsg_SignalModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57478 }
479 }
480
481 bool rv = ChildThread::Send(msg);
482
483 if (pumping_events) {
[email protected]c48de1a2012-11-02 19:06:56484 if (render_view_id != MSG_ROUTING_NONE) {
[email protected]c1f50aa2010-02-18 03:46:57485 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56486 new PluginMsg_ResetModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57487 }
488
[email protected]39065d012010-07-09 11:22:46489 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57490 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57491
[email protected]80fc08c52010-03-09 07:43:50492 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19493 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57494 }
495
496 return rv;
497}
498
[email protected]f1a29a02011-10-06 23:08:44499MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06500 return message_loop();
501}
502
[email protected]f1a29a02011-10-06 23:08:44503IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06504 return channel();
505}
506
[email protected]f1a29a02011-10-06 23:08:44507std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06508 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:02509 // --lang command line flag.
[email protected]526476902011-10-06 20:34:06510 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
511 const std::string& lang =
512 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:02513 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:06514 return lang;
515}
516
[email protected]07bb6332012-01-21 01:07:57517IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
518 return sync_message_filter();
519}
520
[email protected]96191d52012-05-17 01:37:11521scoped_refptr<base::MessageLoopProxy>
522 RenderThreadImpl::GetIOMessageLoopProxy() {
523 return ChildProcess::current()->io_message_loop_proxy();
524}
525
[email protected]c47317e2012-06-20 22:35:31526void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57527 widget_count_++;
528 return ChildThread::AddRoute(routing_id, listener);
529}
530
[email protected]f1a29a02011-10-06 23:08:44531void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57532 widget_count_--;
533 return ChildThread::RemoveRoute(routing_id);
534}
535
[email protected]77fc9b92011-10-15 16:20:37536int RenderThreadImpl::GenerateRoutingID() {
537 int routing_id = MSG_ROUTING_NONE;
538 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
539 return routing_id;
540}
541
[email protected]f1a29a02011-10-06 23:08:44542void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55543 channel()->AddFilter(filter);
544}
545
[email protected]f1a29a02011-10-06 23:08:44546void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55547 channel()->RemoveFilter(filter);
548}
549
[email protected]f1a29a02011-10-06 23:08:44550void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06551 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
552}
553
[email protected]e9ff79c2012-10-19 21:31:26554void RenderThreadImpl::AddObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06555 observers_.AddObserver(observer);
556}
557
[email protected]e9ff79c2012-10-19 21:31:26558void RenderThreadImpl::RemoveObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06559 observers_.RemoveObserver(observer);
560}
561
[email protected]359dfa32011-10-12 01:10:15562void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:26563 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:15564 resource_dispatcher()->set_delegate(delegate);
565}
566
[email protected]f1a29a02011-10-06 23:08:44567void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03568 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50569 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24570
[email protected]e9ff79c2012-10-19 21:31:26571 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24572 return;
573 }
574
575 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44576 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03577}
578
[email protected]f1a29a02011-10-06 23:08:44579void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08580 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03581 hidden_widget_count_--;
[email protected]e9ff79c2012-10-19 21:31:26582 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24583 return;
584 }
[email protected]bee16aab2009-08-26 15:55:03585
[email protected]1784b2f2011-11-24 10:53:48586 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39587}
588
[email protected]f1a29a02011-10-06 23:08:44589void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]8d6cba42011-09-02 10:05:19590 if (webkit_platform_support_.get())
[email protected]d1b8fccc2011-08-03 01:20:13591 return;
592
[email protected]8d6cba42011-09-02 10:05:19593 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
594 WebKit::initialize(webkit_platform_support_.get());
[email protected]00fccb42012-12-11 00:09:59595 WebKit::setSharedWorkerRepository(
596 webkit_platform_support_.get()->sharedWorkerRepository());
[email protected]2a23d3f52013-01-08 01:20:24597 WebKit::setIDBFactory(
598 webkit_platform_support_.get()->idbFactory());
[email protected]d1b8fccc2011-08-03 01:20:13599
[email protected]cd7ce3be2012-09-10 05:19:41600 WebKit::WebCompositorSupport* compositor_support =
601 WebKit::Platform::current()->compositorSupport();
602 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]cd7ce3be2012-09-10 05:19:41603
[email protected]0f21e8582013-01-11 11:06:56604 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing);
[email protected]72787e392012-03-23 05:55:43605 if (enable) {
[email protected]f3150172011-10-22 02:28:45606 compositor_thread_.reset(new CompositorThread(this));
607 AddFilter(compositor_thread_->GetMessageFilter());
[email protected]cd7ce3be2012-09-10 05:19:41608 compositor_support->initialize(compositor_thread_->GetWebThread());
[email protected]a458504b2012-07-23 19:57:06609 } else {
[email protected]cd7ce3be2012-09-10 05:19:41610 compositor_support->initialize(NULL);
[email protected]a458504b2012-07-23 19:57:06611 }
[email protected]2db58cf92011-12-01 21:39:01612 compositor_initialized_ = true;
[email protected]a9fb30aa2011-10-06 06:58:46613
[email protected]1842fe22012-08-13 23:24:35614 MessageLoop* output_surface_loop = enable ?
615 compositor_thread_->message_loop() :
616 MessageLoop::current();
617
618 compositor_output_surface_filter_ = CompositorOutputSurface::CreateFilter(
619 output_surface_loop->message_loop_proxy());
620 AddFilter(compositor_output_surface_filter_.get());
621
[email protected]d1b8fccc2011-08-03 01:20:13622 WebScriptController::enableV8SingleThreadMode();
623
[email protected]58436a12012-03-21 17:10:26624 RenderThreadImpl::RegisterSchemes();
625
[email protected]d1b8fccc2011-08-03 01:20:13626 webkit_glue::EnableWebCoreLogChannels(
627 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
628
[email protected]fa1c17e42012-03-06 22:29:54629 web_database_observer_impl_.reset(
630 new WebDatabaseObserverImpl(sync_message_filter()));
[email protected]d1b8fccc2011-08-03 01:20:13631 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
632
633 WebRuntimeFeatures::enableSockets(
634 !command_line.HasSwitch(switches::kDisableWebSockets));
635
636 WebRuntimeFeatures::enableDatabase(
637 !command_line.HasSwitch(switches::kDisableDatabases));
638
639 WebRuntimeFeatures::enableDataTransferItems(
640 !command_line.HasSwitch(switches::kDisableDataTransferItems));
641
642 WebRuntimeFeatures::enableApplicationCache(
643 !command_line.HasSwitch(switches::kDisableApplicationCache));
644
645 WebRuntimeFeatures::enableNotifications(
646 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
647
648 WebRuntimeFeatures::enableLocalStorage(
649 !command_line.HasSwitch(switches::kDisableLocalStorage));
650 WebRuntimeFeatures::enableSessionStorage(
651 !command_line.HasSwitch(switches::kDisableSessionStorage));
652
[email protected]b3796c82012-01-19 08:34:33653 WebRuntimeFeatures::enableIndexedDatabase(true);
[email protected]d1b8fccc2011-08-03 01:20:13654
655 WebRuntimeFeatures::enableGeolocation(
656 !command_line.HasSwitch(switches::kDisableGeolocation));
657
[email protected]6aa03b32011-10-27 21:44:44658 WebKit::WebRuntimeFeatures::enableMediaSource(
[email protected]da43c082012-09-07 18:56:11659 !command_line.HasSwitch(switches::kDisableMediaSource));
[email protected]6aa03b32011-10-27 21:44:44660
[email protected]433df472012-03-07 20:33:39661 WebRuntimeFeatures::enableMediaPlayer(
662 media::IsMediaLibraryInitialized());
663
[email protected]d9da9582013-01-31 04:59:05664#if defined(OS_ANDROID)
665 WebKit::WebRuntimeFeatures::enableMediaStream(
666 command_line.HasSwitch(switches::kEnableWebRTC));
667 WebKit::WebRuntimeFeatures::enablePeerConnection(
668 command_line.HasSwitch(switches::kEnableWebRTC));
669#else
[email protected]7082fb942012-05-16 23:44:59670 WebKit::WebRuntimeFeatures::enableMediaStream(true);
[email protected]cdb609e72012-08-30 10:49:58671 WebKit::WebRuntimeFeatures::enablePeerConnection(true);
[email protected]d9da9582013-01-31 04:59:05672#endif
[email protected]8ea05a12012-05-02 09:17:47673
[email protected]efdc0282011-08-26 00:36:12674 WebKit::WebRuntimeFeatures::enableFullScreenAPI(
[email protected]5e5671a2011-09-08 02:12:21675 !command_line.HasSwitch(switches::kDisableFullScreen));
[email protected]efdc0282011-08-26 00:36:12676
[email protected]9f5b7822012-04-18 23:39:03677 WebKit::WebRuntimeFeatures::enableEncryptedMedia(
[email protected]36d98412013-01-31 20:28:53678 !command_line.HasSwitch(switches::kDisableEncryptedMedia));
[email protected]9f5b7822012-04-18 23:39:03679
[email protected]634a3bd2012-07-26 04:49:01680#if defined(OS_ANDROID)
681 WebRuntimeFeatures::enableWebAudio(
682 command_line.HasSwitch(switches::kEnableWebAudio) &&
683 media::IsMediaLibraryInitialized());
684#else
[email protected]d1b8fccc2011-08-03 01:20:13685 WebRuntimeFeatures::enableWebAudio(
[email protected]6a1f9cf2012-05-24 21:23:45686 !command_line.HasSwitch(switches::kDisableWebAudio) &&
687 media::IsMediaLibraryInitialized());
[email protected]634a3bd2012-07-26 04:49:01688#endif
[email protected]d1b8fccc2011-08-03 01:20:13689
[email protected]d1b8fccc2011-08-03 01:20:13690 WebRuntimeFeatures::enableDeviceMotion(
691 command_line.HasSwitch(switches::kEnableDeviceMotion));
692
693 WebRuntimeFeatures::enableDeviceOrientation(
694 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
695
696 WebRuntimeFeatures::enableSpeechInput(
697 !command_line.HasSwitch(switches::kDisableSpeechInput));
698
[email protected]0cc3e8022013-01-16 11:41:24699#if defined(OS_ANDROID)
700 // Web Speech API Speech recognition is not implemented on Android yet.
701 WebRuntimeFeatures::enableScriptedSpeech(false);
702#else
[email protected]14f843ea2012-12-01 20:26:29703 WebRuntimeFeatures::enableScriptedSpeech(true);
[email protected]0cc3e8022013-01-16 11:41:24704#endif
[email protected]9b7b57d2012-03-21 13:17:48705
[email protected]d1b8fccc2011-08-03 01:20:13706 WebRuntimeFeatures::enableFileSystem(
707 !command_line.HasSwitch(switches::kDisableFileSystem));
708
709 WebRuntimeFeatures::enableJavaScriptI18NAPI(
710 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI));
711
[email protected]d7a35b72012-05-17 15:59:57712 WebRuntimeFeatures::enableGamepad(true);
[email protected]0205fbf2011-11-30 21:51:36713
[email protected]d1b8fccc2011-08-03 01:20:13714 WebRuntimeFeatures::enableQuota(true);
715
[email protected]739d08d32012-10-12 07:38:14716 WebRuntimeFeatures::enableShadowDOM(true);
[email protected]d2edc6702012-01-30 09:13:16717
[email protected]d9a64602012-12-21 07:28:05718 if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures)) {
719 WebRuntimeFeatures::enableStyleScoped(true);
720 WebRuntimeFeatures::enableCSSExclusions(true);
721 WebRuntimeFeatures::enableExperimentalContentSecurityPolicyFeatures(true);
722 WebRuntimeFeatures::enableCSSRegions(true);
723 WebRuntimeFeatures::enableDialogElement(true);
724 }
[email protected]4ae41b42012-12-06 21:59:03725
[email protected]b9dce9a2012-12-07 22:14:36726 WebRuntimeFeatures::enableWebIntents(
727 command_line.HasSwitch(switches::kWebIntentsInvocationEnabled));
728
[email protected]d3e7aea22013-01-09 08:47:53729 WebRuntimeFeatures::enableSeamlessIFrames(
730 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures));
731
[email protected]d1b8fccc2011-08-03 01:20:13732 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48733
[email protected]b146d6d2012-09-11 10:20:05734 devtools_agent_message_filter_ = new DevToolsAgentFilter();
735 AddFilter(devtools_agent_message_filter_.get());
736
[email protected]e9ff79c2012-10-19 21:31:26737 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]1784b2f2011-11-24 10:53:48738 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]d1b8fccc2011-08-03 01:20:13739}
740
[email protected]58436a12012-03-21 17:10:26741void RenderThreadImpl::RegisterSchemes() {
742 // swappedout: pages should not be accessible, and should also
743 // be treated as empty documents that can commit synchronously.
744 WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme));
745 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme);
746 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme);
747}
748
[email protected]f1a29a02011-10-06 23:08:44749void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06750 Send(new ViewHostMsg_UserMetricsRecordAction(action));
751}
752
[email protected]fb79aa22012-12-13 01:12:13753scoped_ptr<base::SharedMemory>
[email protected]3f892832013-01-11 03:23:59754 RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
755 if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
756 return scoped_ptr<base::SharedMemory>();
757
[email protected]fb79aa22012-12-13 01:12:13758 base::SharedMemoryHandle handle;
759 bool success;
760 IPC::Message* message =
761 new ChildProcessHostMsg_SyncAllocateSharedMemory(size, &handle);
762
763 // Allow calling this from the compositor thread.
764 if (MessageLoop::current() == message_loop())
765 success = ChildThread::Send(message);
766 else
767 success = sync_message_filter()->Send(message);
768
769 if (!success)
770 return scoped_ptr<base::SharedMemory>();
771
772 if (!base::SharedMemory::IsHandleValid(handle))
773 return scoped_ptr<base::SharedMemory>();
774
775 return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false));
[email protected]00614a82011-10-07 22:39:31776}
777
[email protected]f1a29a02011-10-06 23:08:44778void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06779 WebScriptController::registerExtension(extension);
[email protected]526476902011-10-06 20:34:06780}
781
[email protected]6593ae12011-11-14 12:09:44782void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
783 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06784 idle_timer_.Stop();
785 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44786 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44787 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06788}
789
[email protected]f1a29a02011-10-06 23:08:44790void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48791 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:26792 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:48793 RunIdleHandlerWhenWidgetsHidden();
794 if (run_in_foreground_tab) {
795 IdleHandlerInForegroundTab();
796 return;
797 }
[email protected]237a14852012-04-28 02:56:38798
799 base::allocator::ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:06800
801 v8::V8::IdleNotification();
802
803 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44804 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06805 // delay = delay + 1 / (delay + 2)
806 // Using floor(delay) has a dampening effect such as:
807 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44808 // If the delay is in milliseconds, the above formula is equivalent to:
809 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
810 // which is equivalent to
811 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
812 // Note that idle_notification_delay_in_ms_ would be reset to
813 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
814 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
815 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06816
817 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
818}
819
[email protected]1784b2f2011-11-24 10:53:48820void RenderThreadImpl::IdleHandlerInForegroundTab() {
821 // Increase the delay in the same way as in IdleHandler,
822 // but make it periodic by reseting it once it is too big.
823 int64 new_delay_ms = idle_notification_delay_in_ms_ +
824 1000000 / (idle_notification_delay_in_ms_ + 2000);
825 if (new_delay_ms >= kLongIdleHandlerDelayMs)
826 new_delay_ms = kShortIdleHandlerDelayMs;
827
[email protected]1784b2f2011-11-24 10:53:48828 if (idle_notifications_to_skip_ > 0) {
829 idle_notifications_to_skip_--;
[email protected]7e967f82011-12-01 09:35:14830 } else {
[email protected]a47105c832011-12-07 17:24:30831 int cpu_usage = 0;
[email protected]7e967f82011-12-01 09:35:14832 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
[email protected]1393c4a2012-02-07 10:12:58833 // Idle notification hint roughly specifies the expected duration of the
834 // idle pause. We set it proportional to the idle timer delay.
835 int idle_hint = static_cast<int>(new_delay_ms / 10);
[email protected]d7e59252012-03-06 22:26:02836 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
[email protected]237a14852012-04-28 02:56:38837 base::allocator::ReleaseFreeMemory();
[email protected]d7e59252012-03-06 22:26:02838 if (v8::V8::IdleNotification(idle_hint)) {
839 // V8 finished collecting garbage.
840 new_delay_ms = kLongIdleHandlerDelayMs;
841 }
[email protected]1784b2f2011-11-24 10:53:48842 }
843 }
[email protected]1784b2f2011-11-24 10:53:48844 ScheduleIdleHandler(new_delay_ms);
845}
846
[email protected]6593ae12011-11-14 12:09:44847int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
848 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06849}
850
[email protected]6593ae12011-11-14 12:09:44851void RenderThreadImpl::SetIdleNotificationDelayInMs(
852 int64 idle_notification_delay_in_ms) {
853 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08854}
855
[email protected]a1a7ff32012-07-19 14:03:51856void RenderThreadImpl::ToggleWebKitSharedTimer(bool suspend) {
857 if (suspend_webkit_shared_timer_) {
858 EnsureWebKitInitialized();
859 if (suspend) {
860 webkit_platform_support_->SuspendSharedTimer();
861 } else {
862 webkit_platform_support_->ResumeSharedTimer();
863 }
864 }
865}
866
867void RenderThreadImpl::UpdateHistograms(int sequence_number) {
868 child_histogram_message_filter()->SendHistograms(sequence_number);
869}
870
[email protected]b02f5902012-12-19 07:33:00871bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
872 bool result = false;
873 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
874 return result;
875}
876
[email protected]1784b2f2011-11-24 10:53:48877void RenderThreadImpl::PostponeIdleNotification() {
878 idle_notifications_to_skip_ = 2;
879}
880
[email protected]fe476b02012-08-13 21:21:38881/* static */
882void RenderThreadImpl::OnGpuVDAContextLoss() {
883 RenderThreadImpl* self = RenderThreadImpl::current();
884 DCHECK(self);
885 if (!self->gpu_vda_context3d_.get())
886 return;
887 if (self->compositor_thread()) {
888 self->compositor_thread()->GetWebThread()->message_loop()->DeleteSoon(
889 FROM_HERE, self->gpu_vda_context3d_.release());
890 } else {
891 self->gpu_vda_context3d_.reset();
[email protected]3b2afc32012-06-18 21:31:16892 }
[email protected]fe476b02012-08-13 21:21:38893}
894
895WebGraphicsContext3DCommandBufferImpl*
896RenderThreadImpl::GetGpuVDAContext3D() {
[email protected]3b2afc32012-06-18 21:31:16897 if (!gpu_vda_context3d_.get()) {
898 gpu_vda_context3d_.reset(
899 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
[email protected]d1a9e062012-07-13 00:45:14900 this, WebKit::WebGraphicsContext3D::Attributes(),
901 GURL("chrome://gpu/RenderThreadImpl::GetGpuVDAContext3D")));
[email protected]fde3e2f2012-08-14 06:51:37902 if (gpu_vda_context3d_.get())
903 gpu_vda_context3d_->setContextLostCallback(context_lost_cb_.get());
[email protected]3b2afc32012-06-18 21:31:16904 }
[email protected]fe476b02012-08-13 21:21:38905 return gpu_vda_context3d_.get();
[email protected]3b2afc32012-06-18 21:31:16906}
907
[email protected]e9ff79c2012-10-19 21:31:26908AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]3958e972012-07-17 00:25:41909 if (!audio_renderer_mixer_manager_.get()) {
910 audio_renderer_mixer_manager_.reset(new AudioRendererMixerManager(
[email protected]563d665f2013-02-01 04:42:39911 GetAudioHardwareConfig()));
[email protected]3958e972012-07-17 00:25:41912 }
913
914 return audio_renderer_mixer_manager_.get();
915}
916
[email protected]563d665f2013-02-01 04:42:39917media::AudioHardwareConfig* RenderThreadImpl::GetAudioHardwareConfig() {
918 if (!audio_hardware_config_) {
919 int output_buffer_size;
920 int output_sample_rate;
921 int input_sample_rate;
922 media::ChannelLayout input_channel_layout;
923
924 Send(new ViewHostMsg_GetAudioHardwareConfig(
925 &output_buffer_size, &output_sample_rate,
926 &input_sample_rate, &input_channel_layout));
927
928 audio_hardware_config_.reset(new media::AudioHardwareConfig(
929 output_buffer_size, output_sample_rate, input_sample_rate,
930 input_channel_layout));
931 audio_message_filter_->SetAudioHardwareConfig(audio_hardware_config_.get());
932 }
933
934 return audio_hardware_config_.get();
935}
936
[email protected]4a7d6392011-09-19 20:55:08937#if defined(OS_WIN)
[email protected]feb32372012-11-21 01:14:56938void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font,
939 const string16& str) {
940 Send(new ViewHostMsg_PreCacheFontCharacters(log_font, str));
941}
942
[email protected]f1a29a02011-10-06 23:08:44943void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:06944 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:21945}
946
[email protected]f1a29a02011-10-06 23:08:44947void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:06948 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:08949}
[email protected]526476902011-10-06 20:34:06950
[email protected]4a7d6392011-09-19 20:55:08951#endif // OS_WIN
952
[email protected]988aacf2012-02-12 18:10:03953bool RenderThreadImpl::IsWebFrameValid(WebKit::WebFrame* web_frame) {
954 if (!web_frame)
[email protected]4761cf12012-09-12 10:37:55955 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:03956
957 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
958 if (!render_view)
[email protected]4761cf12012-09-12 10:37:55959 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:03960
961 return true;
962}
963
[email protected]b3e83de2012-02-07 03:33:28964bool RenderThreadImpl::IsMainThread() {
965 return !!current();
966}
967
968bool RenderThreadImpl::IsIOThread() {
969 return MessageLoop::current() == ChildProcess::current()->io_message_loop();
970}
971
972MessageLoop* RenderThreadImpl::GetMainLoop() {
973 return message_loop();
974}
[email protected]5b040e592012-02-10 02:56:10975
976scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() {
[email protected]b3e83de2012-02-07 03:33:28977 return ChildProcess::current()->io_message_loop_proxy();
978}
979
980base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() {
981 return ChildProcess::current()->GetShutDownEvent();
982}
983
984scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory(
[email protected]3f892832013-01-11 03:23:59985 size_t size) {
[email protected]fb79aa22012-12-13 01:12:13986 return scoped_ptr<base::SharedMemory>(
987 HostAllocateSharedMemoryBuffer(size));
[email protected]b3e83de2012-02-07 03:33:28988}
989
990int32 RenderThreadImpl::CreateViewCommandBuffer(
991 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) {
[email protected]d13f35d2012-05-18 02:28:15992 TRACE_EVENT1("gpu",
993 "RenderThreadImpl::CreateViewCommandBuffer",
994 "surface_id",
995 surface_id);
996
[email protected]b3e83de2012-02-07 03:33:28997 int32 route_id = MSG_ROUTING_NONE;
[email protected]8b10b332012-02-29 21:02:14998 IPC::Message* message = new GpuHostMsg_CreateViewCommandBuffer(
[email protected]b3e83de2012-02-07 03:33:28999 surface_id,
1000 init_params,
[email protected]8b10b332012-02-29 21:02:141001 &route_id);
1002
1003 // Allow calling this from the compositor thread.
1004 if (MessageLoop::current() == message_loop())
1005 ChildThread::Send(message);
1006 else
1007 sync_message_filter()->Send(message);
1008
[email protected]b3e83de2012-02-07 03:33:281009 return route_id;
1010}
1011
[email protected]09d50362012-10-18 20:54:371012void RenderThreadImpl::CreateImage(
1013 gfx::PluginWindowHandle window,
1014 int32 image_id,
1015 const CreateImageCallback& callback) {
1016 NOTREACHED();
1017}
1018
1019void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) {
1020 NOTREACHED();
1021}
1022
[email protected]f1a29a02011-10-06 23:08:441023void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:061024 suspend_webkit_shared_timer_ = false;
1025}
1026
[email protected]f1a29a02011-10-06 23:08:441027void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:061028 notify_webkit_of_modal_loop_ = false;
1029}
1030
[email protected]4e2a25a2012-01-27 00:42:081031void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& host,
[email protected]f1a29a02011-10-06 23:08:441032 double zoom_level) {
[email protected]4e2a25a2012-01-27 00:42:081033 RenderViewZoomer zoomer(host, zoom_level);
[email protected]e9ff79c2012-10-19 21:31:261034 RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:061035}
1036
[email protected]f1a29a02011-10-06 23:08:441037bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:501038 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
1039 RenderProcessObserver* observer;
1040 while ((observer = it.GetNext()) != NULL) {
1041 if (observer->OnControlMessageReceived(msg))
1042 return true;
1043 }
1044
[email protected]70c19a932010-05-14 12:59:111045 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101046 if (appcache_dispatcher_->OnMessageReceived(msg) ||
1047 dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281048 return true;
[email protected]1910fe82012-05-10 00:04:101049 }
[email protected]1edc16b82009-04-07 17:45:541050
[email protected]a95986a82010-12-24 06:19:281051 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:441052 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:541053 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
1054 OnSetZoomLevelForCurrentURL)
[email protected]8930d472009-02-21 08:05:281055 // TODO(port): removed from render_messages_internal.h;
1056 // is there a new non-windows message I should add here?
1057 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:451058 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:091059 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]b69934e2011-10-29 02:51:521060 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]a95986a82010-12-24 06:19:281061 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281062 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281063 return handled;
initial.commit09911bf2008-07-26 23:55:291064}
1065
[email protected]f1a29a02011-10-06 23:08:441066void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:471067 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:331068 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]6cd7c6b2012-10-25 03:26:231069 RenderViewImpl::Create(
[email protected]6cd7c6b2012-10-25 03:26:231070 params.opener_route_id,
1071 params.renderer_preferences,
1072 params.web_preferences,
1073 new SharedRenderViewCounter(0),
1074 params.view_id,
1075 params.surface_id,
1076 params.session_storage_namespace_id,
1077 params.frame_name,
1078 false,
1079 params.swapped_out,
1080 params.next_page_id,
1081 params.screen_info,
1082 params.accessibility_mode);
[email protected]7f874dec2009-02-06 01:48:271083}
[email protected]4274e582009-01-27 22:09:561084
[email protected]f1a29a02011-10-06 23:08:441085GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:261086 CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]d13f35d2012-05-18 02:28:151087 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1088
[email protected]6217d392010-03-25 22:08:351089 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:221090 // Do nothing if we already have a GPU channel or are already
1091 // establishing one.
[email protected]e09cee42010-11-09 01:50:081092 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
1093 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:041094 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:351095
1096 // Recreate the channel if it has been lost.
[email protected]894e8fc2012-02-24 13:29:501097 gpu_channel_ = NULL;
[email protected]6217d392010-03-25 22:08:351098 }
1099
[email protected]6217d392010-03-25 22:08:351100 // Ask the browser for the channel name.
[email protected]894e8fc2012-02-24 13:29:501101 int client_id = 0;
[email protected]b42a9f62011-06-08 20:36:041102 IPC::ChannelHandle channel_handle;
[email protected]e9ff79c2012-10-19 21:31:261103 GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:041104 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
[email protected]894e8fc2012-02-24 13:29:501105 &client_id,
[email protected]b42a9f62011-06-08 20:36:041106 &channel_handle,
[email protected]b42a9f62011-06-08 20:36:041107 &gpu_info)) ||
[email protected]8bc550e2012-02-07 11:05:561108#if defined(OS_POSIX)
1109 channel_handle.socket.fd == -1 ||
1110#endif
[email protected]cd0bd792012-04-14 00:52:161111 channel_handle.name.empty()) {
[email protected]b42a9f62011-06-08 20:36:041112 // Otherwise cancel the connection.
1113 gpu_channel_ = NULL;
1114 return NULL;
1115 }
[email protected]6217d392010-03-25 22:08:351116
[email protected]03dc8882012-03-08 23:46:291117 gpu_channel_ = new GpuChannelHost(this, 0, client_id);
[email protected]b42a9f62011-06-08 20:36:041118 gpu_channel_->set_gpu_info(gpu_info);
[email protected]e9ff79c2012-10-19 21:31:261119 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]b42a9f62011-06-08 20:36:041120
1121 // Connect to the GPU process if a channel name was received.
[email protected]cd0bd792012-04-14 00:52:161122 gpu_channel_->Connect(channel_handle);
[email protected]b42a9f62011-06-08 20:36:041123
[email protected]f9a2b2fe2010-07-15 21:13:231124 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:341125}
1126
[email protected]d8cd8372012-03-09 10:49:511127WebKit::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1128 WebKit::WebMediaStreamCenterClient* client) {
[email protected]d9da9582013-01-31 04:59:051129#if defined(OS_ANDROID)
1130 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1131 switches::kEnableWebRTC))
1132 return NULL;
1133#endif
1134
[email protected]d8cd8372012-03-09 10:49:511135#if defined(ENABLE_WEBRTC)
[email protected]d8cd8372012-03-09 10:49:511136 if (!media_stream_center_)
[email protected]e9ff79c2012-10-19 21:31:261137 media_stream_center_ = new MediaStreamCenter(
[email protected]6ee10bd2012-09-13 09:01:531138 client, GetMediaStreamDependencyFactory());
[email protected]d8cd8372012-03-09 10:49:511139#endif
1140 return media_stream_center_;
1141}
1142
[email protected]6ee10bd2012-09-13 09:01:531143MediaStreamDependencyFactory*
1144RenderThreadImpl::GetMediaStreamDependencyFactory() {
1145#if defined(ENABLE_WEBRTC)
1146 if (!media_stream_factory_.get()) {
1147 media_stream_factory_.reset(new MediaStreamDependencyFactory(
1148 vc_manager_, p2p_socket_dispatcher_));
1149 }
1150#endif
1151 return media_stream_factory_.get();
1152}
1153
[email protected]f1a29a02011-10-06 23:08:441154GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]6217d392010-03-25 22:08:351155 if (!gpu_channel_.get())
1156 return NULL;
1157
[email protected]e09cee42010-11-09 01:50:081158 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:351159 return NULL;
1160
1161 return gpu_channel_.get();
1162}
1163
[email protected]f1a29a02011-10-06 23:08:441164void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591165 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271166 // The call below will cause a GetPlugins call with refresh=true, but at this
1167 // point we already know that the browser has refreshed its list, so disable
1168 // refresh temporarily to prevent each renderer process causing the list to be
1169 // regenerated.
[email protected]a70b4352012-07-31 22:34:531170 webkit_platform_support_->set_plugin_refresh_allowed(false);
[email protected]b78e168b2009-09-21 22:05:451171 WebKit::resetPluginCache(reload_pages);
[email protected]a70b4352012-07-31 22:34:531172 webkit_platform_support_->set_plugin_refresh_allowed(true);
[email protected]3b48dbc2012-01-06 16:34:171173
1174 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:271175}
[email protected]85c55dc2009-11-06 03:05:461176
[email protected]f1a29a02011-10-06 23:08:441177void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:091178 EnsureWebKitInitialized();
1179 WebNetworkStateNotifier::setOnLine(online);
1180}
1181
[email protected]b69934e2011-10-29 02:51:521182void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
[email protected]e9ff79c2012-10-19 21:31:261183 GetContentClient()->SetActiveURL(data);
[email protected]b69934e2011-10-29 02:51:521184 CHECK(false);
1185}
1186
[email protected]c6a7b862010-08-20 22:19:381187scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:441188RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]c6a7b862010-08-20 22:19:381189 DCHECK(message_loop() == MessageLoop::current());
1190 if (!file_thread_.get()) {
1191 file_thread_.reset(new base::Thread("Renderer::FILE"));
1192 file_thread_->Start();
1193 }
1194 return file_thread_->message_loop_proxy();
1195}
[email protected]e9ff79c2012-10-19 21:31:261196
[email protected]107c0532013-02-06 02:34:091197void RenderThreadImpl::SetFlingCurveParameters(
1198 const std::vector<float>& new_touchpad,
1199 const std::vector<float>& new_touchscreen) {
1200 webkit_platform_support_->SetFlingCurveParameters(new_touchpad,
1201 new_touchscreen);
1202
1203}
1204
[email protected]e9ff79c2012-10-19 21:31:261205} // namespace content