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