[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] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <vector> |
| 9 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 11 | #include "base/lazy_instance.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/shared_memory.h" |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 13 | #include "base/stats_table.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 14 | #include "base/thread_local.h" |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 15 | #include "chrome/common/app_cache/app_cache_context_impl.h" |
| 16 | #include "chrome/common/app_cache/app_cache_dispatcher.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 17 | #include "chrome/common/chrome_switches.h" |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 18 | #include "chrome/common/db_message_filter.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 19 | #include "chrome/common/render_messages.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 20 | #include "chrome/common/renderer_preferences.h" |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 21 | #include "chrome/common/url_constants.h" |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 22 | #include "chrome/plugin/npobject_util.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 23 | // TODO(port) |
| 24 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | #include "chrome/plugin/plugin_channel.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 26 | #else |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 27 | #include "base/scoped_handle.h" |
| 28 | #include "chrome/plugin/plugin_channel_base.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 29 | #endif |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 30 | #include "chrome/renderer/devtools_agent_filter.h" |
[email protected] | ad1f9bd | 2009-07-30 20:23:15 | [diff] [blame^] | 31 | #include "chrome/renderer/extension_groups.h" |
[email protected] | a40caa97 | 2009-04-08 18:35:34 | [diff] [blame] | 32 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 33 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 34 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 3c8e370 | 2009-05-01 16:27:42 | [diff] [blame] | 35 | #include "chrome/renderer/external_extension.h" |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 36 | #include "chrome/renderer/js_only_v8_extensions.h" |
[email protected] | 0bc4655 | 2009-04-07 21:56:42 | [diff] [blame] | 37 | #include "chrome/renderer/loadtimes_extension_bindings.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | #include "chrome/renderer/net/render_dns_master.h" |
| 39 | #include "chrome/renderer/render_process.h" |
| 40 | #include "chrome/renderer/render_view.h" |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 41 | #include "chrome/renderer/renderer_webkitclient_impl.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 42 | #include "chrome/renderer/user_script_slave.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 43 | #include "webkit/api/public/WebCache.h" |
| 44 | #include "webkit/api/public/WebKit.h" |
| 45 | #include "webkit/api/public/WebString.h" |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 46 | #include "webkit/extensions/v8/benchmarking_extension.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 47 | #include "webkit/extensions/v8/gears_extension.h" |
| 48 | #include "webkit/extensions/v8/interval_extension.h" |
| 49 | #include "webkit/extensions/v8/playback_extension.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 50 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 51 | #if defined(OS_WIN) |
| 52 | #include <windows.h> |
| 53 | #include <objbase.h> |
| 54 | #endif |
| 55 | |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 56 | using WebKit::WebCache; |
| 57 | using WebKit::WebString; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 59 | namespace { |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 60 | static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 61 | static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( |
| 62 | base::LINKER_INITIALIZED); |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 63 | static WebAppCacheContext* CreateAppCacheContextForRenderer() { |
| 64 | return new AppCacheContextImpl(RenderThread::current()); |
| 65 | } |
| 66 | |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 67 | #if defined(OS_POSIX) |
| 68 | class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { |
| 69 | void OnChannelError() { |
| 70 | // On POSIX, at least, one can install an unload handler which loops |
| 71 | // forever and leave behind a renderer process which eats 100% CPU forever. |
| 72 | // |
| 73 | // This is because the terminate signals (ViewMsg_ShouldClose and the error |
| 74 | // from the IPC channel) are routed to the main message loop but never |
| 75 | // processed (because that message loop is stuck in V8). |
| 76 | // |
| 77 | // One could make the browser SIGKILL the renderers, but that leaves open a |
| 78 | // large window where a browser failure (or a user, manually terminating |
| 79 | // the browser because "it's stuck") will leave behind a process eating all |
| 80 | // the CPU. |
| 81 | // |
| 82 | // So, we install a filter on the channel so that we can process this event |
| 83 | // here and kill the process. |
| 84 | _exit(0); |
| 85 | } |
| 86 | }; |
| 87 | #endif |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 88 | } // namespace |
| 89 | |
| 90 | // When we run plugins in process, we actually run them on the render thread, |
| 91 | // which means that we need to make the render thread pump UI events. |
| 92 | RenderThread::RenderThread() { |
| 93 | Init(); |
| 94 | } |
| 95 | |
| 96 | RenderThread::RenderThread(const std::string& channel_name) |
| 97 | : ChildThread(channel_name) { |
| 98 | Init(); |
| 99 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 100 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | void RenderThread::Init() { |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 102 | lazy_tls.Pointer()->Set(this); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 103 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 104 | // If you are running plugins in this thread you need COM active but in |
| 105 | // the normal case you don't. |
| 106 | if (RenderProcess::InProcessPlugins()) |
| 107 | CoInitialize(0); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 108 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 109 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 110 | plugin_refresh_allowed_ = true; |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 111 | cache_stats_factory_.reset( |
| 112 | new ScopedRunnableMethodFactory<RenderThread>(this)); |
| 113 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 114 | visited_link_slave_.reset(new VisitedLinkSlave()); |
| 115 | user_script_slave_.reset(new UserScriptSlave()); |
| 116 | dns_master_.reset(new RenderDnsMaster()); |
| 117 | histogram_snapshots_.reset(new RendererHistogramSnapshots()); |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 118 | app_cache_dispatcher_.reset(new AppCacheDispatcher()); |
| 119 | WebAppCacheContext::SetFactory(CreateAppCacheContextForRenderer); |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 120 | devtools_agent_filter_ = new DevToolsAgentFilter(); |
| 121 | AddFilter(devtools_agent_filter_.get()); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 122 | db_message_filter_ = new DBMessageFilter(); |
| 123 | AddFilter(db_message_filter_.get()); |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 124 | |
| 125 | #if defined(OS_POSIX) |
| 126 | suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter; |
| 127 | AddFilter(suicide_on_channel_error_filter_.get()); |
| 128 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 131 | RenderThread::~RenderThread() { |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 132 | // Shutdown in reverse of the initialization order. |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 133 | RemoveFilter(devtools_agent_filter_.get()); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 134 | RemoveFilter(db_message_filter_.get()); |
| 135 | db_message_filter_ = NULL; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 136 | WebAppCacheContext::SetFactory(NULL); |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 137 | if (webkit_client_.get()) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 138 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 139 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 140 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 141 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 142 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 143 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 144 | // Clean up plugin channels before this thread goes away. |
| 145 | PluginChannelBase::CleanupChannels(); |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 146 | // Don't call COM if the renderer is in the sandbox. |
| 147 | if (RenderProcess::InProcessPlugins()) |
| 148 | CoUninitialize(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 149 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 152 | RenderThread* RenderThread::current() { |
| 153 | return lazy_tls.Pointer()->Get(); |
| 154 | } |
| 155 | |
| 156 | void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 157 | channel()->AddFilter(filter); |
| 158 | } |
| 159 | |
| 160 | void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 161 | channel()->RemoveFilter(filter); |
| 162 | } |
| 163 | |
| 164 | void RenderThread::Resolve(const char* name, size_t length) { |
| 165 | return dns_master_->Resolve(name, length); |
| 166 | } |
| 167 | |
| 168 | void RenderThread::SendHistograms(int sequence_number) { |
| 169 | return histogram_snapshots_->SendHistograms(sequence_number); |
| 170 | } |
| 171 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 172 | void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) { |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 173 | DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | visited_link_slave_->Init(table); |
| 175 | } |
| 176 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 177 | void RenderThread::OnAddVisitedLinks( |
| 178 | const VisitedLinkSlave::Fingerprints& fingerprints) { |
| 179 | for (size_t i = 0; i < fingerprints.size(); ++i) |
| 180 | WebView::UpdateVisitedLinkState(fingerprints[i]); |
| 181 | } |
| 182 | |
| 183 | void RenderThread::OnResetVisitedLinks() { |
| 184 | WebView::ResetVisitedLinkState(); |
| 185 | } |
| 186 | |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 187 | void RenderThread::OnUpdateUserScripts( |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 188 | base::SharedMemoryHandle scripts) { |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 189 | DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 190 | user_script_slave_->UpdateScripts(scripts); |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 193 | void RenderThread::OnSetExtensionFunctionNames( |
| 194 | const std::vector<std::string>& names) { |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 195 | ExtensionProcessBindings::SetFunctionNames(names); |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 198 | void RenderThread::OnPageActionsUpdated( |
| 199 | const std::string& extension_id, |
| 200 | const std::vector<std::string>& page_actions) { |
| 201 | ExtensionProcessBindings::SetPageActions(extension_id, page_actions); |
| 202 | } |
| 203 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 204 | void RenderThread::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 205 | // App cache messages are handled by a delegate. |
| 206 | if (app_cache_dispatcher_->OnMessageReceived(msg)) |
| 207 | return; |
| 208 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 209 | IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) |
| 210 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 211 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks) |
| 212 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 213 | IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
| 214 | // TODO(port): removed from render_messages_internal.h; |
| 215 | // is there a new non-windows message I should add here? |
| 216 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
| 217 | IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 218 | IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms, |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 219 | OnGetRendererHistograms) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 220 | IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, |
| 221 | OnGetCacheResourceStats) |
[email protected] | 2f2243e | 2009-05-26 02:27:02 | [diff] [blame] | 222 | IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 223 | OnUpdateUserScripts) |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 224 | // TODO(rafaelw): create an ExtensionDispatcher that handles extension |
| 225 | // messages seperates their handling from the RenderThread. |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 226 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 227 | OnExtensionMessageInvoke) |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 228 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames, |
| 229 | OnSetExtensionFunctionNames) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 230 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, |
| 231 | OnPurgePluginListCache) |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 232 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions, |
| 233 | OnPageActionsUpdated) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 234 | IPC_END_MESSAGE_MAP() |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void RenderThread::OnSetNextPageID(int32 next_page_id) { |
| 238 | // This should only be called at process initialization time, so we shouldn't |
| 239 | // have to worry about thread-safety. |
| 240 | RenderView::SetNextPageID(next_page_id); |
| 241 | } |
| 242 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 243 | void RenderThread::OnCreateNewView(gfx::NativeViewId parent_hwnd, |
| 244 | ModalDialogEvent modal_dialog_event, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 245 | const RendererPreferences& renderer_prefs, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 246 | const WebPreferences& webkit_prefs, |
| 247 | int32 view_id) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 248 | EnsureWebKitInitialized(); |
| 249 | |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 250 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 251 | base::WaitableEvent* waitable_event = new base::WaitableEvent( |
| 252 | #if defined(OS_WIN) |
| 253 | modal_dialog_event.event); |
| 254 | #else |
| 255 | true, false); |
| 256 | #endif |
| 257 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | RenderView::Create( |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 259 | this, parent_hwnd, waitable_event, MSG_ROUTING_NONE, renderer_prefs, |
| 260 | webkit_prefs, new SharedRenderViewCounter(0), view_id); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 261 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 262 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 263 | void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity, |
| 264 | size_t max_dead_capacity, |
| 265 | size_t capacity) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 266 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 267 | WebCache::setCapacities( |
| 268 | min_dead_capacity, max_dead_capacity, capacity); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void RenderThread::OnGetCacheResourceStats() { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 272 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 273 | WebCache::ResourceTypeStats stats; |
| 274 | WebCache::getResourceTypeStats(&stats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 275 | Send(new ViewHostMsg_ResourceTypeStats(stats)); |
| 276 | } |
| 277 | |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 278 | void RenderThread::OnGetRendererHistograms(int sequence_number) { |
| 279 | SendHistograms(sequence_number); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 280 | } |
| 281 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | void RenderThread::InformHostOfCacheStats() { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 283 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 284 | WebCache::UsageStats stats; |
| 285 | WebCache::getUsageStats(&stats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | Send(new ViewHostMsg_UpdatedCacheStats(stats)); |
| 287 | } |
| 288 | |
| 289 | void RenderThread::InformHostOfCacheStatsLater() { |
| 290 | // Rate limit informing the host of our cache stats. |
| 291 | if (!cache_stats_factory_->empty()) |
| 292 | return; |
| 293 | |
| 294 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 295 | cache_stats_factory_->NewRunnableMethod( |
| 296 | &RenderThread::InformHostOfCacheStats), |
| 297 | kCacheStatsDelayMS); |
| 298 | } |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 299 | |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 300 | void RenderThread::CloseIdleConnections() { |
| 301 | Send(new ViewHostMsg_CloseIdleConnections()); |
| 302 | } |
| 303 | |
| 304 | void RenderThread::SetCacheMode(bool enabled) { |
| 305 | Send(new ViewHostMsg_SetCacheMode(enabled)); |
| 306 | } |
| 307 | |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 308 | static void* CreateHistogram( |
| 309 | const char *name, int min, int max, size_t buckets) { |
[email protected] | 56a27b2 | 2009-05-21 00:44:37 | [diff] [blame] | 310 | Histogram* histogram = new Histogram(name, min, max, buckets); |
| 311 | if (histogram) { |
| 312 | histogram->SetFlags(kUmaTargetedHistogramFlag); |
| 313 | } |
| 314 | return histogram; |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static void AddHistogramSample(void* hist, int sample) { |
| 318 | Histogram* histogram = static_cast<Histogram *>(hist); |
| 319 | histogram->Add(sample); |
| 320 | } |
| 321 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 322 | void RenderThread::EnsureWebKitInitialized() { |
| 323 | if (webkit_client_.get()) |
| 324 | return; |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 325 | |
| 326 | v8::V8::SetCounterFunction(StatsTable::FindLocation); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 327 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 328 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 329 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 330 | webkit_client_.reset(new RendererWebKitClientImpl); |
| 331 | WebKit::initialize(webkit_client_.get()); |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 332 | |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 333 | // chrome: pages should not be accessible by normal content, and should |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 334 | // also be unable to script anything but themselves (to help limit the damage |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 335 | // that a corrupt chrome: page could cause). |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 336 | WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme)); |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 337 | WebKit::registerURLSchemeAsLocal(chrome_ui_scheme); |
| 338 | WebKit::registerURLSchemeAsNoAccess(chrome_ui_scheme); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 339 | |
[email protected] | d53d849 | 2009-07-14 01:51:32 | [diff] [blame] | 340 | // print: pages should be not accessible by normal context. |
| 341 | WebString print_ui_scheme(ASCIIToUTF16(chrome::kPrintScheme)); |
| 342 | WebKit::registerURLSchemeAsLocal(print_ui_scheme); |
| 343 | WebKit::registerURLSchemeAsNoAccess(print_ui_scheme); |
| 344 | |
[email protected] | 6cf8b1a2 | 2009-05-26 23:36:00 | [diff] [blame] | 345 | #if defined(OS_WIN) |
| 346 | // We don't yet support Gears on non-Windows, so don't tell pages that we do. |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 347 | WebKit::registerExtension(extensions_v8::GearsExtension::Get()); |
[email protected] | 6cf8b1a2 | 2009-05-26 23:36:00 | [diff] [blame] | 348 | #endif |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 349 | WebKit::registerExtension(extensions_v8::IntervalExtension::Get()); |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 350 | WebKit::registerExtension(extensions_v8::LoadTimesExtension::Get()); |
[email protected] | 3c8e370 | 2009-05-01 16:27:42 | [diff] [blame] | 351 | WebKit::registerExtension(extensions_v8::ExternalExtension::Get()); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 352 | |
[email protected] | ad1f9bd | 2009-07-30 20:23:15 | [diff] [blame^] | 353 | const WebKit::WebString kExtensionScheme = |
| 354 | WebKit::WebString::fromUTF8(chrome::kExtensionScheme); |
| 355 | |
| 356 | WebKit::registerExtension(ExtensionProcessBindings::Get(), kExtensionScheme); |
| 357 | |
| 358 | WebKit::registerExtension(BaseJsV8Extension::Get(), |
| 359 | EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 360 | WebKit::registerExtension(BaseJsV8Extension::Get(), kExtensionScheme); |
| 361 | WebKit::registerExtension(JsonSchemaJsV8Extension::Get(), |
| 362 | EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 363 | WebKit::registerExtension(JsonSchemaJsV8Extension::Get(), kExtensionScheme); |
| 364 | WebKit::registerExtension(EventBindings::Get(), |
| 365 | EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 366 | WebKit::registerExtension(EventBindings::Get(), kExtensionScheme); |
| 367 | WebKit::registerExtension(RendererExtensionBindings::Get(), |
| 368 | EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 369 | WebKit::registerExtension(RendererExtensionBindings::Get(), kExtensionScheme); |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 370 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 371 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 372 | |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 373 | if (command_line.HasSwitch(switches::kEnableBenchmarking)) |
| 374 | WebKit::registerExtension(extensions_v8::BenchmarkingExtension::Get()); |
| 375 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 376 | if (command_line.HasSwitch(switches::kPlaybackMode) || |
[email protected] | ca12c84 | 2009-04-14 22:20:18 | [diff] [blame] | 377 | command_line.HasSwitch(switches::kRecordMode) || |
| 378 | command_line.HasSwitch(switches::kNoJsRandomness)) { |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 379 | WebKit::registerExtension(extensions_v8::PlaybackExtension::Get()); |
| 380 | } |
[email protected] | 2cb8233 | 2009-03-18 17:24:55 | [diff] [blame] | 381 | |
[email protected] | b08eebe | 2009-05-18 22:37:21 | [diff] [blame] | 382 | if (RenderProcess::current()->initialized_media_library()) |
| 383 | WebKit::enableMediaPlayer(); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 384 | |
| 385 | if (command_line.HasSwitch(switches::kEnableDatabases)) { |
| 386 | WebKit::enableDatabases(); |
| 387 | } |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 388 | } |
[email protected] | 75e5a87 | 2009-04-02 23:56:11 | [diff] [blame] | 389 | |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 390 | void RenderThread::OnExtensionMessageInvoke(const std::string& function_name, |
| 391 | const ListValue& args) { |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 392 | RendererExtensionBindings::Invoke(function_name, args, NULL); |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 393 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 394 | |
| 395 | void RenderThread::OnPurgePluginListCache() { |
| 396 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 397 | // point we already know that the browser has refreshed its list, so disable |
| 398 | // refresh temporarily to prevent each renderer process causing the list to be |
| 399 | // regenerated. |
| 400 | plugin_refresh_allowed_ = false; |
| 401 | WebKit::resetPluginCache(); |
| 402 | plugin_refresh_allowed_ = true; |
| 403 | } |