blob: 3e06f1f1dd2f0503b7c75e48a3fdf21be8b571b7 [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]1332623f12012-08-10 03:45:1382#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
[email protected]f8c648b2012-02-28 03:46:4583#include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h"
[email protected]8bd0fe62011-01-17 06:44:3784#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3786#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]2a23d3f52013-01-08 01:20:2487#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
[email protected]8bd0fe62011-01-17 06:44:3788#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]6eac57a2011-07-12 21:15:0989#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]4bd55a32011-07-28 13:28:3890#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
[email protected]8bd0fe62011-01-17 06:44:3791#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
[email protected]58436a12012-03-21 17:10:2693#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]00fccb42012-12-11 00:09:5994#include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerRepository.h"
[email protected]61a796c42012-05-17 21:28:2095#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]c49201a2012-05-24 11:04:5796#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:3297#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:5098#include "v8/include/v8.h"
[email protected]d471190a2011-02-16 14:52:3099#include "webkit/glue/webkit_glue.h"
[email protected]2c62b562009-01-27 19:04:50100
[email protected]da00a2882009-03-09 17:51:19101#if defined(OS_WIN)
102#include <windows.h>
103#include <objbase.h>
[email protected]5f7e4512012-10-01 20:51:37104#include "base/win/scoped_com_initializer.h"
105#else
106// TODO(port)
107#include "base/memory/scoped_handle.h"
108#include "content/common/np_channel_base.h"
[email protected]da00a2882009-03-09 17:51:19109#endif
110
[email protected]6217d392010-03-25 22:08:35111#if defined(OS_POSIX)
112#include "ipc/ipc_channel_posix.h"
113#endif
114
[email protected]950f9ce22012-12-27 00:25:07115#if defined(ENABLE_WEBRTC)
116#include "third_party/webrtc/system_wrappers/interface/event_tracer.h"
117#endif
118
[email protected]b6cb3a842011-06-24 18:28:41119using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:01120using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:09121using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:00122using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:51123using WebKit::WebScriptController;
[email protected]58436a12012-03-21 17:10:26124using WebKit::WebSecurityPolicy;
[email protected]2c434b32009-03-19 06:27:47125using WebKit::WebString;
[email protected]50ae00ef2009-10-19 05:11:03126using WebKit::WebView;
[email protected]e9ff79c2012-10-19 21:31:26127
128namespace content {
initial.commit09911bf2008-07-26 23:55:29129
[email protected]42f1d7822009-07-23 18:17:55130namespace {
[email protected]da9ccfb2012-01-28 00:34:40131
132const int64 kInitialIdleHandlerDelayMs = 1000;
133const int64 kShortIdleHandlerDelayMs = 1000;
134const int64 kLongIdleHandlerDelayMs = 30*1000;
135const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03136
[email protected]f1a29a02011-10-06 23:08:44137// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16138// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40139base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49140 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54141
[email protected]e9ff79c2012-10-19 21:31:26142class RenderViewZoomer : public RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51143 public:
[email protected]367c5c1d2013-03-11 18:59:02144 RenderViewZoomer(const std::string& scheme,
145 const std::string& host,
146 double zoom_level) : scheme_(scheme),
147 host_(host),
148 zoom_level_(zoom_level) {
[email protected]40bd6582009-12-04 23:49:51149 }
150
[email protected]c3e35892013-02-12 02:08:01151 virtual bool Visit(RenderView* render_view) OVERRIDE {
[email protected]a2ef54c2011-10-10 16:20:31152 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41153 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25154
155 // Don't set zoom level for full-page plugin since they don't use the same
156 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41157 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25158 return true;
[email protected]367c5c1d2013-03-11 18:59:02159 GURL url(document.url());
160 // Empty scheme works as wildcard that matches any scheme,
161 if ((net::GetHostOrSpecFromURL(url) == host_) &&
162 (scheme_.empty() || scheme_ == url.scheme())) {
[email protected]40bd6582009-12-04 23:49:51163 webview->setZoomLevel(false, zoom_level_);
[email protected]367c5c1d2013-03-11 18:59:02164 }
[email protected]40bd6582009-12-04 23:49:51165 return true;
166 }
167
168 private:
[email protected]367c5c1d2013-03-11 18:59:02169 const std::string scheme_;
170 const std::string host_;
171 const double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51172
173 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
174};
[email protected]0478d0162010-08-28 08:29:40175
[email protected]b2d98762012-09-03 17:04:06176std::string HostToCustomHistogramSuffix(const std::string& host) {
177 if (host == "mail.google.com")
178 return ".gmail";
179 if (host == "docs.google.com" || host == "drive.google.com")
180 return ".docs";
181 if (host == "plus.google.com")
182 return ".plus";
[email protected]007b3f82013-04-09 08:46:45183 return std::string();
[email protected]b2d98762012-09-03 17:04:06184}
[email protected]42f1d7822009-07-23 18:17:55185
[email protected]b2d98762012-09-03 17:04:06186void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13187 const char *name, int min, int max, size_t buckets) {
188 if (min <= 0)
189 min = 1;
[email protected]b2d98762012-09-03 17:04:06190 std::string histogram_name;
191 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
192 if (render_thread_impl) { // Can be null in tests.
193 histogram_name = render_thread_impl->
194 histogram_customizer()->ConvertToCustomHistogramName(name);
195 } else {
196 histogram_name = std::string(name);
197 }
[email protected]de415552013-01-23 04:12:17198 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06199 histogram_name, min, max, buckets,
200 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13201 return histogram;
202}
203
[email protected]b2d98762012-09-03 17:04:06204void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13205 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
206 histogram->Add(sample);
207}
208
[email protected]950f9ce22012-12-27 00:25:07209#if defined(ENABLE_WEBRTC)
[email protected]da0f6952012-12-26 22:22:39210const unsigned char* GetCategoryEnabled(const char* name) {
211 return TRACE_EVENT_API_GET_CATEGORY_ENABLED(name);
212}
213
214void AddTraceEvent(char phase,
215 const unsigned char* category_enabled,
216 const char* name,
217 unsigned long long id,
218 int num_args,
219 const char** arg_names,
220 const unsigned char* arg_types,
221 const unsigned long long* arg_values,
222 unsigned char flags) {
223 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_enabled, name, id, num_args,
224 arg_names, arg_types, arg_values, flags);
225}
[email protected]950f9ce22012-12-27 00:25:07226#endif
[email protected]da0f6952012-12-26 22:22:39227
[email protected]b2d98762012-09-03 17:04:06228} // namespace
229
[email protected]fe476b02012-08-13 21:21:38230class RenderThreadImpl::GpuVDAContextLostCallback
231 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
232 public:
233 GpuVDAContextLostCallback() {}
234 virtual ~GpuVDAContextLostCallback() {}
235 virtual void onContextLost() {
236 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind(
237 &RenderThreadImpl::OnGpuVDAContextLoss));
238 }
239};
240
[email protected]00874dd2013-03-08 23:51:18241class RenderThreadImpl::RendererContextProviderCommandBuffer
242 : public ContextProviderCommandBuffer {
[email protected]e06e1122013-03-15 17:12:38243 public:
244 static scoped_refptr<RendererContextProviderCommandBuffer> Create() {
245 scoped_refptr<RendererContextProviderCommandBuffer> provider =
246 new RendererContextProviderCommandBuffer();
247 if (!provider->InitializeOnMainThread())
248 return NULL;
249 return provider;
250 }
251
[email protected]00874dd2013-03-08 23:51:18252 protected:
253 virtual ~RendererContextProviderCommandBuffer() {}
254
255 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]aa3174b2013-03-15 09:12:48256 CreateOffscreenContext3d() OVERRIDE {
[email protected]00874dd2013-03-08 23:51:18257 RenderThreadImpl* self = RenderThreadImpl::current();
258 DCHECK(self);
259 return self->CreateOffscreenContext3d().Pass();
260 }
261};
262
[email protected]b2d98762012-09-03 17:04:06263RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
264 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
265 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
266 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
267}
268
269RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
270
271void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
272 const std::string& host, size_t view_count) {
[email protected]9baee832012-12-10 11:07:15273 if (CommandLine::ForCurrentProcess()->HasSwitch(
274 switches::kDisableHistogramCustomizer)) {
275 return;
276 }
[email protected]b2d98762012-09-03 17:04:06277 // Check if all RenderViews are displaying a page from the same host. If there
278 // is only one RenderView, the common host is this view's host. If there are
279 // many, check if this one shares the common host of the other
280 // RenderViews. It's ok to not detect some cases where the RenderViews share a
281 // common host. This information is only used for producing custom histograms.
282 if (view_count == 1)
283 SetCommonHost(host);
284 else if (host != common_host_)
285 SetCommonHost(std::string());
286}
287
288std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
289 const char* histogram_name) const {
290 std::string name(histogram_name);
291 if (!common_host_histogram_suffix_.empty() &&
292 custom_histograms_.find(name) != custom_histograms_.end())
293 name += common_host_histogram_suffix_;
294 return name;
295}
296
297void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
298 const std::string& host) {
299 if (host != common_host_) {
300 common_host_ = host;
301 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
302 v8::V8::SetCreateHistogramFunction(CreateHistogram);
303 }
304}
305
[email protected]f1a29a02011-10-06 23:08:44306RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06307 return lazy_tls.Pointer()->Get();
308}
309
[email protected]42f1d7822009-07-23 18:17:55310// When we run plugins in process, we actually run them on the render thread,
311// which means that we need to make the render thread pump UI events.
[email protected]f1a29a02011-10-06 23:08:44312RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55313 Init();
314}
315
[email protected]f1a29a02011-10-06 23:08:44316RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55317 : ChildThread(channel_name) {
318 Init();
319}
[email protected]5fa1c542009-05-05 20:36:07320
[email protected]f1a29a02011-10-06 23:08:44321void RenderThreadImpl::Init() {
322 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33323
[email protected]c7e948b42012-07-12 09:20:20324 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
325 v8::V8::SetCreateHistogramFunction(CreateHistogram);
326 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
327
[email protected]d3f09092012-02-16 01:52:17328#if defined(OS_MACOSX) || defined(OS_ANDROID)
329 // On Mac and Android, the select popups are rendered by the browser.
[email protected]53c607c2011-03-21 23:19:04330 WebKit::WebView::setUseExternalPopupMenus(true);
331#endif
332
[email protected]94f9a0f682009-06-15 18:30:30333 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28334
[email protected]2c62b562009-01-27 19:04:50335#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34336 // If you are running plugins in this thread you need COM active but in
337 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28338 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12339 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50340#endif
initial.commit09911bf2008-07-26 23:55:29341
[email protected]06c694d2012-02-01 22:26:16342 // Register this object as the main thread.
343 ChildProcess::current()->set_main_thread(this);
344
[email protected]31f87132010-04-21 23:36:21345 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50346 suspend_webkit_shared_timer_ = true;
347 notify_webkit_of_modal_loop_ = true;
[email protected]bee16aab2009-08-26 15:55:03348 widget_count_ = 0;
349 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44350 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48351 idle_notifications_to_skip_ = 0;
[email protected]e1176152013-03-06 09:16:44352 should_send_focus_ipcs_ = true;
[email protected]8be1c582013-03-06 00:55:03353 short_circuit_size_updates_ = false;
[email protected]ac7f5a02013-03-16 16:14:41354 skip_error_pages_ = false;
[email protected]8d86fce2009-02-26 23:37:55355
[email protected]dcc72db2013-01-02 00:44:18356 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
[email protected]1910fe82012-05-10 00:04:10357 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
[email protected]dcc72db2013-01-02 00:44:18358 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13359
[email protected]d8cd8372012-03-09 10:49:51360 media_stream_center_ = NULL;
361
[email protected]017022b2009-07-27 23:06:34362 db_message_filter_ = new DBMessageFilter();
363 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13364
[email protected]4761cf12012-09-12 10:37:55365#if defined(ENABLE_WEBRTC)
[email protected]da0f6952012-12-26 22:22:39366 webrtc::SetupEventTracer(&GetCategoryEnabled, &AddTraceEvent);
[email protected]af089972013-01-10 04:04:40367
368 peer_connection_tracker_.reset(new PeerConnectionTracker());
369 AddObserver(peer_connection_tracker_.get());
370
[email protected]e9ff79c2012-10-19 21:31:26371 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy());
[email protected]4761cf12012-09-12 10:37:55372 AddFilter(p2p_socket_dispatcher_);
373#endif // defined(ENABLE_WEBRTC)
[email protected]80b161a2011-06-27 17:42:11374 vc_manager_ = new VideoCaptureImplManager();
375 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46376
[email protected]e0a938702013-02-25 21:15:56377 audio_input_message_filter_ =
378 new AudioInputMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51379 AddFilter(audio_input_message_filter_.get());
380
[email protected]e0a938702013-02-25 21:15:56381 audio_message_filter_ = new AudioMessageFilter(GetIOMessageLoopProxy());
[email protected]f7eb0a392011-07-12 10:19:51382 AddFilter(audio_message_filter_.get());
383
[email protected]31bfae72011-12-16 02:04:38384 AddFilter(new IndexedDBMessageFilter);
385
[email protected]e9ff79c2012-10-19 21:31:26386 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24387
[email protected]302fe422012-06-11 14:49:11388 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01389 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking))
[email protected]e9ff79c2012-10-19 21:31:26390 RegisterExtension(GpuBenchmarkingExtension::Get());
[email protected]e54ab492012-06-12 19:40:01391
[email protected]6941ac5c2013-02-07 03:59:56392 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
393 RegisterExtension(MemoryBenchmarkingExtension::Get());
394
[email protected]fe476b02012-08-13 21:21:38395 context_lost_cb_.reset(new GpuVDAContextLostCallback());
396
[email protected]433df472012-03-07 20:33:39397 // Note that under Linux, the media library will normally already have
398 // been initialized by the Zygote before this instance became a Renderer.
[email protected]c42de732013-02-16 06:26:31399 base::FilePath media_path;
[email protected]e9ff79c2012-10-19 21:31:26400 PathService::Get(DIR_MEDIA_LIBS, &media_path);
[email protected]433df472012-03-07 20:33:39401 if (!media_path.empty())
402 media::InitializeMediaLibrary(media_path);
403
[email protected]f1a29a02011-10-06 23:08:44404 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29405}
406
[email protected]f1a29a02011-10-06 23:08:44407RenderThreadImpl::~RenderThreadImpl() {
[email protected]1223d6ef2011-03-28 16:47:50408 FOR_EACH_OBSERVER(
409 RenderProcessObserver, observers_, OnRenderProcessShutdown());
410
[email protected]12cbfda32010-01-30 01:04:25411 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08412 if (web_database_observer_impl_.get())
413 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25414
[email protected]8d86fce2009-02-26 23:37:55415 // Shutdown in reverse of the initialization order.
[email protected]b146d6d2012-09-11 10:20:05416 if (devtools_agent_message_filter_.get()) {
417 RemoveFilter(devtools_agent_message_filter_.get());
418 devtools_agent_message_filter_ = NULL;
419 }
[email protected]82622452011-07-22 09:57:20420
[email protected]f7eb0a392011-07-12 10:19:51421 RemoveFilter(audio_input_message_filter_.get());
422 audio_input_message_filter_ = NULL;
423
424 RemoveFilter(audio_message_filter_.get());
425 audio_message_filter_ = NULL;
426
[email protected]80b161a2011-06-27 17:42:11427 RemoveFilter(vc_manager_->video_capture_message_filter());
428
[email protected]017022b2009-07-27 23:06:34429 RemoveFilter(db_message_filter_.get());
430 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25431
[email protected]c6a7b862010-08-20 22:19:38432 // Shutdown the file thread if it's running.
433 if (file_thread_.get())
434 file_thread_->Stop();
435
[email protected]23d2b7e2012-08-14 00:34:09436 if (compositor_output_surface_filter_.get()) {
437 RemoveFilter(compositor_output_surface_filter_.get());
438 compositor_output_surface_filter_ = NULL;
439 }
[email protected]1842fe22012-08-13 23:24:35440
[email protected]79a92b52013-04-08 19:09:02441 compositor_thread_.reset();
[email protected]ea5f70a2013-03-07 12:30:36442 if (input_handler_manager_.get()) {
443 RemoveFilter(input_handler_manager_->GetMessageFilter());
444 input_handler_manager_.reset();
[email protected]a9fb30aa2011-10-06 06:58:46445 }
446
[email protected]8d6cba42011-09-02 10:05:19447 if (webkit_platform_support_.get())
[email protected]9291ed12009-07-23 17:33:22448 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22449
[email protected]94f9a0f682009-06-15 18:30:30450 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30451
[email protected]8d86fce2009-02-26 23:37:55452 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50453#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29454 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50455 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50456#endif
[email protected]00874dd2013-03-08 23:51:18457
458 // Leak shared contexts on other threads, as we can not get to the correct
459 // thread to destroy them.
460 if (shared_contexts_compositor_thread_)
461 shared_contexts_compositor_thread_->set_leak_on_destroy();
initial.commit09911bf2008-07-26 23:55:29462}
463
[email protected]f1a29a02011-10-06 23:08:44464bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14465 // Certain synchronous messages cannot always be processed synchronously by
466 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50467 // This could cause a complete hang of Chrome if a windowed plug-in is trying
468 // to communicate with the renderer thread since the browser's UI thread
469 // could be stuck (within a Windows API call) trying to synchronously
470 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14471 // thread while the browser is processing this request. This creates an
472 // opportunity for re-entrancy into WebKit, so we need to take care to disable
473 // callbacks, timers, and pending network loads that could trigger such
474 // callbacks.
[email protected]38b592902011-04-16 02:08:42475 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50476 if (msg->is_sync()) {
477 if (msg->is_caller_pumping_messages()) {
478 pumping_events = true;
479 } else {
[email protected]38b592902011-04-16 02:08:42480 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
481 msg->type() == ViewHostMsg_GetRawCookies::ID ||
482 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
[email protected]e9ff79c2012-10-19 21:31:26483 GetContentClient()->renderer()->
[email protected]38b592902011-04-16 02:08:42484 ShouldPumpEventsDuringCookieMessage()) {
485 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50486 }
487 }
[email protected]c1f50aa2010-02-18 03:46:57488 }
489
[email protected]80fc08c52010-03-09 07:43:50490 bool suspend_webkit_shared_timer = true; // default value
491 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57492
[email protected]80fc08c52010-03-09 07:43:50493 bool notify_webkit_of_modal_loop = true; // default value
494 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
495
[email protected]c48de1a2012-11-02 19:06:56496 int render_view_id = MSG_ROUTING_NONE;
[email protected]c1f50aa2010-02-18 03:46:57497
498 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50499 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19500 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57501
[email protected]39065d012010-07-09 11:22:46502 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57503 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57504
[email protected]80fc08c52010-03-09 07:43:50505 RenderWidget* widget =
506 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
507 if (widget) {
[email protected]c48de1a2012-11-02 19:06:56508 render_view_id = widget->routing_id();
[email protected]c1f50aa2010-02-18 03:46:57509 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56510 new PluginMsg_SignalModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57511 }
512 }
513
514 bool rv = ChildThread::Send(msg);
515
516 if (pumping_events) {
[email protected]c48de1a2012-11-02 19:06:56517 if (render_view_id != MSG_ROUTING_NONE) {
[email protected]c1f50aa2010-02-18 03:46:57518 PluginChannelHost::Broadcast(
[email protected]c48de1a2012-11-02 19:06:56519 new PluginMsg_ResetModalDialogEvent(render_view_id));
[email protected]c1f50aa2010-02-18 03:46:57520 }
521
[email protected]39065d012010-07-09 11:22:46522 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57523 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57524
[email protected]80fc08c52010-03-09 07:43:50525 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19526 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57527 }
528
529 return rv;
530}
531
[email protected]f1a29a02011-10-06 23:08:44532MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06533 return message_loop();
534}
535
[email protected]f1a29a02011-10-06 23:08:44536IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06537 return channel();
538}
539
[email protected]f1a29a02011-10-06 23:08:44540std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06541 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:02542 // --lang command line flag.
[email protected]526476902011-10-06 20:34:06543 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
544 const std::string& lang =
545 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:02546 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:06547 return lang;
548}
549
[email protected]07bb6332012-01-21 01:07:57550IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
551 return sync_message_filter();
552}
553
[email protected]96191d52012-05-17 01:37:11554scoped_refptr<base::MessageLoopProxy>
555 RenderThreadImpl::GetIOMessageLoopProxy() {
556 return ChildProcess::current()->io_message_loop_proxy();
557}
558
[email protected]c47317e2012-06-20 22:35:31559void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57560 widget_count_++;
561 return ChildThread::AddRoute(routing_id, listener);
562}
563
[email protected]f1a29a02011-10-06 23:08:44564void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57565 widget_count_--;
566 return ChildThread::RemoveRoute(routing_id);
567}
568
[email protected]77fc9b92011-10-15 16:20:37569int RenderThreadImpl::GenerateRoutingID() {
570 int routing_id = MSG_ROUTING_NONE;
571 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
572 return routing_id;
573}
574
[email protected]f1a29a02011-10-06 23:08:44575void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55576 channel()->AddFilter(filter);
577}
578
[email protected]f1a29a02011-10-06 23:08:44579void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55580 channel()->RemoveFilter(filter);
581}
582
[email protected]f1a29a02011-10-06 23:08:44583void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06584 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
585}
586
[email protected]e9ff79c2012-10-19 21:31:26587void RenderThreadImpl::AddObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06588 observers_.AddObserver(observer);
589}
590
[email protected]e9ff79c2012-10-19 21:31:26591void RenderThreadImpl::RemoveObserver(RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06592 observers_.RemoveObserver(observer);
593}
594
[email protected]359dfa32011-10-12 01:10:15595void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:26596 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:15597 resource_dispatcher()->set_delegate(delegate);
598}
599
[email protected]f1a29a02011-10-06 23:08:44600void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03601 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50602 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24603
[email protected]e9ff79c2012-10-19 21:31:26604 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24605 return;
606 }
607
608 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44609 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03610}
611
[email protected]f1a29a02011-10-06 23:08:44612void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08613 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03614 hidden_widget_count_--;
[email protected]e9ff79c2012-10-19 21:31:26615 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]6779aa12011-03-29 17:32:24616 return;
617 }
[email protected]bee16aab2009-08-26 15:55:03618
[email protected]1784b2f2011-11-24 10:53:48619 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39620}
621
[email protected]f1a29a02011-10-06 23:08:44622void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]8d6cba42011-09-02 10:05:19623 if (webkit_platform_support_.get())
[email protected]d1b8fccc2011-08-03 01:20:13624 return;
625
[email protected]8d6cba42011-09-02 10:05:19626 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
627 WebKit::initialize(webkit_platform_support_.get());
[email protected]00fccb42012-12-11 00:09:59628 WebKit::setSharedWorkerRepository(
629 webkit_platform_support_.get()->sharedWorkerRepository());
[email protected]2a23d3f52013-01-08 01:20:24630 WebKit::setIDBFactory(
631 webkit_platform_support_.get()->idbFactory());
[email protected]d1b8fccc2011-08-03 01:20:13632
[email protected]cd7ce3be2012-09-10 05:19:41633 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]cd7ce3be2012-09-10 05:19:41634
[email protected]0f21e8582013-01-11 11:06:56635 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing);
[email protected]72787e392012-03-23 05:55:43636 if (enable) {
[email protected]ea5f70a2013-03-07 12:30:36637 MessageLoop* override_loop =
638 GetContentClient()->renderer()->OverrideCompositorMessageLoop();
639 if (override_loop) {
640 compositor_message_loop_proxy_ = override_loop->message_loop_proxy();
641 } else {
642 compositor_thread_.reset(new base::Thread("Compositor"));
643 compositor_thread_->Start();
644 compositor_message_loop_proxy_ =
645 compositor_thread_->message_loop_proxy();
646 }
647
[email protected]d0874b22013-03-18 20:33:03648 if (GetContentClient()->renderer()->ShouldCreateCompositorInputHandler()) {
649 input_handler_manager_.reset(
650 new InputHandlerManager(this, compositor_message_loop_proxy_));
651 AddFilter(input_handler_manager_->GetMessageFilter());
652 }
[email protected]a458504b2012-07-23 19:57:06653 }
[email protected]a9fb30aa2011-10-06 06:58:46654
[email protected]ea5f70a2013-03-07 12:30:36655 scoped_refptr<base::MessageLoopProxy> output_surface_loop;
[email protected]7f1f63f2013-03-07 06:07:29656 if (enable)
[email protected]ea5f70a2013-03-07 12:30:36657 output_surface_loop = compositor_message_loop_proxy_;
[email protected]7f1f63f2013-03-07 06:07:29658 else
659 output_surface_loop = base::MessageLoopProxy::current();
[email protected]1842fe22012-08-13 23:24:35660
[email protected]7f1f63f2013-03-07 06:07:29661 compositor_output_surface_filter_ =
662 CompositorOutputSurface::CreateFilter(output_surface_loop);
[email protected]1842fe22012-08-13 23:24:35663 AddFilter(compositor_output_surface_filter_.get());
664
[email protected]d1b8fccc2011-08-03 01:20:13665 WebScriptController::enableV8SingleThreadMode();
666
[email protected]58436a12012-03-21 17:10:26667 RenderThreadImpl::RegisterSchemes();
668
[email protected]d1b8fccc2011-08-03 01:20:13669 webkit_glue::EnableWebCoreLogChannels(
670 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
671
[email protected]fa1c17e42012-03-06 22:29:54672 web_database_observer_impl_.reset(
673 new WebDatabaseObserverImpl(sync_message_filter()));
[email protected]d1b8fccc2011-08-03 01:20:13674 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
675
676 WebRuntimeFeatures::enableSockets(
677 !command_line.HasSwitch(switches::kDisableWebSockets));
678
679 WebRuntimeFeatures::enableDatabase(
680 !command_line.HasSwitch(switches::kDisableDatabases));
681
682 WebRuntimeFeatures::enableDataTransferItems(
683 !command_line.HasSwitch(switches::kDisableDataTransferItems));
684
685 WebRuntimeFeatures::enableApplicationCache(
686 !command_line.HasSwitch(switches::kDisableApplicationCache));
687
688 WebRuntimeFeatures::enableNotifications(
689 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
690
691 WebRuntimeFeatures::enableLocalStorage(
692 !command_line.HasSwitch(switches::kDisableLocalStorage));
693 WebRuntimeFeatures::enableSessionStorage(
694 !command_line.HasSwitch(switches::kDisableSessionStorage));
695
[email protected]b3796c82012-01-19 08:34:33696 WebRuntimeFeatures::enableIndexedDatabase(true);
[email protected]d1b8fccc2011-08-03 01:20:13697
698 WebRuntimeFeatures::enableGeolocation(
699 !command_line.HasSwitch(switches::kDisableGeolocation));
700
[email protected]6aa03b32011-10-27 21:44:44701 WebKit::WebRuntimeFeatures::enableMediaSource(
[email protected]da43c082012-09-07 18:56:11702 !command_line.HasSwitch(switches::kDisableMediaSource));
[email protected]6aa03b32011-10-27 21:44:44703
[email protected]433df472012-03-07 20:33:39704 WebRuntimeFeatures::enableMediaPlayer(
705 media::IsMediaLibraryInitialized());
706
[email protected]d9da9582013-01-31 04:59:05707#if defined(OS_ANDROID)
708 WebKit::WebRuntimeFeatures::enableMediaStream(
[email protected]ce585bf2013-03-14 16:25:16709 !command_line.HasSwitch(switches::kDisableWebRTC));
[email protected]d9da9582013-01-31 04:59:05710 WebKit::WebRuntimeFeatures::enablePeerConnection(
[email protected]ce585bf2013-03-14 16:25:16711 !command_line.HasSwitch(switches::kDisableWebRTC));
[email protected]d9da9582013-01-31 04:59:05712#else
[email protected]7082fb942012-05-16 23:44:59713 WebKit::WebRuntimeFeatures::enableMediaStream(true);
[email protected]cdb609e72012-08-30 10:49:58714 WebKit::WebRuntimeFeatures::enablePeerConnection(true);
[email protected]d9da9582013-01-31 04:59:05715#endif
[email protected]8ea05a12012-05-02 09:17:47716
[email protected]efdc0282011-08-26 00:36:12717 WebKit::WebRuntimeFeatures::enableFullScreenAPI(
[email protected]5e5671a2011-09-08 02:12:21718 !command_line.HasSwitch(switches::kDisableFullScreen));
[email protected]efdc0282011-08-26 00:36:12719
[email protected]9f5b7822012-04-18 23:39:03720 WebKit::WebRuntimeFeatures::enableEncryptedMedia(
[email protected]36d98412013-01-31 20:28:53721 !command_line.HasSwitch(switches::kDisableEncryptedMedia));
[email protected]9f5b7822012-04-18 23:39:03722
[email protected]634a3bd2012-07-26 04:49:01723#if defined(OS_ANDROID)
724 WebRuntimeFeatures::enableWebAudio(
725 command_line.HasSwitch(switches::kEnableWebAudio) &&
726 media::IsMediaLibraryInitialized());
727#else
[email protected]d1b8fccc2011-08-03 01:20:13728 WebRuntimeFeatures::enableWebAudio(
[email protected]6a1f9cf2012-05-24 21:23:45729 !command_line.HasSwitch(switches::kDisableWebAudio) &&
730 media::IsMediaLibraryInitialized());
[email protected]634a3bd2012-07-26 04:49:01731#endif
[email protected]d1b8fccc2011-08-03 01:20:13732
[email protected]d1b8fccc2011-08-03 01:20:13733 WebRuntimeFeatures::enableDeviceMotion(
734 command_line.HasSwitch(switches::kEnableDeviceMotion));
735
736 WebRuntimeFeatures::enableDeviceOrientation(
737 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
738
739 WebRuntimeFeatures::enableSpeechInput(
740 !command_line.HasSwitch(switches::kDisableSpeechInput));
741
[email protected]0cc3e8022013-01-16 11:41:24742#if defined(OS_ANDROID)
743 // Web Speech API Speech recognition is not implemented on Android yet.
744 WebRuntimeFeatures::enableScriptedSpeech(false);
745#else
[email protected]14f843ea2012-12-01 20:26:29746 WebRuntimeFeatures::enableScriptedSpeech(true);
[email protected]0cc3e8022013-01-16 11:41:24747#endif
[email protected]9b7b57d2012-03-21 13:17:48748
[email protected]d1b8fccc2011-08-03 01:20:13749 WebRuntimeFeatures::enableFileSystem(
750 !command_line.HasSwitch(switches::kDisableFileSystem));
751
752 WebRuntimeFeatures::enableJavaScriptI18NAPI(
753 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI));
754
[email protected]d7a35b72012-05-17 15:59:57755 WebRuntimeFeatures::enableGamepad(true);
[email protected]0205fbf2011-11-30 21:51:36756
[email protected]d1b8fccc2011-08-03 01:20:13757 WebRuntimeFeatures::enableQuota(true);
758
[email protected]739d08d32012-10-12 07:38:14759 WebRuntimeFeatures::enableShadowDOM(true);
[email protected]d2edc6702012-01-30 09:13:16760
[email protected]d9a64602012-12-21 07:28:05761 if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures)) {
762 WebRuntimeFeatures::enableStyleScoped(true);
[email protected]0374ada2013-03-01 02:58:42763 WebRuntimeFeatures::enableCustomDOMElements(true);
[email protected]d9a64602012-12-21 07:28:05764 WebRuntimeFeatures::enableCSSExclusions(true);
765 WebRuntimeFeatures::enableExperimentalContentSecurityPolicyFeatures(true);
766 WebRuntimeFeatures::enableCSSRegions(true);
767 WebRuntimeFeatures::enableDialogElement(true);
[email protected]7c884162013-03-19 10:19:16768 WebRuntimeFeatures::enableFontLoadEvents(true);
[email protected]d9a64602012-12-21 07:28:05769 }
[email protected]4ae41b42012-12-06 21:59:03770
[email protected]d3e7aea22013-01-09 08:47:53771 WebRuntimeFeatures::enableSeamlessIFrames(
772 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures));
773
[email protected]d1b8fccc2011-08-03 01:20:13774 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48775
[email protected]b146d6d2012-09-11 10:20:05776 devtools_agent_message_filter_ = new DevToolsAgentFilter();
777 AddFilter(devtools_agent_message_filter_.get());
778
[email protected]e9ff79c2012-10-19 21:31:26779 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]1784b2f2011-11-24 10:53:48780 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]d1b8fccc2011-08-03 01:20:13781}
782
[email protected]58436a12012-03-21 17:10:26783void RenderThreadImpl::RegisterSchemes() {
784 // swappedout: pages should not be accessible, and should also
785 // be treated as empty documents that can commit synchronously.
786 WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme));
787 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme);
788 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme);
789}
790
[email protected]f1a29a02011-10-06 23:08:44791void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06792 Send(new ViewHostMsg_UserMetricsRecordAction(action));
793}
794
[email protected]fb79aa22012-12-13 01:12:13795scoped_ptr<base::SharedMemory>
[email protected]3f892832013-01-11 03:23:59796 RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
797 if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
798 return scoped_ptr<base::SharedMemory>();
799
[email protected]fb79aa22012-12-13 01:12:13800 base::SharedMemoryHandle handle;
801 bool success;
802 IPC::Message* message =
803 new ChildProcessHostMsg_SyncAllocateSharedMemory(size, &handle);
804
805 // Allow calling this from the compositor thread.
806 if (MessageLoop::current() == message_loop())
807 success = ChildThread::Send(message);
808 else
809 success = sync_message_filter()->Send(message);
810
811 if (!success)
812 return scoped_ptr<base::SharedMemory>();
813
814 if (!base::SharedMemory::IsHandleValid(handle))
815 return scoped_ptr<base::SharedMemory>();
816
817 return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false));
[email protected]00614a82011-10-07 22:39:31818}
819
[email protected]f1a29a02011-10-06 23:08:44820void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06821 WebScriptController::registerExtension(extension);
[email protected]526476902011-10-06 20:34:06822}
823
[email protected]6593ae12011-11-14 12:09:44824void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
825 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06826 idle_timer_.Stop();
827 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44828 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44829 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06830}
831
[email protected]f1a29a02011-10-06 23:08:44832void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48833 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:26834 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:48835 RunIdleHandlerWhenWidgetsHidden();
836 if (run_in_foreground_tab) {
837 IdleHandlerInForegroundTab();
838 return;
839 }
[email protected]237a14852012-04-28 02:56:38840
841 base::allocator::ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:06842
843 v8::V8::IdleNotification();
844
845 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44846 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06847 // delay = delay + 1 / (delay + 2)
848 // Using floor(delay) has a dampening effect such as:
849 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44850 // If the delay is in milliseconds, the above formula is equivalent to:
851 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
852 // which is equivalent to
853 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
854 // Note that idle_notification_delay_in_ms_ would be reset to
855 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
856 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
857 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06858
859 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
860}
861
[email protected]1784b2f2011-11-24 10:53:48862void RenderThreadImpl::IdleHandlerInForegroundTab() {
863 // Increase the delay in the same way as in IdleHandler,
864 // but make it periodic by reseting it once it is too big.
865 int64 new_delay_ms = idle_notification_delay_in_ms_ +
866 1000000 / (idle_notification_delay_in_ms_ + 2000);
867 if (new_delay_ms >= kLongIdleHandlerDelayMs)
868 new_delay_ms = kShortIdleHandlerDelayMs;
869
[email protected]1784b2f2011-11-24 10:53:48870 if (idle_notifications_to_skip_ > 0) {
871 idle_notifications_to_skip_--;
[email protected]7e967f82011-12-01 09:35:14872 } else {
[email protected]a47105c832011-12-07 17:24:30873 int cpu_usage = 0;
[email protected]7e967f82011-12-01 09:35:14874 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
[email protected]1393c4a2012-02-07 10:12:58875 // Idle notification hint roughly specifies the expected duration of the
876 // idle pause. We set it proportional to the idle timer delay.
877 int idle_hint = static_cast<int>(new_delay_ms / 10);
[email protected]d7e59252012-03-06 22:26:02878 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
[email protected]237a14852012-04-28 02:56:38879 base::allocator::ReleaseFreeMemory();
[email protected]d7e59252012-03-06 22:26:02880 if (v8::V8::IdleNotification(idle_hint)) {
881 // V8 finished collecting garbage.
882 new_delay_ms = kLongIdleHandlerDelayMs;
883 }
[email protected]1784b2f2011-11-24 10:53:48884 }
885 }
[email protected]1784b2f2011-11-24 10:53:48886 ScheduleIdleHandler(new_delay_ms);
887}
888
[email protected]6593ae12011-11-14 12:09:44889int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
890 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06891}
892
[email protected]6593ae12011-11-14 12:09:44893void RenderThreadImpl::SetIdleNotificationDelayInMs(
894 int64 idle_notification_delay_in_ms) {
895 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08896}
897
[email protected]a1a7ff32012-07-19 14:03:51898void RenderThreadImpl::ToggleWebKitSharedTimer(bool suspend) {
899 if (suspend_webkit_shared_timer_) {
900 EnsureWebKitInitialized();
901 if (suspend) {
902 webkit_platform_support_->SuspendSharedTimer();
903 } else {
904 webkit_platform_support_->ResumeSharedTimer();
905 }
906 }
907}
908
909void RenderThreadImpl::UpdateHistograms(int sequence_number) {
910 child_histogram_message_filter()->SendHistograms(sequence_number);
911}
912
[email protected]b02f5902012-12-19 07:33:00913bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
914 bool result = false;
915 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
916 return result;
917}
918
[email protected]1784b2f2011-11-24 10:53:48919void RenderThreadImpl::PostponeIdleNotification() {
920 idle_notifications_to_skip_ = 2;
921}
922
[email protected]fe476b02012-08-13 21:21:38923/* static */
924void RenderThreadImpl::OnGpuVDAContextLoss() {
925 RenderThreadImpl* self = RenderThreadImpl::current();
926 DCHECK(self);
927 if (!self->gpu_vda_context3d_.get())
928 return;
[email protected]ea5f70a2013-03-07 12:30:36929 if (self->compositor_message_loop_proxy()) {
930 self->compositor_message_loop_proxy()->DeleteSoon(
[email protected]fe476b02012-08-13 21:21:38931 FROM_HERE, self->gpu_vda_context3d_.release());
932 } else {
933 self->gpu_vda_context3d_.reset();
[email protected]3b2afc32012-06-18 21:31:16934 }
[email protected]fe476b02012-08-13 21:21:38935}
936
937WebGraphicsContext3DCommandBufferImpl*
938RenderThreadImpl::GetGpuVDAContext3D() {
[email protected]3b2afc32012-06-18 21:31:16939 if (!gpu_vda_context3d_.get()) {
940 gpu_vda_context3d_.reset(
941 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
[email protected]d1a9e062012-07-13 00:45:14942 this, WebKit::WebGraphicsContext3D::Attributes(),
943 GURL("chrome://gpu/RenderThreadImpl::GetGpuVDAContext3D")));
[email protected]fde3e2f2012-08-14 06:51:37944 if (gpu_vda_context3d_.get())
945 gpu_vda_context3d_->setContextLostCallback(context_lost_cb_.get());
[email protected]3b2afc32012-06-18 21:31:16946 }
[email protected]fe476b02012-08-13 21:21:38947 return gpu_vda_context3d_.get();
[email protected]3b2afc32012-06-18 21:31:16948}
949
[email protected]c29b7ff2013-03-06 03:51:04950scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
951RenderThreadImpl::CreateOffscreenContext3d() {
952 WebKit::WebGraphicsContext3D::Attributes attributes;
953 attributes.shareResources = true;
954 attributes.depth = false;
955 attributes.stencil = false;
956 attributes.antialias = false;
957 attributes.noAutomaticFlushes = true;
958
959 return make_scoped_ptr(
960 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
961 this,
962 attributes,
963 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext3d")));
964}
965
[email protected]a45c46e2013-03-07 01:04:46966scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:04967RenderThreadImpl::OffscreenContextProviderForMainThread() {
[email protected]e06e1122013-03-15 17:12:38968 DCHECK(IsMainThread());
969
[email protected]c29b7ff2013-03-06 03:51:04970 if (!shared_contexts_main_thread_ ||
[email protected]e06e1122013-03-15 17:12:38971 shared_contexts_main_thread_->DestroyedOnMainThread()) {
972 shared_contexts_main_thread_ =
973 RendererContextProviderCommandBuffer::Create();
974 if (shared_contexts_main_thread_ &&
975 !shared_contexts_main_thread_->BindToCurrentThread())
976 shared_contexts_main_thread_ = NULL;
977 }
[email protected]c29b7ff2013-03-06 03:51:04978 return shared_contexts_main_thread_;
979}
980
[email protected]a45c46e2013-03-07 01:04:46981scoped_refptr<ContextProviderCommandBuffer>
[email protected]c29b7ff2013-03-06 03:51:04982RenderThreadImpl::OffscreenContextProviderForCompositorThread() {
[email protected]e06e1122013-03-15 17:12:38983 DCHECK(IsMainThread());
984
[email protected]c29b7ff2013-03-06 03:51:04985 if (!shared_contexts_compositor_thread_ ||
986 shared_contexts_compositor_thread_->DestroyedOnMainThread()) {
987 shared_contexts_compositor_thread_ =
[email protected]e06e1122013-03-15 17:12:38988 RendererContextProviderCommandBuffer::Create();
[email protected]c29b7ff2013-03-06 03:51:04989 }
990 return shared_contexts_compositor_thread_;
991}
992
[email protected]e9ff79c2012-10-19 21:31:26993AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]3958e972012-07-17 00:25:41994 if (!audio_renderer_mixer_manager_.get()) {
995 audio_renderer_mixer_manager_.reset(new AudioRendererMixerManager(
[email protected]563d665f2013-02-01 04:42:39996 GetAudioHardwareConfig()));
[email protected]3958e972012-07-17 00:25:41997 }
998
999 return audio_renderer_mixer_manager_.get();
1000}
1001
[email protected]563d665f2013-02-01 04:42:391002media::AudioHardwareConfig* RenderThreadImpl::GetAudioHardwareConfig() {
1003 if (!audio_hardware_config_) {
[email protected]06ea4f7c2013-03-13 20:36:511004 media::AudioParameters input_params;
1005 media::AudioParameters output_params;
[email protected]563d665f2013-02-01 04:42:391006 Send(new ViewHostMsg_GetAudioHardwareConfig(
[email protected]06ea4f7c2013-03-13 20:36:511007 &input_params, &output_params));
[email protected]563d665f2013-02-01 04:42:391008
1009 audio_hardware_config_.reset(new media::AudioHardwareConfig(
[email protected]06ea4f7c2013-03-13 20:36:511010 input_params, output_params));
[email protected]563d665f2013-02-01 04:42:391011 audio_message_filter_->SetAudioHardwareConfig(audio_hardware_config_.get());
1012 }
1013
1014 return audio_hardware_config_.get();
1015}
1016
[email protected]4a7d6392011-09-19 20:55:081017#if defined(OS_WIN)
[email protected]feb32372012-11-21 01:14:561018void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font,
1019 const string16& str) {
1020 Send(new ViewHostMsg_PreCacheFontCharacters(log_font, str));
1021}
1022
[email protected]f1a29a02011-10-06 23:08:441023void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:061024 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:211025}
1026
[email protected]f1a29a02011-10-06 23:08:441027void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:061028 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:081029}
[email protected]526476902011-10-06 20:34:061030
[email protected]4a7d6392011-09-19 20:55:081031#endif // OS_WIN
1032
[email protected]988aacf2012-02-12 18:10:031033bool RenderThreadImpl::IsWebFrameValid(WebKit::WebFrame* web_frame) {
1034 if (!web_frame)
[email protected]4761cf12012-09-12 10:37:551035 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031036
1037 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
1038 if (!render_view)
[email protected]4761cf12012-09-12 10:37:551039 return false; // We must be shutting down.
[email protected]988aacf2012-02-12 18:10:031040
1041 return true;
1042}
1043
[email protected]b3e83de2012-02-07 03:33:281044bool RenderThreadImpl::IsMainThread() {
1045 return !!current();
1046}
1047
1048bool RenderThreadImpl::IsIOThread() {
1049 return MessageLoop::current() == ChildProcess::current()->io_message_loop();
1050}
1051
1052MessageLoop* RenderThreadImpl::GetMainLoop() {
1053 return message_loop();
1054}
[email protected]5b040e592012-02-10 02:56:101055
1056scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() {
[email protected]b3e83de2012-02-07 03:33:281057 return ChildProcess::current()->io_message_loop_proxy();
1058}
1059
1060base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() {
1061 return ChildProcess::current()->GetShutDownEvent();
1062}
1063
1064scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory(
[email protected]3f892832013-01-11 03:23:591065 size_t size) {
[email protected]fb79aa22012-12-13 01:12:131066 return scoped_ptr<base::SharedMemory>(
1067 HostAllocateSharedMemoryBuffer(size));
[email protected]b3e83de2012-02-07 03:33:281068}
1069
1070int32 RenderThreadImpl::CreateViewCommandBuffer(
1071 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) {
[email protected]d13f35d2012-05-18 02:28:151072 TRACE_EVENT1("gpu",
1073 "RenderThreadImpl::CreateViewCommandBuffer",
1074 "surface_id",
1075 surface_id);
1076
[email protected]b3e83de2012-02-07 03:33:281077 int32 route_id = MSG_ROUTING_NONE;
[email protected]8b10b332012-02-29 21:02:141078 IPC::Message* message = new GpuHostMsg_CreateViewCommandBuffer(
[email protected]b3e83de2012-02-07 03:33:281079 surface_id,
1080 init_params,
[email protected]8b10b332012-02-29 21:02:141081 &route_id);
1082
1083 // Allow calling this from the compositor thread.
1084 if (MessageLoop::current() == message_loop())
1085 ChildThread::Send(message);
1086 else
1087 sync_message_filter()->Send(message);
1088
[email protected]b3e83de2012-02-07 03:33:281089 return route_id;
1090}
1091
[email protected]09d50362012-10-18 20:54:371092void RenderThreadImpl::CreateImage(
1093 gfx::PluginWindowHandle window,
1094 int32 image_id,
1095 const CreateImageCallback& callback) {
1096 NOTREACHED();
1097}
1098
1099void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) {
1100 NOTREACHED();
1101}
1102
[email protected]f1a29a02011-10-06 23:08:441103void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:061104 suspend_webkit_shared_timer_ = false;
1105}
1106
[email protected]f1a29a02011-10-06 23:08:441107void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:061108 notify_webkit_of_modal_loop_ = false;
1109}
1110
[email protected]367c5c1d2013-03-11 18:59:021111void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& scheme,
1112 const std::string& host,
[email protected]f1a29a02011-10-06 23:08:441113 double zoom_level) {
[email protected]367c5c1d2013-03-11 18:59:021114 RenderViewZoomer zoomer(scheme, host, zoom_level);
[email protected]e9ff79c2012-10-19 21:31:261115 RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:061116}
1117
[email protected]f1a29a02011-10-06 23:08:441118bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:501119 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
1120 RenderProcessObserver* observer;
1121 while ((observer = it.GetNext()) != NULL) {
1122 if (observer->OnControlMessageReceived(msg))
1123 return true;
1124 }
1125
[email protected]70c19a932010-05-14 12:59:111126 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101127 if (appcache_dispatcher_->OnMessageReceived(msg) ||
1128 dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281129 return true;
[email protected]1910fe82012-05-10 00:04:101130 }
[email protected]1edc16b82009-04-07 17:45:541131
[email protected]a95986a82010-12-24 06:19:281132 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:441133 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:541134 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
1135 OnSetZoomLevelForCurrentURL)
[email protected]8930d472009-02-21 08:05:281136 // TODO(port): removed from render_messages_internal.h;
1137 // is there a new non-windows message I should add here?
1138 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:451139 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:091140 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]b69934e2011-10-29 02:51:521141 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]44363382013-03-12 07:22:471142 IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended,
1143 OnSetWebKitSharedTimersSuspended)
[email protected]a95986a82010-12-24 06:19:281144 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281145 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281146 return handled;
initial.commit09911bf2008-07-26 23:55:291147}
1148
[email protected]f1a29a02011-10-06 23:08:441149void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:471150 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:331151 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]6cd7c6b2012-10-25 03:26:231152 RenderViewImpl::Create(
[email protected]6cd7c6b2012-10-25 03:26:231153 params.opener_route_id,
1154 params.renderer_preferences,
1155 params.web_preferences,
1156 new SharedRenderViewCounter(0),
1157 params.view_id,
1158 params.surface_id,
1159 params.session_storage_namespace_id,
1160 params.frame_name,
1161 false,
1162 params.swapped_out,
1163 params.next_page_id,
1164 params.screen_info,
[email protected]34bb3ac2013-03-08 02:41:281165 params.accessibility_mode,
1166 params.allow_partial_swap);
[email protected]7f874dec2009-02-06 01:48:271167}
[email protected]4274e582009-01-27 22:09:561168
[email protected]f1a29a02011-10-06 23:08:441169GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:261170 CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]d13f35d2012-05-18 02:28:151171 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1172
[email protected]6217d392010-03-25 22:08:351173 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:221174 // Do nothing if we already have a GPU channel or are already
1175 // establishing one.
[email protected]e09cee42010-11-09 01:50:081176 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
1177 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:041178 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:351179
1180 // Recreate the channel if it has been lost.
[email protected]894e8fc2012-02-24 13:29:501181 gpu_channel_ = NULL;
[email protected]6217d392010-03-25 22:08:351182 }
1183
[email protected]6217d392010-03-25 22:08:351184 // Ask the browser for the channel name.
[email protected]894e8fc2012-02-24 13:29:501185 int client_id = 0;
[email protected]b42a9f62011-06-08 20:36:041186 IPC::ChannelHandle channel_handle;
[email protected]e9ff79c2012-10-19 21:31:261187 GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:041188 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
[email protected]894e8fc2012-02-24 13:29:501189 &client_id,
[email protected]b42a9f62011-06-08 20:36:041190 &channel_handle,
[email protected]b42a9f62011-06-08 20:36:041191 &gpu_info)) ||
[email protected]8bc550e2012-02-07 11:05:561192#if defined(OS_POSIX)
1193 channel_handle.socket.fd == -1 ||
1194#endif
[email protected]cd0bd792012-04-14 00:52:161195 channel_handle.name.empty()) {
[email protected]b42a9f62011-06-08 20:36:041196 // Otherwise cancel the connection.
1197 gpu_channel_ = NULL;
1198 return NULL;
1199 }
[email protected]6217d392010-03-25 22:08:351200
[email protected]03dc8882012-03-08 23:46:291201 gpu_channel_ = new GpuChannelHost(this, 0, client_id);
[email protected]b42a9f62011-06-08 20:36:041202 gpu_channel_->set_gpu_info(gpu_info);
[email protected]e9ff79c2012-10-19 21:31:261203 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]b42a9f62011-06-08 20:36:041204
1205 // Connect to the GPU process if a channel name was received.
[email protected]cd0bd792012-04-14 00:52:161206 gpu_channel_->Connect(channel_handle);
[email protected]b42a9f62011-06-08 20:36:041207
[email protected]f9a2b2fe2010-07-15 21:13:231208 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:341209}
1210
[email protected]d8cd8372012-03-09 10:49:511211WebKit::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1212 WebKit::WebMediaStreamCenterClient* client) {
[email protected]d9da9582013-01-31 04:59:051213#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:161214 if (CommandLine::ForCurrentProcess()->HasSwitch(
1215 switches::kDisableWebRTC))
[email protected]d9da9582013-01-31 04:59:051216 return NULL;
1217#endif
1218
[email protected]d8cd8372012-03-09 10:49:511219#if defined(ENABLE_WEBRTC)
[email protected]68e5fee2013-02-18 10:04:221220 if (!media_stream_center_) {
1221 media_stream_center_ = GetContentClient()->renderer()
1222 ->OverrideCreateWebMediaStreamCenter(client);
1223 if (!media_stream_center_) {
1224 media_stream_center_ = new MediaStreamCenter(
1225 client, GetMediaStreamDependencyFactory());
1226 }
1227 }
[email protected]d8cd8372012-03-09 10:49:511228#endif
1229 return media_stream_center_;
1230}
1231
[email protected]6ee10bd2012-09-13 09:01:531232MediaStreamDependencyFactory*
1233RenderThreadImpl::GetMediaStreamDependencyFactory() {
1234#if defined(ENABLE_WEBRTC)
1235 if (!media_stream_factory_.get()) {
1236 media_stream_factory_.reset(new MediaStreamDependencyFactory(
1237 vc_manager_, p2p_socket_dispatcher_));
1238 }
1239#endif
1240 return media_stream_factory_.get();
1241}
1242
[email protected]f1a29a02011-10-06 23:08:441243GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]6217d392010-03-25 22:08:351244 if (!gpu_channel_.get())
1245 return NULL;
1246
[email protected]e09cee42010-11-09 01:50:081247 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:351248 return NULL;
1249
1250 return gpu_channel_.get();
1251}
1252
[email protected]f1a29a02011-10-06 23:08:441253void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591254 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271255 // The call below will cause a GetPlugins call with refresh=true, but at this
1256 // point we already know that the browser has refreshed its list, so disable
1257 // refresh temporarily to prevent each renderer process causing the list to be
1258 // regenerated.
[email protected]a70b4352012-07-31 22:34:531259 webkit_platform_support_->set_plugin_refresh_allowed(false);
[email protected]b78e168b2009-09-21 22:05:451260 WebKit::resetPluginCache(reload_pages);
[email protected]a70b4352012-07-31 22:34:531261 webkit_platform_support_->set_plugin_refresh_allowed(true);
[email protected]3b48dbc2012-01-06 16:34:171262
1263 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:271264}
[email protected]85c55dc2009-11-06 03:05:461265
[email protected]f1a29a02011-10-06 23:08:441266void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:091267 EnsureWebKitInitialized();
1268 WebNetworkStateNotifier::setOnLine(online);
1269}
1270
[email protected]b69934e2011-10-29 02:51:521271void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
[email protected]e9ff79c2012-10-19 21:31:261272 GetContentClient()->SetActiveURL(data);
[email protected]b69934e2011-10-29 02:51:521273 CHECK(false);
1274}
1275
[email protected]44363382013-03-12 07:22:471276void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) {
1277 ToggleWebKitSharedTimer(suspend);
1278}
1279
[email protected]c6a7b862010-08-20 22:19:381280scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:441281RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]c6a7b862010-08-20 22:19:381282 DCHECK(message_loop() == MessageLoop::current());
1283 if (!file_thread_.get()) {
1284 file_thread_.reset(new base::Thread("Renderer::FILE"));
1285 file_thread_->Start();
1286 }
1287 return file_thread_->message_loop_proxy();
1288}
[email protected]e9ff79c2012-10-19 21:31:261289
[email protected]107c0532013-02-06 02:34:091290void RenderThreadImpl::SetFlingCurveParameters(
1291 const std::vector<float>& new_touchpad,
1292 const std::vector<float>& new_touchscreen) {
1293 webkit_platform_support_->SetFlingCurveParameters(new_touchpad,
1294 new_touchscreen);
1295
1296}
1297
[email protected]e9ff79c2012-10-19 21:31:261298} // namespace content