[email protected] | d3d6325d | 2012-01-03 21:17:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 5 | #include "content/renderer/render_thread_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 8 | #include <limits> |
[email protected] | 75e126b93 | 2009-09-28 19:38:49 | [diff] [blame] | 9 | #include <map> |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
[email protected] | 237a1485 | 2012-04-28 02:56:38 | [diff] [blame] | 12 | #include "base/allocator/allocator_extension.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 14 | #include "base/debug/trace_event.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 15 | #include "base/lazy_instance.h" |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 16 | #include "base/logging.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 17 | #include "base/metrics/field_trial.h" |
[email protected] | 6cf19311f | 2011-04-14 23:06:02 | [diff] [blame] | 18 | #include "base/metrics/histogram.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 19 | #include "base/metrics/stats_table.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 20 | #include "base/path_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "base/shared_memory.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 22 | #include "base/strings/string16.h" |
| 23 | #include "base/strings/string_number_conversions.h" // Temporary |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 24 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 1357c32 | 2010-12-30 22:18:56 | [diff] [blame] | 25 | #include "base/threading/thread_local.h" |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 26 | #include "base/threading/thread_restrictions.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 27 | #include "base/values.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 28 | #include "content/child/child_histogram_message_filter.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 29 | #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 30 | #include "content/child/indexed_db/indexed_db_message_filter.h" |
| 31 | #include "content/child/npobject_util.h" |
| 32 | #include "content/child/plugin_messages.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 33 | #include "content/child/resource_dispatcher.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 34 | #include "content/child/web_database_observer_impl.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 35 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 36 | #include "content/common/child_process_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 37 | #include "content/common/database_messages.h" |
| 38 | #include "content/common/db_message_filter.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 39 | #include "content/common/dom_storage_messages.h" |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 40 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 41 | #include "content/common/gpu/client/gpu_channel_host.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 42 | #include "content/common/gpu/gpu_messages.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 43 | #include "content/common/resource_messages.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 44 | #include "content/common/view_messages.h" |
[email protected] | a458504b | 2012-07-23 19:57:06 | [diff] [blame] | 45 | #include "content/public/common/content_constants.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 46 | #include "content/public/common/content_paths.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 47 | #include "content/public/common/content_switches.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 48 | #include "content/public/common/renderer_preferences.h" |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 49 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 50 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 51 | #include "content/public/renderer/render_process_observer.h" |
| 52 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 53 | #include "content/renderer/devtools/devtools_agent_filter.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 54 | #include "content/renderer/dom_storage/dom_storage_dispatcher.h" |
| 55 | #include "content/renderer/dom_storage/webstoragearea_impl.h" |
| 56 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 57 | #include "content/renderer/gpu/compositor_output_surface.h" |
[email protected] | e54ab49 | 2012-06-12 19:40:01 | [diff] [blame] | 58 | #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
[email protected] | b025568 | 2013-06-07 21:24:08 | [diff] [blame] | 59 | #include "content/renderer/gpu/input_event_filter.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 60 | #include "content/renderer/gpu/input_handler_manager.h" |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 61 | #include "content/renderer/media/audio_input_message_filter.h" |
| 62 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 63 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 64 | #include "content/renderer/media/media_stream_center.h" |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 65 | #include "content/renderer/media/media_stream_dependency_factory.h" |
[email protected] | af08997 | 2013-01-10 04:04:40 | [diff] [blame] | 66 | #include "content/renderer/media/peer_connection_tracker.h" |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 67 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | ba164c91 | 2011-06-14 22:07:34 | [diff] [blame] | 68 | #include "content/renderer/media/video_capture_message_filter.h" |
[email protected] | 6941ac5c | 2013-02-07 03:59:56 | [diff] [blame] | 69 | #include "content/renderer/memory_benchmarking_extension.h" |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 70 | #include "content/renderer/p2p/socket_dispatcher.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 71 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 72 | #include "content/renderer/render_process_impl.h" |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 73 | #include "content/renderer/render_view_impl.h" |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 74 | #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
[email protected] | a822825 | 2013-05-14 11:10:05 | [diff] [blame] | 75 | #include "content/renderer/skia_benchmarking_extension.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 76 | #include "grit/content_resources.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 77 | #include "ipc/ipc_channel_handle.h" |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 78 | #include "ipc/ipc_forwarding_message_filter.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 79 | #include "ipc/ipc_platform_file.h" |
[email protected] | 563d665f | 2013-02-01 04:42:39 | [diff] [blame] | 80 | #include "media/base/audio_hardware_config.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 81 | #include "media/base/media.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 82 | #include "net/base/net_errors.h" |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 83 | #include "net/base/net_util.h" |
[email protected] | f8c648b | 2012-02-28 03:46:45 | [diff] [blame] | 84 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 85 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
| 86 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 87 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 88 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 89 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" |
[email protected] | 4bd55a3 | 2011-07-28 13:28:38 | [diff] [blame] | 90 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 91 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 92 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 93 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
[email protected] | 00fccb4 | 2012-12-11 00:09:59 | [diff] [blame] | 94 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerRepository.h" |
[email protected] | 61a796c4 | 2012-05-17 21:28:20 | [diff] [blame] | 95 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 96 | #include "third_party/WebKit/public/platform/WebString.h" |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 97 | #include "ui/base/layout.h" |
[email protected] | 18ad677 | 2011-09-20 21:51:32 | [diff] [blame] | 98 | #include "ui/base/ui_base_switches.h" |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 99 | #include "v8/include/v8.h" |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 100 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 101 | #include "webkit/renderer/appcache/appcache_frontend_impl.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 102 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 103 | #if defined(OS_WIN) |
| 104 | #include <windows.h> |
| 105 | #include <objbase.h> |
[email protected] | 5f7e451 | 2012-10-01 20:51:37 | [diff] [blame] | 106 | #include "base/win/scoped_com_initializer.h" |
| 107 | #else |
| 108 | // TODO(port) |
| 109 | #include "base/memory/scoped_handle.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 110 | #include "content/child/np_channel_base.h" |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 111 | #endif |
| 112 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 113 | #if defined(OS_POSIX) |
| 114 | #include "ipc/ipc_channel_posix.h" |
| 115 | #endif |
| 116 | |
[email protected] | 950f9ce2 | 2012-12-27 00:25:07 | [diff] [blame] | 117 | #if defined(ENABLE_WEBRTC) |
| 118 | #include "third_party/webrtc/system_wrappers/interface/event_tracer.h" |
| 119 | #endif |
| 120 | |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 121 | #if defined(OS_ANDROID) |
[email protected] | 9a1af19 | 2013-06-06 03:09:59 | [diff] [blame] | 122 | #include <cpu-features.h> |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 123 | #include "content/renderer/android/synchronous_compositor_factory.h" |
| 124 | #endif |
| 125 | |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 126 | using base::ThreadRestrictions; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 127 | using WebKit::WebDocument; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 128 | using WebKit::WebFrame; |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 129 | using WebKit::WebNetworkStateNotifier; |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 130 | using WebKit::WebRuntimeFeatures; |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 131 | using WebKit::WebScriptController; |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 132 | using WebKit::WebSecurityPolicy; |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 133 | using WebKit::WebString; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 134 | using WebKit::WebView; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 135 | |
| 136 | namespace content { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 138 | namespace { |
[email protected] | da9ccfb | 2012-01-28 00:34:40 | [diff] [blame] | 139 | |
| 140 | const int64 kInitialIdleHandlerDelayMs = 1000; |
| 141 | const int64 kShortIdleHandlerDelayMs = 1000; |
| 142 | const int64 kLongIdleHandlerDelayMs = 30*1000; |
| 143 | const int kIdleCPUUsageThresholdInPercents = 3; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 144 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 145 | // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
[email protected] | f3ede41 | 2010-06-21 22:52:16 | [diff] [blame] | 146 | // incorrectly from the wrong thread. |
[email protected] | da9ccfb | 2012-01-28 00:34:40 | [diff] [blame] | 147 | base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 148 | lazy_tls = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 149 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 150 | class RenderViewZoomer : public RenderViewVisitor { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 151 | public: |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 152 | RenderViewZoomer(const std::string& scheme, |
| 153 | const std::string& host, |
| 154 | double zoom_level) : scheme_(scheme), |
| 155 | host_(host), |
| 156 | zoom_level_(zoom_level) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | c3e3589 | 2013-02-12 02:08:01 | [diff] [blame] | 159 | virtual bool Visit(RenderView* render_view) OVERRIDE { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 160 | WebView* webview = render_view->GetWebView(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 161 | WebDocument document = webview->mainFrame()->document(); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 162 | |
| 163 | // Don't set zoom level for full-page plugin since they don't use the same |
| 164 | // zoom settings. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 165 | if (document.isPluginDocument()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 166 | return true; |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 167 | GURL url(document.url()); |
| 168 | // Empty scheme works as wildcard that matches any scheme, |
| 169 | if ((net::GetHostOrSpecFromURL(url) == host_) && |
| 170 | (scheme_.empty() || scheme_ == url.scheme())) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 171 | webview->setZoomLevel(false, zoom_level_); |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 172 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 173 | return true; |
| 174 | } |
| 175 | |
| 176 | private: |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 177 | const std::string scheme_; |
| 178 | const std::string host_; |
| 179 | const double zoom_level_; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 180 | |
| 181 | DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
| 182 | }; |
[email protected] | 0478d016 | 2010-08-28 08:29:40 | [diff] [blame] | 183 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 184 | std::string HostToCustomHistogramSuffix(const std::string& host) { |
| 185 | if (host == "mail.google.com") |
| 186 | return ".gmail"; |
| 187 | if (host == "docs.google.com" || host == "drive.google.com") |
| 188 | return ".docs"; |
| 189 | if (host == "plus.google.com") |
| 190 | return ".plus"; |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 191 | return std::string(); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 192 | } |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 193 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 194 | void* CreateHistogram( |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 195 | const char *name, int min, int max, size_t buckets) { |
| 196 | if (min <= 0) |
| 197 | min = 1; |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 198 | std::string histogram_name; |
| 199 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 200 | if (render_thread_impl) { // Can be null in tests. |
| 201 | histogram_name = render_thread_impl-> |
| 202 | histogram_customizer()->ConvertToCustomHistogramName(name); |
| 203 | } else { |
| 204 | histogram_name = std::string(name); |
| 205 | } |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 206 | base::HistogramBase* histogram = base::Histogram::FactoryGet( |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 207 | histogram_name, min, max, buckets, |
| 208 | base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 209 | return histogram; |
| 210 | } |
| 211 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 212 | void AddHistogramSample(void* hist, int sample) { |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 213 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
| 214 | histogram->Add(sample); |
| 215 | } |
| 216 | |
[email protected] | 950f9ce2 | 2012-12-27 00:25:07 | [diff] [blame] | 217 | #if defined(ENABLE_WEBRTC) |
[email protected] | d936677a | 2013-04-19 08:49:03 | [diff] [blame] | 218 | const unsigned char* GetCategoryGroupEnabled(const char* category_group) { |
| 219 | return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); |
[email protected] | da0f695 | 2012-12-26 22:22:39 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void AddTraceEvent(char phase, |
[email protected] | d936677a | 2013-04-19 08:49:03 | [diff] [blame] | 223 | const unsigned char* category_group_enabled, |
[email protected] | da0f695 | 2012-12-26 22:22:39 | [diff] [blame] | 224 | const char* name, |
| 225 | unsigned long long id, |
| 226 | int num_args, |
| 227 | const char** arg_names, |
| 228 | const unsigned char* arg_types, |
| 229 | const unsigned long long* arg_values, |
| 230 | unsigned char flags) { |
[email protected] | d936677a | 2013-04-19 08:49:03 | [diff] [blame] | 231 | TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id, |
| 232 | num_args, arg_names, arg_types, arg_values, |
[email protected] | 7fceeab2 | 2013-05-03 15:40:47 | [diff] [blame] | 233 | NULL, flags); |
[email protected] | da0f695 | 2012-12-26 22:22:39 | [diff] [blame] | 234 | } |
[email protected] | 950f9ce2 | 2012-12-27 00:25:07 | [diff] [blame] | 235 | #endif |
[email protected] | da0f695 | 2012-12-26 22:22:39 | [diff] [blame] | 236 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 237 | } // namespace |
| 238 | |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 239 | class RenderThreadImpl::GpuVDAContextLostCallback |
| 240 | : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
| 241 | public: |
| 242 | GpuVDAContextLostCallback() {} |
| 243 | virtual ~GpuVDAContextLostCallback() {} |
| 244 | virtual void onContextLost() { |
| 245 | ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 246 | &RenderThreadImpl::OnGpuVDAContextLoss)); |
| 247 | } |
| 248 | }; |
| 249 | |
[email protected] | 00874dd | 2013-03-08 23:51:18 | [diff] [blame] | 250 | class RenderThreadImpl::RendererContextProviderCommandBuffer |
| 251 | : public ContextProviderCommandBuffer { |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 252 | public: |
| 253 | static scoped_refptr<RendererContextProviderCommandBuffer> Create() { |
| 254 | scoped_refptr<RendererContextProviderCommandBuffer> provider = |
| 255 | new RendererContextProviderCommandBuffer(); |
| 256 | if (!provider->InitializeOnMainThread()) |
| 257 | return NULL; |
| 258 | return provider; |
| 259 | } |
| 260 | |
[email protected] | 00874dd | 2013-03-08 23:51:18 | [diff] [blame] | 261 | protected: |
| 262 | virtual ~RendererContextProviderCommandBuffer() {} |
| 263 | |
| 264 | virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
[email protected] | aa3174b | 2013-03-15 09:12:48 | [diff] [blame] | 265 | CreateOffscreenContext3d() OVERRIDE { |
[email protected] | 00874dd | 2013-03-08 23:51:18 | [diff] [blame] | 266 | RenderThreadImpl* self = RenderThreadImpl::current(); |
| 267 | DCHECK(self); |
| 268 | return self->CreateOffscreenContext3d().Pass(); |
| 269 | } |
| 270 | }; |
| 271 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 272 | RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() { |
| 273 | custom_histograms_.insert("V8.MemoryExternalFragmentationTotal"); |
| 274 | custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted"); |
| 275 | custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed"); |
| 276 | } |
| 277 | |
| 278 | RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {} |
| 279 | |
| 280 | void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost( |
| 281 | const std::string& host, size_t view_count) { |
[email protected] | 9baee83 | 2012-12-10 11:07:15 | [diff] [blame] | 282 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 283 | switches::kDisableHistogramCustomizer)) { |
| 284 | return; |
| 285 | } |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 286 | // Check if all RenderViews are displaying a page from the same host. If there |
| 287 | // is only one RenderView, the common host is this view's host. If there are |
| 288 | // many, check if this one shares the common host of the other |
| 289 | // RenderViews. It's ok to not detect some cases where the RenderViews share a |
| 290 | // common host. This information is only used for producing custom histograms. |
| 291 | if (view_count == 1) |
| 292 | SetCommonHost(host); |
| 293 | else if (host != common_host_) |
| 294 | SetCommonHost(std::string()); |
| 295 | } |
| 296 | |
| 297 | std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName( |
| 298 | const char* histogram_name) const { |
| 299 | std::string name(histogram_name); |
| 300 | if (!common_host_histogram_suffix_.empty() && |
| 301 | custom_histograms_.find(name) != custom_histograms_.end()) |
| 302 | name += common_host_histogram_suffix_; |
| 303 | return name; |
| 304 | } |
| 305 | |
| 306 | void RenderThreadImpl::HistogramCustomizer::SetCommonHost( |
| 307 | const std::string& host) { |
| 308 | if (host != common_host_) { |
| 309 | common_host_ = host; |
| 310 | common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host); |
| 311 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 312 | } |
| 313 | } |
| 314 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 315 | RenderThreadImpl* RenderThreadImpl::current() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 316 | return lazy_tls.Pointer()->Get(); |
| 317 | } |
| 318 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 319 | // When we run plugins in process, we actually run them on the render thread, |
| 320 | // which means that we need to make the render thread pump UI events. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 321 | RenderThreadImpl::RenderThreadImpl() { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 322 | Init(); |
| 323 | } |
| 324 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 325 | RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 326 | : ChildThread(channel_name) { |
| 327 | Init(); |
| 328 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 329 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 330 | void RenderThreadImpl::Init() { |
| 331 | TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 332 | |
[email protected] | c7e948b4 | 2012-07-12 09:20:20 | [diff] [blame] | 333 | v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
| 334 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 335 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 336 | |
[email protected] | d3f0909 | 2012-02-16 01:52:17 | [diff] [blame] | 337 | #if defined(OS_MACOSX) || defined(OS_ANDROID) |
| 338 | // On Mac and Android, the select popups are rendered by the browser. |
[email protected] | 53c607c | 2011-03-21 23:19:04 | [diff] [blame] | 339 | WebKit::WebView::setUseExternalPopupMenus(true); |
| 340 | #endif |
| 341 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 342 | lazy_tls.Pointer()->Set(this); |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 343 | |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 344 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 345 | // If you are running plugins in this thread you need COM active but in |
| 346 | // the normal case you don't. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 347 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | 1a77126 | 2011-10-31 09:11:12 | [diff] [blame] | 348 | initialize_com_.reset(new base::win::ScopedCOMInitializer()); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 349 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 350 | |
[email protected] | 06c694d | 2012-02-01 22:26:16 | [diff] [blame] | 351 | // Register this object as the main thread. |
| 352 | ChildProcess::current()->set_main_thread(this); |
| 353 | |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 354 | // In single process the single process is all there is. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 355 | suspend_webkit_shared_timer_ = true; |
| 356 | notify_webkit_of_modal_loop_ = true; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 357 | widget_count_ = 0; |
| 358 | hidden_widget_count_ = 0; |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 359 | idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 360 | idle_notifications_to_skip_ = 0; |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 361 | layout_test_mode_ = false; |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 362 | |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 363 | appcache_dispatcher_.reset( |
| 364 | new AppCacheDispatcher(Get(), new appcache::AppCacheFrontendImpl())); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 365 | dom_storage_dispatcher_.reset(new DomStorageDispatcher()); |
[email protected] | dcc72db | 2013-01-02 00:44:18 | [diff] [blame] | 366 | main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 367 | |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 368 | media_stream_center_ = NULL; |
| 369 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 370 | db_message_filter_ = new DBMessageFilter(); |
| 371 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 372 | |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 373 | #if defined(ENABLE_WEBRTC) |
[email protected] | d936677a | 2013-04-19 08:49:03 | [diff] [blame] | 374 | webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent); |
[email protected] | af08997 | 2013-01-10 04:04:40 | [diff] [blame] | 375 | |
| 376 | peer_connection_tracker_.reset(new PeerConnectionTracker()); |
| 377 | AddObserver(peer_connection_tracker_.get()); |
| 378 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 379 | p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 380 | AddFilter(p2p_socket_dispatcher_.get()); |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 381 | #endif // defined(ENABLE_WEBRTC) |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 382 | vc_manager_ = new VideoCaptureImplManager(); |
| 383 | AddFilter(vc_manager_->video_capture_message_filter()); |
[email protected] | e25f4d7 | 2011-06-08 20:58:46 | [diff] [blame] | 384 | |
[email protected] | e0a93870 | 2013-02-25 21:15:56 | [diff] [blame] | 385 | audio_input_message_filter_ = |
| 386 | new AudioInputMessageFilter(GetIOMessageLoopProxy()); |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 387 | AddFilter(audio_input_message_filter_.get()); |
| 388 | |
[email protected] | e0a93870 | 2013-02-25 21:15:56 | [diff] [blame] | 389 | audio_message_filter_ = new AudioMessageFilter(GetIOMessageLoopProxy()); |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 390 | AddFilter(audio_message_filter_.get()); |
| 391 | |
[email protected] | 31bfae7 | 2011-12-16 02:04:38 | [diff] [blame] | 392 | AddFilter(new IndexedDBMessageFilter); |
| 393 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 394 | GetContentClient()->renderer()->RenderThreadStarted(); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 395 | |
[email protected] | 302fe42 | 2012-06-11 14:49:11 | [diff] [blame] | 396 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | e54ab49 | 2012-06-12 19:40:01 | [diff] [blame] | 397 | if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 398 | RegisterExtension(GpuBenchmarkingExtension::Get()); |
[email protected] | e54ab49 | 2012-06-12 19:40:01 | [diff] [blame] | 399 | |
[email protected] | a70ed8b3 | 2013-05-24 15:16:34 | [diff] [blame] | 400 | #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) |
[email protected] | 6941ac5c | 2013-02-07 03:59:56 | [diff] [blame] | 401 | if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking)) |
| 402 | RegisterExtension(MemoryBenchmarkingExtension::Get()); |
[email protected] | a70ed8b3 | 2013-05-24 15:16:34 | [diff] [blame] | 403 | #endif // USE_TCMALLOC |
[email protected] | 6941ac5c | 2013-02-07 03:59:56 | [diff] [blame] | 404 | |
[email protected] | a822825 | 2013-05-14 11:10:05 | [diff] [blame] | 405 | if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking)) { |
| 406 | LOG(WARNING) << "Enabling unsafe Skia benchmarking extension."; |
| 407 | RegisterExtension(SkiaBenchmarkingExtension::Get()); |
| 408 | } |
| 409 | |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 410 | context_lost_cb_.reset(new GpuVDAContextLostCallback()); |
| 411 | |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 412 | // Note that under Linux, the media library will normally already have |
| 413 | // been initialized by the Zygote before this instance became a Renderer. |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 414 | base::FilePath media_path; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 415 | PathService::Get(DIR_MEDIA_LIBS, &media_path); |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 416 | if (!media_path.empty()) |
| 417 | media::InitializeMediaLibrary(media_path); |
| 418 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 419 | TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 420 | } |
| 421 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 422 | RenderThreadImpl::~RenderThreadImpl() { |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void RenderThreadImpl::Shutdown() { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 426 | FOR_EACH_OBSERVER( |
| 427 | RenderProcessObserver, observers_, OnRenderProcessShutdown()); |
| 428 | |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 429 | // Wait for all databases to be closed. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 430 | if (web_database_observer_impl_) |
[email protected] | 2b437e23 | 2010-04-02 01:30:08 | [diff] [blame] | 431 | web_database_observer_impl_->WaitForAllDatabasesToClose(); |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 432 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 433 | // Shutdown in reverse of the initialization order. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 434 | if (devtools_agent_message_filter_.get()) { |
[email protected] | b146d6d | 2012-09-11 10:20:05 | [diff] [blame] | 435 | RemoveFilter(devtools_agent_message_filter_.get()); |
| 436 | devtools_agent_message_filter_ = NULL; |
| 437 | } |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 438 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 439 | RemoveFilter(audio_input_message_filter_.get()); |
| 440 | audio_input_message_filter_ = NULL; |
| 441 | |
| 442 | RemoveFilter(audio_message_filter_.get()); |
| 443 | audio_message_filter_ = NULL; |
| 444 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 445 | RemoveFilter(vc_manager_->video_capture_message_filter()); |
| 446 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 447 | RemoveFilter(db_message_filter_.get()); |
| 448 | db_message_filter_ = NULL; |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 449 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 450 | // Shutdown the file thread if it's running. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 451 | if (file_thread_) |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 452 | file_thread_->Stop(); |
| 453 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 454 | if (compositor_output_surface_filter_.get()) { |
[email protected] | 23d2b7e | 2012-08-14 00:34:09 | [diff] [blame] | 455 | RemoveFilter(compositor_output_surface_filter_.get()); |
| 456 | compositor_output_surface_filter_ = NULL; |
| 457 | } |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 458 | |
[email protected] | 79a92b5 | 2013-04-08 19:09:02 | [diff] [blame] | 459 | compositor_thread_.reset(); |
[email protected] | b025568 | 2013-06-07 21:24:08 | [diff] [blame] | 460 | input_handler_manager_.reset(); |
| 461 | if (input_event_filter_) { |
| 462 | RemoveFilter(input_event_filter_.get()); |
| 463 | input_event_filter_ = NULL; |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 464 | } |
| 465 | |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 466 | if (webkit_platform_support_) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 467 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 468 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 469 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 470 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 471 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 472 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 473 | // Clean up plugin channels before this thread goes away. |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 474 | NPChannelBase::CleanupChannels(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 475 | #endif |
[email protected] | 00874dd | 2013-03-08 23:51:18 | [diff] [blame] | 476 | |
| 477 | // Leak shared contexts on other threads, as we can not get to the correct |
| 478 | // thread to destroy them. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 479 | if (shared_contexts_compositor_thread_.get()) |
[email protected] | 00874dd | 2013-03-08 23:51:18 | [diff] [blame] | 480 | shared_contexts_compositor_thread_->set_leak_on_destroy(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 481 | } |
| 482 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 483 | bool RenderThreadImpl::Send(IPC::Message* msg) { |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 484 | // Certain synchronous messages cannot always be processed synchronously by |
| 485 | // the browser, e.g., Chrome frame communicating with the embedding browser. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 486 | // This could cause a complete hang of Chrome if a windowed plug-in is trying |
| 487 | // to communicate with the renderer thread since the browser's UI thread |
| 488 | // could be stuck (within a Windows API call) trying to synchronously |
| 489 | // communicate with the plug-in. The remedy is to pump messages on this |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 490 | // thread while the browser is processing this request. This creates an |
| 491 | // opportunity for re-entrancy into WebKit, so we need to take care to disable |
| 492 | // callbacks, timers, and pending network loads that could trigger such |
| 493 | // callbacks. |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 494 | bool pumping_events = false; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 495 | if (msg->is_sync()) { |
| 496 | if (msg->is_caller_pumping_messages()) { |
| 497 | pumping_events = true; |
| 498 | } else { |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 499 | if ((msg->type() == ViewHostMsg_GetCookies::ID || |
| 500 | msg->type() == ViewHostMsg_GetRawCookies::ID || |
| 501 | msg->type() == ViewHostMsg_CookiesEnabled::ID) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 502 | GetContentClient()->renderer()-> |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 503 | ShouldPumpEventsDuringCookieMessage()) { |
| 504 | pumping_events = true; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 505 | } |
| 506 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 509 | bool suspend_webkit_shared_timer = true; // default value |
| 510 | std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 511 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 512 | bool notify_webkit_of_modal_loop = true; // default value |
| 513 | std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); |
| 514 | |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 515 | int render_view_id = MSG_ROUTING_NONE; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 516 | |
| 517 | if (pumping_events) { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 518 | if (suspend_webkit_shared_timer) |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 519 | webkit_platform_support_->SuspendSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 520 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 521 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 522 | WebView::willEnterModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 523 | |
[email protected] | bae061f7 | 2013-04-26 16:22:29 | [diff] [blame] | 524 | RenderViewImpl* render_view = |
| 525 | RenderViewImpl::FromRoutingID(msg->routing_id()); |
| 526 | if (render_view) { |
| 527 | render_view_id = msg->routing_id(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 528 | PluginChannelHost::Broadcast( |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 529 | new PluginMsg_SignalModalDialogEvent(render_view_id)); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | bool rv = ChildThread::Send(msg); |
| 534 | |
| 535 | if (pumping_events) { |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 536 | if (render_view_id != MSG_ROUTING_NONE) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 537 | PluginChannelHost::Broadcast( |
[email protected] | c48de1a | 2012-11-02 19:06:56 | [diff] [blame] | 538 | new PluginMsg_ResetModalDialogEvent(render_view_id)); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 541 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 542 | WebView::didExitModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 543 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 544 | if (suspend_webkit_shared_timer) |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 545 | webkit_platform_support_->ResumeSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | return rv; |
| 549 | } |
| 550 | |
[email protected] | 9e715412 | 2013-05-30 23:11:04 | [diff] [blame] | 551 | base::MessageLoop* RenderThreadImpl::GetMessageLoop() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 552 | return message_loop(); |
| 553 | } |
| 554 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 555 | IPC::SyncChannel* RenderThreadImpl::GetChannel() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 556 | return channel(); |
| 557 | } |
| 558 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 559 | std::string RenderThreadImpl::GetLocale() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 560 | // The browser process should have passed the locale to the renderer via the |
[email protected] | dfd5365 | 2012-10-25 00:20:02 | [diff] [blame] | 561 | // --lang command line flag. |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 562 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 563 | const std::string& lang = |
| 564 | parsed_command_line.GetSwitchValueASCII(switches::kLang); |
[email protected] | dfd5365 | 2012-10-25 00:20:02 | [diff] [blame] | 565 | DCHECK(!lang.empty()); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 566 | return lang; |
| 567 | } |
| 568 | |
[email protected] | 07bb633 | 2012-01-21 01:07:57 | [diff] [blame] | 569 | IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() { |
| 570 | return sync_message_filter(); |
| 571 | } |
| 572 | |
[email protected] | 96191d5 | 2012-05-17 01:37:11 | [diff] [blame] | 573 | scoped_refptr<base::MessageLoopProxy> |
| 574 | RenderThreadImpl::GetIOMessageLoopProxy() { |
| 575 | return ChildProcess::current()->io_message_loop_proxy(); |
| 576 | } |
| 577 | |
[email protected] | c47317e | 2012-06-20 22:35:31 | [diff] [blame] | 578 | void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 579 | widget_count_++; |
| 580 | return ChildThread::AddRoute(routing_id, listener); |
| 581 | } |
| 582 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 583 | void RenderThreadImpl::RemoveRoute(int32 routing_id) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 584 | widget_count_--; |
| 585 | return ChildThread::RemoveRoute(routing_id); |
| 586 | } |
| 587 | |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 588 | int RenderThreadImpl::GenerateRoutingID() { |
| 589 | int routing_id = MSG_ROUTING_NONE; |
| 590 | Send(new ViewHostMsg_GenerateRoutingID(&routing_id)); |
| 591 | return routing_id; |
| 592 | } |
| 593 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 594 | void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 595 | channel()->AddFilter(filter); |
| 596 | } |
| 597 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 598 | void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 599 | channel()->RemoveFilter(filter); |
| 600 | } |
| 601 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 602 | void RenderThreadImpl::SetOutgoingMessageFilter( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 603 | IPC::ChannelProxy::OutgoingMessageFilter* filter) { |
| 604 | } |
| 605 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 606 | void RenderThreadImpl::AddObserver(RenderProcessObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 607 | observers_.AddObserver(observer); |
| 608 | } |
| 609 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 610 | void RenderThreadImpl::RemoveObserver(RenderProcessObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 611 | observers_.RemoveObserver(observer); |
| 612 | } |
| 613 | |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 614 | void RenderThreadImpl::SetResourceDispatcherDelegate( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 615 | ResourceDispatcherDelegate* delegate) { |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 616 | resource_dispatcher()->set_delegate(delegate); |
| 617 | } |
| 618 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 619 | void RenderThreadImpl::WidgetHidden() { |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 620 | DCHECK(hidden_widget_count_ < widget_count_); |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 621 | hidden_widget_count_++; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 622 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 623 | if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 624 | return; |
| 625 | } |
| 626 | |
| 627 | if (widget_count_ && hidden_widget_count_ == widget_count_) |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 628 | ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 631 | void RenderThreadImpl::WidgetRestored() { |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 632 | DCHECK_GT(hidden_widget_count_, 0); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 633 | hidden_widget_count_--; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 634 | if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 635 | return; |
| 636 | } |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 637 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 638 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 641 | static void AdjustRuntimeFeatureDefaultsForPlatform() { |
| 642 | #if defined(OS_ANDROID) && !defined(GOOGLE_TV) |
[email protected] | 5bf1223a5 | 2013-05-14 21:42:31 | [diff] [blame] | 643 | WebRuntimeFeatures::enableWebKitMediaSource(false); |
[email protected] | 16c242d | 2013-05-31 23:56:47 | [diff] [blame] | 644 | WebRuntimeFeatures::enableLegacyEncryptedMedia(false); |
| 645 | WebRuntimeFeatures::enableEncryptedMedia(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 646 | #endif |
| 647 | |
| 648 | #if defined(OS_ANDROID) |
| 649 | WebRuntimeFeatures::enableWebAudio(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 650 | // Android does not support the Gamepad API. |
| 651 | WebRuntimeFeatures::enableGamepad(false); |
| 652 | // input[type=week] in Android is incomplete. crbug.com/135938 |
| 653 | WebRuntimeFeatures::enableInputTypeWeek(false); |
[email protected] | 0912828 | 2013-05-17 16:42:52 | [diff] [blame] | 654 | // Android does not have support for PagePopup |
| 655 | WebRuntimeFeatures::enablePagePopup(false); |
[email protected] | 0338ce79 | 2013-05-24 11:15:59 | [diff] [blame] | 656 | // datalist on Android is not enabled |
| 657 | WebRuntimeFeatures::enableDataListElement(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 658 | #endif |
| 659 | } |
| 660 | |
| 661 | static void AdjustRuntimeFeaturesFromArgs(const CommandLine& command_line) { |
| 662 | if (command_line.HasSwitch(switches::kDisableDatabases)) |
| 663 | WebRuntimeFeatures::enableDatabase(false); |
| 664 | |
| 665 | if (command_line.HasSwitch(switches::kDisableApplicationCache)) |
| 666 | WebRuntimeFeatures::enableApplicationCache(false); |
| 667 | |
| 668 | if (command_line.HasSwitch(switches::kDisableDesktopNotifications)) |
| 669 | WebRuntimeFeatures::enableNotifications(false); |
| 670 | |
| 671 | if (command_line.HasSwitch(switches::kDisableLocalStorage)) |
| 672 | WebRuntimeFeatures::enableLocalStorage(false); |
| 673 | |
| 674 | if (command_line.HasSwitch(switches::kDisableSessionStorage)) |
| 675 | WebRuntimeFeatures::enableSessionStorage(false); |
| 676 | |
| 677 | if (command_line.HasSwitch(switches::kDisableGeolocation)) |
| 678 | WebRuntimeFeatures::enableGeolocation(false); |
| 679 | |
[email protected] | 85dd7ca | 2013-05-30 23:53:00 | [diff] [blame] | 680 | #if defined(OS_ANDROID) && !defined(GOOGLE_TV) |
| 681 | if (command_line.HasSwitch(switches::kEnableWebKitMediaSource)) |
| 682 | WebRuntimeFeatures::enableWebKitMediaSource(true); |
| 683 | #else |
[email protected] | 5bf1223a5 | 2013-05-14 21:42:31 | [diff] [blame] | 684 | if (command_line.HasSwitch(switches::kDisableWebKitMediaSource)) |
| 685 | WebRuntimeFeatures::enableWebKitMediaSource(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 686 | #endif |
| 687 | |
| 688 | #if defined(OS_ANDROID) |
[email protected] | 3bd0aab | 2013-05-30 20:07:49 | [diff] [blame] | 689 | if (command_line.HasSwitch(switches::kDisableWebRTC)) { |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 690 | WebRuntimeFeatures::enableMediaStream(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 691 | WebRuntimeFeatures::enablePeerConnection(false); |
[email protected] | 3bd0aab | 2013-05-30 20:07:49 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | if (!command_line.HasSwitch(switches::kEnableSpeechRecognition)) |
| 695 | WebRuntimeFeatures::enableScriptedSpeech(false); |
| 696 | |
[email protected] | 9a1af19 | 2013-06-06 03:09:59 | [diff] [blame] | 697 | if (command_line.HasSwitch(switches::kEnableWebAudio)) { |
| 698 | bool enable_webaudio = true; |
| 699 | #if defined(ARCH_CPU_ARMEL) |
| 700 | enable_webaudio = |
| 701 | ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0); |
| 702 | #endif |
| 703 | WebRuntimeFeatures::enableWebAudio(enable_webaudio); |
| 704 | } |
[email protected] | 3bd0aab | 2013-05-30 20:07:49 | [diff] [blame] | 705 | #else |
| 706 | if (command_line.HasSwitch(switches::kDisableWebAudio)) |
| 707 | WebRuntimeFeatures::enableWebAudio(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 708 | #endif |
| 709 | |
| 710 | if (command_line.HasSwitch(switches::kDisableFullScreen)) |
[email protected] | d2414bb | 2013-05-10 21:29:27 | [diff] [blame] | 711 | WebRuntimeFeatures::enableFullscreen(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 712 | |
[email protected] | 16c242d | 2013-05-31 23:56:47 | [diff] [blame] | 713 | if (command_line.HasSwitch(switches::kEnableEncryptedMedia)) |
| 714 | WebRuntimeFeatures::enableEncryptedMedia(true); |
| 715 | |
| 716 | if (command_line.HasSwitch(switches::kDisableLegacyEncryptedMedia)) |
| 717 | WebRuntimeFeatures::enableLegacyEncryptedMedia(false); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 718 | |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 719 | if (command_line.HasSwitch(switches::kEnableWebMIDI)) |
| 720 | WebRuntimeFeatures::enableWebMIDI(true); |
| 721 | |
| 722 | if (command_line.HasSwitch(switches::kEnableDeviceMotion)) |
| 723 | WebRuntimeFeatures::enableDeviceMotion(true); |
| 724 | |
| 725 | if (command_line.HasSwitch(switches::kDisableDeviceOrientation)) |
| 726 | WebRuntimeFeatures::enableDeviceOrientation(false); |
| 727 | |
| 728 | if (command_line.HasSwitch(switches::kDisableSpeechInput)) |
| 729 | WebRuntimeFeatures::enableSpeechInput(false); |
| 730 | |
| 731 | if (command_line.HasSwitch(switches::kDisableFileSystem)) |
| 732 | WebRuntimeFeatures::enableFileSystem(false); |
| 733 | |
| 734 | if (command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)) |
| 735 | WebRuntimeFeatures::enableJavaScriptI18NAPI(false); |
| 736 | |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 737 | if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures)) |
| 738 | WebRuntimeFeatures::enableExperimentalCanvasFeatures(true); |
| 739 | |
| 740 | if (command_line.HasSwitch(switches::kEnableSpeechSynthesis)) |
| 741 | WebRuntimeFeatures::enableSpeechSynthesis(true); |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 742 | |
| 743 | if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions)) |
| 744 | WebRuntimeFeatures::enableWebGLDraftExtensions(true); |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 747 | void RenderThreadImpl::EnsureWebKitInitialized() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 748 | if (webkit_platform_support_) |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 749 | return; |
| 750 | |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 751 | webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
| 752 | WebKit::initialize(webkit_platform_support_.get()); |
[email protected] | 00fccb4 | 2012-12-11 00:09:59 | [diff] [blame] | 753 | WebKit::setSharedWorkerRepository( |
| 754 | webkit_platform_support_.get()->sharedWorkerRepository()); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 755 | |
[email protected] | cd7ce3be | 2012-09-10 05:19:41 | [diff] [blame] | 756 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | cd7ce3be | 2012-09-10 05:19:41 | [diff] [blame] | 757 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 758 | bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing); |
[email protected] | 72787e39 | 2012-03-23 05:55:43 | [diff] [blame] | 759 | if (enable) { |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 760 | #if defined(OS_ANDROID) |
| 761 | if (SynchronousCompositorFactory* factory = |
| 762 | SynchronousCompositorFactory::GetInstance()) |
| 763 | compositor_message_loop_proxy_ = |
| 764 | factory->GetCompositorMessageLoop(); |
| 765 | #endif |
| 766 | if (!compositor_message_loop_proxy_) { |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 767 | compositor_thread_.reset(new base::Thread("Compositor")); |
| 768 | compositor_thread_->Start(); |
[email protected] | b38864d | 2013-05-24 14:42:36 | [diff] [blame] | 769 | #if defined(OS_ANDROID) |
| 770 | compositor_thread_->SetPriority(base::kThreadPriority_Display); |
| 771 | #endif |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 772 | compositor_message_loop_proxy_ = |
| 773 | compositor_thread_->message_loop_proxy(); |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 774 | compositor_message_loop_proxy_->PostTask( |
| 775 | FROM_HERE, |
| 776 | base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), |
| 777 | false)); |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 778 | } |
| 779 | |
[email protected] | b025568 | 2013-06-07 21:24:08 | [diff] [blame] | 780 | InputHandlerManagerClient* input_handler_manager_client = NULL; |
| 781 | #if defined(OS_ANDROID) |
| 782 | if (SynchronousCompositorFactory* factory = |
| 783 | SynchronousCompositorFactory::GetInstance()) { |
| 784 | input_handler_manager_client = factory->GetInputHandlerManagerClient(); |
| 785 | } |
| 786 | #endif |
| 787 | if (!input_handler_manager_client) { |
| 788 | input_event_filter_ = |
| 789 | new InputEventFilter(this, compositor_message_loop_proxy_); |
| 790 | AddFilter(input_event_filter_.get()); |
| 791 | input_handler_manager_client = input_event_filter_.get(); |
| 792 | } |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 793 | input_handler_manager_.reset( |
[email protected] | b025568 | 2013-06-07 21:24:08 | [diff] [blame] | 794 | new InputHandlerManager(compositor_message_loop_proxy_, |
| 795 | input_handler_manager_client)); |
[email protected] | a458504b | 2012-07-23 19:57:06 | [diff] [blame] | 796 | } |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 797 | |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 798 | scoped_refptr<base::MessageLoopProxy> output_surface_loop; |
[email protected] | 7f1f63f | 2013-03-07 06:07:29 | [diff] [blame] | 799 | if (enable) |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 800 | output_surface_loop = compositor_message_loop_proxy_; |
[email protected] | 7f1f63f | 2013-03-07 06:07:29 | [diff] [blame] | 801 | else |
| 802 | output_surface_loop = base::MessageLoopProxy::current(); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 803 | |
[email protected] | 7f1f63f | 2013-03-07 06:07:29 | [diff] [blame] | 804 | compositor_output_surface_filter_ = |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 805 | CompositorOutputSurface::CreateFilter(output_surface_loop.get()); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 806 | AddFilter(compositor_output_surface_filter_.get()); |
| 807 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 808 | WebScriptController::enableV8SingleThreadMode(); |
| 809 | |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 810 | RenderThreadImpl::RegisterSchemes(); |
| 811 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 812 | webkit_glue::EnableWebCoreLogChannels( |
| 813 | command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); |
| 814 | |
[email protected] | fa1c17e4 | 2012-03-06 22:29:54 | [diff] [blame] | 815 | web_database_observer_impl_.reset( |
| 816 | new WebDatabaseObserverImpl(sync_message_filter())); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 817 | WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); |
| 818 | |
[email protected] | d1bf64b | 2013-05-06 12:13:53 | [diff] [blame] | 819 | WebRuntimeFeatures::enableStableFeatures(true); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 820 | |
[email protected] | d1bf64b | 2013-05-06 12:13:53 | [diff] [blame] | 821 | if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures)) |
| 822 | WebRuntimeFeatures::enableExperimentalFeatures(true); |
[email protected] | 4ae41b4 | 2012-12-06 21:59:03 | [diff] [blame] | 823 | |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 824 | AdjustRuntimeFeatureDefaultsForPlatform(); |
| 825 | AdjustRuntimeFeaturesFromArgs(command_line); |
[email protected] | d3e7aea2 | 2013-01-09 08:47:53 | [diff] [blame] | 826 | |
[email protected] | 205855d | 2013-04-24 01:42:18 | [diff] [blame] | 827 | // Enabled by default for testing. |
| 828 | // TODO(urvang): Go back to using the command-line option after a few days. |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 829 | // https://code.google.com/p/chromium/issues/detail?id=234437 |
[email protected] | 205855d | 2013-04-24 01:42:18 | [diff] [blame] | 830 | WebRuntimeFeatures::enableWebPInAcceptHeader(true); |
[email protected] | 8027acd | 2013-04-18 08:35:15 | [diff] [blame] | 831 | |
[email protected] | 78b86f9a | 2013-05-03 23:33:40 | [diff] [blame] | 832 | if (!media::IsMediaLibraryInitialized()) { |
| 833 | WebRuntimeFeatures::enableMediaPlayer(false); |
| 834 | WebRuntimeFeatures::enableWebAudio(false); |
| 835 | } |
[email protected] | 7a06d28 | 2013-05-03 04:39:33 | [diff] [blame] | 836 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 837 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized()); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 838 | |
[email protected] | b146d6d | 2012-09-11 10:20:05 | [diff] [blame] | 839 | devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
| 840 | AddFilter(devtools_agent_message_filter_.get()); |
| 841 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 842 | if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 843 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 844 | } |
| 845 | |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 846 | void RenderThreadImpl::RegisterSchemes() { |
| 847 | // swappedout: pages should not be accessible, and should also |
| 848 | // be treated as empty documents that can commit synchronously. |
| 849 | WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme)); |
| 850 | WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme); |
| 851 | WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme); |
| 852 | } |
| 853 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 854 | void RenderThreadImpl::RecordUserMetrics(const std::string& action) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 855 | Send(new ViewHostMsg_UserMetricsRecordAction(action)); |
| 856 | } |
| 857 | |
[email protected] | fb79aa2 | 2012-12-13 01:12:13 | [diff] [blame] | 858 | scoped_ptr<base::SharedMemory> |
[email protected] | 3f89283 | 2013-01-11 03:23:59 | [diff] [blame] | 859 | RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) { |
| 860 | if (size > static_cast<size_t>(std::numeric_limits<int>::max())) |
| 861 | return scoped_ptr<base::SharedMemory>(); |
| 862 | |
[email protected] | fb79aa2 | 2012-12-13 01:12:13 | [diff] [blame] | 863 | base::SharedMemoryHandle handle; |
| 864 | bool success; |
| 865 | IPC::Message* message = |
| 866 | new ChildProcessHostMsg_SyncAllocateSharedMemory(size, &handle); |
| 867 | |
| 868 | // Allow calling this from the compositor thread. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 869 | if (base::MessageLoop::current() == message_loop()) |
[email protected] | fb79aa2 | 2012-12-13 01:12:13 | [diff] [blame] | 870 | success = ChildThread::Send(message); |
| 871 | else |
| 872 | success = sync_message_filter()->Send(message); |
| 873 | |
| 874 | if (!success) |
| 875 | return scoped_ptr<base::SharedMemory>(); |
| 876 | |
| 877 | if (!base::SharedMemory::IsHandleValid(handle)) |
| 878 | return scoped_ptr<base::SharedMemory>(); |
| 879 | |
| 880 | return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false)); |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 881 | } |
| 882 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 883 | void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 884 | WebScriptController::registerExtension(extension); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 885 | } |
| 886 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 887 | void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) { |
| 888 | idle_notification_delay_in_ms_ = initial_delay_ms; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 889 | idle_timer_.Stop(); |
| 890 | idle_timer_.Start(FROM_HERE, |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 891 | base::TimeDelta::FromMilliseconds(initial_delay_ms), |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 892 | this, &RenderThreadImpl::IdleHandler); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 893 | } |
| 894 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 895 | void RenderThreadImpl::IdleHandler() { |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 896 | bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 897 | GetContentClient()->renderer()-> |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 898 | RunIdleHandlerWhenWidgetsHidden(); |
| 899 | if (run_in_foreground_tab) { |
| 900 | IdleHandlerInForegroundTab(); |
| 901 | return; |
| 902 | } |
[email protected] | 237a1485 | 2012-04-28 02:56:38 | [diff] [blame] | 903 | |
| 904 | base::allocator::ReleaseFreeMemory(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 905 | |
| 906 | v8::V8::IdleNotification(); |
| 907 | |
| 908 | // Schedule next invocation. |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 909 | // Dampen the delay using the algorithm (if delay is in seconds): |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 910 | // delay = delay + 1 / (delay + 2) |
| 911 | // Using floor(delay) has a dampening effect such as: |
| 912 | // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 913 | // If the delay is in milliseconds, the above formula is equivalent to: |
| 914 | // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) |
| 915 | // which is equivalent to |
| 916 | // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). |
| 917 | // Note that idle_notification_delay_in_ms_ would be reset to |
| 918 | // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden. |
| 919 | ScheduleIdleHandler(idle_notification_delay_in_ms_ + |
| 920 | 1000000 / (idle_notification_delay_in_ms_ + 2000)); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 921 | |
| 922 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
| 923 | } |
| 924 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 925 | void RenderThreadImpl::IdleHandlerInForegroundTab() { |
| 926 | // Increase the delay in the same way as in IdleHandler, |
| 927 | // but make it periodic by reseting it once it is too big. |
| 928 | int64 new_delay_ms = idle_notification_delay_in_ms_ + |
| 929 | 1000000 / (idle_notification_delay_in_ms_ + 2000); |
| 930 | if (new_delay_ms >= kLongIdleHandlerDelayMs) |
| 931 | new_delay_ms = kShortIdleHandlerDelayMs; |
| 932 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 933 | if (idle_notifications_to_skip_ > 0) { |
| 934 | idle_notifications_to_skip_--; |
[email protected] | 7e967f8 | 2011-12-01 09:35:14 | [diff] [blame] | 935 | } else { |
[email protected] | a47105c83 | 2011-12-07 17:24:30 | [diff] [blame] | 936 | int cpu_usage = 0; |
[email protected] | 7e967f8 | 2011-12-01 09:35:14 | [diff] [blame] | 937 | Send(new ViewHostMsg_GetCPUUsage(&cpu_usage)); |
[email protected] | 1393c4a | 2012-02-07 10:12:58 | [diff] [blame] | 938 | // Idle notification hint roughly specifies the expected duration of the |
| 939 | // idle pause. We set it proportional to the idle timer delay. |
| 940 | int idle_hint = static_cast<int>(new_delay_ms / 10); |
[email protected] | d7e5925 | 2012-03-06 22:26:02 | [diff] [blame] | 941 | if (cpu_usage < kIdleCPUUsageThresholdInPercents) { |
[email protected] | 237a1485 | 2012-04-28 02:56:38 | [diff] [blame] | 942 | base::allocator::ReleaseFreeMemory(); |
[email protected] | d7e5925 | 2012-03-06 22:26:02 | [diff] [blame] | 943 | if (v8::V8::IdleNotification(idle_hint)) { |
| 944 | // V8 finished collecting garbage. |
| 945 | new_delay_ms = kLongIdleHandlerDelayMs; |
| 946 | } |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 947 | } |
| 948 | } |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 949 | ScheduleIdleHandler(new_delay_ms); |
| 950 | } |
| 951 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 952 | int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
| 953 | return idle_notification_delay_in_ms_; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 956 | void RenderThreadImpl::SetIdleNotificationDelayInMs( |
| 957 | int64 idle_notification_delay_in_ms) { |
| 958 | idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 959 | } |
| 960 | |
[email protected] | a1a7ff3 | 2012-07-19 14:03:51 | [diff] [blame] | 961 | void RenderThreadImpl::ToggleWebKitSharedTimer(bool suspend) { |
| 962 | if (suspend_webkit_shared_timer_) { |
| 963 | EnsureWebKitInitialized(); |
| 964 | if (suspend) { |
| 965 | webkit_platform_support_->SuspendSharedTimer(); |
| 966 | } else { |
| 967 | webkit_platform_support_->ResumeSharedTimer(); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | void RenderThreadImpl::UpdateHistograms(int sequence_number) { |
| 973 | child_histogram_message_filter()->SendHistograms(sequence_number); |
| 974 | } |
| 975 | |
[email protected] | b02f590 | 2012-12-19 07:33:00 | [diff] [blame] | 976 | bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) { |
| 977 | bool result = false; |
| 978 | Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list)); |
| 979 | return result; |
| 980 | } |
| 981 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 982 | void RenderThreadImpl::PostponeIdleNotification() { |
| 983 | idle_notifications_to_skip_ = 2; |
| 984 | } |
| 985 | |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 986 | /* static */ |
| 987 | void RenderThreadImpl::OnGpuVDAContextLoss() { |
| 988 | RenderThreadImpl* self = RenderThreadImpl::current(); |
| 989 | DCHECK(self); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 990 | if (!self->gpu_vda_context3d_) |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 991 | return; |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 992 | if (self->compositor_message_loop_proxy()) { |
| 993 | self->compositor_message_loop_proxy()->DeleteSoon( |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 994 | FROM_HERE, self->gpu_vda_context3d_.release()); |
| 995 | } else { |
| 996 | self->gpu_vda_context3d_.reset(); |
[email protected] | 3b2afc3 | 2012-06-18 21:31:16 | [diff] [blame] | 997 | } |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | WebGraphicsContext3DCommandBufferImpl* |
| 1001 | RenderThreadImpl::GetGpuVDAContext3D() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1002 | if (!gpu_vda_context3d_) { |
[email protected] | 3b2afc3 | 2012-06-18 21:31:16 | [diff] [blame] | 1003 | gpu_vda_context3d_.reset( |
| 1004 | WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 1005 | this, WebKit::WebGraphicsContext3D::Attributes(), |
| 1006 | GURL("chrome://gpu/RenderThreadImpl::GetGpuVDAContext3D"))); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1007 | if (gpu_vda_context3d_) |
[email protected] | fde3e2f | 2012-08-14 06:51:37 | [diff] [blame] | 1008 | gpu_vda_context3d_->setContextLostCallback(context_lost_cb_.get()); |
[email protected] | 3b2afc3 | 2012-06-18 21:31:16 | [diff] [blame] | 1009 | } |
[email protected] | fe476b0 | 2012-08-13 21:21:38 | [diff] [blame] | 1010 | return gpu_vda_context3d_.get(); |
[email protected] | 3b2afc3 | 2012-06-18 21:31:16 | [diff] [blame] | 1011 | } |
| 1012 | |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1013 | scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 1014 | RenderThreadImpl::CreateOffscreenContext3d() { |
| 1015 | WebKit::WebGraphicsContext3D::Attributes attributes; |
| 1016 | attributes.shareResources = true; |
| 1017 | attributes.depth = false; |
| 1018 | attributes.stencil = false; |
| 1019 | attributes.antialias = false; |
| 1020 | attributes.noAutomaticFlushes = true; |
| 1021 | |
| 1022 | return make_scoped_ptr( |
| 1023 | WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
| 1024 | this, |
| 1025 | attributes, |
| 1026 | GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext3d"))); |
| 1027 | } |
| 1028 | |
[email protected] | 788dba5 | 2013-06-07 21:48:49 | [diff] [blame] | 1029 | scoped_refptr<cc::ContextProvider> |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1030 | RenderThreadImpl::OffscreenContextProviderForMainThread() { |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1031 | DCHECK(IsMainThread()); |
| 1032 | |
[email protected] | 788dba5 | 2013-06-07 21:48:49 | [diff] [blame] | 1033 | #if defined(OS_ANDROID) |
| 1034 | if (SynchronousCompositorFactory* factory = |
| 1035 | SynchronousCompositorFactory::GetInstance()) { |
| 1036 | return factory->GetOffscreenContextProviderForMainThread(); |
| 1037 | } |
| 1038 | #endif |
| 1039 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1040 | if (!shared_contexts_main_thread_.get() || |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1041 | shared_contexts_main_thread_->DestroyedOnMainThread()) { |
| 1042 | shared_contexts_main_thread_ = |
| 1043 | RendererContextProviderCommandBuffer::Create(); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1044 | if (shared_contexts_main_thread_.get() && |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1045 | !shared_contexts_main_thread_->BindToCurrentThread()) |
| 1046 | shared_contexts_main_thread_ = NULL; |
| 1047 | } |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1048 | return shared_contexts_main_thread_; |
| 1049 | } |
| 1050 | |
[email protected] | 788dba5 | 2013-06-07 21:48:49 | [diff] [blame] | 1051 | scoped_refptr<cc::ContextProvider> |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1052 | RenderThreadImpl::OffscreenContextProviderForCompositorThread() { |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1053 | DCHECK(IsMainThread()); |
| 1054 | |
[email protected] | 788dba5 | 2013-06-07 21:48:49 | [diff] [blame] | 1055 | #if defined(OS_ANDROID) |
| 1056 | if (SynchronousCompositorFactory* factory = |
| 1057 | SynchronousCompositorFactory::GetInstance()) { |
| 1058 | return factory->GetOffscreenContextProviderForCompositorThread(); |
| 1059 | } |
| 1060 | #endif |
| 1061 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1062 | if (!shared_contexts_compositor_thread_.get() || |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1063 | shared_contexts_compositor_thread_->DestroyedOnMainThread()) { |
| 1064 | shared_contexts_compositor_thread_ = |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1065 | RendererContextProviderCommandBuffer::Create(); |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1066 | } |
| 1067 | return shared_contexts_compositor_thread_; |
| 1068 | } |
| 1069 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1070 | AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1071 | if (!audio_renderer_mixer_manager_) { |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 1072 | audio_renderer_mixer_manager_.reset(new AudioRendererMixerManager( |
[email protected] | 563d665f | 2013-02-01 04:42:39 | [diff] [blame] | 1073 | GetAudioHardwareConfig())); |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | return audio_renderer_mixer_manager_.get(); |
| 1077 | } |
| 1078 | |
[email protected] | 563d665f | 2013-02-01 04:42:39 | [diff] [blame] | 1079 | media::AudioHardwareConfig* RenderThreadImpl::GetAudioHardwareConfig() { |
| 1080 | if (!audio_hardware_config_) { |
[email protected] | 06ea4f7c | 2013-03-13 20:36:51 | [diff] [blame] | 1081 | media::AudioParameters input_params; |
| 1082 | media::AudioParameters output_params; |
[email protected] | 563d665f | 2013-02-01 04:42:39 | [diff] [blame] | 1083 | Send(new ViewHostMsg_GetAudioHardwareConfig( |
[email protected] | 06ea4f7c | 2013-03-13 20:36:51 | [diff] [blame] | 1084 | &input_params, &output_params)); |
[email protected] | 563d665f | 2013-02-01 04:42:39 | [diff] [blame] | 1085 | |
| 1086 | audio_hardware_config_.reset(new media::AudioHardwareConfig( |
[email protected] | 06ea4f7c | 2013-03-13 20:36:51 | [diff] [blame] | 1087 | input_params, output_params)); |
[email protected] | 563d665f | 2013-02-01 04:42:39 | [diff] [blame] | 1088 | audio_message_filter_->SetAudioHardwareConfig(audio_hardware_config_.get()); |
| 1089 | } |
| 1090 | |
| 1091 | return audio_hardware_config_.get(); |
| 1092 | } |
| 1093 | |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1094 | #if defined(OS_WIN) |
[email protected] | feb3237 | 2012-11-21 01:14:56 | [diff] [blame] | 1095 | void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font, |
| 1096 | const string16& str) { |
| 1097 | Send(new ViewHostMsg_PreCacheFontCharacters(log_font, str)); |
| 1098 | } |
| 1099 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1100 | void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1101 | Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
[email protected] | 79fff82 | 2011-09-20 03:33:21 | [diff] [blame] | 1102 | } |
| 1103 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1104 | void RenderThreadImpl::ReleaseCachedFonts() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1105 | Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1106 | } |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1107 | |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1108 | #endif // OS_WIN |
| 1109 | |
[email protected] | 988aacf | 2012-02-12 18:10:03 | [diff] [blame] | 1110 | bool RenderThreadImpl::IsWebFrameValid(WebKit::WebFrame* web_frame) { |
| 1111 | if (!web_frame) |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 1112 | return false; // We must be shutting down. |
[email protected] | 988aacf | 2012-02-12 18:10:03 | [diff] [blame] | 1113 | |
| 1114 | RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view()); |
| 1115 | if (!render_view) |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 1116 | return false; // We must be shutting down. |
[email protected] | 988aacf | 2012-02-12 18:10:03 | [diff] [blame] | 1117 | |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1121 | bool RenderThreadImpl::IsMainThread() { |
| 1122 | return !!current(); |
| 1123 | } |
| 1124 | |
| 1125 | bool RenderThreadImpl::IsIOThread() { |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 1126 | return base::MessageLoop::current() == |
| 1127 | ChildProcess::current()->io_message_loop(); |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1128 | } |
| 1129 | |
[email protected] | 9e715412 | 2013-05-30 23:11:04 | [diff] [blame] | 1130 | base::MessageLoop* RenderThreadImpl::GetMainLoop() { |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1131 | return message_loop(); |
| 1132 | } |
[email protected] | 5b040e59 | 2012-02-10 02:56:10 | [diff] [blame] | 1133 | |
| 1134 | scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() { |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1135 | return ChildProcess::current()->io_message_loop_proxy(); |
| 1136 | } |
| 1137 | |
| 1138 | base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() { |
| 1139 | return ChildProcess::current()->GetShutDownEvent(); |
| 1140 | } |
| 1141 | |
| 1142 | scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( |
[email protected] | 3f89283 | 2013-01-11 03:23:59 | [diff] [blame] | 1143 | size_t size) { |
[email protected] | fb79aa2 | 2012-12-13 01:12:13 | [diff] [blame] | 1144 | return scoped_ptr<base::SharedMemory>( |
| 1145 | HostAllocateSharedMemoryBuffer(size)); |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | int32 RenderThreadImpl::CreateViewCommandBuffer( |
| 1149 | int32 surface_id, const GPUCreateCommandBufferConfig& init_params) { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 1150 | TRACE_EVENT1("gpu", |
| 1151 | "RenderThreadImpl::CreateViewCommandBuffer", |
| 1152 | "surface_id", |
| 1153 | surface_id); |
| 1154 | |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1155 | int32 route_id = MSG_ROUTING_NONE; |
[email protected] | 8b10b33 | 2012-02-29 21:02:14 | [diff] [blame] | 1156 | IPC::Message* message = new GpuHostMsg_CreateViewCommandBuffer( |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1157 | surface_id, |
| 1158 | init_params, |
[email protected] | 8b10b33 | 2012-02-29 21:02:14 | [diff] [blame] | 1159 | &route_id); |
| 1160 | |
| 1161 | // Allow calling this from the compositor thread. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 1162 | if (base::MessageLoop::current() == message_loop()) |
[email protected] | 8b10b33 | 2012-02-29 21:02:14 | [diff] [blame] | 1163 | ChildThread::Send(message); |
| 1164 | else |
| 1165 | sync_message_filter()->Send(message); |
| 1166 | |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1167 | return route_id; |
| 1168 | } |
| 1169 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 1170 | void RenderThreadImpl::CreateImage( |
| 1171 | gfx::PluginWindowHandle window, |
| 1172 | int32 image_id, |
| 1173 | const CreateImageCallback& callback) { |
| 1174 | NOTREACHED(); |
| 1175 | } |
| 1176 | |
| 1177 | void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) { |
| 1178 | NOTREACHED(); |
| 1179 | } |
| 1180 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1181 | void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1182 | suspend_webkit_shared_timer_ = false; |
| 1183 | } |
| 1184 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1185 | void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1186 | notify_webkit_of_modal_loop_ = false; |
| 1187 | } |
| 1188 | |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 1189 | void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& scheme, |
| 1190 | const std::string& host, |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1191 | double zoom_level) { |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 1192 | RenderViewZoomer zoomer(scheme, host, zoom_level); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1193 | RenderView::ForEach(&zoomer); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1194 | } |
| 1195 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1196 | bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 1197 | ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |
| 1198 | RenderProcessObserver* observer; |
| 1199 | while ((observer = it.GetNext()) != NULL) { |
| 1200 | if (observer->OnControlMessageReceived(msg)) |
| 1201 | return true; |
| 1202 | } |
| 1203 | |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 1204 | // Some messages are handled by delegates. |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1205 | if (appcache_dispatcher_->OnMessageReceived(msg) || |
| 1206 | dom_storage_dispatcher_->OnMessageReceived(msg)) { |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1207 | return true; |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1208 | } |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 1209 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1210 | bool handled = true; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1211 | IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1212 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |
| 1213 | OnSetZoomLevelForCurrentURL) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1214 | // TODO(port): removed from render_messages_internal.h; |
| 1215 | // is there a new non-windows message I should add here? |
| 1216 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 1217 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 1218 | IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) |
[email protected] | b69934e | 2011-10-29 02:51:52 | [diff] [blame] | 1219 | IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData) |
[email protected] | 4436338 | 2013-03-12 07:22:47 | [diff] [blame] | 1220 | IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended, |
| 1221 | OnSetWebKitSharedTimersSuspended) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1222 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1223 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1224 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1225 | } |
| 1226 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1227 | void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 1228 | EnsureWebKitInitialized(); |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 1229 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 1230 | RenderViewImpl::Create( |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 1231 | params.opener_route_id, |
| 1232 | params.renderer_preferences, |
| 1233 | params.web_preferences, |
| 1234 | new SharedRenderViewCounter(0), |
| 1235 | params.view_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1236 | params.main_frame_routing_id, |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 1237 | params.surface_id, |
| 1238 | params.session_storage_namespace_id, |
| 1239 | params.frame_name, |
| 1240 | false, |
| 1241 | params.swapped_out, |
| 1242 | params.next_page_id, |
| 1243 | params.screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1244 | params.accessibility_mode, |
| 1245 | params.allow_partial_swap); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 1246 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 1247 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1248 | GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1249 | CauseForGpuLaunch cause_for_gpu_launch) { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 1250 | TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1251 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1252 | if (gpu_channel_.get()) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 1253 | // Do nothing if we already have a GPU channel or are already |
| 1254 | // establishing one. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 1255 | if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
| 1256 | gpu_channel_->state() == GpuChannelHost::kConnected) |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1257 | return GetGpuChannel(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1258 | |
| 1259 | // Recreate the channel if it has been lost. |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 1260 | gpu_channel_ = NULL; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1261 | } |
| 1262 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1263 | // Ask the browser for the channel name. |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 1264 | int client_id = 0; |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1265 | IPC::ChannelHandle channel_handle; |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 1266 | gpu::GPUInfo gpu_info; |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1267 | if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch, |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 1268 | &client_id, |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1269 | &channel_handle, |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1270 | &gpu_info)) || |
[email protected] | 8bc550e | 2012-02-07 11:05:56 | [diff] [blame] | 1271 | #if defined(OS_POSIX) |
| 1272 | channel_handle.socket.fd == -1 || |
| 1273 | #endif |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 1274 | channel_handle.name.empty()) { |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1275 | // Otherwise cancel the connection. |
| 1276 | gpu_channel_ = NULL; |
| 1277 | return NULL; |
| 1278 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1279 | |
[email protected] | 03dc888 | 2012-03-08 23:46:29 | [diff] [blame] | 1280 | gpu_channel_ = new GpuChannelHost(this, 0, client_id); |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1281 | gpu_channel_->set_gpu_info(gpu_info); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1282 | GetContentClient()->SetGpuInfo(gpu_info); |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1283 | |
| 1284 | // Connect to the GPU process if a channel name was received. |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 1285 | gpu_channel_->Connect(channel_handle); |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1286 | |
[email protected] | f9a2b2fe | 2010-07-15 21:13:23 | [diff] [blame] | 1287 | return GetGpuChannel(); |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 1288 | } |
| 1289 | |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 1290 | WebKit::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter( |
| 1291 | WebKit::WebMediaStreamCenterClient* client) { |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 1292 | #if defined(OS_ANDROID) |
[email protected] | ce585bf | 2013-03-14 16:25:16 | [diff] [blame] | 1293 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1294 | switches::kDisableWebRTC)) |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 1295 | return NULL; |
| 1296 | #endif |
| 1297 | |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 1298 | #if defined(ENABLE_WEBRTC) |
[email protected] | 68e5fee | 2013-02-18 10:04:22 | [diff] [blame] | 1299 | if (!media_stream_center_) { |
| 1300 | media_stream_center_ = GetContentClient()->renderer() |
| 1301 | ->OverrideCreateWebMediaStreamCenter(client); |
| 1302 | if (!media_stream_center_) { |
| 1303 | media_stream_center_ = new MediaStreamCenter( |
| 1304 | client, GetMediaStreamDependencyFactory()); |
| 1305 | } |
| 1306 | } |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 1307 | #endif |
| 1308 | return media_stream_center_; |
| 1309 | } |
| 1310 | |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 1311 | MediaStreamDependencyFactory* |
| 1312 | RenderThreadImpl::GetMediaStreamDependencyFactory() { |
| 1313 | #if defined(ENABLE_WEBRTC) |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1314 | if (!media_stream_factory_) { |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 1315 | media_stream_factory_.reset(new MediaStreamDependencyFactory( |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1316 | vc_manager_.get(), p2p_socket_dispatcher_.get())); |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 1317 | } |
| 1318 | #endif |
| 1319 | return media_stream_factory_.get(); |
| 1320 | } |
| 1321 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1322 | GpuChannelHost* RenderThreadImpl::GetGpuChannel() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1323 | if (!gpu_channel_.get()) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1324 | return NULL; |
| 1325 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 1326 | if (gpu_channel_->state() != GpuChannelHost::kConnected) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1327 | return NULL; |
| 1328 | |
| 1329 | return gpu_channel_.get(); |
| 1330 | } |
| 1331 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1332 | void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 1333 | EnsureWebKitInitialized(); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 1334 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 1335 | // point we already know that the browser has refreshed its list, so disable |
| 1336 | // refresh temporarily to prevent each renderer process causing the list to be |
| 1337 | // regenerated. |
[email protected] | a70b435 | 2012-07-31 22:34:53 | [diff] [blame] | 1338 | webkit_platform_support_->set_plugin_refresh_allowed(false); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 1339 | WebKit::resetPluginCache(reload_pages); |
[email protected] | a70b435 | 2012-07-31 22:34:53 | [diff] [blame] | 1340 | webkit_platform_support_->set_plugin_refresh_allowed(true); |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 1341 | |
| 1342 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged()); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 1343 | } |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1344 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1345 | void RenderThreadImpl::OnNetworkStateChanged(bool online) { |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 1346 | EnsureWebKitInitialized(); |
| 1347 | WebNetworkStateNotifier::setOnLine(online); |
| 1348 | } |
| 1349 | |
[email protected] | b69934e | 2011-10-29 02:51:52 | [diff] [blame] | 1350 | void RenderThreadImpl::OnTempCrashWithData(const GURL& data) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1351 | GetContentClient()->SetActiveURL(data); |
[email protected] | b69934e | 2011-10-29 02:51:52 | [diff] [blame] | 1352 | CHECK(false); |
| 1353 | } |
| 1354 | |
[email protected] | 4436338 | 2013-03-12 07:22:47 | [diff] [blame] | 1355 | void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) { |
| 1356 | ToggleWebKitSharedTimer(suspend); |
| 1357 | } |
| 1358 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 1359 | scoped_refptr<base::MessageLoopProxy> |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1360 | RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 1361 | DCHECK(message_loop() == base::MessageLoop::current()); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1362 | if (!file_thread_) { |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 1363 | file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 1364 | file_thread_->Start(); |
| 1365 | } |
| 1366 | return file_thread_->message_loop_proxy(); |
| 1367 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1368 | |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 1369 | scoped_refptr<base::MessageLoopProxy> |
| 1370 | RenderThreadImpl::GetMediaThreadMessageLoopProxy() { |
| 1371 | DCHECK(message_loop() == base::MessageLoop::current()); |
| 1372 | if (!media_thread_) { |
| 1373 | media_thread_.reset(new base::Thread("Media")); |
| 1374 | media_thread_->Start(); |
| 1375 | } |
| 1376 | return media_thread_->message_loop_proxy(); |
| 1377 | } |
| 1378 | |
[email protected] | 107c053 | 2013-02-06 02:34:09 | [diff] [blame] | 1379 | void RenderThreadImpl::SetFlingCurveParameters( |
| 1380 | const std::vector<float>& new_touchpad, |
| 1381 | const std::vector<float>& new_touchscreen) { |
| 1382 | webkit_platform_support_->SetFlingCurveParameters(new_touchpad, |
| 1383 | new_touchscreen); |
| 1384 | |
| 1385 | } |
| 1386 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1387 | } // namespace content |