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