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