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