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