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