[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] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 5 | #include "content/renderer/render_thread_impl.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] | 1a77126 | 2011-10-31 09:11:12 | [diff] [blame] | 24 | #include "base/win/scoped_com_initializer.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 25 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 26 | #include "content/common/child_process_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 27 | #include "content/common/database_messages.h" |
| 28 | #include "content/common/db_message_filter.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 29 | #include "content/common/dom_storage_messages.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 30 | #include "content/common/gpu/gpu_messages.h" |
[email protected] | d3fd748b | 2011-09-20 17:39:17 | [diff] [blame] | 31 | #include "content/common/npobject_util.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 32 | #include "content/common/plugin_messages.h" |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 33 | #include "content/common/resource_dispatcher.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 34 | #include "content/common/resource_messages.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 35 | #include "content/common/view_messages.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 36 | #include "content/common/web_database_observer_impl.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 37 | #include "content/public/common/content_switches.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 38 | #include "content/public/common/renderer_preferences.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 39 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 40 | #include "content/public/renderer/render_process_observer.h" |
| 41 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 42 | #include "content/renderer/devtools_agent_filter.h" |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 43 | #include "content/renderer/gpu/compositor_thread.h" |
[email protected] | a03a222 | 2011-05-25 21:26:40 | [diff] [blame] | 44 | #include "content/renderer/gpu/gpu_channel_host.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 45 | #include "content/renderer/indexed_db_dispatcher.h" |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 46 | #include "content/renderer/media/audio_input_message_filter.h" |
| 47 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 48 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | ba164c91 | 2011-06-14 22:07:34 | [diff] [blame] | 49 | #include "content/renderer/media/video_capture_message_filter.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 50 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 51 | #include "content/renderer/render_process_impl.h" |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 52 | #include "content/renderer/render_view_impl.h" |
[email protected] | acb9472 | 2011-03-18 01:33:34 | [diff] [blame] | 53 | #include "content/renderer/renderer_webidbfactory_impl.h" |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 54 | #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 55 | #include "ipc/ipc_channel_handle.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 56 | #include "ipc/ipc_platform_file.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 57 | #include "net/base/net_errors.h" |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 58 | #include "net/base/net_util.h" |
[email protected] | 1b1f3eb | 2009-12-01 13:48:04 | [diff] [blame] | 59 | #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 60 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h" |
[email protected] | 028217e | 2011-11-19 00:19:08 | [diff] [blame] | 61 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 62 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
| 63 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 64 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 65 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 66 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" |
[email protected] | 4bd55a3 | 2011-07-28 13:28:38 | [diff] [blame] | 67 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 68 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 69 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 70 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" |
| 71 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 72 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | 18ad677 | 2011-09-20 21:51:32 | [diff] [blame] | 73 | #include "ui/base/ui_base_switches.h" |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 74 | #include "v8/include/v8.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 75 | #include "webkit/extensions/v8/playback_extension.h" |
[email protected] | d471190a | 2011-02-16 14:52:30 | [diff] [blame] | 76 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 77 | |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 78 | // TODO(port) |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 79 | #if !defined(OS_WIN) |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 80 | #include "base/memory/scoped_handle.h" |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 81 | #include "content/common/np_channel_base.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 82 | #endif |
| 83 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 84 | #if defined(OS_WIN) |
| 85 | #include <windows.h> |
| 86 | #include <objbase.h> |
| 87 | #endif |
| 88 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 89 | #if defined(OS_POSIX) |
| 90 | #include "ipc/ipc_channel_posix.h" |
| 91 | #endif |
| 92 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 93 | using WebKit::WebDocument; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 94 | using WebKit::WebFrame; |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 95 | using WebKit::WebNetworkStateNotifier; |
[email protected] | adf00bc | 2009-11-02 18:35:00 | [diff] [blame] | 96 | using WebKit::WebRuntimeFeatures; |
[email protected] | 98d7127b | 2009-10-23 18:26:51 | [diff] [blame] | 97 | using WebKit::WebScriptController; |
[email protected] | 2c434b3 | 2009-03-19 06:27:47 | [diff] [blame] | 98 | using WebKit::WebString; |
[email protected] | b7c7bcf | 2009-10-03 07:07:34 | [diff] [blame] | 99 | using WebKit::WebStorageEventDispatcher; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 100 | using WebKit::WebView; |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 101 | using content::RenderProcessObserver; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 103 | namespace { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 104 | static const int64 kInitialIdleHandlerDelayMs = 1000; |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 105 | static const int64 kShortIdleHandlerDelayMs = 1000; |
| 106 | static const int64 kLongIdleHandlerDelayMs = 30*1000; |
| 107 | static const int kIdleCPUUsageThresholdInPercents = 3; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 108 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 109 | // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
[email protected] | f3ede41 | 2010-06-21 22:52:16 | [diff] [blame] | 110 | // incorrectly from the wrong thread. |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 111 | static base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > |
| 112 | lazy_tls = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 113 | |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 114 | class RenderViewZoomer : public content::RenderViewVisitor { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 115 | public: |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 116 | RenderViewZoomer(const GURL& url, double zoom_level) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 117 | : zoom_level_(zoom_level) { |
| 118 | host_ = net::GetHostOrSpecFromURL(url); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 121 | virtual bool Visit(content::RenderView* render_view) { |
| 122 | WebView* webview = render_view->GetWebView(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 123 | WebDocument document = webview->mainFrame()->document(); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 124 | |
| 125 | // Don't set zoom level for full-page plugin since they don't use the same |
| 126 | // zoom settings. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 127 | if (document.isPluginDocument()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 128 | return true; |
| 129 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 130 | if (net::GetHostOrSpecFromURL(GURL(document.url())) == host_) |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 131 | webview->setZoomLevel(false, zoom_level_); |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | private: |
| 136 | std::string host_; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 137 | double zoom_level_; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 138 | |
| 139 | DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
| 140 | }; |
[email protected] | 0478d016 | 2010-08-28 08:29:40 | [diff] [blame] | 141 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 142 | } // namespace |
| 143 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 144 | static void* CreateHistogram( |
| 145 | const char *name, int min, int max, size_t buckets) { |
| 146 | if (min <= 0) |
| 147 | min = 1; |
| 148 | base::Histogram* histogram = base::Histogram::FactoryGet( |
| 149 | name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); |
| 150 | return histogram; |
| 151 | } |
| 152 | |
| 153 | static void AddHistogramSample(void* hist, int sample) { |
| 154 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
| 155 | histogram->Add(sample); |
| 156 | } |
| 157 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 158 | RenderThreadImpl* RenderThreadImpl::current() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 159 | return lazy_tls.Pointer()->Get(); |
| 160 | } |
| 161 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 162 | // When we run plugins in process, we actually run them on the render thread, |
| 163 | // which means that we need to make the render thread pump UI events. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 164 | RenderThreadImpl::RenderThreadImpl() { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 165 | Init(); |
| 166 | } |
| 167 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 168 | RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 169 | : ChildThread(channel_name) { |
| 170 | Init(); |
| 171 | } |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 172 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 173 | void RenderThreadImpl::Init() { |
| 174 | TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 175 | |
[email protected] | 53c607c | 2011-03-21 23:19:04 | [diff] [blame] | 176 | #if defined(OS_MACOSX) |
| 177 | // On Mac, the select popups are rendered by the browser. |
| 178 | WebKit::WebView::setUseExternalPopupMenus(true); |
| 179 | #endif |
| 180 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 181 | lazy_tls.Pointer()->Set(this); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 182 | #if defined(OS_WIN) |
[email protected] | bdef78b5 | 2009-04-16 19:31:34 | [diff] [blame] | 183 | // If you are running plugins in this thread you need COM active but in |
| 184 | // the normal case you don't. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 185 | if (RenderProcessImpl::InProcessPlugins()) |
[email protected] | 1a77126 | 2011-10-31 09:11:12 | [diff] [blame] | 186 | initialize_com_.reset(new base::win::ScopedCOMInitializer()); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 187 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 188 | |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 189 | // In single process the single process is all there is. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 190 | suspend_webkit_shared_timer_ = true; |
| 191 | notify_webkit_of_modal_loop_ = true; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 192 | plugin_refresh_allowed_ = true; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 193 | widget_count_ = 0; |
| 194 | hidden_widget_count_ = 0; |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 195 | idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 196 | idle_notifications_to_skip_ = 0; |
| 197 | base::ProcessHandle handle = base::GetCurrentProcessHandle(); |
| 198 | #if defined(OS_MACOSX) |
| 199 | process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle, |
| 200 | NULL)); |
| 201 | #else |
| 202 | process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); |
| 203 | #endif |
| 204 | process_metrics_->GetCPUUsage(); // Initialize CPU usage counters. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 205 | task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this)); |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 206 | |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 207 | appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 208 | indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 209 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 210 | db_message_filter_ = new DBMessageFilter(); |
| 211 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 212 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 213 | vc_manager_ = new VideoCaptureImplManager(); |
| 214 | AddFilter(vc_manager_->video_capture_message_filter()); |
[email protected] | e25f4d7 | 2011-06-08 20:58:46 | [diff] [blame] | 215 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 216 | audio_input_message_filter_ = new AudioInputMessageFilter(); |
| 217 | AddFilter(audio_input_message_filter_.get()); |
| 218 | |
| 219 | audio_message_filter_ = new AudioMessageFilter(); |
| 220 | AddFilter(audio_message_filter_.get()); |
| 221 | |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 222 | devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
| 223 | AddFilter(devtools_agent_message_filter_.get()); |
| 224 | |
[email protected] | 8d97ade | 2011-04-14 18:17:08 | [diff] [blame] | 225 | content::GetContentClient()->renderer()->RenderThreadStarted(); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 226 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 227 | TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 230 | RenderThreadImpl::~RenderThreadImpl() { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 231 | FOR_EACH_OBSERVER( |
| 232 | RenderProcessObserver, observers_, OnRenderProcessShutdown()); |
| 233 | |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 234 | // Wait for all databases to be closed. |
[email protected] | 2b437e23 | 2010-04-02 01:30:08 | [diff] [blame] | 235 | if (web_database_observer_impl_.get()) |
| 236 | web_database_observer_impl_->WaitForAllDatabasesToClose(); |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 237 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 238 | // Shutdown in reverse of the initialization order. |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 239 | RemoveFilter(devtools_agent_message_filter_.get()); |
| 240 | devtools_agent_message_filter_ = NULL; |
| 241 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 242 | RemoveFilter(audio_input_message_filter_.get()); |
| 243 | audio_input_message_filter_ = NULL; |
| 244 | |
| 245 | RemoveFilter(audio_message_filter_.get()); |
| 246 | audio_message_filter_ = NULL; |
| 247 | |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 248 | RemoveFilter(vc_manager_->video_capture_message_filter()); |
| 249 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 250 | RemoveFilter(db_message_filter_.get()); |
| 251 | db_message_filter_ = NULL; |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 252 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 253 | // Shutdown the file thread if it's running. |
| 254 | if (file_thread_.get()) |
| 255 | file_thread_->Stop(); |
| 256 | |
[email protected] | 028217e | 2011-11-19 00:19:08 | [diff] [blame] | 257 | #ifdef WEBCOMPOSITOR_HAS_INITIALIZE |
| 258 | WebKit::WebCompositor::shutdown(); |
| 259 | #endif |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 260 | if (compositor_thread_.get()) { |
| 261 | RemoveFilter(compositor_thread_->GetMessageFilter()); |
| 262 | compositor_thread_.reset(); |
| 263 | } |
| 264 | |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 265 | if (webkit_platform_support_.get()) |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 266 | WebKit::shutdown(); |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 267 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 268 | lazy_tls.Pointer()->Set(NULL); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 269 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 270 | // TODO(port) |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 271 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | // Clean up plugin channels before this thread goes away. |
[email protected] | 099587b7 | 2011-09-20 00:40:50 | [diff] [blame] | 273 | NPChannelBase::CleanupChannels(); |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 274 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 275 | } |
| 276 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 277 | bool RenderThreadImpl::Send(IPC::Message* msg) { |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 278 | // Certain synchronous messages cannot always be processed synchronously by |
| 279 | // the browser, e.g., Chrome frame communicating with the embedding browser. |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 280 | // This could cause a complete hang of Chrome if a windowed plug-in is trying |
| 281 | // to communicate with the renderer thread since the browser's UI thread |
| 282 | // could be stuck (within a Windows API call) trying to synchronously |
| 283 | // communicate with the plug-in. The remedy is to pump messages on this |
[email protected] | f23d4da9 | 2010-11-24 21:36:14 | [diff] [blame] | 284 | // thread while the browser is processing this request. This creates an |
| 285 | // opportunity for re-entrancy into WebKit, so we need to take care to disable |
| 286 | // callbacks, timers, and pending network loads that could trigger such |
| 287 | // callbacks. |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 288 | bool pumping_events = false; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 289 | if (msg->is_sync()) { |
| 290 | if (msg->is_caller_pumping_messages()) { |
| 291 | pumping_events = true; |
| 292 | } else { |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 293 | if ((msg->type() == ViewHostMsg_GetCookies::ID || |
| 294 | msg->type() == ViewHostMsg_GetRawCookies::ID || |
| 295 | msg->type() == ViewHostMsg_CookiesEnabled::ID) && |
| 296 | content::GetContentClient()->renderer()-> |
| 297 | ShouldPumpEventsDuringCookieMessage()) { |
| 298 | pumping_events = true; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 299 | } |
| 300 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 301 | } |
| 302 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 303 | bool suspend_webkit_shared_timer = true; // default value |
| 304 | std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 305 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 306 | bool notify_webkit_of_modal_loop = true; // default value |
| 307 | std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); |
| 308 | |
| 309 | gfx::NativeViewId host_window = 0; |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 310 | |
| 311 | if (pumping_events) { |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 312 | if (suspend_webkit_shared_timer) |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 313 | webkit_platform_support_->SuspendSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 314 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 315 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 316 | WebView::willEnterModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 317 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 318 | RenderWidget* widget = |
| 319 | static_cast<RenderWidget*>(ResolveRoute(msg->routing_id())); |
| 320 | if (widget) { |
| 321 | host_window = widget->host_window(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 322 | PluginChannelHost::Broadcast( |
| 323 | new PluginMsg_SignalModalDialogEvent(host_window)); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | bool rv = ChildThread::Send(msg); |
| 328 | |
| 329 | if (pumping_events) { |
| 330 | if (host_window) { |
| 331 | PluginChannelHost::Broadcast( |
| 332 | new PluginMsg_ResetModalDialogEvent(host_window)); |
| 333 | } |
| 334 | |
[email protected] | 39065d01 | 2010-07-09 11:22:46 | [diff] [blame] | 335 | if (notify_webkit_of_modal_loop) |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 336 | WebView::didExitModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 337 | |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 338 | if (suspend_webkit_shared_timer) |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 339 | webkit_platform_support_->ResumeSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | return rv; |
| 343 | } |
| 344 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 345 | MessageLoop* RenderThreadImpl::GetMessageLoop() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 346 | return message_loop(); |
| 347 | } |
| 348 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 349 | IPC::SyncChannel* RenderThreadImpl::GetChannel() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 350 | return channel(); |
| 351 | } |
| 352 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 353 | std::string RenderThreadImpl::GetLocale() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 354 | // The browser process should have passed the locale to the renderer via the |
| 355 | // --lang command line flag. In single process mode, this will return the |
| 356 | // wrong value. TODO(tc): Fix this for single process mode. |
| 357 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 358 | const std::string& lang = |
| 359 | parsed_command_line.GetSwitchValueASCII(switches::kLang); |
| 360 | DCHECK(!lang.empty() || |
| 361 | (!parsed_command_line.HasSwitch(switches::kRendererProcess) && |
| 362 | !parsed_command_line.HasSwitch(switches::kPluginProcess))); |
| 363 | return lang; |
| 364 | } |
| 365 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 366 | void RenderThreadImpl::AddRoute(int32 routing_id, |
| 367 | IPC::Channel::Listener* listener) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 368 | widget_count_++; |
| 369 | return ChildThread::AddRoute(routing_id, listener); |
| 370 | } |
| 371 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 372 | void RenderThreadImpl::RemoveRoute(int32 routing_id) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 373 | widget_count_--; |
| 374 | return ChildThread::RemoveRoute(routing_id); |
| 375 | } |
| 376 | |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 377 | int RenderThreadImpl::GenerateRoutingID() { |
| 378 | int routing_id = MSG_ROUTING_NONE; |
| 379 | Send(new ViewHostMsg_GenerateRoutingID(&routing_id)); |
| 380 | return routing_id; |
| 381 | } |
| 382 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 383 | void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 384 | channel()->AddFilter(filter); |
| 385 | } |
| 386 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 387 | void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 388 | channel()->RemoveFilter(filter); |
| 389 | } |
| 390 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 391 | void RenderThreadImpl::SetOutgoingMessageFilter( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 392 | IPC::ChannelProxy::OutgoingMessageFilter* filter) { |
| 393 | } |
| 394 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 395 | void RenderThreadImpl::AddObserver(content::RenderProcessObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 396 | observers_.AddObserver(observer); |
| 397 | } |
| 398 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 399 | void RenderThreadImpl::RemoveObserver( |
| 400 | content::RenderProcessObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 401 | observers_.RemoveObserver(observer); |
| 402 | } |
| 403 | |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 404 | void RenderThreadImpl::SetResourceDispatcherDelegate( |
| 405 | content::ResourceDispatcherDelegate* delegate) { |
| 406 | resource_dispatcher()->set_delegate(delegate); |
| 407 | } |
| 408 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 409 | void RenderThreadImpl::WidgetHidden() { |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 410 | DCHECK(hidden_widget_count_ < widget_count_); |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 411 | hidden_widget_count_++; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 412 | |
| 413 | if (!content::GetContentClient()->renderer()-> |
| 414 | RunIdleHandlerWhenWidgetsHidden()) { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | if (widget_count_ && hidden_widget_count_ == widget_count_) |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 419 | ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 420 | } |
| 421 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 422 | void RenderThreadImpl::WidgetRestored() { |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 423 | DCHECK_GT(hidden_widget_count_, 0); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 424 | hidden_widget_count_--; |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 425 | if (!content::GetContentClient()->renderer()-> |
| 426 | RunIdleHandlerWhenWidgetsHidden()) { |
| 427 | return; |
| 428 | } |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 429 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 430 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 431 | } |
| 432 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 433 | void RenderThreadImpl::EnsureWebKitInitialized() { |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 434 | if (webkit_platform_support_.get()) |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 435 | return; |
| 436 | |
| 437 | v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
| 438 | v8::V8::SetCreateHistogramFunction(CreateHistogram); |
| 439 | v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 440 | |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 441 | webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
| 442 | WebKit::initialize(webkit_platform_support_.get()); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 443 | |
[email protected] | f315017 | 2011-10-22 02:28:45 | [diff] [blame] | 444 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 445 | switches::kEnableThreadedCompositing)) { |
| 446 | compositor_thread_.reset(new CompositorThread(this)); |
| 447 | AddFilter(compositor_thread_->GetMessageFilter()); |
[email protected] | 028217e | 2011-11-19 00:19:08 | [diff] [blame] | 448 | #ifdef WEBCOMPOSITOR_HAS_INITIALIZE |
| 449 | WebKit::WebCompositor::initialize(compositor_thread_->GetWebThread()); |
| 450 | #else |
| 451 | WebKit::WebCompositor::setThread(compositor_thread_->GetWebThread()); |
| 452 | #endif |
| 453 | } else { |
| 454 | #ifdef WEBCOMPOSITOR_HAS_INITIALIZE |
| 455 | WebKit::WebCompositor::initialize(NULL); |
| 456 | #endif |
[email protected] | f315017 | 2011-10-22 02:28:45 | [diff] [blame] | 457 | } |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 458 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 459 | WebScriptController::enableV8SingleThreadMode(); |
| 460 | |
| 461 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 462 | |
| 463 | webkit_glue::EnableWebCoreLogChannels( |
| 464 | command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); |
| 465 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 466 | if (command_line.HasSwitch(switches::kPlaybackMode) || |
| 467 | command_line.HasSwitch(switches::kRecordMode) || |
| 468 | command_line.HasSwitch(switches::kNoJsRandomness)) { |
| 469 | RegisterExtension(extensions_v8::PlaybackExtension::Get()); |
| 470 | } |
| 471 | |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 472 | web_database_observer_impl_.reset(new WebDatabaseObserverImpl(Get())); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 473 | WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); |
| 474 | |
| 475 | WebRuntimeFeatures::enableSockets( |
| 476 | !command_line.HasSwitch(switches::kDisableWebSockets)); |
| 477 | |
| 478 | WebRuntimeFeatures::enableDatabase( |
| 479 | !command_line.HasSwitch(switches::kDisableDatabases)); |
| 480 | |
| 481 | WebRuntimeFeatures::enableDataTransferItems( |
| 482 | !command_line.HasSwitch(switches::kDisableDataTransferItems)); |
| 483 | |
| 484 | WebRuntimeFeatures::enableApplicationCache( |
| 485 | !command_line.HasSwitch(switches::kDisableApplicationCache)); |
| 486 | |
| 487 | WebRuntimeFeatures::enableNotifications( |
| 488 | !command_line.HasSwitch(switches::kDisableDesktopNotifications)); |
| 489 | |
| 490 | WebRuntimeFeatures::enableLocalStorage( |
| 491 | !command_line.HasSwitch(switches::kDisableLocalStorage)); |
| 492 | WebRuntimeFeatures::enableSessionStorage( |
| 493 | !command_line.HasSwitch(switches::kDisableSessionStorage)); |
| 494 | |
| 495 | WebRuntimeFeatures::enableIndexedDatabase( |
| 496 | !command_line.HasSwitch(switches::kDisableIndexedDatabase)); |
| 497 | |
| 498 | WebRuntimeFeatures::enableGeolocation( |
| 499 | !command_line.HasSwitch(switches::kDisableGeolocation)); |
| 500 | |
[email protected] | 6aa03b3 | 2011-10-27 21:44:44 | [diff] [blame] | 501 | WebKit::WebRuntimeFeatures::enableMediaSource( |
| 502 | command_line.HasSwitch(switches::kEnableMediaSource)); |
| 503 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 504 | WebKit::WebRuntimeFeatures::enableMediaStream( |
| 505 | command_line.HasSwitch(switches::kEnableMediaStream)); |
| 506 | |
[email protected] | efdc028 | 2011-08-26 00:36:12 | [diff] [blame] | 507 | WebKit::WebRuntimeFeatures::enableFullScreenAPI( |
[email protected] | 5e5671a | 2011-09-08 02:12:21 | [diff] [blame] | 508 | !command_line.HasSwitch(switches::kDisableFullScreen)); |
[email protected] | efdc028 | 2011-08-26 00:36:12 | [diff] [blame] | 509 | |
[email protected] | e4e68dbb | 2011-11-18 01:50:22 | [diff] [blame] | 510 | WebKit::WebRuntimeFeatures::enablePointerLock( |
| 511 | command_line.HasSwitch(switches::kEnablePointerLock)); |
| 512 | |
[email protected] | f5da41d | 2011-10-08 17:40:07 | [diff] [blame] | 513 | WebKit::WebRuntimeFeatures::enableVideoTrack( |
| 514 | command_line.HasSwitch(switches::kEnableVideoTrack)); |
| 515 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 516 | #if defined(OS_CHROMEOS) |
| 517 | // TODO(crogers): enable once Web Audio has been tested and optimized. |
| 518 | WebRuntimeFeatures::enableWebAudio(false); |
| 519 | #else |
| 520 | WebRuntimeFeatures::enableWebAudio( |
| 521 | !command_line.HasSwitch(switches::kDisableWebAudio)); |
| 522 | #endif |
| 523 | |
| 524 | WebRuntimeFeatures::enablePushState(true); |
| 525 | |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 526 | WebRuntimeFeatures::enableTouch(false); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 527 | |
| 528 | WebRuntimeFeatures::enableDeviceMotion( |
| 529 | command_line.HasSwitch(switches::kEnableDeviceMotion)); |
| 530 | |
| 531 | WebRuntimeFeatures::enableDeviceOrientation( |
| 532 | !command_line.HasSwitch(switches::kDisableDeviceOrientation)); |
| 533 | |
| 534 | WebRuntimeFeatures::enableSpeechInput( |
| 535 | !command_line.HasSwitch(switches::kDisableSpeechInput)); |
| 536 | |
| 537 | WebRuntimeFeatures::enableFileSystem( |
| 538 | !command_line.HasSwitch(switches::kDisableFileSystem)); |
| 539 | |
| 540 | WebRuntimeFeatures::enableJavaScriptI18NAPI( |
| 541 | !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)); |
| 542 | |
| 543 | WebRuntimeFeatures::enableQuota(true); |
| 544 | |
| 545 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized()); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 546 | |
| 547 | if (content::GetContentClient()->renderer()-> |
| 548 | RunIdleHandlerWhenWidgetsHidden()) { |
| 549 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 550 | } |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 551 | } |
| 552 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 553 | void RenderThreadImpl::RecordUserMetrics(const std::string& action) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 554 | Send(new ViewHostMsg_UserMetricsRecordAction(action)); |
| 555 | } |
| 556 | |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 557 | base::SharedMemoryHandle RenderThreadImpl::HostAllocateSharedMemoryBuffer( |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 558 | uint32 buffer_size) { |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 559 | base::SharedMemoryHandle mem_handle; |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 560 | Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( |
| 561 | buffer_size, &mem_handle)); |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 562 | return mem_handle; |
| 563 | } |
| 564 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 565 | void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 566 | WebScriptController::registerExtension(extension); |
| 567 | v8_extensions_.insert(extension->name()); |
| 568 | } |
| 569 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 570 | bool RenderThreadImpl::IsRegisteredExtension( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 571 | const std::string& v8_extension_name) const { |
| 572 | return v8_extensions_.find(v8_extension_name) != v8_extensions_.end(); |
| 573 | } |
| 574 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 575 | void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) { |
| 576 | idle_notification_delay_in_ms_ = initial_delay_ms; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 577 | idle_timer_.Stop(); |
| 578 | idle_timer_.Start(FROM_HERE, |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 579 | base::TimeDelta::FromMilliseconds(initial_delay_ms), |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 580 | this, &RenderThreadImpl::IdleHandler); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 581 | } |
| 582 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 583 | void RenderThreadImpl::IdleHandler() { |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 584 | bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && |
| 585 | content::GetContentClient()->renderer()-> |
| 586 | RunIdleHandlerWhenWidgetsHidden(); |
| 587 | if (run_in_foreground_tab) { |
| 588 | IdleHandlerInForegroundTab(); |
| 589 | return; |
| 590 | } |
| 591 | #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 592 | MallocExtension::instance()->ReleaseFreeMemory(); |
| 593 | #endif |
| 594 | |
| 595 | v8::V8::IdleNotification(); |
| 596 | |
| 597 | // Schedule next invocation. |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 598 | // Dampen the delay using the algorithm (if delay is in seconds): |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 599 | // delay = delay + 1 / (delay + 2) |
| 600 | // Using floor(delay) has a dampening effect such as: |
| 601 | // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 602 | // If the delay is in milliseconds, the above formula is equivalent to: |
| 603 | // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) |
| 604 | // which is equivalent to |
| 605 | // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). |
| 606 | // Note that idle_notification_delay_in_ms_ would be reset to |
| 607 | // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden. |
| 608 | ScheduleIdleHandler(idle_notification_delay_in_ms_ + |
| 609 | 1000000 / (idle_notification_delay_in_ms_ + 2000)); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 610 | |
| 611 | FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
| 612 | } |
| 613 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 614 | void RenderThreadImpl::IdleHandlerInForegroundTab() { |
| 615 | // Increase the delay in the same way as in IdleHandler, |
| 616 | // but make it periodic by reseting it once it is too big. |
| 617 | int64 new_delay_ms = idle_notification_delay_in_ms_ + |
| 618 | 1000000 / (idle_notification_delay_in_ms_ + 2000); |
| 619 | if (new_delay_ms >= kLongIdleHandlerDelayMs) |
| 620 | new_delay_ms = kShortIdleHandlerDelayMs; |
| 621 | |
| 622 | // Sample the CPU usage on each timer event, so that it is more accurate. |
| 623 | double cpu_usage = process_metrics_->GetCPUUsage(); |
| 624 | |
| 625 | if (idle_notifications_to_skip_ > 0) { |
| 626 | idle_notifications_to_skip_--; |
| 627 | } else if (cpu_usage < kIdleCPUUsageThresholdInPercents) { |
| 628 | if (v8::V8::IdleNotification()) { |
| 629 | // V8 finished collecting garbage. |
| 630 | new_delay_ms = kLongIdleHandlerDelayMs; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | ScheduleIdleHandler(new_delay_ms); |
| 635 | } |
| 636 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 637 | int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
| 638 | return idle_notification_delay_in_ms_; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 641 | void RenderThreadImpl::SetIdleNotificationDelayInMs( |
| 642 | int64 idle_notification_delay_in_ms) { |
| 643 | idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame^] | 646 | void RenderThreadImpl::PostponeIdleNotification() { |
| 647 | idle_notifications_to_skip_ = 2; |
| 648 | } |
| 649 | |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 650 | #if defined(OS_WIN) |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 651 | void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 652 | Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
[email protected] | 79fff82 | 2011-09-20 03:33:21 | [diff] [blame] | 653 | } |
| 654 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 655 | void RenderThreadImpl::ReleaseCachedFonts() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 656 | Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 657 | } |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 658 | |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 659 | #endif // OS_WIN |
| 660 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 661 | int32 RenderThreadImpl::RoutingIDForCurrentContext() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 662 | int32 routing_id = MSG_ROUTING_CONTROL; |
| 663 | if (v8::Context::InContext()) { |
| 664 | WebFrame* frame = WebFrame::frameForCurrentContext(); |
| 665 | if (frame) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 666 | RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view()); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 667 | if (view) |
| 668 | routing_id = view->routing_id(); |
| 669 | } |
| 670 | } else { |
| 671 | DLOG(WARNING) << "Not called within a script context!"; |
| 672 | } |
| 673 | return routing_id; |
| 674 | } |
| 675 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 676 | void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 677 | suspend_webkit_shared_timer_ = false; |
| 678 | } |
| 679 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 680 | void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 681 | notify_webkit_of_modal_loop_ = false; |
| 682 | } |
| 683 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 684 | void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const GURL& url, |
| 685 | double zoom_level) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 686 | RenderViewZoomer zoomer(url, zoom_level); |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 687 | content::RenderView::ForEach(&zoomer); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 688 | } |
| 689 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 690 | void RenderThreadImpl::OnDOMStorageEvent( |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 691 | const DOMStorageMsg_Event_Params& params) { |
[email protected] | 0654cc8 | 2011-11-17 09:20:59 | [diff] [blame] | 692 | if (!dom_storage_event_dispatcher_.get()) { |
| 693 | EnsureWebKitInitialized(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 694 | dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); |
[email protected] | 0654cc8 | 2011-11-17 09:20:59 | [diff] [blame] | 695 | } |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 696 | dom_storage_event_dispatcher_->dispatchStorageEvent(params.key, |
| 697 | params.old_value, params.new_value, params.origin, params.url, |
| 698 | params.storage_type == DOM_STORAGE_LOCAL); |
| 699 | } |
| 700 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 701 | bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 702 | ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |
| 703 | RenderProcessObserver* observer; |
| 704 | while ((observer = it.GetNext()) != NULL) { |
| 705 | if (observer->OnControlMessageReceived(msg)) |
| 706 | return true; |
| 707 | } |
| 708 | |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 709 | // Some messages are handled by delegates. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 710 | if (appcache_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 711 | return true; |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 712 | if (indexed_db_dispatcher_->OnMessageReceived(msg)) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 713 | return true; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 714 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 715 | bool handled = true; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 716 | IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 717 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |
| 718 | OnSetZoomLevelForCurrentURL) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 719 | IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 720 | IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 721 | // TODO(port): removed from render_messages_internal.h; |
| 722 | // is there a new non-windows message I should add here? |
| 723 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 724 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 725 | IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) |
[email protected] | 3e26719 | 2011-03-25 01:55:45 | [diff] [blame] | 726 | IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) |
[email protected] | b69934e | 2011-10-29 02:51:52 | [diff] [blame] | 727 | IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 728 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 729 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 730 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 731 | } |
| 732 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 733 | void RenderThreadImpl::OnSetNextPageID(int32 next_page_id) { |
[email protected] | ae195eca7 | 2011-11-17 21:18:38 | [diff] [blame] | 734 | // This is called at process initialization time or when this process is |
| 735 | // being re-used for a new RenderView. It is ok if another RenderView |
| 736 | // has identical page_ids or inflates next_page_id_ just before this arrives, |
| 737 | // as long as we ensure next_page_id_ is at least this large. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 738 | RenderViewImpl::SetNextPageID(next_page_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 739 | } |
| 740 | |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 741 | // Called when to register CSS Color name->system color mappings. |
| 742 | // We update the colors one by one and then tell WebKit to refresh all render |
| 743 | // views. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 744 | void RenderThreadImpl::OnSetCSSColors( |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 745 | const std::vector<CSSColors::CSSColorMapping>& colors) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 746 | EnsureWebKitInitialized(); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame] | 747 | size_t num_colors = colors.size(); |
| 748 | scoped_array<WebKit::WebColorName> color_names( |
| 749 | new WebKit::WebColorName[num_colors]); |
| 750 | scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); |
| 751 | size_t i = 0; |
| 752 | for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = |
| 753 | colors.begin(); |
| 754 | it != colors.end(); |
| 755 | ++it, ++i) { |
| 756 | color_names[i] = it->first; |
| 757 | web_colors[i] = it->second; |
| 758 | } |
| 759 | WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); |
| 760 | } |
| 761 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 762 | void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) { |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 763 | EnsureWebKitInitialized(); |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 764 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 765 | RenderViewImpl::Create( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 766 | params.parent_window, |
| 767 | MSG_ROUTING_NONE, |
| 768 | params.renderer_preferences, |
| 769 | params.web_preferences, |
| 770 | new SharedRenderViewCounter(0), |
| 771 | params.view_id, |
| 772 | params.session_storage_namespace_id, |
| 773 | params.frame_name); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 774 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 775 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 776 | GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync( |
[email protected] | 7f3a2cf | 2011-04-06 00:10:50 | [diff] [blame] | 777 | content::CauseForGpuLaunch cause_for_gpu_launch) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 778 | if (gpu_channel_.get()) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 779 | // Do nothing if we already have a GPU channel or are already |
| 780 | // establishing one. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 781 | if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
| 782 | gpu_channel_->state() == GpuChannelHost::kConnected) |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 783 | return GetGpuChannel(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 784 | |
| 785 | // Recreate the channel if it has been lost. |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 786 | if (gpu_channel_->state() == GpuChannelHost::kLost) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 787 | gpu_channel_ = NULL; |
| 788 | } |
| 789 | |
| 790 | if (!gpu_channel_.get()) |
| 791 | gpu_channel_ = new GpuChannelHost; |
| 792 | |
| 793 | // Ask the browser for the channel name. |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 794 | IPC::ChannelHandle channel_handle; |
| 795 | base::ProcessHandle renderer_process_for_gpu; |
[email protected] | a80f5ece | 2011-10-20 23:56:55 | [diff] [blame] | 796 | content::GPUInfo gpu_info; |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 797 | if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch, |
| 798 | &channel_handle, |
| 799 | &renderer_process_for_gpu, |
| 800 | &gpu_info)) || |
| 801 | channel_handle.name.empty() || |
| 802 | renderer_process_for_gpu == base::kNullProcessHandle) { |
| 803 | // Otherwise cancel the connection. |
| 804 | gpu_channel_ = NULL; |
| 805 | return NULL; |
| 806 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 807 | |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 808 | gpu_channel_->set_gpu_info(gpu_info); |
| 809 | content::GetContentClient()->SetGpuInfo(gpu_info); |
| 810 | |
| 811 | // Connect to the GPU process if a channel name was received. |
| 812 | gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); |
| 813 | |
[email protected] | f9a2b2fe | 2010-07-15 21:13:23 | [diff] [blame] | 814 | return GetGpuChannel(); |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 815 | } |
| 816 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 817 | GpuChannelHost* RenderThreadImpl::GetGpuChannel() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 818 | if (!gpu_channel_.get()) |
| 819 | return NULL; |
| 820 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 821 | if (gpu_channel_->state() != GpuChannelHost::kConnected) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 822 | return NULL; |
| 823 | |
| 824 | return gpu_channel_.get(); |
| 825 | } |
| 826 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 827 | void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | f5e4b9bf | 2009-10-08 00:59:59 | [diff] [blame] | 828 | EnsureWebKitInitialized(); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 829 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 830 | // point we already know that the browser has refreshed its list, so disable |
| 831 | // refresh temporarily to prevent each renderer process causing the list to be |
| 832 | // regenerated. |
| 833 | plugin_refresh_allowed_ = false; |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 834 | WebKit::resetPluginCache(reload_pages); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 835 | plugin_refresh_allowed_ = true; |
| 836 | } |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 837 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 838 | void RenderThreadImpl::OnNetworkStateChanged(bool online) { |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 839 | EnsureWebKitInitialized(); |
| 840 | WebNetworkStateNotifier::setOnLine(online); |
| 841 | } |
| 842 | |
[email protected] | b69934e | 2011-10-29 02:51:52 | [diff] [blame] | 843 | void RenderThreadImpl::OnTempCrashWithData(const GURL& data) { |
| 844 | content::GetContentClient()->SetActiveURL(data); |
| 845 | CHECK(false); |
| 846 | } |
| 847 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 848 | scoped_refptr<base::MessageLoopProxy> |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 849 | RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 850 | DCHECK(message_loop() == MessageLoop::current()); |
| 851 | if (!file_thread_.get()) { |
| 852 | file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 853 | file_thread_->Start(); |
| 854 | } |
| 855 | return file_thread_->message_loop_proxy(); |
| 856 | } |