[email protected] | 7785b17f | 2011-03-23 01:20:28 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
[email protected] | 10e6ab57 | 2011-04-14 23:42:00 | [diff] [blame] | 5 | #include "content/renderer/render_thread.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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" |
[email protected] | 6cf19311f | 2011-04-14 23:06:02 | [diff] [blame] | 17 | #include "base/metrics/histogram.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 18 | #include "base/metrics/stats_table.h" |
[email protected] | d4104109 | 2009-10-08 06:56:57 | [diff] [blame] | 19 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | #include "base/shared_memory.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] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 23 | #include "base/values.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 24 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 25 | #include "content/common/content_switches.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 26 | #include "content/common/database_messages.h" |
| 27 | #include "content/common/db_message_filter.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 28 | #include "content/common/dom_storage_messages.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 29 | #include "content/common/gpu/gpu_messages.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 30 | #include "content/common/plugin_messages.h" |
[email protected] | 6091604 | 2011-03-19 00:43:36 | [diff] [blame] | 31 | #include "content/common/renderer_preferences.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 32 | #include "content/common/resource_messages.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 33 | #include "content/common/view_messages.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 34 | #include "content/common/web_database_observer_impl.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 35 | #include "content/plugin/npobject_util.h" |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 36 | #include "content/renderer/content_renderer_client.h" |
[email protected] | a03a222 | 2011-05-25 21:26:40 | [diff] [blame] | 37 | #include "content/renderer/gpu/gpu_channel_host.h" |
| 38 | #include "content/renderer/gpu/gpu_video_service_host.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 39 | #include "content/renderer/indexed_db_dispatcher.h" |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 40 | #include "content/renderer/media/audio_input_message_filter.h" |
| 41 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 42 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | ba164c91 | 2011-06-14 22:07:34 | [diff] [blame] | 43 | #include "content/renderer/media/video_capture_message_filter.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 44 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 45 | #include "content/renderer/render_process_impl.h" |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 46 | #include "content/renderer/render_process_observer.h" |
[email protected] | 6091604 | 2011-03-19 00:43:36 | [diff] [blame] | 47 | #include "content/renderer/render_view.h" |
| 48 | #include "content/renderer/render_view_visitor.h" |
[email protected] | acb9472 | 2011-03-18 01:33:34 | [diff] [blame] | 49 | #include "content/renderer/renderer_webidbfactory_impl.h" |
| 50 | #include "content/renderer/renderer_webkitclient_impl.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 51 | #include "ipc/ipc_channel_handle.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 52 | #include "ipc/ipc_platform_file.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 53 | #include "net/base/net_errors.h" |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 54 | #include "net/base/net_util.h" |
[email protected] | 1b1f3eb | 2009-12-01 13:48:04 | [diff] [blame] | 55 | #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 56 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 57 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
| 58 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 59 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 60 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame^] | 61 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 62 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 63 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 64 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" |
| 65 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 66 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 67 | #include "v8/include/v8.h" |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 68 | #include "webkit/extensions/v8/benchmarking_extension.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 69 | #include "webkit/extensions/v8/playback_extension.h" |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 70 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 71 | |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 72 | // TODO(port) |
| 73 | #if defined(OS_WIN) |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 74 | #include "content/plugin/plugin_channel.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 75 | #else |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 76 | #include "base/memory/scoped_handle.h" |
[email protected] | 3c5c6d8 | 2011-03-16 17:23:58 | [diff] [blame] | 77 | #include "content/plugin/plugin_channel_base.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 78 | #endif |
| 79 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 80 | #if defined(OS_WIN) |
| 81 | #include <windows.h> |
| 82 | #include <objbase.h> |
| 83 | #endif |
| 84 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 85 | #if defined(OS_POSIX) |
| 86 | #include "ipc/ipc_channel_posix.h" |
| 87 | #endif |
| 88 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 89 | using WebKit::WebDocument; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 90 | using WebKit::WebFrame; |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame^] | 91 | using WebKit::WebNetworkStateNotifier; |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 92 | using WebKit::WebRuntimeFeatures; |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 93 | using WebKit::WebScriptController; |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 94 | using WebKit::WebString; |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 95 | using WebKit::WebStorageEventDispatcher; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 96 | using WebKit::WebView; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 98 | namespace { |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 99 | static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; |
| 100 | |
[email protected] | f3ede41 | 2010-06-21 22:52:16 | [diff] [blame] | 101 | // Keep the global RenderThread in a TLS slot so it is impossible to access |
| 102 | // incorrectly from the wrong thread. |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 103 | static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( |
| 104 | base::LINKER_INITIALIZED); |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 105 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 106 | class RenderViewZoomer : public RenderViewVisitor { |
| 107 | public: |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 108 | RenderViewZoomer(const GURL& url, double zoom_level) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 109 | : zoom_level_(zoom_level) { |
| 110 | host_ = net::GetHostOrSpecFromURL(url); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | virtual bool Visit(RenderView* render_view) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 114 | WebView* webview = render_view->webview(); |
| 115 | WebDocument document = webview->mainFrame()->document(); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 116 | |
| 117 | // Don't set zoom level for full-page plugin since they don't use the same |
| 118 | // zoom settings. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 119 | if (document.isPluginDocument()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 120 | return true; |
| 121 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 122 | if (net::GetHostOrSpecFromURL(GURL(document.url())) == host_) |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 123 | webview->setZoomLevel(false, zoom_level_); |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | std::string host_; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 129 | double zoom_level_; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 130 | |
| 131 | DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
| 132 | }; |
[email protected] | 0478d016 | 2010-08-28 08:29:40 | [diff] [blame] | 133 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 134 | } // namespace |
| 135 | |
| 136 | // When we run plugins in process, we actually run them on the render thread, |
| 137 | // which means that we need to make the render thread pump UI events. |
| 138 | RenderThread::RenderThread() { |
| 139 | Init(); |
| 140 | } |
| 141 | |
| 142 | RenderThread::RenderThread(const std::string& channel_name) |
| 143 | : ChildThread(channel_name) { |
| 144 | Init(); |
| 145 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 146 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 147 | void RenderThread::Init() { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 148 | TRACE_EVENT_BEGIN_ETW("RenderThread::Init", 0, ""); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 149 | |
[email protected] | 53c607c | 2011-03-21 23:19:04 | [diff] [blame] | 150 | #if defined(OS_MACOSX) |
| 151 | // On Mac, the select popups are rendered by the browser. |
| 152 | WebKit::WebView::setUseExternalPopupMenus(true); |
| 153 | #endif |
| 154 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 155 | lazy_tls.Pointer()->Set(this); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 156 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 157 | // If you are running plugins in this thread you need COM active but in |
| 158 | // the normal case you don't. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 159 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 160 | CoInitialize(0); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 161 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 162 | |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 163 | // In single process the single process is all there is. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 164 | suspend_webkit_shared_timer_ = true; |
| 165 | notify_webkit_of_modal_loop_ = true; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 166 | plugin_refresh_allowed_ = true; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 167 | widget_count_ = 0; |
| 168 | hidden_widget_count_ = 0; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 169 | idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 170 | task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 171 | |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 172 | appcache_dispatcher_.reset(new AppCacheDispatcher(this)); |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 173 | indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 174 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 175 | db_message_filter_ = new DBMessageFilter(); |
| 176 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 177 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 178 | vc_manager_ = new VideoCaptureImplManager(); |
| 179 | AddFilter(vc_manager_->video_capture_message_filter()); |
[email protected] | e25f4d7 | 2011-06-08 20:58:46 | [diff] [blame] | 180 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 181 | audio_input_message_filter_ = new AudioInputMessageFilter(); |
| 182 | AddFilter(audio_input_message_filter_.get()); |
| 183 | |
| 184 | audio_message_filter_ = new AudioMessageFilter(); |
| 185 | AddFilter(audio_message_filter_.get()); |
| 186 | |
[email protected] | 8d97ade | 2011-04-14 18:17:08 | [diff] [blame] | 187 | content::GetContentClient()->renderer()->RenderThreadStarted(); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 188 | |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 189 | TRACE_EVENT_END_ETW("RenderThread::Init", 0, ""); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 192 | RenderThread::~RenderThread() { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 193 | FOR_EACH_OBSERVER( |
| 194 | RenderProcessObserver, observers_, OnRenderProcessShutdown()); |
| 195 | |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 196 | // Wait for all databases to be closed. |
[email protected] | 2b437e23 | 2010-04-02 01:30:08 | [diff] [blame] | 197 | if (web_database_observer_impl_.get()) |
| 198 | web_database_observer_impl_->WaitForAllDatabasesToClose(); |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 199 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 200 | // Shutdown in reverse of the initialization order. |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 201 | RemoveFilter(audio_input_message_filter_.get()); |
| 202 | audio_input_message_filter_ = NULL; |
| 203 | |
| 204 | RemoveFilter(audio_message_filter_.get()); |
| 205 | audio_message_filter_ = NULL; |
| 206 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 207 | RemoveFilter(vc_manager_->video_capture_message_filter()); |
| 208 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 209 | RemoveFilter(db_message_filter_.get()); |
| 210 | db_message_filter_ = NULL; |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 211 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 212 | // Shutdown the file thread if it's running. |
| 213 | if (file_thread_.get()) |
| 214 | file_thread_->Stop(); |
| 215 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 216 | if (webkit_client_.get()) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 217 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 218 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 219 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 220 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 221 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 222 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 223 | // Clean up plugin channels before this thread goes away. |
| 224 | PluginChannelBase::CleanupChannels(); |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 225 | // Don't call COM if the renderer is in the sandbox. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 226 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 227 | CoUninitialize(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 228 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 229 | } |
| 230 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 231 | RenderThread* RenderThread::current() { |
| 232 | return lazy_tls.Pointer()->Get(); |
| 233 | } |
| 234 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 235 | int32 RenderThread::RoutingIDForCurrentContext() { |
| 236 | int32 routing_id = MSG_ROUTING_CONTROL; |
| 237 | if (v8::Context::InContext()) { |
[email protected] | d5ddf9a | 2010-03-04 00:48:29 | [diff] [blame] | 238 | WebFrame* frame = WebFrame::frameForCurrentContext(); |
| 239 | if (frame) { |
| 240 | RenderView* view = RenderView::FromWebView(frame->view()); |
| 241 | if (view) |
| 242 | routing_id = view->routing_id(); |
| 243 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 244 | } else { |
| 245 | DLOG(WARNING) << "Not called within a script context!"; |
| 246 | } |
| 247 | return routing_id; |
| 248 | } |
| 249 | |
| 250 | bool RenderThread::Send(IPC::Message* msg) { |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 251 | // Certain synchronous messages cannot always be processed synchronously by |
| 252 | // the browser, e.g., Chrome frame communicating with the embedding browser. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 253 | // This could cause a complete hang of Chrome if a windowed plug-in is trying |
| 254 | // to communicate with the renderer thread since the browser's UI thread |
| 255 | // could be stuck (within a Windows API call) trying to synchronously |
| 256 | // communicate with the plug-in. The remedy is to pump messages on this |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 257 | // thread while the browser is processing this request. This creates an |
| 258 | // opportunity for re-entrancy into WebKit, so we need to take care to disable |
| 259 | // callbacks, timers, and pending network loads that could trigger such |
| 260 | // callbacks. |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 261 | bool pumping_events = false; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 262 | if (msg->is_sync()) { |
| 263 | if (msg->is_caller_pumping_messages()) { |
| 264 | pumping_events = true; |
| 265 | } else { |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 266 | if ((msg->type() == ViewHostMsg_GetCookies::ID || |
| 267 | msg->type() == ViewHostMsg_GetRawCookies::ID || |
| 268 | msg->type() == ViewHostMsg_CookiesEnabled::ID) && |
| 269 | content::GetContentClient()->renderer()-> |
| 270 | ShouldPumpEventsDuringCookieMessage()) { |
| 271 | pumping_events = true; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 272 | } |
| 273 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 276 | bool suspend_webkit_shared_timer = true; // default value |
| 277 | std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 278 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 279 | bool notify_webkit_of_modal_loop = true; // default value |
| 280 | std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); |
| 281 | |
| 282 | gfx::NativeViewId host_window = 0; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 283 | |
| 284 | if (pumping_events) { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 285 | if (suspend_webkit_shared_timer) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 286 | webkit_client_->SuspendSharedTimer(); |
| 287 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 288 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 289 | WebView::willEnterModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 290 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 291 | RenderWidget* widget = |
| 292 | static_cast<RenderWidget*>(ResolveRoute(msg->routing_id())); |
| 293 | if (widget) { |
| 294 | host_window = widget->host_window(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 295 | PluginChannelHost::Broadcast( |
| 296 | new PluginMsg_SignalModalDialogEvent(host_window)); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | bool rv = ChildThread::Send(msg); |
| 301 | |
| 302 | if (pumping_events) { |
| 303 | if (host_window) { |
| 304 | PluginChannelHost::Broadcast( |
| 305 | new PluginMsg_ResetModalDialogEvent(host_window)); |
| 306 | } |
| 307 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 308 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 309 | WebView::didExitModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 310 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 311 | if (suspend_webkit_shared_timer) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 312 | webkit_client_->ResumeSharedTimer(); |
| 313 | } |
| 314 | |
| 315 | return rv; |
| 316 | } |
| 317 | |
| 318 | void RenderThread::AddRoute(int32 routing_id, |
| 319 | IPC::Channel::Listener* listener) { |
| 320 | widget_count_++; |
| 321 | return ChildThread::AddRoute(routing_id, listener); |
| 322 | } |
| 323 | |
| 324 | void RenderThread::RemoveRoute(int32 routing_id) { |
| 325 | widget_count_--; |
| 326 | return ChildThread::RemoveRoute(routing_id); |
| 327 | } |
| 328 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 329 | void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 330 | channel()->AddFilter(filter); |
| 331 | } |
| 332 | |
| 333 | void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 334 | channel()->RemoveFilter(filter); |
| 335 | } |
| 336 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 337 | void RenderThread::WidgetHidden() { |
| 338 | DCHECK(hidden_widget_count_ < widget_count_); |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 339 | hidden_widget_count_++; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 340 | |
| 341 | if (!content::GetContentClient()->renderer()-> |
| 342 | RunIdleHandlerWhenWidgetsHidden()) { |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | if (widget_count_ && hidden_widget_count_ == widget_count_) |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 347 | ScheduleIdleHandler(kInitialIdleHandlerDelayS); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void RenderThread::WidgetRestored() { |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 351 | DCHECK_GT(hidden_widget_count_, 0); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 352 | hidden_widget_count_--; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 353 | if (!content::GetContentClient()->renderer()-> |
| 354 | RunIdleHandlerWhenWidgetsHidden()) { |
| 355 | return; |
| 356 | } |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 357 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 358 | idle_timer_.Stop(); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 361 | void RenderThread::AddObserver(RenderProcessObserver* observer) { |
| 362 | observers_.AddObserver(observer); |
| 363 | } |
| 364 | |
| 365 | void RenderThread::RemoveObserver(RenderProcessObserver* observer) { |
| 366 | observers_.RemoveObserver(observer); |
| 367 | } |
| 368 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 369 | void RenderThread::DoNotSuspendWebKitSharedTimer() { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 370 | suspend_webkit_shared_timer_ = false; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | void RenderThread::DoNotNotifyWebKitOfModalLoop() { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 374 | notify_webkit_of_modal_loop_ = false; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 377 | void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url, |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 378 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 379 | RenderViewZoomer zoomer(url, zoom_level); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 380 | RenderView::ForEach(&zoomer); |
| 381 | } |
| 382 | |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 383 | void RenderThread::OnDOMStorageEvent( |
[email protected] | 56879f93 | 2010-12-13 21:05:37 | [diff] [blame] | 384 | const DOMStorageMsg_Event_Params& params) { |
[email protected] | c61cc65 | 2009-11-04 05:44:40 | [diff] [blame] | 385 | if (!dom_storage_event_dispatcher_.get()) |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 386 | dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); |
[email protected] | 56879f93 | 2010-12-13 21:05:37 | [diff] [blame] | 387 | dom_storage_event_dispatcher_->dispatchStorageEvent(params.key, |
| 388 | params.old_value, params.new_value, params.origin, params.url, |
| 389 | params.storage_type == DOM_STORAGE_LOCAL); |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 392 | bool RenderThread::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 393 | ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |
| 394 | RenderProcessObserver* observer; |
| 395 | while ((observer = it.GetNext()) != NULL) { |
| 396 | if (observer->OnControlMessageReceived(msg)) |
| 397 | return true; |
| 398 | } |
| 399 | |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 400 | // Some messages are handled by delegates. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 401 | if (appcache_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 402 | return true; |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 403 | if (indexed_db_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 404 | return true; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 405 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 406 | bool handled = true; |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 407 | IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 408 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |
| 409 | OnSetZoomLevelForCurrentURL) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 410 | IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 411 | IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 412 | // TODO(port): removed from render_messages_internal.h; |
| 413 | // is there a new non-windows message I should add here? |
| 414 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 415 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame^] | 416 | IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 417 | IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 418 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 419 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 420 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void RenderThread::OnSetNextPageID(int32 next_page_id) { |
| 424 | // This should only be called at process initialization time, so we shouldn't |
| 425 | // have to worry about thread-safety. |
| 426 | RenderView::SetNextPageID(next_page_id); |
| 427 | } |
| 428 | |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 429 | // Called when to register CSS Color name->system color mappings. |
| 430 | // We update the colors one by one and then tell WebKit to refresh all render |
| 431 | // views. |
| 432 | void RenderThread::OnSetCSSColors( |
| 433 | const std::vector<CSSColors::CSSColorMapping>& colors) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 434 | EnsureWebKitInitialized(); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 435 | size_t num_colors = colors.size(); |
| 436 | scoped_array<WebKit::WebColorName> color_names( |
| 437 | new WebKit::WebColorName[num_colors]); |
| 438 | scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); |
| 439 | size_t i = 0; |
| 440 | for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = |
| 441 | colors.begin(); |
| 442 | it != colors.end(); |
| 443 | ++it, ++i) { |
| 444 | color_names[i] = it->first; |
| 445 | web_colors[i] = it->second; |
| 446 | } |
| 447 | WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); |
| 448 | } |
| 449 | |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 450 | void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 451 | EnsureWebKitInitialized(); |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 452 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | RenderView::Create( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 454 | this, |
| 455 | params.parent_window, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 456 | MSG_ROUTING_NONE, |
| 457 | params.renderer_preferences, |
| 458 | params.web_preferences, |
| 459 | new SharedRenderViewCounter(0), |
| 460 | params.view_id, |
| 461 | params.session_storage_namespace_id, |
| 462 | params.frame_name); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 463 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 464 | |
[email protected] | c40acc3 | 2010-01-14 01:02:53 | [diff] [blame] | 465 | void RenderThread::CloseCurrentConnections() { |
| 466 | Send(new ViewHostMsg_CloseCurrentConnections()); |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void RenderThread::SetCacheMode(bool enabled) { |
| 470 | Send(new ViewHostMsg_SetCacheMode(enabled)); |
| 471 | } |
| 472 | |
[email protected] | 0e34852a | 2011-02-15 23:14:44 | [diff] [blame] | 473 | void RenderThread::ClearCache(bool preserve_ssl_host_info) { |
[email protected] | c5d7934 | 2010-06-05 01:27:34 | [diff] [blame] | 474 | int rv; |
[email protected] | 0e34852a | 2011-02-15 23:14:44 | [diff] [blame] | 475 | Send(new ViewHostMsg_ClearCache(preserve_ssl_host_info, &rv)); |
[email protected] | c5d7934 | 2010-06-05 01:27:34 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | 8990e471 | 2011-03-28 20:50:55 | [diff] [blame] | 478 | void RenderThread::ClearHostResolverCache() { |
| 479 | int rv; |
| 480 | Send(new ViewHostMsg_ClearHostResolverCache(&rv)); |
| 481 | } |
| 482 | |
| 483 | void RenderThread::ClearPredictorCache() { |
| 484 | int rv; |
| 485 | Send(new ViewHostMsg_ClearPredictorCache(&rv)); |
| 486 | } |
| 487 | |
[email protected] | 12893c3 | 2010-08-19 17:30:54 | [diff] [blame] | 488 | void RenderThread::EnableSpdy(bool enable) { |
| 489 | Send(new ViewHostMsg_EnableSpdy(enable)); |
| 490 | } |
| 491 | |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 492 | GpuChannelHost* RenderThread::EstablishGpuChannelSync( |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 493 | content::CauseForGpuLaunch cause_for_gpu_launch) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 494 | if (gpu_channel_.get()) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 495 | // Do nothing if we already have a GPU channel or are already |
| 496 | // establishing one. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 497 | if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
| 498 | gpu_channel_->state() == GpuChannelHost::kConnected) |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 499 | return GetGpuChannel(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 500 | |
| 501 | // Recreate the channel if it has been lost. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 502 | if (gpu_channel_->state() == GpuChannelHost::kLost) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 503 | gpu_channel_ = NULL; |
| 504 | } |
| 505 | |
| 506 | if (!gpu_channel_.get()) |
| 507 | gpu_channel_ = new GpuChannelHost; |
| 508 | |
| 509 | // Ask the browser for the channel name. |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 510 | IPC::ChannelHandle channel_handle; |
| 511 | base::ProcessHandle renderer_process_for_gpu; |
| 512 | GPUInfo gpu_info; |
| 513 | if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch, |
| 514 | &channel_handle, |
| 515 | &renderer_process_for_gpu, |
| 516 | &gpu_info)) || |
| 517 | channel_handle.name.empty() || |
| 518 | renderer_process_for_gpu == base::kNullProcessHandle) { |
| 519 | // Otherwise cancel the connection. |
| 520 | gpu_channel_ = NULL; |
| 521 | return NULL; |
| 522 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 523 | |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 524 | gpu_channel_->set_gpu_info(gpu_info); |
| 525 | content::GetContentClient()->SetGpuInfo(gpu_info); |
| 526 | |
| 527 | // Connect to the GPU process if a channel name was received. |
| 528 | gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); |
| 529 | |
[email protected] | f9a2b2fe | 2010-07-15 21:13:23 | [diff] [blame] | 530 | return GetGpuChannel(); |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 531 | } |
| 532 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 533 | GpuChannelHost* RenderThread::GetGpuChannel() { |
| 534 | if (!gpu_channel_.get()) |
| 535 | return NULL; |
| 536 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 537 | if (gpu_channel_->state() != GpuChannelHost::kConnected) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 538 | return NULL; |
| 539 | |
| 540 | return gpu_channel_.get(); |
| 541 | } |
| 542 | |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 543 | static void* CreateHistogram( |
| 544 | const char *name, int min, int max, size_t buckets) { |
[email protected] | e8829a19 | 2009-12-06 00:09:37 | [diff] [blame] | 545 | if (min <= 0) |
| 546 | min = 1; |
[email protected] | 81ce9f3b | 2011-04-05 04:48:53 | [diff] [blame] | 547 | base::Histogram* histogram = base::Histogram::FactoryGet( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 548 | name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | 81ce9f3b | 2011-04-05 04:48:53 | [diff] [blame] | 549 | return histogram; |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static void AddHistogramSample(void* hist, int sample) { |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 553 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 554 | histogram->Add(sample); |
| 555 | } |
| 556 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 557 | void RenderThread::EnsureWebKitInitialized() { |
| 558 | if (webkit_client_.get()) |
| 559 | return; |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 560 | |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 561 | v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
[email protected] | 3df0c20 | 2009-03-31 23:51:26 | [diff] [blame] | 562 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 563 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 564 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 565 | webkit_client_.reset(new RendererWebKitClientImpl); |
| 566 | WebKit::initialize(webkit_client_.get()); |
[email protected] | 8881eca8 | 2009-03-12 18:20:44 | [diff] [blame] | 567 | |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 568 | WebScriptController::enableV8SingleThreadMode(); |
[email protected] | 4ea00e8 | 2009-07-30 22:59:34 | [diff] [blame] | 569 | |
[email protected] | c8310d8 | 2011-01-13 23:42:28 | [diff] [blame] | 570 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 571 | |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 572 | webkit_glue::EnableWebCoreLogChannels( |
| 573 | command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); |
| 574 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 575 | if (command_line.HasSwitch(switches::kEnableBenchmarking)) |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 576 | RegisterExtension(extensions_v8::BenchmarkingExtension::Get()); |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 577 | |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 578 | if (command_line.HasSwitch(switches::kPlaybackMode) || |
[email protected] | ca12c84 | 2009-04-14 22:20:18 | [diff] [blame] | 579 | command_line.HasSwitch(switches::kRecordMode) || |
| 580 | command_line.HasSwitch(switches::kNoJsRandomness)) { |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 581 | RegisterExtension(extensions_v8::PlaybackExtension::Get()); |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 582 | } |
[email protected] | 2cb8233 | 2009-03-18 17:24:55 | [diff] [blame] | 583 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 584 | web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this)); |
| 585 | WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); |
[email protected] | a9602de | 2010-03-18 23:43:11 | [diff] [blame] | 586 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 587 | WebRuntimeFeatures::enableSockets( |
[email protected] | cdf2478 | 2009-11-05 09:32:47 | [diff] [blame] | 588 | !command_line.HasSwitch(switches::kDisableWebSockets)); |
[email protected] | 0afb993 | 2009-10-24 00:37:58 | [diff] [blame] | 589 | |
[email protected] | b1b1321 | 2009-10-30 06:42:01 | [diff] [blame] | 590 | WebRuntimeFeatures::enableDatabase( |
[email protected] | 90a7ad52 | 2009-11-20 22:42:53 | [diff] [blame] | 591 | !command_line.HasSwitch(switches::kDisableDatabases)); |
[email protected] | bfa69d49 | 2009-10-31 03:27:19 | [diff] [blame] | 592 | |
[email protected] | 27d2748 | 2011-03-08 22:45:39 | [diff] [blame] | 593 | WebRuntimeFeatures::enableDataTransferItems( |
[email protected] | 2d9b6ce | 2011-04-08 22:19:54 | [diff] [blame] | 594 | !command_line.HasSwitch(switches::kDisableDataTransferItems)); |
[email protected] | 27d2748 | 2011-03-08 22:45:39 | [diff] [blame] | 595 | |
[email protected] | 13bc0d82 | 2009-11-07 01:17:14 | [diff] [blame] | 596 | WebRuntimeFeatures::enableApplicationCache( |
[email protected] | 425c27064 | 2010-01-26 20:42:37 | [diff] [blame] | 597 | !command_line.HasSwitch(switches::kDisableApplicationCache)); |
[email protected] | 13bc0d82 | 2009-11-07 01:17:14 | [diff] [blame] | 598 | |
[email protected] | bfa69d49 | 2009-10-31 03:27:19 | [diff] [blame] | 599 | WebRuntimeFeatures::enableNotifications( |
[email protected] | 380f186 | 2009-11-14 02:48:01 | [diff] [blame] | 600 | !command_line.HasSwitch(switches::kDisableDesktopNotifications)); |
[email protected] | 7ee66e6 | 2009-11-05 09:16:30 | [diff] [blame] | 601 | |
| 602 | WebRuntimeFeatures::enableLocalStorage( |
[email protected] | 5cf1836 | 2009-11-06 18:45:01 | [diff] [blame] | 603 | !command_line.HasSwitch(switches::kDisableLocalStorage)); |
[email protected] | 7ee66e6 | 2009-11-05 09:16:30 | [diff] [blame] | 604 | WebRuntimeFeatures::enableSessionStorage( |
[email protected] | 0356780 | 2010-02-24 11:48:53 | [diff] [blame] | 605 | !command_line.HasSwitch(switches::kDisableSessionStorage)); |
[email protected] | 2236bd1f | 2010-01-20 15:17:08 | [diff] [blame] | 606 | |
[email protected] | 582fab73 | 2010-02-02 02:50:28 | [diff] [blame] | 607 | WebRuntimeFeatures::enableIndexedDatabase( |
[email protected] | af1f9f3 | 2010-10-09 21:30:26 | [diff] [blame] | 608 | !command_line.HasSwitch(switches::kDisableIndexedDatabase)); |
[email protected] | 582fab73 | 2010-02-02 02:50:28 | [diff] [blame] | 609 | |
[email protected] | 2236bd1f | 2010-01-20 15:17:08 | [diff] [blame] | 610 | WebRuntimeFeatures::enableGeolocation( |
[email protected] | d0569f4 | 2010-04-01 10:48:18 | [diff] [blame] | 611 | !command_line.HasSwitch(switches::kDisableGeolocation)); |
[email protected] | 7a716c8 | 2010-03-03 10:33:44 | [diff] [blame] | 612 | |
[email protected] | 24101d60 | 2011-06-23 15:40:24 | [diff] [blame] | 613 | WebKit::WebRuntimeFeatures::enableMediaStream( |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 614 | command_line.HasSwitch(switches::kEnableMediaStream)); |
[email protected] | 24101d60 | 2011-06-23 15:40:24 | [diff] [blame] | 615 | |
[email protected] | 104aaeac | 2011-06-27 22:03:01 | [diff] [blame] | 616 | #if defined(OS_CHROMEOS) |
| 617 | // TODO(crogers): enable once Web Audio has been tested and optimized. |
| 618 | WebRuntimeFeatures::enableWebAudio(false); |
| 619 | #else |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 620 | WebRuntimeFeatures::enableWebAudio( |
[email protected] | 104aaeac | 2011-06-27 22:03:01 | [diff] [blame] | 621 | !command_line.HasSwitch(switches::kDisableWebAudio)); |
| 622 | #endif |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 623 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 624 | WebRuntimeFeatures::enablePushState(true); |
[email protected] | f2e3d6c | 2010-04-30 14:23:04 | [diff] [blame] | 625 | |
[email protected] | 7785b17f | 2011-03-23 01:20:28 | [diff] [blame] | 626 | #ifdef TOUCH_UI |
| 627 | WebRuntimeFeatures::enableTouch(true); |
| 628 | #else |
| 629 | // TODO(saintlou): in the future touch should always be enabled |
| 630 | WebRuntimeFeatures::enableTouch(false); |
| 631 | #endif |
[email protected] | 66249e2 | 2010-07-22 09:55:33 | [diff] [blame] | 632 | |
[email protected] | 1f50197 | 2010-08-09 05:40:02 | [diff] [blame] | 633 | WebRuntimeFeatures::enableDeviceMotion( |
| 634 | command_line.HasSwitch(switches::kEnableDeviceMotion)); |
| 635 | |
[email protected] | 66249e2 | 2010-07-22 09:55:33 | [diff] [blame] | 636 | WebRuntimeFeatures::enableDeviceOrientation( |
[email protected] | 7145320 | 2010-08-27 15:47:37 | [diff] [blame] | 637 | !command_line.HasSwitch(switches::kDisableDeviceOrientation)); |
[email protected] | c864727 | 2010-07-30 21:52:57 | [diff] [blame] | 638 | |
[email protected] | 21e0cbf6 | 2011-03-04 07:55:03 | [diff] [blame] | 639 | WebRuntimeFeatures::enableSpeechInput( |
| 640 | !command_line.HasSwitch(switches::kDisableSpeechInput)); |
[email protected] | 4c56ef5 | 2010-09-03 01:56:04 | [diff] [blame] | 641 | |
| 642 | WebRuntimeFeatures::enableFileSystem( |
[email protected] | 2a524d2 | 2010-10-16 01:16:23 | [diff] [blame] | 643 | !command_line.HasSwitch(switches::kDisableFileSystem)); |
[email protected] | be8a927 | 2011-02-10 22:06:07 | [diff] [blame] | 644 | |
| 645 | WebRuntimeFeatures::enableJavaScriptI18NAPI( |
[email protected] | 7a0c143 | 2011-03-10 21:33:41 | [diff] [blame] | 646 | !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 647 | |
[email protected] | 72654a6 | 2011-05-31 08:22:13 | [diff] [blame] | 648 | WebRuntimeFeatures::enableQuota(true); |
[email protected] | 8a009ee | 2011-04-27 08:53:43 | [diff] [blame] | 649 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 650 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized()); |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 651 | } |
[email protected] | 75e5a87 | 2009-04-02 23:56:11 | [diff] [blame] | 652 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 653 | void RenderThread::IdleHandler() { |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 654 | #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
[email protected] | e94afbb9 | 2009-10-01 00:25:41 | [diff] [blame] | 655 | MallocExtension::instance()->ReleaseFreeMemory(); |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 656 | #endif |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 657 | |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 658 | v8::V8::IdleNotification(); |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 659 | |
| 660 | // Schedule next invocation. |
| 661 | // Dampen the delay using the algorithm: |
| 662 | // delay = delay + 1 / (delay + 2) |
| 663 | // Using floor(delay) has a dampening effect such as: |
| 664 | // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 665 | // Note that idle_notification_delay_in_s_ would be reset to |
| 666 | // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden. |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 667 | ScheduleIdleHandler(idle_notification_delay_in_s_ + |
| 668 | 1.0 / (idle_notification_delay_in_s_ + 2.0)); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 669 | |
| 670 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 671 | } |
[email protected] | 0500118 | 2009-09-15 23:34:22 | [diff] [blame] | 672 | |
[email protected] | 71d6d85 | 2009-12-07 22:12:36 | [diff] [blame] | 673 | void RenderThread::ScheduleIdleHandler(double initial_delay_s) { |
| 674 | idle_notification_delay_in_s_ = initial_delay_s; |
| 675 | idle_timer_.Stop(); |
| 676 | idle_timer_.Start( |
| 677 | base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), |
| 678 | this, &RenderThread::IdleHandler); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 679 | } |
| 680 | |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 681 | void RenderThread::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 682 | EnsureWebKitInitialized(); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 683 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 684 | // point we already know that the browser has refreshed its list, so disable |
| 685 | // refresh temporarily to prevent each renderer process causing the list to be |
| 686 | // regenerated. |
| 687 | plugin_refresh_allowed_ = false; |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 688 | WebKit::resetPluginCache(reload_pages); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 689 | plugin_refresh_allowed_ = true; |
| 690 | } |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 691 | |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame^] | 692 | void RenderThread::OnNetworkStateChanged(bool online) { |
| 693 | EnsureWebKitInitialized(); |
| 694 | WebNetworkStateNotifier::setOnLine(online); |
| 695 | } |
| 696 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 697 | scoped_refptr<base::MessageLoopProxy> |
| 698 | RenderThread::GetFileThreadMessageLoopProxy() { |
| 699 | DCHECK(message_loop() == MessageLoop::current()); |
| 700 | if (!file_thread_.get()) { |
| 701 | file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 702 | file_thread_->Start(); |
| 703 | } |
| 704 | return file_thread_->message_loop_proxy(); |
| 705 | } |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 706 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 707 | void RenderThread::RegisterExtension(v8::Extension* extension) { |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 708 | WebScriptController::registerExtension(extension); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 709 | v8_extensions_.insert(extension->name()); |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 710 | } |
[email protected] | c6e27b9 | 2011-04-30 17:03:43 | [diff] [blame] | 711 | |
| 712 | bool RenderThread::IsRegisteredExtension( |
| 713 | const std::string& v8_extension_name) const { |
| 714 | return v8_extensions_.find(v8_extension_name) != v8_extensions_.end(); |
| 715 | } |