[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1 | // Copyright (c) 2010 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> |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 8 | #include <limits> |
[email protected] | 75e126b93 | 2009-09-28 19:38:49 | [diff] [blame] | 9 | #include <map> |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 13 | #include "base/debug/trace_event.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 14 | #include "base/lazy_instance.h" |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 15 | #include "base/logging.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
| 17 | #include "base/metrics/stats_table.h" |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 18 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | #include "base/shared_memory.h" |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 20 | #include "base/string_util.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 21 | #include "base/task.h" |
[email protected] | 1357c32 | 2010-12-30 22:18:56 | [diff] [blame] | 22 | #include "base/threading/thread_local.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 23 | #include "base/utf_string_conversions.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 24 | #include "base/values.h" |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 25 | #include "chrome/common/child_process_logging.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 26 | #include "chrome/common/chrome_switches.h" |
[email protected] | ec7db28 | 2011-01-29 01:11:36 | [diff] [blame] | 27 | #include "chrome/common/extensions/extension.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 28 | #include "chrome/common/extensions/extension_localization_peer.h" |
[email protected] | ec7db28 | 2011-01-29 01:11:36 | [diff] [blame] | 29 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 30 | #include "chrome/common/render_messages.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 31 | #include "chrome/common/render_messages_params.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 32 | #include "chrome/common/renderer_preferences.h" |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 33 | #include "chrome/common/url_constants.h" |
[email protected] | a9602de | 2010-03-18 23:43:11 | [diff] [blame] | 34 | #include "chrome/renderer/automation/dom_automation_v8_extension.h" |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 35 | #include "chrome/renderer/devtools_agent_filter.h" |
[email protected] | ad1f9bd | 2009-07-30 20:23:15 | [diff] [blame] | 36 | #include "chrome/renderer/extension_groups.h" |
[email protected] | 2747dd84 | 2010-08-27 14:22:12 | [diff] [blame] | 37 | #include "chrome/renderer/extensions/chrome_app_bindings.h" |
[email protected] | a40caa97 | 2009-04-08 18:35:34 | [diff] [blame] | 38 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 39 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | be77f0a | 2009-08-25 08:31:17 | [diff] [blame] | 40 | #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 41 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 3c8e370 | 2009-05-01 16:27:42 | [diff] [blame] | 42 | #include "chrome/renderer/external_extension.h" |
[email protected] | 0bc4655 | 2009-04-07 21:56:42 | [diff] [blame] | 43 | #include "chrome/renderer/loadtimes_extension_bindings.h" |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 44 | #include "chrome/renderer/net/renderer_net_predictor.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 45 | #include "chrome/renderer/render_process_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | #include "chrome/renderer/render_view.h" |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 47 | #include "chrome/renderer/render_view_visitor.h" |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 48 | #include "chrome/renderer/renderer_histogram_snapshots.h" |
[email protected] | 7ef8f60 | 2010-07-30 11:09:47 | [diff] [blame] | 49 | #include "chrome/renderer/renderer_webidbfactory_impl.h" |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 50 | #include "chrome/renderer/renderer_webkitclient_impl.h" |
[email protected] | 3ead132 | 2010-11-19 20:01:00 | [diff] [blame] | 51 | #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 52 | #include "chrome/renderer/search_extension.h" |
[email protected] | ce83328 | 2010-11-04 15:48:39 | [diff] [blame] | 53 | #include "chrome/renderer/searchbox_extension.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 54 | #include "chrome/renderer/security_filter_peer.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 55 | #include "chrome/renderer/spellchecker/spellcheck.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 56 | #include "chrome/renderer/user_script_slave.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 57 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 58 | #include "content/common/database_messages.h" |
| 59 | #include "content/common/db_message_filter.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 60 | #include "content/common/dom_storage_messages.h" |
[email protected] | d6d8f71 | 2011-03-10 22:54:43 | [diff] [blame] | 61 | #include "content/common/gpu_messages.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 62 | #include "content/common/plugin_messages.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 63 | #include "content/common/resource_dispatcher.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 64 | #include "content/common/resource_messages.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 65 | #include "content/common/web_database_observer_impl.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 66 | #include "content/plugin/npobject_util.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 67 | #include "content/renderer/cookie_message_filter.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame^] | 68 | #include "content/renderer/gpu_channel_host.h" |
| 69 | #include "content/renderer/gpu_video_service_host.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 70 | #include "content/renderer/indexed_db_dispatcher.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame^] | 71 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 72 | #include "ipc/ipc_channel_handle.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 73 | #include "ipc/ipc_platform_file.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 74 | #include "net/base/net_errors.h" |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 75 | #include "net/base/net_util.h" |
[email protected] | e33cba4 | 2010-08-18 23:37:03 | [diff] [blame] | 76 | #include "third_party/sqlite/sqlite3.h" |
[email protected] | 1b1f3eb | 2009-12-01 13:48:04 | [diff] [blame] | 77 | #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 78 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" |
| 79 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h" |
| 80 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h" |
| 81 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
| 82 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 83 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h" |
| 84 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 85 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 86 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 87 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" |
| 88 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
| 89 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" |
| 90 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 91 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 92 | #include "webkit/extensions/v8/benchmarking_extension.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 93 | #include "webkit/extensions/v8/playback_extension.h" |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 94 | #include "webkit/glue/webkit_glue.h" |
[email protected] | e0d92f28 | 2010-04-03 06:04:27 | [diff] [blame] | 95 | #include "v8/include/v8.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 96 | |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 97 | // TODO(port) |
| 98 | #if defined(OS_WIN) |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 99 | #include "content/plugin/plugin_channel.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 100 | #else |
| 101 | #include "base/scoped_handle.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 102 | #include "content/plugin/plugin_channel_base.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 103 | #endif |
| 104 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 105 | #if defined(OS_WIN) |
| 106 | #include <windows.h> |
| 107 | #include <objbase.h> |
| 108 | #endif |
| 109 | |
[email protected] | fe819f5 | 2009-12-15 07:58:11 | [diff] [blame] | 110 | #if defined(OS_MACOSX) |
| 111 | #include "chrome/app/breakpad_mac.h" |
| 112 | #endif |
| 113 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 114 | #if defined(OS_POSIX) |
| 115 | #include "ipc/ipc_channel_posix.h" |
| 116 | #endif |
| 117 | |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 118 | using WebKit::WebCache; |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 119 | using WebKit::WebCrossOriginPreflightResultCache; |
| 120 | using WebKit::WebFontCache; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 121 | using WebKit::WebFrame; |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 122 | using WebKit::WebRuntimeFeatures; |
[email protected] | 204758c | 2009-10-22 03:56:30 | [diff] [blame] | 123 | using WebKit::WebSecurityPolicy; |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 124 | using WebKit::WebScriptController; |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 125 | using WebKit::WebString; |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 126 | using WebKit::WebStorageEventDispatcher; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 127 | using WebKit::WebView; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 128 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 129 | namespace { |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 130 | static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 131 | static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 132 | static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; |
| 133 | static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 134 | |
[email protected] | f3ede41 | 2010-06-21 22:52:16 | [diff] [blame] | 135 | // Keep the global RenderThread in a TLS slot so it is impossible to access |
| 136 | // incorrectly from the wrong thread. |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 137 | static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( |
| 138 | base::LINKER_INITIALIZED); |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 139 | |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 140 | #if defined(OS_POSIX) |
| 141 | class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { |
| 142 | void OnChannelError() { |
| 143 | // On POSIX, at least, one can install an unload handler which loops |
| 144 | // forever and leave behind a renderer process which eats 100% CPU forever. |
| 145 | // |
| 146 | // This is because the terminate signals (ViewMsg_ShouldClose and the error |
| 147 | // from the IPC channel) are routed to the main message loop but never |
| 148 | // processed (because that message loop is stuck in V8). |
| 149 | // |
| 150 | // One could make the browser SIGKILL the renderers, but that leaves open a |
| 151 | // large window where a browser failure (or a user, manually terminating |
| 152 | // the browser because "it's stuck") will leave behind a process eating all |
| 153 | // the CPU. |
| 154 | // |
| 155 | // So, we install a filter on the channel so that we can process this event |
| 156 | // here and kill the process. |
[email protected] | fe819f5 | 2009-12-15 07:58:11 | [diff] [blame] | 157 | |
| 158 | #if defined(OS_MACOSX) |
| 159 | // TODO(viettrungluu): crbug.com/28547: The following is needed, as a |
| 160 | // stopgap, to avoid leaking due to not releasing Breakpad properly. |
| 161 | // TODO(viettrungluu): Investigate why this is being called. |
| 162 | if (IsCrashReporterEnabled()) { |
[email protected] | 593df61 | 2010-10-20 20:20:21 | [diff] [blame] | 163 | VLOG(1) << "Cleaning up Breakpad."; |
[email protected] | fe819f5 | 2009-12-15 07:58:11 | [diff] [blame] | 164 | DestructCrashReporter(); |
| 165 | } else { |
[email protected] | 593df61 | 2010-10-20 20:20:21 | [diff] [blame] | 166 | VLOG(1) << "Breakpad not enabled; no clean-up needed."; |
[email protected] | fe819f5 | 2009-12-15 07:58:11 | [diff] [blame] | 167 | } |
| 168 | #endif // OS_MACOSX |
| 169 | |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 170 | _exit(0); |
| 171 | } |
| 172 | }; |
| 173 | #endif |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 174 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 175 | class RenderViewContentSettingsSetter : public RenderViewVisitor { |
| 176 | public: |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 177 | RenderViewContentSettingsSetter(const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 178 | const ContentSettings& content_settings) |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 179 | : url_(url), |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 180 | content_settings_(content_settings) { |
| 181 | } |
| 182 | |
| 183 | virtual bool Visit(RenderView* render_view) { |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 184 | if (GURL(render_view->webview()->mainFrame()->url()) == url_) |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 185 | render_view->SetContentSettings(content_settings_); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 186 | return true; |
| 187 | } |
| 188 | |
| 189 | private: |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 190 | GURL url_; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 191 | ContentSettings content_settings_; |
| 192 | |
| 193 | DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter); |
| 194 | }; |
| 195 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 196 | class RenderViewZoomer : public RenderViewVisitor { |
| 197 | public: |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 198 | RenderViewZoomer(const GURL& url, double zoom_level) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 199 | : zoom_level_(zoom_level) { |
| 200 | host_ = net::GetHostOrSpecFromURL(url); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | virtual bool Visit(RenderView* render_view) { |
| 204 | WebView* webview = render_view->webview(); // Guaranteed non-NULL. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 205 | |
| 206 | // Don't set zoom level for full-page plugin since they don't use the same |
| 207 | // zoom settings. |
| 208 | if (webview->mainFrame()->document().isPluginDocument()) |
| 209 | return true; |
| 210 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 211 | if (net::GetHostOrSpecFromURL(GURL(webview->mainFrame()->url())) == host_) |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 212 | webview->setZoomLevel(false, zoom_level_); |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | private: |
| 217 | std::string host_; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 218 | double zoom_level_; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 219 | |
| 220 | DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
| 221 | }; |
[email protected] | 0478d016 | 2010-08-28 08:29:40 | [diff] [blame] | 222 | |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 223 | class RenderResourceObserver : public ResourceDispatcher::Observer { |
| 224 | public: |
| 225 | RenderResourceObserver() { |
| 226 | } |
| 227 | |
| 228 | virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete( |
| 229 | webkit_glue::ResourceLoaderBridge::Peer* current_peer, |
| 230 | ResourceType::Type resource_type, |
| 231 | const net::URLRequestStatus& status) { |
[email protected] | a37ea30 | 2011-03-07 18:39:47 | [diff] [blame] | 232 | // Update the browser about our cache. |
| 233 | RenderThread::current()->InformHostOfCacheStatsLater(); |
| 234 | |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 235 | if (status.status() != net::URLRequestStatus::CANCELED || |
| 236 | status.os_error() == net::ERR_ABORTED) { |
| 237 | return NULL; |
| 238 | } |
| 239 | |
| 240 | // Resource canceled with a specific error are filtered. |
| 241 | return SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( |
| 242 | resource_type, current_peer, status.os_error()); |
| 243 | } |
| 244 | |
| 245 | virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse( |
| 246 | webkit_glue::ResourceLoaderBridge::Peer* current_peer, |
| 247 | const std::string& mime_type, |
| 248 | const GURL& url) { |
| 249 | return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( |
| 250 | current_peer, RenderThread::current(), mime_type, url); |
| 251 | } |
| 252 | |
| 253 | private: |
| 254 | DISALLOW_COPY_AND_ASSIGN(RenderResourceObserver); |
| 255 | }; |
| 256 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 257 | } // namespace |
| 258 | |
| 259 | // When we run plugins in process, we actually run them on the render thread, |
| 260 | // which means that we need to make the render thread pump UI events. |
| 261 | RenderThread::RenderThread() { |
| 262 | Init(); |
| 263 | } |
| 264 | |
| 265 | RenderThread::RenderThread(const std::string& channel_name) |
| 266 | : ChildThread(channel_name) { |
| 267 | Init(); |
| 268 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 269 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 270 | void RenderThread::Init() { |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 271 | TRACE_EVENT_BEGIN("RenderThread::Init", 0, ""); |
| 272 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 273 | lazy_tls.Pointer()->Set(this); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 274 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 275 | // If you are running plugins in this thread you need COM active but in |
| 276 | // the normal case you don't. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 277 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 278 | CoInitialize(0); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 279 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 280 | |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 281 | std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 282 | switches::kProcessType); |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 283 | // In single process the single process is all there is. |
| 284 | is_extension_process_ = type_str == switches::kExtensionProcess || |
| 285 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
[email protected] | b2a74ca | 2010-03-12 17:57:09 | [diff] [blame] | 286 | is_incognito_process_ = false; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 287 | suspend_webkit_shared_timer_ = true; |
| 288 | notify_webkit_of_modal_loop_ = true; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 289 | plugin_refresh_allowed_ = true; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 290 | cache_stats_task_pending_ = false; |
| 291 | widget_count_ = 0; |
| 292 | hidden_widget_count_ = 0; |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 293 | idle_notification_delay_in_s_ = is_extension_process_ ? |
| 294 | kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 295 | task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 296 | |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 297 | resource_dispatcher()->set_observer(new RenderResourceObserver()); |
| 298 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 299 | visited_link_slave_.reset(new VisitedLinkSlave()); |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 300 | user_script_slave_.reset(new UserScriptSlave(&extensions_)); |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 301 | renderer_net_predictor_.reset(new RendererNetPredictor()); |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 302 | histogram_snapshots_.reset(new RendererHistogramSnapshots()); |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 303 | appcache_dispatcher_.reset(new AppCacheDispatcher(this)); |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 304 | indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 305 | spellchecker_.reset(new SpellCheck()); |
| 306 | |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 307 | devtools_agent_filter_ = new DevToolsAgentFilter(); |
| 308 | AddFilter(devtools_agent_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 309 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 310 | db_message_filter_ = new DBMessageFilter(); |
| 311 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 312 | |
| 313 | cookie_message_filter_ = new CookieMessageFilter(); |
| 314 | AddFilter(cookie_message_filter_.get()); |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 315 | |
| 316 | #if defined(OS_POSIX) |
| 317 | suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter; |
| 318 | AddFilter(suicide_on_channel_error_filter_.get()); |
| 319 | #endif |
[email protected] | 515c716 | 2010-07-12 23:46:17 | [diff] [blame] | 320 | |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 321 | TRACE_EVENT_END("RenderThread::Init", 0, ""); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 322 | } |
| 323 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 324 | RenderThread::~RenderThread() { |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 325 | // Wait for all databases to be closed. |
[email protected] | 2b437e23 | 2010-04-02 01:30:08 | [diff] [blame] | 326 | if (web_database_observer_impl_.get()) |
| 327 | web_database_observer_impl_->WaitForAllDatabasesToClose(); |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 328 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 329 | // Shutdown in reverse of the initialization order. |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 330 | RemoveFilter(db_message_filter_.get()); |
| 331 | db_message_filter_ = NULL; |
[email protected] | 2b437e23 | 2010-04-02 01:30:08 | [diff] [blame] | 332 | RemoveFilter(devtools_agent_filter_.get()); |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 333 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 334 | // Shutdown the file thread if it's running. |
| 335 | if (file_thread_.get()) |
| 336 | file_thread_->Stop(); |
| 337 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 338 | if (webkit_client_.get()) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 339 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 340 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 341 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 342 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 343 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 344 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 345 | // Clean up plugin channels before this thread goes away. |
| 346 | PluginChannelBase::CleanupChannels(); |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 347 | // Don't call COM if the renderer is in the sandbox. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 348 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 349 | CoUninitialize(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 350 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 353 | RenderThread* RenderThread::current() { |
| 354 | return lazy_tls.Pointer()->Get(); |
| 355 | } |
| 356 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 357 | int32 RenderThread::RoutingIDForCurrentContext() { |
| 358 | int32 routing_id = MSG_ROUTING_CONTROL; |
| 359 | if (v8::Context::InContext()) { |
[email protected] | d5ddf9a | 2010-03-04 00:48:29 | [diff] [blame] | 360 | WebFrame* frame = WebFrame::frameForCurrentContext(); |
| 361 | if (frame) { |
| 362 | RenderView* view = RenderView::FromWebView(frame->view()); |
| 363 | if (view) |
| 364 | routing_id = view->routing_id(); |
| 365 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 366 | } else { |
| 367 | DLOG(WARNING) << "Not called within a script context!"; |
| 368 | } |
| 369 | return routing_id; |
| 370 | } |
| 371 | |
[email protected] | ec7db28 | 2011-01-29 01:11:36 | [diff] [blame] | 372 | const ExtensionSet* RenderThread::GetExtensions() const { |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 373 | return &extensions_; |
| 374 | } |
| 375 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 376 | bool RenderThread::Send(IPC::Message* msg) { |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 377 | // Certain synchronous messages cannot always be processed synchronously by |
| 378 | // the browser, e.g., Chrome frame communicating with the embedding browser. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 379 | // This could cause a complete hang of Chrome if a windowed plug-in is trying |
| 380 | // to communicate with the renderer thread since the browser's UI thread |
| 381 | // could be stuck (within a Windows API call) trying to synchronously |
| 382 | // communicate with the plug-in. The remedy is to pump messages on this |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 383 | // thread while the browser is processing this request. This creates an |
| 384 | // opportunity for re-entrancy into WebKit, so we need to take care to disable |
| 385 | // callbacks, timers, and pending network loads that could trigger such |
| 386 | // callbacks. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 387 | bool pumping_events = false, may_show_cookie_prompt = false; |
| 388 | if (msg->is_sync()) { |
| 389 | if (msg->is_caller_pumping_messages()) { |
| 390 | pumping_events = true; |
| 391 | } else { |
[email protected] | 426dcd7 | 2011-03-16 23:40:39 | [diff] [blame] | 392 | // We only need to pump events for chrome frame processes as the |
| 393 | // cookie policy is controlled by the host browser (IE). If the |
| 394 | // policy is set to prompt then the host would put up UI which |
| 395 | // would require plugins if any to also pump to ensure that we |
| 396 | // don't have a deadlock. |
| 397 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 398 | switches::kChromeFrame)) { |
| 399 | switch (msg->type()) { |
| 400 | case ViewHostMsg_GetCookies::ID: |
| 401 | case ViewHostMsg_GetRawCookies::ID: |
| 402 | case ViewHostMsg_CookiesEnabled::ID: |
| 403 | case DOMStorageHostMsg_SetItem::ID: |
| 404 | case ResourceHostMsg_SyncLoad::ID: |
| 405 | case DatabaseHostMsg_Allow::ID: |
| 406 | may_show_cookie_prompt = true; |
| 407 | pumping_events = true; |
| 408 | break; |
| 409 | default: |
| 410 | break; |
| 411 | } |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 412 | } |
| 413 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 414 | } |
| 415 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 416 | bool suspend_webkit_shared_timer = true; // default value |
| 417 | std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 418 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 419 | bool notify_webkit_of_modal_loop = true; // default value |
| 420 | std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); |
| 421 | |
| 422 | gfx::NativeViewId host_window = 0; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 423 | |
| 424 | if (pumping_events) { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 425 | // See ViewMsg_SignalCookiePromptEvent. |
| 426 | if (may_show_cookie_prompt) { |
| 427 | static_cast<IPC::SyncMessage*>(msg)->set_pump_messages_event( |
| 428 | cookie_message_filter_->pump_messages_event()); |
| 429 | } |
| 430 | |
| 431 | if (suspend_webkit_shared_timer) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 432 | webkit_client_->SuspendSharedTimer(); |
| 433 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 434 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 435 | WebView::willEnterModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 436 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 437 | RenderWidget* widget = |
| 438 | static_cast<RenderWidget*>(ResolveRoute(msg->routing_id())); |
| 439 | if (widget) { |
| 440 | host_window = widget->host_window(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 441 | PluginChannelHost::Broadcast( |
| 442 | new PluginMsg_SignalModalDialogEvent(host_window)); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | bool rv = ChildThread::Send(msg); |
| 447 | |
| 448 | if (pumping_events) { |
| 449 | if (host_window) { |
| 450 | PluginChannelHost::Broadcast( |
| 451 | new PluginMsg_ResetModalDialogEvent(host_window)); |
| 452 | } |
| 453 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 454 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 455 | WebView::didExitModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 456 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 457 | if (suspend_webkit_shared_timer) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 458 | webkit_client_->ResumeSharedTimer(); |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 459 | |
| 460 | // We may end up nesting calls to Send, so we defer the reset until we |
| 461 | // return to the top-most message loop. |
| 462 | if (may_show_cookie_prompt && |
| 463 | cookie_message_filter_->pump_messages_event()->IsSignaled()) { |
| 464 | MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
| 465 | NewRunnableMethod(cookie_message_filter_.get(), |
| 466 | &CookieMessageFilter::ResetPumpMessagesEvent)); |
| 467 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | return rv; |
| 471 | } |
| 472 | |
| 473 | void RenderThread::AddRoute(int32 routing_id, |
| 474 | IPC::Channel::Listener* listener) { |
| 475 | widget_count_++; |
[email protected] | 3231c2e | 2010-09-02 12:41:05 | [diff] [blame] | 476 | child_process_logging::SetNumberOfViews(widget_count_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 477 | return ChildThread::AddRoute(routing_id, listener); |
| 478 | } |
| 479 | |
| 480 | void RenderThread::RemoveRoute(int32 routing_id) { |
| 481 | widget_count_--; |
[email protected] | 3231c2e | 2010-09-02 12:41:05 | [diff] [blame] | 482 | child_process_logging::SetNumberOfViews(widget_count_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 483 | return ChildThread::RemoveRoute(routing_id); |
| 484 | } |
| 485 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 486 | void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 487 | channel()->AddFilter(filter); |
| 488 | } |
| 489 | |
| 490 | void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 491 | channel()->RemoveFilter(filter); |
| 492 | } |
| 493 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 494 | void RenderThread::WidgetHidden() { |
| 495 | DCHECK(hidden_widget_count_ < widget_count_); |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 496 | hidden_widget_count_++; |
[email protected] | b8f41a19 | 2010-04-19 18:25:04 | [diff] [blame] | 497 | if (!is_extension_process_ && |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 498 | widget_count_ && hidden_widget_count_ == widget_count_) |
| 499 | ScheduleIdleHandler(kInitialIdleHandlerDelayS); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | void RenderThread::WidgetRestored() { |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 503 | DCHECK_GT(hidden_widget_count_, 0); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 504 | hidden_widget_count_--; |
[email protected] | b8f41a19 | 2010-04-19 18:25:04 | [diff] [blame] | 505 | if (!is_extension_process_) |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 506 | idle_timer_.Stop(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 509 | bool RenderThread::IsExtensionProcess() const { |
| 510 | return is_extension_process_; |
| 511 | } |
| 512 | |
| 513 | bool RenderThread::IsIncognitoProcess() const { |
| 514 | return is_incognito_process_; |
| 515 | } |
| 516 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 517 | void RenderThread::DoNotSuspendWebKitSharedTimer() { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 518 | suspend_webkit_shared_timer_ = false; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void RenderThread::DoNotNotifyWebKitOfModalLoop() { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 522 | notify_webkit_of_modal_loop_ = false; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 523 | } |
| 524 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 525 | void RenderThread::Resolve(const char* name, size_t length) { |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 526 | return renderer_net_predictor_->Resolve(name, length); |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | void RenderThread::SendHistograms(int sequence_number) { |
| 530 | return histogram_snapshots_->SendHistograms(sequence_number); |
| 531 | } |
| 532 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 533 | void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) { |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 534 | DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 535 | visited_link_slave_->Init(table); |
| 536 | } |
| 537 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 538 | void RenderThread::OnAddVisitedLinks( |
| 539 | const VisitedLinkSlave::Fingerprints& fingerprints) { |
| 540 | for (size_t i = 0; i < fingerprints.size(); ++i) |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 541 | WebView::updateVisitedLinkState(fingerprints[i]); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | void RenderThread::OnResetVisitedLinks() { |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 545 | WebView::resetVisitedLinkState(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 546 | } |
| 547 | |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 548 | void RenderThread::OnSetContentSettingsForCurrentURL( |
| 549 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 550 | const ContentSettings& content_settings) { |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 551 | RenderViewContentSettingsSetter setter(url, content_settings); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 552 | RenderView::ForEach(&setter); |
| 553 | } |
| 554 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 555 | void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url, |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 556 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 557 | RenderViewZoomer zoomer(url, zoom_level); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 558 | RenderView::ForEach(&zoomer); |
| 559 | } |
| 560 | |
[email protected] | b2a74ca | 2010-03-12 17:57:09 | [diff] [blame] | 561 | void RenderThread::OnUpdateUserScripts(base::SharedMemoryHandle scripts) { |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 562 | DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
[email protected] | ee908064 | 2010-04-07 00:23:06 | [diff] [blame] | 563 | user_script_slave_->UpdateScripts(scripts); |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 564 | UpdateActiveExtensions(); |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 565 | } |
| 566 | |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 567 | void RenderThread::OnSetExtensionFunctionNames( |
| 568 | const std::vector<std::string>& names) { |
[email protected] | a1a0df0 | 2009-04-09 08:18:04 | [diff] [blame] | 569 | ExtensionProcessBindings::SetFunctionNames(names); |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 572 | void RenderThread::OnExtensionLoaded( |
| 573 | const ViewMsg_ExtensionLoaded_Params& params) { |
| 574 | scoped_refptr<const Extension> extension(params.ConvertToExtension()); |
| 575 | if (!extension) { |
| 576 | // This can happen if extension parsing fails for any reason. One reason |
| 577 | // this can legitimately happen is if the |
| 578 | // --enable-experimental-extension-apis changes at runtime, which happens |
| 579 | // during browser tests. Existing renderers won't know about the change. |
| 580 | return; |
| 581 | } |
| 582 | |
[email protected] | ec7db28 | 2011-01-29 01:11:36 | [diff] [blame] | 583 | extensions_.Insert(extension); |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void RenderThread::OnSetExtensionScriptingWhitelist( |
| 587 | const Extension::ScriptingWhitelist& extension_ids) { |
| 588 | Extension::SetScriptingWhitelist(extension_ids); |
| 589 | } |
| 590 | |
| 591 | void RenderThread::OnExtensionUnloaded(const std::string& id) { |
| 592 | extensions_.Remove(id); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 593 | } |
| 594 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 595 | void RenderThread::OnPageActionsUpdated( |
| 596 | const std::string& extension_id, |
| 597 | const std::vector<std::string>& page_actions) { |
| 598 | ExtensionProcessBindings::SetPageActions(extension_id, page_actions); |
| 599 | } |
| 600 | |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 601 | void RenderThread::OnExtensionSetAPIPermissions( |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 602 | const std::string& extension_id, |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 603 | const std::set<std::string>& permissions) { |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 604 | ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions); |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 605 | |
| 606 | // This is called when starting a new extension page, so start the idle |
| 607 | // handler ticking. |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 608 | ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS); |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 609 | |
| 610 | UpdateActiveExtensions(); |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | void RenderThread::OnExtensionSetHostPermissions( |
| 614 | const GURL& extension_url, const std::vector<URLPattern>& permissions) { |
| 615 | ExtensionProcessBindings::SetHostPermissions(extension_url, permissions); |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 616 | } |
| 617 | |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 618 | void RenderThread::OnDOMStorageEvent( |
[email protected] | 56879f93 | 2010-12-13 21:05:37 | [diff] [blame] | 619 | const DOMStorageMsg_Event_Params& params) { |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 620 | if (!dom_storage_event_dispatcher_.get()) |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 621 | dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); |
[email protected] | 56879f93 | 2010-12-13 21:05:37 | [diff] [blame] | 622 | dom_storage_event_dispatcher_->dispatchStorageEvent(params.key, |
| 623 | params.old_value, params.new_value, params.origin, params.url, |
| 624 | params.storage_type == DOM_STORAGE_LOCAL); |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 625 | } |
| 626 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 627 | bool RenderThread::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 628 | // Some messages are handled by delegates. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 629 | if (appcache_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 630 | return true; |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 631 | if (indexed_db_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 632 | return true; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 633 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 634 | bool handled = true; |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 635 | IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) |
| 636 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 637 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks) |
| 638 | IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks) |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 639 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL, |
| 640 | OnSetContentSettingsForCurrentURL) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 641 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |
| 642 | OnSetZoomLevelForCurrentURL) |
[email protected] | b2a74ca | 2010-03-12 17:57:09 | [diff] [blame] | 643 | IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 644 | IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 645 | IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 646 | // TODO(port): removed from render_messages_internal.h; |
| 647 | // is there a new non-windows message I should add here? |
| 648 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
| 649 | IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) |
[email protected] | 163753f | 2010-10-01 20:59:03 | [diff] [blame] | 650 | IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache) |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 651 | IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms, |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 652 | OnGetRendererHistograms) |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 653 | #if defined(USE_TCMALLOC) |
| 654 | IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, |
| 655 | OnGetRendererTcmalloc) |
| 656 | #endif |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame] | 657 | IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 658 | IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, |
| 659 | OnGetCacheResourceStats) |
[email protected] | 2f2243e | 2009-05-26 02:27:02 | [diff] [blame] | 660 | IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 661 | OnUpdateUserScripts) |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 662 | // TODO(rafaelw): create an ExtensionDispatcher that handles extension |
| 663 | // messages seperates their handling from the RenderThread. |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 664 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 665 | OnExtensionMessageInvoke) |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 666 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames, |
| 667 | OnSetExtensionFunctionNames) |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 668 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionLoaded, |
| 669 | OnExtensionLoaded) |
| 670 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionUnloaded, |
| 671 | OnExtensionUnloaded) |
| 672 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetScriptingWhitelist, |
| 673 | OnSetExtensionScriptingWhitelist) |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 674 | IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 675 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, |
| 676 | OnPurgePluginListCache) |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 677 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions, |
| 678 | OnPageActionsUpdated) |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 679 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions, |
| 680 | OnExtensionSetAPIPermissions) |
| 681 | IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions, |
| 682 | OnExtensionSetHostPermissions) |
[email protected] | 56879f93 | 2010-12-13 21:05:37 | [diff] [blame] | 683 | IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 684 | OnDOMStorageEvent) |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 685 | IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_Init, |
| 686 | OnInitSpellChecker) |
| 687 | IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_WordAdded, |
| 688 | OnSpellCheckWordAdded) |
| 689 | IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_EnableAutoSpellCorrect, |
| 690 | OnSpellCheckEnableAutoSpellCorrect) |
[email protected] | d6d8f71 | 2011-03-10 22:54:43 | [diff] [blame] | 691 | IPC_MESSAGE_HANDLER(GpuMsg_GpuChannelEstablished, OnGpuChannelEstablished) |
[email protected] | 31c90db | 2010-09-23 00:59:18 | [diff] [blame] | 692 | IPC_MESSAGE_HANDLER(ViewMsg_SetPhishingModel, OnSetPhishingModel) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 693 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 694 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 695 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | void RenderThread::OnSetNextPageID(int32 next_page_id) { |
| 699 | // This should only be called at process initialization time, so we shouldn't |
| 700 | // have to worry about thread-safety. |
| 701 | RenderView::SetNextPageID(next_page_id); |
| 702 | } |
| 703 | |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 704 | // Called when to register CSS Color name->system color mappings. |
| 705 | // We update the colors one by one and then tell WebKit to refresh all render |
| 706 | // views. |
| 707 | void RenderThread::OnSetCSSColors( |
| 708 | const std::vector<CSSColors::CSSColorMapping>& colors) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 709 | EnsureWebKitInitialized(); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 710 | size_t num_colors = colors.size(); |
| 711 | scoped_array<WebKit::WebColorName> color_names( |
| 712 | new WebKit::WebColorName[num_colors]); |
| 713 | scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); |
| 714 | size_t i = 0; |
| 715 | for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = |
| 716 | colors.begin(); |
| 717 | it != colors.end(); |
| 718 | ++it, ++i) { |
| 719 | color_names[i] = it->first; |
| 720 | web_colors[i] = it->second; |
| 721 | } |
| 722 | WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); |
| 723 | } |
| 724 | |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 725 | void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 726 | EnsureWebKitInitialized(); |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 727 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 728 | RenderView::Create( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 729 | this, |
| 730 | params.parent_window, |
| 731 | MSG_ROUTING_NONE, |
| 732 | params.renderer_preferences, |
| 733 | params.web_preferences, |
| 734 | new SharedRenderViewCounter(0), |
| 735 | params.view_id, |
| 736 | params.session_storage_namespace_id, |
| 737 | params.frame_name); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 738 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 739 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 740 | void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity, |
| 741 | size_t max_dead_capacity, |
| 742 | size_t capacity) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 743 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 744 | WebCache::setCapacities( |
| 745 | min_dead_capacity, max_dead_capacity, capacity); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 746 | } |
| 747 | |
[email protected] | 163753f | 2010-10-01 20:59:03 | [diff] [blame] | 748 | void RenderThread::OnClearCache() { |
| 749 | EnsureWebKitInitialized(); |
| 750 | WebCache::clear(); |
| 751 | } |
| 752 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 753 | void RenderThread::OnGetCacheResourceStats() { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 754 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 755 | WebCache::ResourceTypeStats stats; |
| 756 | WebCache::getResourceTypeStats(&stats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 757 | Send(new ViewHostMsg_ResourceTypeStats(stats)); |
| 758 | } |
| 759 | |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 760 | void RenderThread::OnGetRendererHistograms(int sequence_number) { |
| 761 | SendHistograms(sequence_number); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 762 | } |
| 763 | |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 764 | #if defined(USE_TCMALLOC) |
| 765 | void RenderThread::OnGetRendererTcmalloc() { |
| 766 | std::string result; |
| 767 | char buffer[1024 * 32]; |
[email protected] | a4dc33f | 2009-10-20 15:09:55 | [diff] [blame] | 768 | base::ProcessId pid = base::GetCurrentProcId(); |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 769 | MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); |
| 770 | result.append(buffer); |
| 771 | Send(new ViewHostMsg_RendererTcmalloc(pid, result)); |
| 772 | } |
| 773 | #endif |
| 774 | |
[email protected] | 38b48a8 | 2009-11-11 01:51:32 | [diff] [blame] | 775 | void RenderThread::OnGetV8HeapStats() { |
| 776 | v8::HeapStatistics heap_stats; |
| 777 | v8::V8::GetHeapStatistics(&heap_stats); |
| 778 | Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(), |
| 779 | heap_stats.used_heap_size())); |
| 780 | } |
| 781 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 782 | void RenderThread::InformHostOfCacheStats() { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 783 | EnsureWebKitInitialized(); |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 784 | WebCache::UsageStats stats; |
| 785 | WebCache::getUsageStats(&stats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 786 | Send(new ViewHostMsg_UpdatedCacheStats(stats)); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 787 | cache_stats_task_pending_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | void RenderThread::InformHostOfCacheStatsLater() { |
| 791 | // Rate limit informing the host of our cache stats. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 792 | if (cache_stats_task_pending_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 793 | return; |
| 794 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 795 | cache_stats_task_pending_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 796 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 797 | task_factory_->NewRunnableMethod( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 798 | &RenderThread::InformHostOfCacheStats), |
| 799 | kCacheStatsDelayMS); |
| 800 | } |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 801 | |
[email protected] | c40acc3 | 2010-01-14 01:02:53 | [diff] [blame] | 802 | void RenderThread::CloseCurrentConnections() { |
| 803 | Send(new ViewHostMsg_CloseCurrentConnections()); |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | void RenderThread::SetCacheMode(bool enabled) { |
| 807 | Send(new ViewHostMsg_SetCacheMode(enabled)); |
| 808 | } |
| 809 | |
[email protected] | 0e34852a | 2011-02-15 23:14:44 | [diff] [blame] | 810 | void RenderThread::ClearCache(bool preserve_ssl_host_info) { |
[email protected] | c5d7934 | 2010-06-05 01:27:34 | [diff] [blame] | 811 | int rv; |
[email protected] | 0e34852a | 2011-02-15 23:14:44 | [diff] [blame] | 812 | Send(new ViewHostMsg_ClearCache(preserve_ssl_host_info, &rv)); |
[email protected] | c5d7934 | 2010-06-05 01:27:34 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | 12893c3 | 2010-08-19 17:30:54 | [diff] [blame] | 815 | void RenderThread::EnableSpdy(bool enable) { |
| 816 | Send(new ViewHostMsg_EnableSpdy(enable)); |
| 817 | } |
| 818 | |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 819 | void RenderThread::UpdateActiveExtensions() { |
| 820 | // In single-process mode, the browser process reports the active extensions. |
| 821 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
| 822 | return; |
| 823 | |
| 824 | std::set<std::string> active_extensions; |
| 825 | user_script_slave_->GetActiveExtensions(&active_extensions); |
| 826 | ExtensionProcessBindings::GetActiveExtensions(&active_extensions); |
| 827 | child_process_logging::SetActiveExtensions(active_extensions); |
| 828 | } |
| 829 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 830 | void RenderThread::EstablishGpuChannel() { |
| 831 | if (gpu_channel_.get()) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 832 | // Do nothing if we already have a GPU channel or are already |
| 833 | // establishing one. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 834 | if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
| 835 | gpu_channel_->state() == GpuChannelHost::kConnected) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 836 | return; |
| 837 | |
| 838 | // Recreate the channel if it has been lost. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 839 | if (gpu_channel_->state() == GpuChannelHost::kLost) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 840 | gpu_channel_ = NULL; |
| 841 | } |
| 842 | |
| 843 | if (!gpu_channel_.get()) |
| 844 | gpu_channel_ = new GpuChannelHost; |
| 845 | |
| 846 | // Ask the browser for the channel name. |
[email protected] | 7822132 | 2011-01-31 16:29:04 | [diff] [blame] | 847 | Send(new GpuHostMsg_EstablishGpuChannel()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 848 | } |
| 849 | |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 850 | GpuChannelHost* RenderThread::EstablishGpuChannelSync() { |
[email protected] | f9a2b2fe | 2010-07-15 21:13:23 | [diff] [blame] | 851 | EstablishGpuChannel(); |
[email protected] | 7822132 | 2011-01-31 16:29:04 | [diff] [blame] | 852 | Send(new GpuHostMsg_SynchronizeGpu()); |
[email protected] | f9a2b2fe | 2010-07-15 21:13:23 | [diff] [blame] | 853 | return GetGpuChannel(); |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 854 | } |
| 855 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 856 | GpuChannelHost* RenderThread::GetGpuChannel() { |
| 857 | if (!gpu_channel_.get()) |
| 858 | return NULL; |
| 859 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 860 | if (gpu_channel_->state() != GpuChannelHost::kConnected) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 861 | return NULL; |
| 862 | |
| 863 | return gpu_channel_.get(); |
| 864 | } |
| 865 | |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 866 | static void* CreateHistogram( |
| 867 | const char *name, int min, int max, size_t buckets) { |
[email protected] | e8829a19 | 2009-12-06 00:09:37 | [diff] [blame] | 868 | if (min <= 0) |
| 869 | min = 1; |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 870 | scoped_refptr<base::Histogram> histogram = base::Histogram::FactoryGet( |
| 871 | name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | e8829a19 | 2009-12-06 00:09:37 | [diff] [blame] | 872 | // We'll end up leaking these histograms, unless there is some code hiding in |
| 873 | // there to do the dec-ref. |
[email protected] | 2753b39 | 2009-12-28 06:59:52 | [diff] [blame] | 874 | // TODO(jar): Handle reference counting in webkit glue. |
[email protected] | e8829a19 | 2009-12-06 00:09:37 | [diff] [blame] | 875 | histogram->AddRef(); |
| 876 | return histogram.get(); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | static void AddHistogramSample(void* hist, int sample) { |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 880 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 881 | histogram->Add(sample); |
| 882 | } |
| 883 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 884 | void RenderThread::EnsureWebKitInitialized() { |
| 885 | if (webkit_client_.get()) |
| 886 | return; |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 887 | |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 888 | // For extensions, we want to ensure we call the IdleHandler every so often, |
| 889 | // even if the extension keeps up activity. |
[email protected] | b8f41a19 | 2010-04-19 18:25:04 | [diff] [blame] | 890 | if (is_extension_process_) { |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 891 | forced_idle_timer_.Start( |
| 892 | base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS), |
| 893 | this, &RenderThread::IdleHandler); |
| 894 | } |
| 895 | |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 896 | v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 897 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 898 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 899 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 900 | webkit_client_.reset(new RendererWebKitClientImpl); |
| 901 | WebKit::initialize(webkit_client_.get()); |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 902 | |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 903 | WebScriptController::enableV8SingleThreadMode(); |
[email protected] | 4ea00e8 | 2009-07-30 22:59:34 | [diff] [blame] | 904 | |
[email protected] | c8310d8 | 2011-01-13 23:42:28 | [diff] [blame] | 905 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 906 | |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 907 | webkit_glue::EnableWebCoreLogChannels( |
| 908 | command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); |
| 909 | |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 910 | // chrome: pages should not be accessible by normal content, and should |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 911 | // also be unable to script anything but themselves (to help limit the damage |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 912 | // that a corrupt chrome: page could cause). |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 913 | WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme)); |
[email protected] | c931d52 | 2011-01-26 22:21:06 | [diff] [blame] | 914 | WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 915 | |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 916 | // chrome-extension: resources shouldn't trigger insecure content warnings. |
[email protected] | 37e5a9a | 2010-03-13 09:42:39 | [diff] [blame] | 917 | WebString extension_scheme(ASCIIToUTF16(chrome::kExtensionScheme)); |
| 918 | WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme); |
| 919 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 920 | RegisterExtension(extensions_v8::LoadTimesExtension::Get(), false); |
| 921 | RegisterExtension(extensions_v8::ChromeAppExtension::Get(), false); |
| 922 | RegisterExtension(extensions_v8::ExternalExtension::Get(), false); |
[email protected] | ce83328 | 2010-11-04 15:48:39 | [diff] [blame] | 923 | RegisterExtension(extensions_v8::SearchBoxExtension::Get(), false); |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 924 | v8::Extension* search_extension = extensions_v8::SearchExtension::Get(); |
| 925 | // search_extension is null if not enabled. |
| 926 | if (search_extension) |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 927 | RegisterExtension(search_extension, false); |
[email protected] | e2b2d4a | 2009-10-24 03:32:59 | [diff] [blame] | 928 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 929 | if (command_line.HasSwitch(switches::kEnableBenchmarking)) |
| 930 | RegisterExtension(extensions_v8::BenchmarkingExtension::Get(), false); |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 931 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 932 | if (command_line.HasSwitch(switches::kPlaybackMode) || |
[email protected] | ca12c84 | 2009-04-14 22:20:18 | [diff] [blame] | 933 | command_line.HasSwitch(switches::kRecordMode) || |
| 934 | command_line.HasSwitch(switches::kNoJsRandomness)) { |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 935 | RegisterExtension(extensions_v8::PlaybackExtension::Get(), false); |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 936 | } |
[email protected] | 2cb8233 | 2009-03-18 17:24:55 | [diff] [blame] | 937 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 938 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 939 | RegisterExtension(DomAutomationV8Extension::Get(), false); |
| 940 | |
| 941 | // Add v8 extensions related to chrome extensions. |
| 942 | RegisterExtension(ExtensionProcessBindings::Get(), true); |
| 943 | RegisterExtension(BaseJsV8Extension::Get(), true); |
| 944 | RegisterExtension(JsonSchemaJsV8Extension::Get(), true); |
| 945 | RegisterExtension(EventBindings::Get(), true); |
| 946 | RegisterExtension(RendererExtensionBindings::Get(), true); |
| 947 | RegisterExtension(ExtensionApiTestV8Extension::Get(), true); |
| 948 | |
| 949 | web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this)); |
| 950 | WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); |
[email protected] | a9602de | 2010-03-18 23:43:11 | [diff] [blame] | 951 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 952 | WebRuntimeFeatures::enableMediaPlayer( |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 953 | RenderProcess::current()->HasInitializedMediaLibrary()); |
[email protected] | 3553c6cc | 2009-10-20 05:51:55 | [diff] [blame] | 954 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 955 | WebRuntimeFeatures::enableSockets( |
[email protected] | cdf2478 | 2009-11-05 09:32:47 | [diff] [blame] | 956 | !command_line.HasSwitch(switches::kDisableWebSockets)); |
[email protected] | 0afb993 | 2009-10-24 00:37:58 | [diff] [blame] | 957 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 958 | WebRuntimeFeatures::enableDatabase( |
[email protected] | 90a7ad52 | 2009-11-20 22:42:53 | [diff] [blame] | 959 | !command_line.HasSwitch(switches::kDisableDatabases)); |
[email protected] | bfa69d49 | 2009-10-31 03:27:19 | [diff] [blame] | 960 | |
[email protected] | 27d2748 | 2011-03-08 22:45:39 | [diff] [blame] | 961 | WebRuntimeFeatures::enableDataTransferItems( |
| 962 | command_line.HasSwitch(switches::kEnableDataTransferItems)); |
| 963 | |
[email protected] | 13bc0d82 | 2009-11-07 01:17:14 | [diff] [blame] | 964 | WebRuntimeFeatures::enableApplicationCache( |
[email protected] | 425c27064 | 2010-01-26 20:42:37 | [diff] [blame] | 965 | !command_line.HasSwitch(switches::kDisableApplicationCache)); |
[email protected] | 13bc0d82 | 2009-11-07 01:17:14 | [diff] [blame] | 966 | |
[email protected] | bfa69d49 | 2009-10-31 03:27:19 | [diff] [blame] | 967 | WebRuntimeFeatures::enableNotifications( |
[email protected] | 380f186 | 2009-11-14 02:48:01 | [diff] [blame] | 968 | !command_line.HasSwitch(switches::kDisableDesktopNotifications)); |
[email protected] | 7ee66e6 | 2009-11-05 09:16:30 | [diff] [blame] | 969 | |
| 970 | WebRuntimeFeatures::enableLocalStorage( |
[email protected] | 5cf1836 | 2009-11-06 18:45:01 | [diff] [blame] | 971 | !command_line.HasSwitch(switches::kDisableLocalStorage)); |
[email protected] | 7ee66e6 | 2009-11-05 09:16:30 | [diff] [blame] | 972 | WebRuntimeFeatures::enableSessionStorage( |
[email protected] | 0356780 | 2010-02-24 11:48:53 | [diff] [blame] | 973 | !command_line.HasSwitch(switches::kDisableSessionStorage)); |
[email protected] | 2236bd1f | 2010-01-20 15:17:08 | [diff] [blame] | 974 | |
[email protected] | 582fab73 | 2010-02-02 02:50:28 | [diff] [blame] | 975 | WebRuntimeFeatures::enableIndexedDatabase( |
[email protected] | af1f9f3 | 2010-10-09 21:30:26 | [diff] [blame] | 976 | !command_line.HasSwitch(switches::kDisableIndexedDatabase)); |
[email protected] | 582fab73 | 2010-02-02 02:50:28 | [diff] [blame] | 977 | |
[email protected] | 2236bd1f | 2010-01-20 15:17:08 | [diff] [blame] | 978 | WebRuntimeFeatures::enableGeolocation( |
[email protected] | d0569f4 | 2010-04-01 10:48:18 | [diff] [blame] | 979 | !command_line.HasSwitch(switches::kDisableGeolocation)); |
[email protected] | 7a716c8 | 2010-03-03 10:33:44 | [diff] [blame] | 980 | |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 981 | WebRuntimeFeatures::enableWebAudio( |
| 982 | command_line.HasSwitch(switches::kEnableWebAudio)); |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 983 | |
[email protected] | 7a716c8 | 2010-03-03 10:33:44 | [diff] [blame] | 984 | WebRuntimeFeatures::enableWebGL( |
[email protected] | 97123dc | 2010-12-21 02:12:33 | [diff] [blame] | 985 | !command_line.HasSwitch(switches::kDisable3DAPIs) && |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 986 | !command_line.HasSwitch(switches::kDisableExperimentalWebGL)); |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 987 | |
| 988 | WebRuntimeFeatures::enablePushState(true); |
[email protected] | f2e3d6c | 2010-04-30 14:23:04 | [diff] [blame] | 989 | |
| 990 | WebRuntimeFeatures::enableTouch( |
| 991 | command_line.HasSwitch(switches::kEnableTouch)); |
[email protected] | 66249e2 | 2010-07-22 09:55:33 | [diff] [blame] | 992 | |
[email protected] | 1f50197 | 2010-08-09 05:40:02 | [diff] [blame] | 993 | WebRuntimeFeatures::enableDeviceMotion( |
| 994 | command_line.HasSwitch(switches::kEnableDeviceMotion)); |
| 995 | |
[email protected] | 66249e2 | 2010-07-22 09:55:33 | [diff] [blame] | 996 | WebRuntimeFeatures::enableDeviceOrientation( |
[email protected] | 7145320 | 2010-08-27 15:47:37 | [diff] [blame] | 997 | !command_line.HasSwitch(switches::kDisableDeviceOrientation)); |
[email protected] | c864727 | 2010-07-30 21:52:57 | [diff] [blame] | 998 | |
[email protected] | 21e0cbf6 | 2011-03-04 07:55:03 | [diff] [blame] | 999 | WebRuntimeFeatures::enableSpeechInput( |
| 1000 | !command_line.HasSwitch(switches::kDisableSpeechInput)); |
[email protected] | 4c56ef5 | 2010-09-03 01:56:04 | [diff] [blame] | 1001 | |
| 1002 | WebRuntimeFeatures::enableFileSystem( |
[email protected] | 2a524d2 | 2010-10-16 01:16:23 | [diff] [blame] | 1003 | !command_line.HasSwitch(switches::kDisableFileSystem)); |
[email protected] | be8a927 | 2011-02-10 22:06:07 | [diff] [blame] | 1004 | |
| 1005 | WebRuntimeFeatures::enableJavaScriptI18NAPI( |
[email protected] | 7a0c143 | 2011-03-10 21:33:41 | [diff] [blame] | 1006 | !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)); |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 1007 | } |
[email protected] | 75e5a87 | 2009-04-02 23:56:11 | [diff] [blame] | 1008 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1009 | void RenderThread::IdleHandler() { |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 1010 | #if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC) |
[email protected] | e94afbb9 | 2009-10-01 00:25:41 | [diff] [blame] | 1011 | MallocExtension::instance()->ReleaseFreeMemory(); |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 1012 | #endif |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1013 | |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 1014 | v8::V8::IdleNotification(); |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 1015 | |
| 1016 | // Schedule next invocation. |
| 1017 | // Dampen the delay using the algorithm: |
| 1018 | // delay = delay + 1 / (delay + 2) |
| 1019 | // Using floor(delay) has a dampening effect such as: |
| 1020 | // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 1021 | // Note that idle_notification_delay_in_s_ would be reset to |
| 1022 | // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden. |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 1023 | ScheduleIdleHandler(idle_notification_delay_in_s_ + |
| 1024 | 1.0 / (idle_notification_delay_in_s_ + 2.0)); |
[email protected] | b8f41a19 | 2010-04-19 18:25:04 | [diff] [blame] | 1025 | if (is_extension_process_) { |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 1026 | // Dampen the forced delay as well if the extension stays idle for long |
| 1027 | // periods of time. |
| 1028 | int64 forced_delay_s = |
| 1029 | std::max(static_cast<int64>(idle_notification_delay_in_s_), |
| 1030 | kMaxExtensionIdleHandlerDelayS); |
| 1031 | forced_idle_timer_.Stop(); |
| 1032 | forced_idle_timer_.Start( |
| 1033 | base::TimeDelta::FromSeconds(forced_delay_s), |
| 1034 | this, &RenderThread::IdleHandler); |
| 1035 | } |
| 1036 | } |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 1037 | |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 1038 | void RenderThread::ScheduleIdleHandler(double initial_delay_s) { |
| 1039 | idle_notification_delay_in_s_ = initial_delay_s; |
| 1040 | idle_timer_.Stop(); |
| 1041 | idle_timer_.Start( |
| 1042 | base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), |
| 1043 | this, &RenderThread::IdleHandler); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1044 | } |
| 1045 | |
[email protected] | a7ab1b78 | 2010-10-21 23:24:16 | [diff] [blame] | 1046 | void RenderThread::OnExtensionMessageInvoke(const std::string& extension_id, |
| 1047 | const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 1048 | const ListValue& args, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 1049 | const GURL& event_url) { |
| 1050 | RendererExtensionBindings::Invoke( |
[email protected] | a7ab1b78 | 2010-10-21 23:24:16 | [diff] [blame] | 1051 | extension_id, function_name, args, NULL, event_url); |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 1052 | |
| 1053 | // Reset the idle handler each time there's any activity like event or message |
| 1054 | // dispatch, for which Invoke is the chokepoint. |
[email protected] | b8f41a19 | 2010-04-19 18:25:04 | [diff] [blame] | 1055 | if (is_extension_process_) |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 1056 | ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS); |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 1057 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 1058 | |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 1059 | void RenderThread::OnPurgeMemory() { |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1060 | spellchecker_.reset(new SpellCheck()); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1061 | |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 1062 | EnsureWebKitInitialized(); |
| 1063 | |
| 1064 | // Clear the object cache (as much as possible; some live objects cannot be |
| 1065 | // freed). |
| 1066 | WebCache::clear(); |
| 1067 | |
| 1068 | // Clear the font/glyph cache. |
| 1069 | WebFontCache::clear(); |
| 1070 | |
| 1071 | // Clear the Cross-Origin Preflight cache. |
| 1072 | WebCrossOriginPreflightResultCache::clear(); |
| 1073 | |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 1074 | // Release all freeable memory from the SQLite process-global page cache (a |
| 1075 | // low-level object which backs the Connection-specific page caches). |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 1076 | while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) { |
| 1077 | } |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 1078 | |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 1079 | // Repeatedly call the V8 idle notification until it returns true ("nothing |
| 1080 | // more to free"). Note that it makes more sense to do this than to implement |
| 1081 | // a new "delete everything" pass because object references make it difficult |
| 1082 | // to free everything possible in just one pass. |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 1083 | while (!v8::V8::IdleNotification()) { |
| 1084 | } |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 1085 | |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 1086 | #if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC) |
[email protected] | fede6ca1 | 2009-10-08 18:24:26 | [diff] [blame] | 1087 | // Tell tcmalloc to release any free pages it's still holding. |
| 1088 | MallocExtension::instance()->ReleaseFreeMemory(); |
| 1089 | #endif |
| 1090 | } |
| 1091 | |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 1092 | void RenderThread::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 1093 | EnsureWebKitInitialized(); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 1094 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 1095 | // point we already know that the browser has refreshed its list, so disable |
| 1096 | // refresh temporarily to prevent each renderer process causing the list to be |
| 1097 | // regenerated. |
| 1098 | plugin_refresh_allowed_ = false; |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 1099 | WebKit::resetPluginCache(reload_pages); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 1100 | plugin_refresh_allowed_ = true; |
| 1101 | } |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1102 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1103 | void RenderThread::OnInitSpellChecker( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1104 | IPC::PlatformFileForTransit bdict_file, |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1105 | const std::vector<std::string>& custom_words, |
| 1106 | const std::string& language, |
| 1107 | bool auto_spell_correct) { |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1108 | spellchecker_->Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file), |
| 1109 | custom_words, language); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1110 | spellchecker_->EnableAutoSpellCorrect(auto_spell_correct); |
| 1111 | } |
| 1112 | |
| 1113 | void RenderThread::OnSpellCheckWordAdded(const std::string& word) { |
| 1114 | spellchecker_->WordAdded(word); |
| 1115 | } |
| 1116 | |
| 1117 | void RenderThread::OnSpellCheckEnableAutoSpellCorrect(bool enable) { |
| 1118 | spellchecker_->EnableAutoSpellCorrect(enable); |
| 1119 | } |
[email protected] | b2a74ca | 2010-03-12 17:57:09 | [diff] [blame] | 1120 | |
| 1121 | void RenderThread::OnSetIsIncognitoProcess(bool is_incognito_process) { |
| 1122 | is_incognito_process_ = is_incognito_process; |
| 1123 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1124 | |
| 1125 | void RenderThread::OnGpuChannelEstablished( |
[email protected] | 0100b7a | 2011-02-24 22:54:50 | [diff] [blame] | 1126 | const IPC::ChannelHandle& channel_handle, |
| 1127 | base::ProcessHandle renderer_process_for_gpu, |
| 1128 | const GPUInfo& gpu_info) { |
[email protected] | 4bce24e | 2010-09-07 20:45:01 | [diff] [blame] | 1129 | gpu_channel_->set_gpu_info(gpu_info); |
| 1130 | |
[email protected] | 6775e40a | 2011-03-04 21:03:47 | [diff] [blame] | 1131 | if (!channel_handle.name.empty()) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1132 | // Connect to the GPU process if a channel name was received. |
[email protected] | 0100b7a | 2011-02-24 22:54:50 | [diff] [blame] | 1133 | gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1134 | } else { |
| 1135 | // Otherwise cancel the connection. |
| 1136 | gpu_channel_ = NULL; |
| 1137 | } |
| 1138 | } |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 1139 | |
[email protected] | 31c90db | 2010-09-23 00:59:18 | [diff] [blame] | 1140 | void RenderThread::OnSetPhishingModel(IPC::PlatformFileForTransit model_file) { |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 1141 | safe_browsing::PhishingClassifierDelegate::SetPhishingModel(model_file); |
[email protected] | 31c90db | 2010-09-23 00:59:18 | [diff] [blame] | 1142 | } |
| 1143 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 1144 | scoped_refptr<base::MessageLoopProxy> |
| 1145 | RenderThread::GetFileThreadMessageLoopProxy() { |
| 1146 | DCHECK(message_loop() == MessageLoop::current()); |
| 1147 | if (!file_thread_.get()) { |
| 1148 | file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 1149 | file_thread_->Start(); |
| 1150 | } |
| 1151 | return file_thread_->message_loop_proxy(); |
| 1152 | } |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 1153 | |
| 1154 | bool RenderThread::AllowScriptExtension(const std::string& v8_extension_name, |
| 1155 | const GURL& url, |
| 1156 | int extension_group) { |
| 1157 | // If we don't know about it, it was added by WebCore, so we should allow it. |
| 1158 | if (v8_extensions_.find(v8_extension_name) == v8_extensions_.end()) |
| 1159 | return true; |
| 1160 | |
| 1161 | // If the V8 extension is not restricted, allow it to run anywhere. |
| 1162 | bool restrict_to_extensions = v8_extensions_[v8_extension_name]; |
| 1163 | if (!restrict_to_extensions) |
| 1164 | return true; |
| 1165 | |
| 1166 | // Extension-only bindings should be restricted to content scripts and |
| 1167 | // extension-blessed URLs. |
| 1168 | if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 1169 | extensions_.ExtensionBindingsAllowed(url)) { |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 1170 | return true; |
| 1171 | } |
| 1172 | |
| 1173 | return false; |
| 1174 | } |
| 1175 | |
| 1176 | void RenderThread::RegisterExtension(v8::Extension* extension, |
| 1177 | bool restrict_to_extensions) { |
| 1178 | WebScriptController::registerExtension(extension); |
| 1179 | v8_extensions_[extension->name()] = restrict_to_extensions; |
| 1180 | } |