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