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