[email protected] | 7785b17f | 2011-03-23 01:20:28 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 13 | #include "base/debug/trace_event.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 14 | #include "base/lazy_instance.h" |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 15 | #include "base/logging.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
[email protected] | 6cf19311f | 2011-04-14 23:06:02 | [diff] [blame] | 17 | #include "base/metrics/histogram.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 18 | #include "base/metrics/stats_table.h" |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 19 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | #include "base/shared_memory.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 21 | #include "base/task.h" |
[email protected] | 1357c32 | 2010-12-30 22:18:56 | [diff] [blame] | 22 | #include "base/threading/thread_local.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 23 | #include "base/values.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 24 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 25 | #include "content/common/content_switches.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 26 | #include "content/common/database_messages.h" |
| 27 | #include "content/common/db_message_filter.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 28 | #include "content/common/dom_storage_messages.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 29 | #include "content/common/gpu/gpu_messages.h" |
[email protected] | d3fd748b | 2011-09-20 17:39:17 | [diff] [blame] | 30 | #include "content/common/npobject_util.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 31 | #include "content/common/plugin_messages.h" |
[email protected] | 6091604 | 2011-03-19 00:43:36 | [diff] [blame] | 32 | #include "content/common/renderer_preferences.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 33 | #include "content/common/resource_messages.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 34 | #include "content/common/view_messages.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 35 | #include "content/common/web_database_observer_impl.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 36 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 37 | #include "content/public/renderer/render_process_observer.h" |
| 38 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 39 | #include "content/renderer/devtools_agent_filter.h" |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 40 | #include "content/renderer/gpu/compositor_thread.h" |
[email protected] | a03a222 | 2011-05-25 21:26:40 | [diff] [blame] | 41 | #include "content/renderer/gpu/gpu_channel_host.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 42 | #include "content/renderer/indexed_db_dispatcher.h" |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 43 | #include "content/renderer/media/audio_input_message_filter.h" |
| 44 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 45 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | ba164c91 | 2011-06-14 22:07:34 | [diff] [blame] | 46 | #include "content/renderer/media/video_capture_message_filter.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 47 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 48 | #include "content/renderer/render_process_impl.h" |
[email protected] | 6091604 | 2011-03-19 00:43:36 | [diff] [blame] | 49 | #include "content/renderer/render_view.h" |
[email protected] | acb9472 | 2011-03-18 01:33:34 | [diff] [blame] | 50 | #include "content/renderer/renderer_webidbfactory_impl.h" |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 51 | #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 52 | #include "ipc/ipc_channel_handle.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 53 | #include "ipc/ipc_platform_file.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 54 | #include "net/base/net_errors.h" |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 55 | #include "net/base/net_util.h" |
[email protected] | 1b1f3eb | 2009-12-01 13:48:04 | [diff] [blame] | 56 | #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 57 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 58 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
| 59 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 60 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 61 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 62 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" |
[email protected] | 4bd55a3 | 2011-07-28 13:28:38 | [diff] [blame] | 63 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 64 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 65 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 66 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" |
| 67 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 68 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | 18ad677 | 2011-09-20 21:51:32 | [diff] [blame] | 69 | #include "ui/base/ui_base_switches.h" |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 70 | #include "v8/include/v8.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 71 | #include "webkit/extensions/v8/playback_extension.h" |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 72 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 73 | |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 74 | // TODO(port) |
| 75 | #if defined(OS_WIN) |
[email protected] | 79fff82 | 2011-09-20 03:33:21 | [diff] [blame] | 76 | #include "content/common/child_process_messages.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 77 | #else |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 78 | #include "base/memory/scoped_handle.h" |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 79 | #include "content/common/np_channel_base.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 80 | #endif |
| 81 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 82 | #if defined(OS_WIN) |
| 83 | #include <windows.h> |
| 84 | #include <objbase.h> |
| 85 | #endif |
| 86 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 87 | #if defined(OS_POSIX) |
| 88 | #include "ipc/ipc_channel_posix.h" |
| 89 | #endif |
| 90 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 91 | using WebKit::WebDocument; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 92 | using WebKit::WebFrame; |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 93 | using WebKit::WebNetworkStateNotifier; |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 94 | using WebKit::WebRuntimeFeatures; |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 95 | using WebKit::WebScriptController; |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 96 | using WebKit::WebString; |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 97 | using WebKit::WebStorageEventDispatcher; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 98 | using WebKit::WebView; |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 99 | using content::RenderProcessObserver; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 101 | namespace { |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 102 | static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; |
| 103 | |
[email protected] | 4bd55a3 | 2011-07-28 13:28:38 | [diff] [blame] | 104 | #if defined(TOUCH_UI) |
| 105 | static const int kPopupListBoxMinimumRowHeight = 60; |
| 106 | #endif |
| 107 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 108 | // 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] | 109 | // incorrectly from the wrong thread. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 110 | static base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > lazy_tls( |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 111 | base::LINKER_INITIALIZED); |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 112 | |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 113 | class RenderViewZoomer : public content::RenderViewVisitor { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 114 | public: |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 115 | RenderViewZoomer(const GURL& url, double zoom_level) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 116 | : zoom_level_(zoom_level) { |
| 117 | host_ = net::GetHostOrSpecFromURL(url); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | virtual bool Visit(RenderView* render_view) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 121 | WebView* webview = render_view->webview(); |
| 122 | WebDocument document = webview->mainFrame()->document(); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 123 | |
| 124 | // Don't set zoom level for full-page plugin since they don't use the same |
| 125 | // zoom settings. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 126 | if (document.isPluginDocument()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 127 | return true; |
| 128 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 129 | if (net::GetHostOrSpecFromURL(GURL(document.url())) == host_) |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 130 | webview->setZoomLevel(false, zoom_level_); |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | std::string host_; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 136 | double zoom_level_; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 137 | |
| 138 | DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
| 139 | }; |
[email protected] | 0478d016 | 2010-08-28 08:29:40 | [diff] [blame] | 140 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 141 | } // namespace |
| 142 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 143 | static void* CreateHistogram( |
| 144 | const char *name, int min, int max, size_t buckets) { |
| 145 | if (min <= 0) |
| 146 | min = 1; |
| 147 | base::Histogram* histogram = base::Histogram::FactoryGet( |
| 148 | name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); |
| 149 | return histogram; |
| 150 | } |
| 151 | |
| 152 | static void AddHistogramSample(void* hist, int sample) { |
| 153 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
| 154 | histogram->Add(sample); |
| 155 | } |
| 156 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 157 | RenderThreadImpl* RenderThreadImpl::current() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 158 | return lazy_tls.Pointer()->Get(); |
| 159 | } |
| 160 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 161 | // When we run plugins in process, we actually run them on the render thread, |
| 162 | // which means that we need to make the render thread pump UI events. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 163 | RenderThreadImpl::RenderThreadImpl() { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 164 | Init(); |
| 165 | } |
| 166 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 167 | RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 168 | : ChildThread(channel_name) { |
| 169 | Init(); |
| 170 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 171 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 172 | void RenderThreadImpl::Init() { |
| 173 | TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 174 | |
[email protected] | 53c607c | 2011-03-21 23:19:04 | [diff] [blame] | 175 | #if defined(OS_MACOSX) |
| 176 | // On Mac, the select popups are rendered by the browser. |
| 177 | WebKit::WebView::setUseExternalPopupMenus(true); |
| 178 | #endif |
| 179 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 180 | lazy_tls.Pointer()->Set(this); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 181 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 182 | // If you are running plugins in this thread you need COM active but in |
| 183 | // the normal case you don't. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 184 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 185 | CoInitialize(0); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 186 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 188 | // In single process the single process is all there is. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 189 | suspend_webkit_shared_timer_ = true; |
| 190 | notify_webkit_of_modal_loop_ = true; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 191 | plugin_refresh_allowed_ = true; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 192 | widget_count_ = 0; |
| 193 | hidden_widget_count_ = 0; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 194 | idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 195 | task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this)); |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 196 | |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 197 | appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 198 | indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 199 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 200 | db_message_filter_ = new DBMessageFilter(); |
| 201 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 202 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 203 | vc_manager_ = new VideoCaptureImplManager(); |
| 204 | AddFilter(vc_manager_->video_capture_message_filter()); |
[email protected] | e25f4d7 | 2011-06-08 20:58:46 | [diff] [blame] | 205 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 206 | audio_input_message_filter_ = new AudioInputMessageFilter(); |
| 207 | AddFilter(audio_input_message_filter_.get()); |
| 208 | |
| 209 | audio_message_filter_ = new AudioMessageFilter(); |
| 210 | AddFilter(audio_message_filter_.get()); |
| 211 | |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 212 | devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
| 213 | AddFilter(devtools_agent_message_filter_.get()); |
| 214 | |
[email protected] | 8d97ade | 2011-04-14 18:17:08 | [diff] [blame] | 215 | content::GetContentClient()->renderer()->RenderThreadStarted(); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 216 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 217 | TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 218 | } |
| 219 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 220 | RenderThreadImpl::~RenderThreadImpl() { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 221 | FOR_EACH_OBSERVER( |
| 222 | RenderProcessObserver, observers_, OnRenderProcessShutdown()); |
| 223 | |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 224 | // Wait for all databases to be closed. |
[email protected] | 2b437e23 | 2010-04-02 01:30:08 | [diff] [blame] | 225 | if (web_database_observer_impl_.get()) |
| 226 | web_database_observer_impl_->WaitForAllDatabasesToClose(); |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 227 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 228 | // Shutdown in reverse of the initialization order. |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 229 | RemoveFilter(devtools_agent_message_filter_.get()); |
| 230 | devtools_agent_message_filter_ = NULL; |
| 231 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 232 | RemoveFilter(audio_input_message_filter_.get()); |
| 233 | audio_input_message_filter_ = NULL; |
| 234 | |
| 235 | RemoveFilter(audio_message_filter_.get()); |
| 236 | audio_message_filter_ = NULL; |
| 237 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 238 | RemoveFilter(vc_manager_->video_capture_message_filter()); |
| 239 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 240 | RemoveFilter(db_message_filter_.get()); |
| 241 | db_message_filter_ = NULL; |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 242 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 243 | // Shutdown the file thread if it's running. |
| 244 | if (file_thread_.get()) |
| 245 | file_thread_->Stop(); |
| 246 | |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 247 | if (compositor_thread_.get()) { |
| 248 | RemoveFilter(compositor_thread_->GetMessageFilter()); |
| 249 | compositor_thread_.reset(); |
| 250 | } |
| 251 | |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 252 | if (webkit_platform_support_.get()) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 253 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 254 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 255 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 256 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 257 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 258 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 259 | // Clean up plugin channels before this thread goes away. |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 260 | NPChannelBase::CleanupChannels(); |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 261 | // Don't call COM if the renderer is in the sandbox. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 262 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 263 | CoUninitialize(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 264 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 267 | bool RenderThreadImpl::Send(IPC::Message* msg) { |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 268 | // Certain synchronous messages cannot always be processed synchronously by |
| 269 | // the browser, e.g., Chrome frame communicating with the embedding browser. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 270 | // This could cause a complete hang of Chrome if a windowed plug-in is trying |
| 271 | // to communicate with the renderer thread since the browser's UI thread |
| 272 | // could be stuck (within a Windows API call) trying to synchronously |
| 273 | // communicate with the plug-in. The remedy is to pump messages on this |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 274 | // thread while the browser is processing this request. This creates an |
| 275 | // opportunity for re-entrancy into WebKit, so we need to take care to disable |
| 276 | // callbacks, timers, and pending network loads that could trigger such |
| 277 | // callbacks. |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 278 | bool pumping_events = false; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 279 | if (msg->is_sync()) { |
| 280 | if (msg->is_caller_pumping_messages()) { |
| 281 | pumping_events = true; |
| 282 | } else { |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 283 | if ((msg->type() == ViewHostMsg_GetCookies::ID || |
| 284 | msg->type() == ViewHostMsg_GetRawCookies::ID || |
| 285 | msg->type() == ViewHostMsg_CookiesEnabled::ID) && |
| 286 | content::GetContentClient()->renderer()-> |
| 287 | ShouldPumpEventsDuringCookieMessage()) { |
| 288 | pumping_events = true; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 289 | } |
| 290 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 291 | } |
| 292 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 293 | bool suspend_webkit_shared_timer = true; // default value |
| 294 | std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 295 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 296 | bool notify_webkit_of_modal_loop = true; // default value |
| 297 | std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); |
| 298 | |
| 299 | gfx::NativeViewId host_window = 0; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 300 | |
| 301 | if (pumping_events) { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 302 | if (suspend_webkit_shared_timer) |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 303 | webkit_platform_support_->SuspendSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 304 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 305 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 306 | WebView::willEnterModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 307 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 308 | RenderWidget* widget = |
| 309 | static_cast<RenderWidget*>(ResolveRoute(msg->routing_id())); |
| 310 | if (widget) { |
| 311 | host_window = widget->host_window(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 312 | PluginChannelHost::Broadcast( |
| 313 | new PluginMsg_SignalModalDialogEvent(host_window)); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | bool rv = ChildThread::Send(msg); |
| 318 | |
| 319 | if (pumping_events) { |
| 320 | if (host_window) { |
| 321 | PluginChannelHost::Broadcast( |
| 322 | new PluginMsg_ResetModalDialogEvent(host_window)); |
| 323 | } |
| 324 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 325 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 326 | WebView::didExitModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 327 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 328 | if (suspend_webkit_shared_timer) |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 329 | webkit_platform_support_->ResumeSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | return rv; |
| 333 | } |
| 334 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 335 | MessageLoop* RenderThreadImpl::GetMessageLoop() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 336 | return message_loop(); |
| 337 | } |
| 338 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 339 | IPC::SyncChannel* RenderThreadImpl::GetChannel() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 340 | return channel(); |
| 341 | } |
| 342 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 343 | ResourceDispatcher* RenderThreadImpl::GetResourceDispatcher() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 344 | return resource_dispatcher(); |
| 345 | } |
| 346 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 347 | std::string RenderThreadImpl::GetLocale() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 348 | // The browser process should have passed the locale to the renderer via the |
| 349 | // --lang command line flag. In single process mode, this will return the |
| 350 | // wrong value. TODO(tc): Fix this for single process mode. |
| 351 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 352 | const std::string& lang = |
| 353 | parsed_command_line.GetSwitchValueASCII(switches::kLang); |
| 354 | DCHECK(!lang.empty() || |
| 355 | (!parsed_command_line.HasSwitch(switches::kRendererProcess) && |
| 356 | !parsed_command_line.HasSwitch(switches::kPluginProcess))); |
| 357 | return lang; |
| 358 | } |
| 359 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 360 | void RenderThreadImpl::AddRoute(int32 routing_id, |
| 361 | IPC::Channel::Listener* listener) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 362 | widget_count_++; |
| 363 | return ChildThread::AddRoute(routing_id, listener); |
| 364 | } |
| 365 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 366 | void RenderThreadImpl::RemoveRoute(int32 routing_id) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 367 | widget_count_--; |
| 368 | return ChildThread::RemoveRoute(routing_id); |
| 369 | } |
| 370 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 371 | void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 372 | channel()->AddFilter(filter); |
| 373 | } |
| 374 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 375 | void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 376 | channel()->RemoveFilter(filter); |
| 377 | } |
| 378 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 379 | void RenderThreadImpl::SetOutgoingMessageFilter( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 380 | IPC::ChannelProxy::OutgoingMessageFilter* filter) { |
| 381 | } |
| 382 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 383 | void RenderThreadImpl::AddObserver(content::RenderProcessObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 384 | observers_.AddObserver(observer); |
| 385 | } |
| 386 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 387 | void RenderThreadImpl::RemoveObserver( |
| 388 | content::RenderProcessObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 389 | observers_.RemoveObserver(observer); |
| 390 | } |
| 391 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 392 | void RenderThreadImpl::WidgetHidden() { |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 393 | DCHECK(hidden_widget_count_ < widget_count_); |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 394 | hidden_widget_count_++; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 395 | |
| 396 | if (!content::GetContentClient()->renderer()-> |
| 397 | RunIdleHandlerWhenWidgetsHidden()) { |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | if (widget_count_ && hidden_widget_count_ == widget_count_) |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 402 | ScheduleIdleHandler(kInitialIdleHandlerDelayS); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 403 | } |
| 404 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 405 | void RenderThreadImpl::WidgetRestored() { |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 406 | DCHECK_GT(hidden_widget_count_, 0); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 407 | hidden_widget_count_--; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 408 | if (!content::GetContentClient()->renderer()-> |
| 409 | RunIdleHandlerWhenWidgetsHidden()) { |
| 410 | return; |
| 411 | } |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 412 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 413 | idle_timer_.Stop(); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 414 | } |
| 415 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 416 | void RenderThreadImpl::EnsureWebKitInitialized() { |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 417 | if (webkit_platform_support_.get()) |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 418 | return; |
| 419 | |
| 420 | v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
| 421 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 422 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 423 | |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 424 | webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
| 425 | WebKit::initialize(webkit_platform_support_.get()); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 426 | |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 427 | compositor_thread_.reset(new CompositorThread(this)); |
| 428 | AddFilter(compositor_thread_->GetMessageFilter()); |
| 429 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 430 | WebScriptController::enableV8SingleThreadMode(); |
| 431 | |
| 432 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 433 | |
| 434 | webkit_glue::EnableWebCoreLogChannels( |
| 435 | command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); |
| 436 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 437 | if (command_line.HasSwitch(switches::kPlaybackMode) || |
| 438 | command_line.HasSwitch(switches::kRecordMode) || |
| 439 | command_line.HasSwitch(switches::kNoJsRandomness)) { |
| 440 | RegisterExtension(extensions_v8::PlaybackExtension::Get()); |
| 441 | } |
| 442 | |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 443 | web_database_observer_impl_.reset(new WebDatabaseObserverImpl(Get())); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 444 | WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); |
| 445 | |
| 446 | WebRuntimeFeatures::enableSockets( |
| 447 | !command_line.HasSwitch(switches::kDisableWebSockets)); |
| 448 | |
| 449 | WebRuntimeFeatures::enableDatabase( |
| 450 | !command_line.HasSwitch(switches::kDisableDatabases)); |
| 451 | |
| 452 | WebRuntimeFeatures::enableDataTransferItems( |
| 453 | !command_line.HasSwitch(switches::kDisableDataTransferItems)); |
| 454 | |
| 455 | WebRuntimeFeatures::enableApplicationCache( |
| 456 | !command_line.HasSwitch(switches::kDisableApplicationCache)); |
| 457 | |
| 458 | WebRuntimeFeatures::enableNotifications( |
| 459 | !command_line.HasSwitch(switches::kDisableDesktopNotifications)); |
| 460 | |
| 461 | WebRuntimeFeatures::enableLocalStorage( |
| 462 | !command_line.HasSwitch(switches::kDisableLocalStorage)); |
| 463 | WebRuntimeFeatures::enableSessionStorage( |
| 464 | !command_line.HasSwitch(switches::kDisableSessionStorage)); |
| 465 | |
| 466 | WebRuntimeFeatures::enableIndexedDatabase( |
| 467 | !command_line.HasSwitch(switches::kDisableIndexedDatabase)); |
| 468 | |
| 469 | WebRuntimeFeatures::enableGeolocation( |
| 470 | !command_line.HasSwitch(switches::kDisableGeolocation)); |
| 471 | |
| 472 | WebKit::WebRuntimeFeatures::enableMediaStream( |
| 473 | command_line.HasSwitch(switches::kEnableMediaStream)); |
| 474 | |
[email protected] | efdc028 | 2011-08-26 00:36:12 | [diff] [blame] | 475 | WebKit::WebRuntimeFeatures::enableFullScreenAPI( |
[email protected] | 5e5671a | 2011-09-08 02:12:21 | [diff] [blame] | 476 | !command_line.HasSwitch(switches::kDisableFullScreen)); |
[email protected] | efdc028 | 2011-08-26 00:36:12 | [diff] [blame] | 477 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 478 | #if defined(OS_CHROMEOS) |
| 479 | // TODO(crogers): enable once Web Audio has been tested and optimized. |
| 480 | WebRuntimeFeatures::enableWebAudio(false); |
| 481 | #else |
| 482 | WebRuntimeFeatures::enableWebAudio( |
| 483 | !command_line.HasSwitch(switches::kDisableWebAudio)); |
| 484 | #endif |
| 485 | |
| 486 | WebRuntimeFeatures::enablePushState(true); |
| 487 | |
| 488 | #ifdef TOUCH_UI |
| 489 | WebRuntimeFeatures::enableTouch(true); |
| 490 | WebKit::WebPopupMenu::setMinimumRowHeight(kPopupListBoxMinimumRowHeight); |
| 491 | #else |
| 492 | // TODO(saintlou): in the future touch should always be enabled |
| 493 | WebRuntimeFeatures::enableTouch(false); |
| 494 | #endif |
| 495 | |
| 496 | WebRuntimeFeatures::enableDeviceMotion( |
| 497 | command_line.HasSwitch(switches::kEnableDeviceMotion)); |
| 498 | |
| 499 | WebRuntimeFeatures::enableDeviceOrientation( |
| 500 | !command_line.HasSwitch(switches::kDisableDeviceOrientation)); |
| 501 | |
| 502 | WebRuntimeFeatures::enableSpeechInput( |
| 503 | !command_line.HasSwitch(switches::kDisableSpeechInput)); |
| 504 | |
| 505 | WebRuntimeFeatures::enableFileSystem( |
| 506 | !command_line.HasSwitch(switches::kDisableFileSystem)); |
| 507 | |
| 508 | WebRuntimeFeatures::enableJavaScriptI18NAPI( |
| 509 | !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)); |
| 510 | |
| 511 | WebRuntimeFeatures::enableQuota(true); |
| 512 | |
| 513 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized()); |
| 514 | } |
| 515 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 516 | void RenderThreadImpl::RecordUserMetrics(const std::string& action) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 517 | Send(new ViewHostMsg_UserMetricsRecordAction(action)); |
| 518 | } |
| 519 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 520 | void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 521 | WebScriptController::registerExtension(extension); |
| 522 | v8_extensions_.insert(extension->name()); |
| 523 | } |
| 524 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 525 | bool RenderThreadImpl::IsRegisteredExtension( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 526 | const std::string& v8_extension_name) const { |
| 527 | return v8_extensions_.find(v8_extension_name) != v8_extensions_.end(); |
| 528 | } |
| 529 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 530 | void RenderThreadImpl::ScheduleIdleHandler(double initial_delay_s) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 531 | idle_notification_delay_in_s_ = initial_delay_s; |
| 532 | idle_timer_.Stop(); |
| 533 | idle_timer_.Start(FROM_HERE, |
| 534 | base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 535 | this, &RenderThreadImpl::IdleHandler); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 536 | } |
| 537 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 538 | void RenderThreadImpl::IdleHandler() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 539 | #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
| 540 | MallocExtension::instance()->ReleaseFreeMemory(); |
| 541 | #endif |
| 542 | |
| 543 | v8::V8::IdleNotification(); |
| 544 | |
| 545 | // Schedule next invocation. |
| 546 | // Dampen the delay using the algorithm: |
| 547 | // delay = delay + 1 / (delay + 2) |
| 548 | // Using floor(delay) has a dampening effect such as: |
| 549 | // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 550 | // Note that idle_notification_delay_in_s_ would be reset to |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 551 | // kInitialIdleHandlerDelayS in RenderThreadImpl::WidgetHidden. |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 552 | ScheduleIdleHandler(idle_notification_delay_in_s_ + |
| 553 | 1.0 / (idle_notification_delay_in_s_ + 2.0)); |
| 554 | |
| 555 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
| 556 | } |
| 557 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 558 | double RenderThreadImpl::GetIdleNotificationDelayInS() const { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 559 | return idle_notification_delay_in_s_; |
| 560 | } |
| 561 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 562 | void RenderThreadImpl::SetIdleNotificationDelayInS( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 563 | double idle_notification_delay_in_s) { |
| 564 | idle_notification_delay_in_s_ = idle_notification_delay_in_s; |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | #if defined(OS_WIN) |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 568 | void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 569 | Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
[email protected] | 79fff82 | 2011-09-20 03:33:21 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 572 | void RenderThreadImpl::ReleaseCachedFonts() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 573 | Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 574 | } |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 575 | |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 576 | #endif // OS_WIN |
| 577 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 578 | int32 RenderThreadImpl::RoutingIDForCurrentContext() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 579 | int32 routing_id = MSG_ROUTING_CONTROL; |
| 580 | if (v8::Context::InContext()) { |
| 581 | WebFrame* frame = WebFrame::frameForCurrentContext(); |
| 582 | if (frame) { |
| 583 | RenderView* view = RenderView::FromWebView(frame->view()); |
| 584 | if (view) |
| 585 | routing_id = view->routing_id(); |
| 586 | } |
| 587 | } else { |
| 588 | DLOG(WARNING) << "Not called within a script context!"; |
| 589 | } |
| 590 | return routing_id; |
| 591 | } |
| 592 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 593 | void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 594 | suspend_webkit_shared_timer_ = false; |
| 595 | } |
| 596 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 597 | void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 598 | notify_webkit_of_modal_loop_ = false; |
| 599 | } |
| 600 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 601 | void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const GURL& url, |
| 602 | double zoom_level) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 603 | RenderViewZoomer zoomer(url, zoom_level); |
| 604 | RenderView::ForEach(&zoomer); |
| 605 | } |
| 606 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 607 | void RenderThreadImpl::OnDOMStorageEvent( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 608 | const DOMStorageMsg_Event_Params& params) { |
| 609 | if (!dom_storage_event_dispatcher_.get()) |
| 610 | dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); |
| 611 | dom_storage_event_dispatcher_->dispatchStorageEvent(params.key, |
| 612 | params.old_value, params.new_value, params.origin, params.url, |
| 613 | params.storage_type == DOM_STORAGE_LOCAL); |
| 614 | } |
| 615 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 616 | bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 617 | ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |
| 618 | RenderProcessObserver* observer; |
| 619 | while ((observer = it.GetNext()) != NULL) { |
| 620 | if (observer->OnControlMessageReceived(msg)) |
| 621 | return true; |
| 622 | } |
| 623 | |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 624 | // Some messages are handled by delegates. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 625 | if (appcache_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 626 | return true; |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 627 | if (indexed_db_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 628 | return true; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 629 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 630 | bool handled = true; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 631 | IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 632 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |
| 633 | OnSetZoomLevelForCurrentURL) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 634 | IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 635 | IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 636 | // TODO(port): removed from render_messages_internal.h; |
| 637 | // is there a new non-windows message I should add here? |
| 638 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 639 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 640 | IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 641 | IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 642 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 643 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 644 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 645 | } |
| 646 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 647 | void RenderThreadImpl::OnSetNextPageID(int32 next_page_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 648 | // This should only be called at process initialization time, so we shouldn't |
| 649 | // have to worry about thread-safety. |
| 650 | RenderView::SetNextPageID(next_page_id); |
| 651 | } |
| 652 | |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 653 | // Called when to register CSS Color name->system color mappings. |
| 654 | // We update the colors one by one and then tell WebKit to refresh all render |
| 655 | // views. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 656 | void RenderThreadImpl::OnSetCSSColors( |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 657 | const std::vector<CSSColors::CSSColorMapping>& colors) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 658 | EnsureWebKitInitialized(); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 659 | size_t num_colors = colors.size(); |
| 660 | scoped_array<WebKit::WebColorName> color_names( |
| 661 | new WebKit::WebColorName[num_colors]); |
| 662 | scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); |
| 663 | size_t i = 0; |
| 664 | for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = |
| 665 | colors.begin(); |
| 666 | it != colors.end(); |
| 667 | ++it, ++i) { |
| 668 | color_names[i] = it->first; |
| 669 | web_colors[i] = it->second; |
| 670 | } |
| 671 | WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); |
| 672 | } |
| 673 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 674 | void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 675 | EnsureWebKitInitialized(); |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 676 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 677 | RenderView::Create( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 678 | this, |
| 679 | params.parent_window, |
| 680 | MSG_ROUTING_NONE, |
| 681 | params.renderer_preferences, |
| 682 | params.web_preferences, |
| 683 | new SharedRenderViewCounter(0), |
| 684 | params.view_id, |
| 685 | params.session_storage_namespace_id, |
| 686 | params.frame_name); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 687 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 688 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 689 | GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync( |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 690 | content::CauseForGpuLaunch cause_for_gpu_launch) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 691 | if (gpu_channel_.get()) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 692 | // Do nothing if we already have a GPU channel or are already |
| 693 | // establishing one. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 694 | if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
| 695 | gpu_channel_->state() == GpuChannelHost::kConnected) |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 696 | return GetGpuChannel(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 697 | |
| 698 | // Recreate the channel if it has been lost. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 699 | if (gpu_channel_->state() == GpuChannelHost::kLost) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 700 | gpu_channel_ = NULL; |
| 701 | } |
| 702 | |
| 703 | if (!gpu_channel_.get()) |
| 704 | gpu_channel_ = new GpuChannelHost; |
| 705 | |
| 706 | // Ask the browser for the channel name. |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 707 | IPC::ChannelHandle channel_handle; |
| 708 | base::ProcessHandle renderer_process_for_gpu; |
| 709 | GPUInfo gpu_info; |
| 710 | if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch, |
| 711 | &channel_handle, |
| 712 | &renderer_process_for_gpu, |
| 713 | &gpu_info)) || |
| 714 | channel_handle.name.empty() || |
| 715 | renderer_process_for_gpu == base::kNullProcessHandle) { |
| 716 | // Otherwise cancel the connection. |
| 717 | gpu_channel_ = NULL; |
| 718 | return NULL; |
| 719 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 720 | |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 721 | gpu_channel_->set_gpu_info(gpu_info); |
| 722 | content::GetContentClient()->SetGpuInfo(gpu_info); |
| 723 | |
| 724 | // Connect to the GPU process if a channel name was received. |
| 725 | gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); |
| 726 | |
[email protected] | f9a2b2fe | 2010-07-15 21:13:23 | [diff] [blame] | 727 | return GetGpuChannel(); |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 730 | GpuChannelHost* RenderThreadImpl::GetGpuChannel() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 731 | if (!gpu_channel_.get()) |
| 732 | return NULL; |
| 733 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 734 | if (gpu_channel_->state() != GpuChannelHost::kConnected) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 735 | return NULL; |
| 736 | |
| 737 | return gpu_channel_.get(); |
| 738 | } |
| 739 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 740 | void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 741 | EnsureWebKitInitialized(); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 742 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 743 | // point we already know that the browser has refreshed its list, so disable |
| 744 | // refresh temporarily to prevent each renderer process causing the list to be |
| 745 | // regenerated. |
| 746 | plugin_refresh_allowed_ = false; |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 747 | WebKit::resetPluginCache(reload_pages); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 748 | plugin_refresh_allowed_ = true; |
| 749 | } |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 750 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 751 | void RenderThreadImpl::OnNetworkStateChanged(bool online) { |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 752 | EnsureWebKitInitialized(); |
| 753 | WebNetworkStateNotifier::setOnLine(online); |
| 754 | } |
| 755 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 756 | scoped_refptr<base::MessageLoopProxy> |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame^] | 757 | RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 758 | DCHECK(message_loop() == MessageLoop::current()); |
| 759 | if (!file_thread_.get()) { |
| 760 | file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 761 | file_thread_->Start(); |
| 762 | } |
| 763 | return file_thread_->message_loop_proxy(); |
| 764 | } |