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