[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 1 | // Copyright (c) 2009 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 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5 | #include "chrome/renderer/render_thread.h" |
| 6 | |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame] | 7 | #include <v8.h> |
| 8 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | 75e126b93 | 2009-09-28 19:38:49 | [diff] [blame] | 10 | #include <map> |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 13 | #if defined(USE_SYSTEM_SQLITE) |
| 14 | #include <sqlite3.h> |
| 15 | #else |
| 16 | #include "third_party/sqlite/preprocessed/sqlite3.h" |
| 17 | #endif |
| 18 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 19 | #include "base/command_line.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 20 | #include "base/lazy_instance.h" |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 21 | #include "base/logging.h" |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 22 | #include "base/nullable_string16.h" |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 23 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | #include "base/shared_memory.h" |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 25 | #include "base/stats_table.h" |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 26 | #include "base/string_util.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 27 | #include "base/thread_local.h" |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 28 | #include "chrome/common/appcache/appcache_dispatcher.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 29 | #include "chrome/common/chrome_switches.h" |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 30 | #include "chrome/common/db_message_filter.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 31 | #include "chrome/common/render_messages.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 32 | #include "chrome/common/renderer_preferences.h" |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 33 | #include "chrome/common/url_constants.h" |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 34 | #include "chrome/plugin/npobject_util.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 35 | // TODO(port) |
| 36 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | #include "chrome/plugin/plugin_channel.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 38 | #else |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 39 | #include "base/scoped_handle.h" |
| 40 | #include "chrome/plugin/plugin_channel_base.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 41 | #endif |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 42 | #include "chrome/renderer/devtools_agent_filter.h" |
[email protected] | ad1f9bd | 2009-07-30 20:23:15 | [diff] [blame] | 43 | #include "chrome/renderer/extension_groups.h" |
[email protected] | a40caa97 | 2009-04-08 18:35:34 | [diff] [blame] | 44 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 45 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | be77f0a | 2009-08-25 08:31:17 | [diff] [blame] | 46 | #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 47 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 3c8e370 | 2009-05-01 16:27:42 | [diff] [blame] | 48 | #include "chrome/renderer/external_extension.h" |
[email protected] | 0bc4655 | 2009-04-07 21:56:42 | [diff] [blame] | 49 | #include "chrome/renderer/loadtimes_extension_bindings.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | #include "chrome/renderer/net/render_dns_master.h" |
| 51 | #include "chrome/renderer/render_process.h" |
| 52 | #include "chrome/renderer/render_view.h" |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 53 | #include "chrome/renderer/renderer_webkitclient_impl.h" |
[email protected] | e2b2d4a | 2009-10-24 03:32:59 | [diff] [blame] | 54 | #include "chrome/renderer/renderer_web_database_observer.h" |
[email protected] | 327344ef | 2009-10-29 06:18:11 | [diff] [blame] | 55 | #include "chrome/renderer/socket_stream_dispatcher.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 56 | #if defined(SPELLCHECKER_IN_RENDERER) |
| 57 | #include "chrome/renderer/spellchecker/spellcheck.h" |
| 58 | #endif |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 59 | #include "chrome/renderer/user_script_slave.h" |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 60 | #include "ipc/ipc_message.h" |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 61 | #include "third_party/tcmalloc/tcmalloc/src/google/malloc_extension.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 62 | #include "webkit/api/public/WebCache.h" |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 63 | #include "webkit/api/public/WebColor.h" |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 64 | #include "webkit/api/public/WebCrossOriginPreflightResultCache.h" |
[email protected] | e2b2d4a | 2009-10-24 03:32:59 | [diff] [blame] | 65 | #include "webkit/api/public/WebDatabase.h" |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 66 | #include "webkit/api/public/WebFontCache.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 67 | #include "webkit/api/public/WebKit.h" |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 68 | #include "webkit/api/public/WebRuntimeFeatures.h" |
[email protected] | 09cdd4f2 | 2009-10-16 04:01:46 | [diff] [blame] | 69 | #include "webkit/api/public/WebScriptController.h" |
[email protected] | 204758c | 2009-10-22 03:56:30 | [diff] [blame] | 70 | #include "webkit/api/public/WebSecurityPolicy.h" |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 71 | #include "webkit/api/public/WebStorageEventDispatcher.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 72 | #include "webkit/api/public/WebString.h" |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 73 | #include "webkit/extensions/v8/benchmarking_extension.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 74 | #include "webkit/extensions/v8/gears_extension.h" |
| 75 | #include "webkit/extensions/v8/interval_extension.h" |
| 76 | #include "webkit/extensions/v8/playback_extension.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 77 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 78 | #if defined(OS_WIN) |
| 79 | #include <windows.h> |
| 80 | #include <objbase.h> |
| 81 | #endif |
| 82 | |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 83 | using WebKit::WebCache; |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 84 | using WebKit::WebCrossOriginPreflightResultCache; |
| 85 | using WebKit::WebFontCache; |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 86 | using WebKit::WebRuntimeFeatures; |
[email protected] | 204758c | 2009-10-22 03:56:30 | [diff] [blame] | 87 | using WebKit::WebSecurityPolicy; |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 88 | using WebKit::WebScriptController; |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 89 | using WebKit::WebString; |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 90 | using WebKit::WebStorageEventDispatcher; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 91 | using WebKit::WebView; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 93 | namespace { |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 94 | static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 95 | static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; |
| 96 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 97 | static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( |
| 98 | base::LINKER_INITIALIZED); |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 99 | |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 100 | #if defined(OS_POSIX) |
| 101 | class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { |
| 102 | void OnChannelError() { |
| 103 | // On POSIX, at least, one can install an unload handler which loops |
| 104 | // forever and leave behind a renderer process which eats 100% CPU forever. |
| 105 | // |
| 106 | // This is because the terminate signals (ViewMsg_ShouldClose and the error |
| 107 | // from the IPC channel) are routed to the main message loop but never |
| 108 | // processed (because that message loop is stuck in V8). |
| 109 | // |
| 110 | // One could make the browser SIGKILL the renderers, but that leaves open a |
| 111 | // large window where a browser failure (or a user, manually terminating |
| 112 | // the browser because "it's stuck") will leave behind a process eating all |
| 113 | // the CPU. |
| 114 | // |
| 115 | // So, we install a filter on the channel so that we can process this event |
| 116 | // here and kill the process. |
| 117 | _exit(0); |
| 118 | } |
| 119 | }; |
| 120 | #endif |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 121 | } // namespace |
| 122 | |
| 123 | // When we run plugins in process, we actually run them on the render thread, |
| 124 | // which means that we need to make the render thread pump UI events. |
| 125 | RenderThread::RenderThread() { |
| 126 | Init(); |
| 127 | } |
| 128 | |
| 129 | RenderThread::RenderThread(const std::string& channel_name) |
| 130 | : ChildThread(channel_name) { |
| 131 | Init(); |
| 132 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 133 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | void RenderThread::Init() { |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 135 | lazy_tls.Pointer()->Set(this); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 136 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 137 | // If you are running plugins in this thread you need COM active but in |
| 138 | // the normal case you don't. |
| 139 | if (RenderProcess::InProcessPlugins()) |
| 140 | CoInitialize(0); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 141 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 143 | plugin_refresh_allowed_ = true; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 144 | cache_stats_task_pending_ = false; |
| 145 | widget_count_ = 0; |
| 146 | hidden_widget_count_ = 0; |
| 147 | idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; |
| 148 | task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 149 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 150 | visited_link_slave_.reset(new VisitedLinkSlave()); |
| 151 | user_script_slave_.reset(new UserScriptSlave()); |
| 152 | dns_master_.reset(new RenderDnsMaster()); |
| 153 | histogram_snapshots_.reset(new RendererHistogramSnapshots()); |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 154 | appcache_dispatcher_.reset(new AppCacheDispatcher(this)); |
[email protected] | 327344ef | 2009-10-29 06:18:11 | [diff] [blame] | 155 | socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 156 | devtools_agent_filter_ = new DevToolsAgentFilter(); |
| 157 | AddFilter(devtools_agent_filter_.get()); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 158 | db_message_filter_ = new DBMessageFilter(); |
| 159 | AddFilter(db_message_filter_.get()); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 160 | #if defined(SPELLCHECKER_IN_RENDERER) |
| 161 | spellchecker_.reset(new SpellCheck()); |
| 162 | #endif |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 163 | |
| 164 | #if defined(OS_POSIX) |
| 165 | suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter; |
| 166 | AddFilter(suicide_on_channel_error_filter_.get()); |
| 167 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 170 | RenderThread::~RenderThread() { |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 171 | // Shutdown in reverse of the initialization order. |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 172 | RemoveFilter(devtools_agent_filter_.get()); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 173 | RemoveFilter(db_message_filter_.get()); |
| 174 | db_message_filter_ = NULL; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 175 | if (webkit_client_.get()) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 176 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 177 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 178 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 179 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 180 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 181 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 182 | // Clean up plugin channels before this thread goes away. |
| 183 | PluginChannelBase::CleanupChannels(); |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 184 | // Don't call COM if the renderer is in the sandbox. |
| 185 | if (RenderProcess::InProcessPlugins()) |
| 186 | CoUninitialize(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 187 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 188 | } |
| 189 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 190 | RenderThread* RenderThread::current() { |
| 191 | return lazy_tls.Pointer()->Get(); |
| 192 | } |
| 193 | |
| 194 | void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 195 | channel()->AddFilter(filter); |
| 196 | } |
| 197 | |
| 198 | void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 199 | channel()->RemoveFilter(filter); |
| 200 | } |
| 201 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 202 | void RenderThread::WidgetHidden() { |
| 203 | DCHECK(hidden_widget_count_ < widget_count_); |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame^] | 204 | hidden_widget_count_++; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 205 | if (widget_count_ && hidden_widget_count_ == widget_count_) { |
| 206 | // Reset the delay. |
| 207 | idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; |
| 208 | |
| 209 | // Schedule the IdleHandler to wakeup in a bit. |
| 210 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 211 | task_factory_->NewRunnableMethod(&RenderThread::IdleHandler), |
| 212 | static_cast<int64>(floor(idle_notification_delay_in_s_)) * 1000); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void RenderThread::WidgetRestored() { |
| 217 | DCHECK(hidden_widget_count_ > 0); |
| 218 | hidden_widget_count_--; |
| 219 | |
| 220 | // Note: we may have a timer pending to call the IdleHandler (see the |
| 221 | // WidgetHidden() code). But we don't bother to cancel it as it is |
| 222 | // benign and won't do anything if the tab is un-hidden when it is |
| 223 | // called. |
| 224 | } |
| 225 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 226 | void RenderThread::Resolve(const char* name, size_t length) { |
| 227 | return dns_master_->Resolve(name, length); |
| 228 | } |
| 229 | |
| 230 | void RenderThread::SendHistograms(int sequence_number) { |
| 231 | return histogram_snapshots_->SendHistograms(sequence_number); |
| 232 | } |
| 233 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 234 | void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) { |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 235 | DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 236 | visited_link_slave_->Init(table); |
| 237 | } |
| 238 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 239 | void RenderThread::OnAddVisitedLinks( |
| 240 | const VisitedLinkSlave::Fingerprints& fingerprints) { |
| 241 | for (size_t i = 0; i < fingerprints.size(); ++i) |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 242 | WebView::updateVisitedLinkState(fingerprints[i]); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void RenderThread::OnResetVisitedLinks() { |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 246 | WebView::resetVisitedLinkState(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 247 | } |
| 248 | |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 249 | void RenderThread::OnUpdateUserScripts( |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 250 | base::SharedMemoryHandle scripts) { |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 251 | DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 252 | user_script_slave_->UpdateScripts(scripts); |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 255 | void RenderThread::OnSetExtensionFunctionNames( |
| 256 | const std::vector<std::string>& names) { |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 257 | ExtensionProcessBindings::SetFunctionNames(names); |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 258 | } |
| 259 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 260 | void RenderThread::OnPageActionsUpdated( |
| 261 | const std::string& extension_id, |
| 262 | const std::vector<std::string>& page_actions) { |
| 263 | ExtensionProcessBindings::SetPageActions(extension_id, page_actions); |
| 264 | } |
| 265 | |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 266 | void RenderThread::OnExtensionSetAPIPermissions( |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 267 | const std::string& extension_id, |
| 268 | const std::vector<std::string>& permissions) { |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 269 | ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions); |
| 270 | } |
| 271 | |
| 272 | void RenderThread::OnExtensionSetHostPermissions( |
| 273 | const GURL& extension_url, const std::vector<URLPattern>& permissions) { |
| 274 | ExtensionProcessBindings::SetHostPermissions(extension_url, permissions); |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 275 | } |
| 276 | |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 277 | void RenderThread::OnDOMStorageEvent( |
| 278 | const ViewMsg_DOMStorageEvent_Params& params) { |
| 279 | if (!dom_storage_event_dispatcher_.get()) |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 280 | dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 281 | dom_storage_event_dispatcher_->dispatchStorageEvent(params.key_, |
[email protected] | ee2be5b3 | 2009-11-05 09:13:12 | [diff] [blame] | 282 | params.old_value_, params.new_value_, params.origin_, params.url_, |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 283 | params.storage_type_ == DOM_STORAGE_LOCAL); |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 75e126b93 | 2009-09-28 19:38:49 | [diff] [blame] | 286 | void RenderThread::OnExtensionSetL10nMessages( |
| 287 | const std::string& extension_id, |
| 288 | const std::map<std::string, std::string>& l10n_messages) { |
| 289 | ExtensionProcessBindings::SetL10nMessages(extension_id, l10n_messages); |
| 290 | } |
| 291 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 292 | void RenderThread::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 293 | // App cache messages are handled by a delegate. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 294 | if (appcache_dispatcher_->OnMessageReceived(msg)) |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 295 | return; |
[email protected] | 327344ef | 2009-10-29 06:18:11 | [diff] [blame] | 296 | if (socket_stream_dispatcher_->OnMessageReceived(msg)) |
| 297 | return; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 298 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 299 | IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) |
| 300 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 301 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks) |
| 302 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 303 | IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 304 | IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 305 | // TODO(port): removed from render_messages_internal.h; |
| 306 | // is there a new non-windows message I should add here? |
| 307 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
| 308 | IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 309 | IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms, |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 310 | OnGetRendererHistograms) |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 311 | #if defined(USE_TCMALLOC) |
| 312 | IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, |
| 313 | OnGetRendererTcmalloc) |
| 314 | #endif |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame] | 315 | IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 316 | IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, |
| 317 | OnGetCacheResourceStats) |
[email protected] | 2f2243e | 2009-05-26 02:27:02 | [diff] [blame] | 318 | IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 319 | OnUpdateUserScripts) |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 320 | // TODO(rafaelw): create an ExtensionDispatcher that handles extension |
| 321 | // messages seperates their handling from the RenderThread. |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 322 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 323 | OnExtensionMessageInvoke) |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 324 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames, |
| 325 | OnSetExtensionFunctionNames) |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 326 | IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 327 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, |
| 328 | OnPurgePluginListCache) |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 329 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions, |
| 330 | OnPageActionsUpdated) |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 331 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions, |
| 332 | OnExtensionSetAPIPermissions) |
| 333 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions, |
| 334 | OnExtensionSetHostPermissions) |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 335 | IPC_MESSAGE_HANDLER(ViewMsg_DOMStorageEvent, |
| 336 | OnDOMStorageEvent) |
[email protected] | 75e126b93 | 2009-09-28 19:38:49 | [diff] [blame] | 337 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetL10nMessages, |
| 338 | OnExtensionSetL10nMessages) |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 339 | #if defined(IPC_MESSAGE_LOG_ENABLED) |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 340 | IPC_MESSAGE_HANDLER(ViewMsg_SetIPCLoggingEnabled, |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 341 | OnSetIPCLoggingEnabled) |
| 342 | #endif |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 343 | #if defined(SPELLCHECKER_IN_RENDERER) |
| 344 | IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_Init, |
| 345 | OnInitSpellChecker) |
| 346 | IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_WordAdded, |
| 347 | OnSpellCheckWordAdded) |
| 348 | IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_EnableAutoSpellCorrect, |
| 349 | OnSpellCheckEnableAutoSpellCorrect) |
| 350 | #endif |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 351 | IPC_END_MESSAGE_MAP() |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void RenderThread::OnSetNextPageID(int32 next_page_id) { |
| 355 | // This should only be called at process initialization time, so we shouldn't |
| 356 | // have to worry about thread-safety. |
| 357 | RenderView::SetNextPageID(next_page_id); |
| 358 | } |
| 359 | |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 360 | // Called when to register CSS Color name->system color mappings. |
| 361 | // We update the colors one by one and then tell WebKit to refresh all render |
| 362 | // views. |
| 363 | void RenderThread::OnSetCSSColors( |
| 364 | const std::vector<CSSColors::CSSColorMapping>& colors) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 365 | EnsureWebKitInitialized(); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 366 | size_t num_colors = colors.size(); |
| 367 | scoped_array<WebKit::WebColorName> color_names( |
| 368 | new WebKit::WebColorName[num_colors]); |
| 369 | scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); |
| 370 | size_t i = 0; |
| 371 | for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = |
| 372 | colors.begin(); |
| 373 | it != colors.end(); |
| 374 | ++it, ++i) { |
| 375 | color_names[i] = it->first; |
| 376 | web_colors[i] = it->second; |
| 377 | } |
| 378 | WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); |
| 379 | } |
| 380 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 381 | void RenderThread::OnCreateNewView(gfx::NativeViewId parent_hwnd, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 382 | const RendererPreferences& renderer_prefs, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 383 | const WebPreferences& webkit_prefs, |
| 384 | int32 view_id) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 385 | EnsureWebKitInitialized(); |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 386 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 387 | RenderView::Create( |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 388 | this, parent_hwnd, MSG_ROUTING_NONE, renderer_prefs, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 389 | webkit_prefs, new SharedRenderViewCounter(0), view_id); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 390 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 391 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 392 | void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity, |
| 393 | size_t max_dead_capacity, |
| 394 | size_t capacity) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 395 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 396 | WebCache::setCapacities( |
| 397 | min_dead_capacity, max_dead_capacity, capacity); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void RenderThread::OnGetCacheResourceStats() { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 401 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 402 | WebCache::ResourceTypeStats stats; |
| 403 | WebCache::getResourceTypeStats(&stats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 404 | Send(new ViewHostMsg_ResourceTypeStats(stats)); |
| 405 | } |
| 406 | |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 407 | void RenderThread::OnGetRendererHistograms(int sequence_number) { |
| 408 | SendHistograms(sequence_number); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 411 | #if defined(USE_TCMALLOC) |
| 412 | void RenderThread::OnGetRendererTcmalloc() { |
| 413 | std::string result; |
| 414 | char buffer[1024 * 32]; |
[email protected] | a4dc33f | 2009-10-20 15:09:55 | [diff] [blame] | 415 | base::ProcessId pid = base::GetCurrentProcId(); |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 416 | MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); |
| 417 | result.append(buffer); |
| 418 | Send(new ViewHostMsg_RendererTcmalloc(pid, result)); |
| 419 | } |
| 420 | #endif |
| 421 | |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame] | 422 | void RenderThread::OnGetV8HeapStats() { |
| 423 | v8::HeapStatistics heap_stats; |
| 424 | v8::V8::GetHeapStatistics(&heap_stats); |
| 425 | Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(), |
| 426 | heap_stats.used_heap_size())); |
| 427 | } |
| 428 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 429 | void RenderThread::InformHostOfCacheStats() { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 430 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 431 | WebCache::UsageStats stats; |
| 432 | WebCache::getUsageStats(&stats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 433 | Send(new ViewHostMsg_UpdatedCacheStats(stats)); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 434 | cache_stats_task_pending_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void RenderThread::InformHostOfCacheStatsLater() { |
| 438 | // Rate limit informing the host of our cache stats. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 439 | if (cache_stats_task_pending_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | return; |
| 441 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 442 | cache_stats_task_pending_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 443 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 444 | task_factory_->NewRunnableMethod( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 445 | &RenderThread::InformHostOfCacheStats), |
| 446 | kCacheStatsDelayMS); |
| 447 | } |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 448 | |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 449 | void RenderThread::CloseIdleConnections() { |
| 450 | Send(new ViewHostMsg_CloseIdleConnections()); |
| 451 | } |
| 452 | |
| 453 | void RenderThread::SetCacheMode(bool enabled) { |
| 454 | Send(new ViewHostMsg_SetCacheMode(enabled)); |
| 455 | } |
| 456 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 457 | #if defined(SPELLCHECKER_IN_RENDERER) |
| 458 | void RenderThread::RequestSpellCheckDictionary() { |
| 459 | Send(new ViewHostMsg_SpellChecker_RequestDictionary); |
| 460 | } |
| 461 | #endif |
| 462 | |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 463 | static void* CreateHistogram( |
| 464 | const char *name, int min, int max, size_t buckets) { |
[email protected] | 56a27b2 | 2009-05-21 00:44:37 | [diff] [blame] | 465 | Histogram* histogram = new Histogram(name, min, max, buckets); |
| 466 | if (histogram) { |
| 467 | histogram->SetFlags(kUmaTargetedHistogramFlag); |
| 468 | } |
| 469 | return histogram; |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static void AddHistogramSample(void* hist, int sample) { |
| 473 | Histogram* histogram = static_cast<Histogram *>(hist); |
| 474 | histogram->Add(sample); |
| 475 | } |
| 476 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 477 | void RenderThread::EnsureWebKitInitialized() { |
| 478 | if (webkit_client_.get()) |
| 479 | return; |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 480 | |
| 481 | v8::V8::SetCounterFunction(StatsTable::FindLocation); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 482 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 483 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 484 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 485 | webkit_client_.reset(new RendererWebKitClientImpl); |
| 486 | WebKit::initialize(webkit_client_.get()); |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 487 | |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 488 | WebScriptController::enableV8SingleThreadMode(); |
[email protected] | 4ea00e8 | 2009-07-30 22:59:34 | [diff] [blame] | 489 | |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 490 | // chrome: pages should not be accessible by normal content, and should |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 491 | // also be unable to script anything but themselves (to help limit the damage |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 492 | // that a corrupt chrome: page could cause). |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 493 | WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme)); |
[email protected] | 204758c | 2009-10-22 03:56:30 | [diff] [blame] | 494 | WebSecurityPolicy::registerURLSchemeAsLocal(chrome_ui_scheme); |
| 495 | WebSecurityPolicy::registerURLSchemeAsNoAccess(chrome_ui_scheme); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 496 | |
[email protected] | d53d849 | 2009-07-14 01:51:32 | [diff] [blame] | 497 | // print: pages should be not accessible by normal context. |
| 498 | WebString print_ui_scheme(ASCIIToUTF16(chrome::kPrintScheme)); |
[email protected] | 204758c | 2009-10-22 03:56:30 | [diff] [blame] | 499 | WebSecurityPolicy::registerURLSchemeAsLocal(print_ui_scheme); |
| 500 | WebSecurityPolicy::registerURLSchemeAsNoAccess(print_ui_scheme); |
[email protected] | d53d849 | 2009-07-14 01:51:32 | [diff] [blame] | 501 | |
[email protected] | 6cf8b1a2 | 2009-05-26 23:36:00 | [diff] [blame] | 502 | #if defined(OS_WIN) |
| 503 | // We don't yet support Gears on non-Windows, so don't tell pages that we do. |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 504 | WebScriptController::registerExtension(extensions_v8::GearsExtension::Get()); |
[email protected] | 6cf8b1a2 | 2009-05-26 23:36:00 | [diff] [blame] | 505 | #endif |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 506 | WebScriptController::registerExtension( |
| 507 | extensions_v8::IntervalExtension::Get()); |
| 508 | WebScriptController::registerExtension( |
| 509 | extensions_v8::LoadTimesExtension::Get()); |
| 510 | WebScriptController::registerExtension( |
| 511 | extensions_v8::ExternalExtension::Get()); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 512 | |
[email protected] | ad1f9bd | 2009-07-30 20:23:15 | [diff] [blame] | 513 | const WebKit::WebString kExtensionScheme = |
| 514 | WebKit::WebString::fromUTF8(chrome::kExtensionScheme); |
| 515 | |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 516 | WebScriptController::registerExtension( |
| 517 | ExtensionProcessBindings::Get(), kExtensionScheme); |
[email protected] | ad1f9bd | 2009-07-30 20:23:15 | [diff] [blame] | 518 | |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 519 | WebScriptController::registerExtension( |
| 520 | BaseJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 521 | WebScriptController::registerExtension( |
| 522 | BaseJsV8Extension::Get(), kExtensionScheme); |
| 523 | WebScriptController::registerExtension( |
| 524 | JsonSchemaJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 525 | WebScriptController::registerExtension(JsonSchemaJsV8Extension::Get(), |
| 526 | kExtensionScheme); |
| 527 | WebScriptController::registerExtension( |
| 528 | EventBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 529 | WebScriptController::registerExtension(EventBindings::Get(), |
| 530 | kExtensionScheme); |
| 531 | WebScriptController::registerExtension( |
| 532 | RendererExtensionBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 533 | WebScriptController::registerExtension( |
| 534 | RendererExtensionBindings::Get(), kExtensionScheme); |
| 535 | WebScriptController::registerExtension( |
| 536 | ExtensionApiTestV8Extension::Get(), kExtensionScheme); |
| 537 | WebScriptController::registerExtension( |
| 538 | ExtensionApiTestV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 539 | |
[email protected] | e2b2d4a | 2009-10-24 03:32:59 | [diff] [blame] | 540 | renderer_web_database_observer_.reset(new RendererWebDatabaseObserver(this)); |
| 541 | WebKit::WebDatabase::setObserver(renderer_web_database_observer_.get()); |
| 542 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 543 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 544 | |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 545 | if (command_line.HasSwitch(switches::kEnableBenchmarking)) { |
| 546 | WebScriptController::registerExtension( |
| 547 | extensions_v8::BenchmarkingExtension::Get()); |
| 548 | } |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 549 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 550 | if (command_line.HasSwitch(switches::kPlaybackMode) || |
[email protected] | ca12c84 | 2009-04-14 22:20:18 | [diff] [blame] | 551 | command_line.HasSwitch(switches::kRecordMode) || |
| 552 | command_line.HasSwitch(switches::kNoJsRandomness)) { |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 553 | WebScriptController::registerExtension( |
| 554 | extensions_v8::PlaybackExtension::Get()); |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 555 | } |
[email protected] | 2cb8233 | 2009-03-18 17:24:55 | [diff] [blame] | 556 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 557 | WebRuntimeFeatures::enableMediaPlayer( |
| 558 | RenderProcess::current()->initialized_media_library()); |
[email protected] | 3553c6cc | 2009-10-20 05:51:55 | [diff] [blame] | 559 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 560 | WebRuntimeFeatures::enableSockets( |
[email protected] | cdf2478 | 2009-11-05 09:32:47 | [diff] [blame] | 561 | !command_line.HasSwitch(switches::kDisableWebSockets)); |
[email protected] | 0afb993 | 2009-10-24 00:37:58 | [diff] [blame] | 562 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 563 | WebRuntimeFeatures::enableDatabase( |
| 564 | command_line.HasSwitch(switches::kEnableDatabases)); |
[email protected] | bfa69d49 | 2009-10-31 03:27:19 | [diff] [blame] | 565 | |
[email protected] | 13bc0d82 | 2009-11-07 01:17:14 | [diff] [blame] | 566 | WebRuntimeFeatures::enableApplicationCache( |
| 567 | command_line.HasSwitch(switches::kEnableApplicationCache)); |
| 568 | |
[email protected] | bfa69d49 | 2009-10-31 03:27:19 | [diff] [blame] | 569 | #if defined(OS_WIN) |
| 570 | // We don't yet support notifications on non-Windows, so hide it from pages. |
| 571 | WebRuntimeFeatures::enableNotifications( |
| 572 | command_line.HasSwitch(switches::kEnableDesktopNotifications)); |
| 573 | #endif |
[email protected] | 7ee66e6 | 2009-11-05 09:16:30 | [diff] [blame] | 574 | |
| 575 | WebRuntimeFeatures::enableLocalStorage( |
[email protected] | 5cf1836 | 2009-11-06 18:45:01 | [diff] [blame] | 576 | !command_line.HasSwitch(switches::kDisableLocalStorage)); |
[email protected] | 7ee66e6 | 2009-11-05 09:16:30 | [diff] [blame] | 577 | WebRuntimeFeatures::enableSessionStorage( |
| 578 | command_line.HasSwitch(switches::kEnableSessionStorage)); |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 579 | } |
[email protected] | 75e5a87 | 2009-04-02 23:56:11 | [diff] [blame] | 580 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 581 | void RenderThread::IdleHandler() { |
| 582 | // It is possible that the timer was set while the widgets were idle, |
| 583 | // but that they are no longer idle. If so, just return. |
| 584 | if (!widget_count_ || hidden_widget_count_ < widget_count_) |
| 585 | return; |
| 586 | |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 587 | #if defined(OS_WIN) |
[email protected] | e94afbb9 | 2009-10-01 00:25:41 | [diff] [blame] | 588 | MallocExtension::instance()->ReleaseFreeMemory(); |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 589 | #endif |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 590 | |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 591 | LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this; |
| 592 | v8::V8::IdleNotification(); |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 593 | |
| 594 | // Schedule next invocation. |
| 595 | // Dampen the delay using the algorithm: |
| 596 | // delay = delay + 1 / (delay + 2) |
| 597 | // Using floor(delay) has a dampening effect such as: |
| 598 | // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 599 | // Note that idle_notification_delay_in_s_ would be reset to |
| 600 | // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden. |
| 601 | idle_notification_delay_in_s_ += |
| 602 | 1.0 / (idle_notification_delay_in_s_ + 2.0); |
| 603 | |
| 604 | // Schedule the next timer. |
| 605 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 606 | task_factory_->NewRunnableMethod(&RenderThread::IdleHandler), |
| 607 | static_cast<int64>(floor(idle_notification_delay_in_s_)) * 1000); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 608 | } |
| 609 | |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 610 | void RenderThread::OnExtensionMessageInvoke(const std::string& function_name, |
| 611 | const ListValue& args) { |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 612 | RendererExtensionBindings::Invoke(function_name, args, NULL); |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 613 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 614 | |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 615 | void RenderThread::OnPurgeMemory() { |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 616 | #if defined(SPELLCHECKER_IN_RENDERER) |
| 617 | spellchecker_.reset(new SpellCheck()); |
| 618 | #endif |
| 619 | |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 620 | EnsureWebKitInitialized(); |
| 621 | |
| 622 | // Clear the object cache (as much as possible; some live objects cannot be |
| 623 | // freed). |
| 624 | WebCache::clear(); |
| 625 | |
| 626 | // Clear the font/glyph cache. |
| 627 | WebFontCache::clear(); |
| 628 | |
| 629 | // Clear the Cross-Origin Preflight cache. |
| 630 | WebCrossOriginPreflightResultCache::clear(); |
| 631 | |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 632 | // Release all freeable memory from the SQLite process-global page cache (a |
| 633 | // low-level object which backs the Connection-specific page caches). |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame^] | 634 | while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) { |
| 635 | } |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 636 | |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 637 | // Repeatedly call the V8 idle notification until it returns true ("nothing |
| 638 | // more to free"). Note that it makes more sense to do this than to implement |
| 639 | // a new "delete everything" pass because object references make it difficult |
| 640 | // to free everything possible in just one pass. |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame^] | 641 | while (!v8::V8::IdleNotification()) { |
| 642 | } |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 643 | |
| 644 | #if defined(OS_WIN) |
| 645 | // Tell tcmalloc to release any free pages it's still holding. |
| 646 | MallocExtension::instance()->ReleaseFreeMemory(); |
| 647 | #endif |
| 648 | } |
| 649 | |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 650 | void RenderThread::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 651 | EnsureWebKitInitialized(); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 652 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 653 | // point we already know that the browser has refreshed its list, so disable |
| 654 | // refresh temporarily to prevent each renderer process causing the list to be |
| 655 | // regenerated. |
| 656 | plugin_refresh_allowed_ = false; |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 657 | WebKit::resetPluginCache(reload_pages); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 658 | plugin_refresh_allowed_ = true; |
| 659 | } |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 660 | |
| 661 | #if defined(SPELLCHECKER_IN_RENDERER) |
| 662 | void RenderThread::OnInitSpellChecker( |
| 663 | const base::FileDescriptor& bdict_fd, |
| 664 | const std::vector<std::string>& custom_words, |
| 665 | const std::string& language, |
| 666 | bool auto_spell_correct) { |
| 667 | spellchecker_->Init(bdict_fd, custom_words, language); |
| 668 | spellchecker_->EnableAutoSpellCorrect(auto_spell_correct); |
| 669 | } |
| 670 | |
| 671 | void RenderThread::OnSpellCheckWordAdded(const std::string& word) { |
| 672 | spellchecker_->WordAdded(word); |
| 673 | } |
| 674 | |
| 675 | void RenderThread::OnSpellCheckEnableAutoSpellCorrect(bool enable) { |
| 676 | spellchecker_->EnableAutoSpellCorrect(enable); |
| 677 | } |
| 678 | #endif |