blob: c9f4099261df42fee02ec6c47396d87fa4c00ab6 [file] [log] [blame]
[email protected]d3d6325d2012-01-03 21:17:361// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f1a29a02011-10-06 23:08:445#include "content/renderer/render_thread_impl.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]da00a2882009-03-09 17:51:197#include <algorithm>
[email protected]61a9b2d82010-02-26 00:31:088#include <limits>
[email protected]75e126b932009-09-28 19:38:499#include <map>
[email protected]da00a2882009-03-09 17:51:1910#include <vector>
11
[email protected]06533c0b2009-03-05 21:39:1112#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5013#include "base/debug/trace_event.h"
[email protected]94f9a0f682009-06-15 18:30:3014#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0315#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/field_trial.h"
[email protected]6cf19311f2011-04-14 23:06:0217#include "base/metrics/histogram.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/stats_table.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/shared_memory.h"
[email protected]8c380582011-12-02 03:16:1020#include "base/string_number_conversions.h" // Temporary
[email protected]1357c322010-12-30 22:18:5621#include "base/threading/thread_local.h"
[email protected]7a4de7a62010-08-17 18:38:2422#include "base/values.h"
[email protected]1a771262011-10-31 09:11:1223#include "base/win/scoped_com_initializer.h"
[email protected]e93e04e2011-03-14 00:27:1024#include "content/common/appcache/appcache_dispatcher.h"
[email protected]bdae9812011-10-15 00:33:0325#include "content/common/child_process_messages.h"
[email protected]37666cf2011-03-13 21:51:4226#include "content/common/database_messages.h"
27#include "content/common/db_message_filter.h"
[email protected]127dd582011-03-16 21:32:1028#include "content/common/dom_storage_messages.h"
[email protected]202b54ff2011-04-22 21:36:3829#include "content/common/gpu/gpu_messages.h"
[email protected]d3fd748b2011-09-20 17:39:1730#include "content/common/npobject_util.h"
[email protected]105303e2011-03-14 22:16:1031#include "content/common/plugin_messages.h"
[email protected]359dfa32011-10-12 01:10:1532#include "content/common/resource_dispatcher.h"
[email protected]94dc971d2011-03-05 19:08:3233#include "content/common/resource_messages.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
[email protected]e93e04e2011-03-14 00:27:1035#include "content/common/web_database_observer_impl.h"
[email protected]c08950d22011-10-13 22:20:2936#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3137#include "content/public/common/renderer_preferences.h"
[email protected]d344114c2011-10-01 01:24:3438#include "content/public/renderer/content_renderer_client.h"
[email protected]64ffa0442011-10-03 22:08:3639#include "content/public/renderer/render_process_observer.h"
40#include "content/public/renderer/render_view_visitor.h"
[email protected]82622452011-07-22 09:57:2041#include "content/renderer/devtools_agent_filter.h"
[email protected]a9fb30aa2011-10-06 06:58:4642#include "content/renderer/gpu/compositor_thread.h"
[email protected]a03a2222011-05-25 21:26:4043#include "content/renderer/gpu/gpu_channel_host.h"
[email protected]44e1fbf02011-12-20 22:04:2844#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]f7eb0a392011-07-12 10:19:5147#include "content/renderer/media/audio_input_message_filter.h"
48#include "content/renderer/media/audio_message_filter.h"
[email protected]80b161a2011-06-27 17:42:1149#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:3450#include "content/renderer/media/video_capture_message_filter.h"
[email protected]6f516082011-03-17 19:15:3551#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0552#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:2853#include "content/renderer/render_view_impl.h"
[email protected]8d6cba42011-09-02 10:05:1954#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]46f36a492010-07-28 19:36:4155#include "ipc/ipc_channel_handle.h"
[email protected]cb6037d2009-11-16 22:55:1756#include "ipc/ipc_platform_file.h"
[email protected]620161e2011-03-07 18:05:2657#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5458#include "net/base/net_util.h"
[email protected]1b1f3eb2009-12-01 13:48:0459#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
[email protected]e6e90dc2011-12-03 00:01:3760#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebColor.h"
[email protected]028217e2011-11-19 00:19:0861#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
[email protected]8bd0fe62011-01-17 06:44:3762#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
63#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3764#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
65#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]6eac57a2011-07-12 21:15:0966#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]4bd55a32011-07-28 13:28:3867#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
[email protected]8bd0fe62011-01-17 06:44:3768#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
69#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
[email protected]8bd0fe62011-01-17 06:44:3770#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
[email protected]e6e90dc2011-12-03 00:01:3771#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]8bd0fe62011-01-17 06:44:3772#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]18ad6772011-09-20 21:51:3273#include "ui/base/ui_base_switches.h"
[email protected]7f3a2cf2011-04-06 00:10:5074#include "v8/include/v8.h"
[email protected]06533c0b2009-03-05 21:39:1175#include "webkit/extensions/v8/playback_extension.h"
[email protected]d471190a2011-02-16 14:52:3076#include "webkit/glue/webkit_glue.h"
[email protected]2c62b562009-01-27 19:04:5077
[email protected]94dc971d2011-03-05 19:08:3278// TODO(port)
[email protected]bdae9812011-10-15 00:33:0379#if !defined(OS_WIN)
[email protected]3b63f8f42011-03-28 01:54:1580#include "base/memory/scoped_handle.h"
[email protected]099587b72011-09-20 00:40:5081#include "content/common/np_channel_base.h"
[email protected]94dc971d2011-03-05 19:08:3282#endif
83
[email protected]da00a2882009-03-09 17:51:1984#if defined(OS_WIN)
85#include <windows.h>
86#include <objbase.h>
87#endif
88
[email protected]6217d392010-03-25 22:08:3589#if defined(OS_POSIX)
90#include "ipc/ipc_channel_posix.h"
91#endif
92
[email protected]b6cb3a842011-06-24 18:28:4193using WebKit::WebDocument;
[email protected]f85f0702010-01-30 09:31:0194using WebKit::WebFrame;
[email protected]6eac57a2011-07-12 21:15:0995using WebKit::WebNetworkStateNotifier;
[email protected]adf00bc2009-11-02 18:35:0096using WebKit::WebRuntimeFeatures;
[email protected]98d7127b2009-10-23 18:26:5197using WebKit::WebScriptController;
[email protected]2c434b32009-03-19 06:27:4798using WebKit::WebString;
[email protected]b7c7bcf2009-10-03 07:07:3499using WebKit::WebStorageEventDispatcher;
[email protected]50ae00ef2009-10-19 05:11:03100using WebKit::WebView;
[email protected]64ffa0442011-10-03 22:08:36101using content::RenderProcessObserver;
initial.commit09911bf2008-07-26 23:55:29102
[email protected]42f1d7822009-07-23 18:17:55103namespace {
[email protected]da9ccfb2012-01-28 00:34:40104
105const int64 kInitialIdleHandlerDelayMs = 1000;
106const int64 kShortIdleHandlerDelayMs = 1000;
107const int64 kLongIdleHandlerDelayMs = 30*1000;
108const int kIdleCPUUsageThresholdInPercents = 3;
[email protected]bee16aab2009-08-26 15:55:03109
[email protected]f1a29a02011-10-06 23:08:44110// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16111// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40112base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49113 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54114
[email protected]64ffa0442011-10-03 22:08:36115class RenderViewZoomer : public content::RenderViewVisitor {
[email protected]40bd6582009-12-04 23:49:51116 public:
[email protected]4e2a25a2012-01-27 00:42:08117 RenderViewZoomer(const std::string& host, double zoom_level)
118 : host_(host), zoom_level_(zoom_level) {
[email protected]40bd6582009-12-04 23:49:51119 }
120
[email protected]a2ef54c2011-10-10 16:20:31121 virtual bool Visit(content::RenderView* render_view) {
122 WebView* webview = render_view->GetWebView();
[email protected]b6cb3a842011-06-24 18:28:41123 WebDocument document = webview->mainFrame()->document();
[email protected]b75b8292010-10-01 07:28:25124
125 // Don't set zoom level for full-page plugin since they don't use the same
126 // zoom settings.
[email protected]b6cb3a842011-06-24 18:28:41127 if (document.isPluginDocument())
[email protected]b75b8292010-10-01 07:28:25128 return true;
129
[email protected]b6cb3a842011-06-24 18:28:41130 if (net::GetHostOrSpecFromURL(GURL(document.url())) == host_)
[email protected]40bd6582009-12-04 23:49:51131 webview->setZoomLevel(false, zoom_level_);
132 return true;
133 }
134
135 private:
136 std::string host_;
[email protected]b75b8292010-10-01 07:28:25137 double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51138
139 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
140};
[email protected]0478d0162010-08-28 08:29:40141
[email protected]42f1d7822009-07-23 18:17:55142} // namespace
143
[email protected]d1b8fccc2011-08-03 01:20:13144static 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
153static void AddHistogramSample(void* hist, int sample) {
154 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
155 histogram->Add(sample);
156}
157
[email protected]f1a29a02011-10-06 23:08:44158RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06159 return lazy_tls.Pointer()->Get();
160}
161
[email protected]42f1d7822009-07-23 18:17:55162// 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]f1a29a02011-10-06 23:08:44164RenderThreadImpl::RenderThreadImpl() {
[email protected]42f1d7822009-07-23 18:17:55165 Init();
166}
167
[email protected]f1a29a02011-10-06 23:08:44168RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
[email protected]42f1d7822009-07-23 18:17:55169 : ChildThread(channel_name) {
170 Init();
171}
[email protected]5fa1c542009-05-05 20:36:07172
[email protected]f1a29a02011-10-06 23:08:44173void RenderThreadImpl::Init() {
174 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, "");
[email protected]a872ea1f2010-08-11 04:45:33175
[email protected]53c607c2011-03-21 23:19:04176#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]94f9a0f682009-06-15 18:30:30181 lazy_tls.Pointer()->Set(this);
[email protected]2c62b562009-01-27 19:04:50182#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34183 // If you are running plugins in this thread you need COM active but in
184 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28185 if (RenderProcessImpl::InProcessPlugins())
[email protected]1a771262011-10-31 09:11:12186 initialize_com_.reset(new base::win::ScopedCOMInitializer());
[email protected]2c62b562009-01-27 19:04:50187#endif
initial.commit09911bf2008-07-26 23:55:29188
[email protected]31f87132010-04-21 23:36:21189 // In single process the single process is all there is.
[email protected]80fc08c52010-03-09 07:43:50190 suspend_webkit_shared_timer_ = true;
191 notify_webkit_of_modal_loop_ = true;
[email protected]42f1d7822009-07-23 18:17:55192 plugin_refresh_allowed_ = true;
[email protected]bee16aab2009-08-26 15:55:03193 widget_count_ = 0;
194 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44195 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48196 idle_notifications_to_skip_ = 0;
[email protected]2db58cf92011-12-01 21:39:01197 compositor_initialized_ = false;
[email protected]8d86fce2009-02-26 23:37:55198
[email protected]526476902011-10-06 20:34:06199 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
[email protected]31bfae72011-12-16 02:04:38200 main_thread_indexed_db_dispatcher_.reset(
201 IndexedDBDispatcher::ThreadSpecificInstance());
[email protected]dd9241932010-02-24 19:23:13202
[email protected]017022b2009-07-27 23:06:34203 db_message_filter_ = new DBMessageFilter();
204 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13205
[email protected]80b161a2011-06-27 17:42:11206 vc_manager_ = new VideoCaptureImplManager();
207 AddFilter(vc_manager_->video_capture_message_filter());
[email protected]e25f4d72011-06-08 20:58:46208
[email protected]f7eb0a392011-07-12 10:19:51209 audio_input_message_filter_ = new AudioInputMessageFilter();
210 AddFilter(audio_input_message_filter_.get());
211
212 audio_message_filter_ = new AudioMessageFilter();
213 AddFilter(audio_message_filter_.get());
214
[email protected]82622452011-07-22 09:57:20215 devtools_agent_message_filter_ = new DevToolsAgentFilter();
216 AddFilter(devtools_agent_message_filter_.get());
217
[email protected]31bfae72011-12-16 02:04:38218 AddFilter(new IndexedDBMessageFilter);
219
[email protected]8d97ade2011-04-14 18:17:08220 content::GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24221
[email protected]f1a29a02011-10-06 23:08:44222 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29223}
224
[email protected]f1a29a02011-10-06 23:08:44225RenderThreadImpl::~RenderThreadImpl() {
[email protected]1223d6ef2011-03-28 16:47:50226 FOR_EACH_OBSERVER(
227 RenderProcessObserver, observers_, OnRenderProcessShutdown());
228
[email protected]12cbfda32010-01-30 01:04:25229 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08230 if (web_database_observer_impl_.get())
231 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25232
[email protected]8d86fce2009-02-26 23:37:55233 // Shutdown in reverse of the initialization order.
[email protected]82622452011-07-22 09:57:20234 RemoveFilter(devtools_agent_message_filter_.get());
235 devtools_agent_message_filter_ = NULL;
236
[email protected]f7eb0a392011-07-12 10:19:51237 RemoveFilter(audio_input_message_filter_.get());
238 audio_input_message_filter_ = NULL;
239
240 RemoveFilter(audio_message_filter_.get());
241 audio_message_filter_ = NULL;
242
[email protected]80b161a2011-06-27 17:42:11243 RemoveFilter(vc_manager_->video_capture_message_filter());
244
[email protected]017022b2009-07-27 23:06:34245 RemoveFilter(db_message_filter_.get());
246 db_message_filter_ = NULL;
[email protected]12cbfda32010-01-30 01:04:25247
[email protected]c6a7b862010-08-20 22:19:38248 // Shutdown the file thread if it's running.
249 if (file_thread_.get())
250 file_thread_->Stop();
251
[email protected]028217e2011-11-19 00:19:08252#ifdef WEBCOMPOSITOR_HAS_INITIALIZE
[email protected]2db58cf92011-12-01 21:39:01253 if (compositor_initialized_) {
254 WebKit::WebCompositor::shutdown();
255 compositor_initialized_ = false;
256 }
[email protected]028217e2011-11-19 00:19:08257#endif
[email protected]a9fb30aa2011-10-06 06:58:46258 if (compositor_thread_.get()) {
259 RemoveFilter(compositor_thread_->GetMessageFilter());
260 compositor_thread_.reset();
261 }
262
[email protected]8d6cba42011-09-02 10:05:19263 if (webkit_platform_support_.get())
[email protected]9291ed12009-07-23 17:33:22264 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22265
[email protected]94f9a0f682009-06-15 18:30:30266 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30267
[email protected]8d86fce2009-02-26 23:37:55268 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50269#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29270 // Clean up plugin channels before this thread goes away.
[email protected]099587b72011-09-20 00:40:50271 NPChannelBase::CleanupChannels();
[email protected]2c62b562009-01-27 19:04:50272#endif
initial.commit09911bf2008-07-26 23:55:29273}
274
[email protected]f1a29a02011-10-06 23:08:44275bool RenderThreadImpl::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14276 // Certain synchronous messages cannot always be processed synchronously by
277 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50278 // This could cause a complete hang of Chrome if a windowed plug-in is trying
279 // to communicate with the renderer thread since the browser's UI thread
280 // could be stuck (within a Windows API call) trying to synchronously
281 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14282 // thread while the browser is processing this request. This creates an
283 // opportunity for re-entrancy into WebKit, so we need to take care to disable
284 // callbacks, timers, and pending network loads that could trigger such
285 // callbacks.
[email protected]38b592902011-04-16 02:08:42286 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:50287 if (msg->is_sync()) {
288 if (msg->is_caller_pumping_messages()) {
289 pumping_events = true;
290 } else {
[email protected]38b592902011-04-16 02:08:42291 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
292 msg->type() == ViewHostMsg_GetRawCookies::ID ||
293 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
294 content::GetContentClient()->renderer()->
295 ShouldPumpEventsDuringCookieMessage()) {
296 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:50297 }
298 }
[email protected]c1f50aa2010-02-18 03:46:57299 }
300
[email protected]80fc08c52010-03-09 07:43:50301 bool suspend_webkit_shared_timer = true; // default value
302 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57303
[email protected]80fc08c52010-03-09 07:43:50304 bool notify_webkit_of_modal_loop = true; // default value
305 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
306
307 gfx::NativeViewId host_window = 0;
[email protected]c1f50aa2010-02-18 03:46:57308
309 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50310 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19311 webkit_platform_support_->SuspendSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57312
[email protected]39065d012010-07-09 11:22:46313 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57314 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57315
[email protected]80fc08c52010-03-09 07:43:50316 RenderWidget* widget =
317 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
318 if (widget) {
319 host_window = widget->host_window();
[email protected]c1f50aa2010-02-18 03:46:57320 PluginChannelHost::Broadcast(
321 new PluginMsg_SignalModalDialogEvent(host_window));
322 }
323 }
324
325 bool rv = ChildThread::Send(msg);
326
327 if (pumping_events) {
328 if (host_window) {
329 PluginChannelHost::Broadcast(
330 new PluginMsg_ResetModalDialogEvent(host_window));
331 }
332
[email protected]39065d012010-07-09 11:22:46333 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57334 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57335
[email protected]80fc08c52010-03-09 07:43:50336 if (suspend_webkit_shared_timer)
[email protected]8d6cba42011-09-02 10:05:19337 webkit_platform_support_->ResumeSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:57338 }
339
340 return rv;
341}
342
[email protected]f1a29a02011-10-06 23:08:44343MessageLoop* RenderThreadImpl::GetMessageLoop() {
[email protected]526476902011-10-06 20:34:06344 return message_loop();
345}
346
[email protected]f1a29a02011-10-06 23:08:44347IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:06348 return channel();
349}
350
[email protected]f1a29a02011-10-06 23:08:44351std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:06352 // The browser process should have passed the locale to the renderer via the
353 // --lang command line flag. In single process mode, this will return the
354 // wrong value. TODO(tc): Fix this for single process mode.
355 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
356 const std::string& lang =
357 parsed_command_line.GetSwitchValueASCII(switches::kLang);
358 DCHECK(!lang.empty() ||
359 (!parsed_command_line.HasSwitch(switches::kRendererProcess) &&
360 !parsed_command_line.HasSwitch(switches::kPluginProcess)));
361 return lang;
362}
363
[email protected]07bb6332012-01-21 01:07:57364IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
365 return sync_message_filter();
366}
367
[email protected]f1a29a02011-10-06 23:08:44368void RenderThreadImpl::AddRoute(int32 routing_id,
369 IPC::Channel::Listener* listener) {
[email protected]c1f50aa2010-02-18 03:46:57370 widget_count_++;
371 return ChildThread::AddRoute(routing_id, listener);
372}
373
[email protected]f1a29a02011-10-06 23:08:44374void RenderThreadImpl::RemoveRoute(int32 routing_id) {
[email protected]c1f50aa2010-02-18 03:46:57375 widget_count_--;
376 return ChildThread::RemoveRoute(routing_id);
377}
378
[email protected]77fc9b92011-10-15 16:20:37379int RenderThreadImpl::GenerateRoutingID() {
380 int routing_id = MSG_ROUTING_NONE;
381 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
382 return routing_id;
383}
384
[email protected]f1a29a02011-10-06 23:08:44385void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55386 channel()->AddFilter(filter);
387}
388
[email protected]f1a29a02011-10-06 23:08:44389void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:55390 channel()->RemoveFilter(filter);
391}
392
[email protected]f1a29a02011-10-06 23:08:44393void RenderThreadImpl::SetOutgoingMessageFilter(
[email protected]526476902011-10-06 20:34:06394 IPC::ChannelProxy::OutgoingMessageFilter* filter) {
395}
396
[email protected]f1a29a02011-10-06 23:08:44397void RenderThreadImpl::AddObserver(content::RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06398 observers_.AddObserver(observer);
399}
400
[email protected]f1a29a02011-10-06 23:08:44401void RenderThreadImpl::RemoveObserver(
402 content::RenderProcessObserver* observer) {
[email protected]526476902011-10-06 20:34:06403 observers_.RemoveObserver(observer);
404}
405
[email protected]359dfa32011-10-12 01:10:15406void RenderThreadImpl::SetResourceDispatcherDelegate(
407 content::ResourceDispatcherDelegate* delegate) {
408 resource_dispatcher()->set_delegate(delegate);
409}
410
[email protected]f1a29a02011-10-06 23:08:44411void RenderThreadImpl::WidgetHidden() {
[email protected]bee16aab2009-08-26 15:55:03412 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50413 hidden_widget_count_++;
[email protected]6779aa12011-03-29 17:32:24414
415 if (!content::GetContentClient()->renderer()->
416 RunIdleHandlerWhenWidgetsHidden()) {
417 return;
418 }
419
420 if (widget_count_ && hidden_widget_count_ == widget_count_)
[email protected]6593ae12011-11-14 12:09:44421 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
[email protected]bee16aab2009-08-26 15:55:03422}
423
[email protected]f1a29a02011-10-06 23:08:44424void RenderThreadImpl::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08425 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03426 hidden_widget_count_--;
[email protected]6779aa12011-03-29 17:32:24427 if (!content::GetContentClient()->renderer()->
428 RunIdleHandlerWhenWidgetsHidden()) {
429 return;
430 }
[email protected]bee16aab2009-08-26 15:55:03431
[email protected]1784b2f2011-11-24 10:53:48432 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]e4be2dd2010-12-14 00:44:39433}
434
[email protected]f1a29a02011-10-06 23:08:44435void RenderThreadImpl::EnsureWebKitInitialized() {
[email protected]8d6cba42011-09-02 10:05:19436 if (webkit_platform_support_.get())
[email protected]d1b8fccc2011-08-03 01:20:13437 return;
438
439 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
440 v8::V8::SetCreateHistogramFunction(CreateHistogram);
441 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
442
[email protected]8d6cba42011-09-02 10:05:19443 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
444 WebKit::initialize(webkit_platform_support_.get());
[email protected]d1b8fccc2011-08-03 01:20:13445
[email protected]f3150172011-10-22 02:28:45446 if (CommandLine::ForCurrentProcess()->HasSwitch(
447 switches::kEnableThreadedCompositing)) {
448 compositor_thread_.reset(new CompositorThread(this));
449 AddFilter(compositor_thread_->GetMessageFilter());
[email protected]028217e2011-11-19 00:19:08450#ifdef WEBCOMPOSITOR_HAS_INITIALIZE
451 WebKit::WebCompositor::initialize(compositor_thread_->GetWebThread());
452#else
453 WebKit::WebCompositor::setThread(compositor_thread_->GetWebThread());
454#endif
455 } else {
456#ifdef WEBCOMPOSITOR_HAS_INITIALIZE
457 WebKit::WebCompositor::initialize(NULL);
458#endif
[email protected]f3150172011-10-22 02:28:45459 }
[email protected]2db58cf92011-12-01 21:39:01460 compositor_initialized_ = true;
[email protected]a9fb30aa2011-10-06 06:58:46461
[email protected]d1b8fccc2011-08-03 01:20:13462 WebScriptController::enableV8SingleThreadMode();
463
464 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
465
466 webkit_glue::EnableWebCoreLogChannels(
467 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
468
[email protected]d1b8fccc2011-08-03 01:20:13469 if (command_line.HasSwitch(switches::kPlaybackMode) ||
470 command_line.HasSwitch(switches::kRecordMode) ||
471 command_line.HasSwitch(switches::kNoJsRandomness)) {
472 RegisterExtension(extensions_v8::PlaybackExtension::Get());
473 }
474
[email protected]526476902011-10-06 20:34:06475 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(Get()));
[email protected]d1b8fccc2011-08-03 01:20:13476 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
477
478 WebRuntimeFeatures::enableSockets(
479 !command_line.HasSwitch(switches::kDisableWebSockets));
480
481 WebRuntimeFeatures::enableDatabase(
482 !command_line.HasSwitch(switches::kDisableDatabases));
483
484 WebRuntimeFeatures::enableDataTransferItems(
485 !command_line.HasSwitch(switches::kDisableDataTransferItems));
486
487 WebRuntimeFeatures::enableApplicationCache(
488 !command_line.HasSwitch(switches::kDisableApplicationCache));
489
490 WebRuntimeFeatures::enableNotifications(
491 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
492
493 WebRuntimeFeatures::enableLocalStorage(
494 !command_line.HasSwitch(switches::kDisableLocalStorage));
495 WebRuntimeFeatures::enableSessionStorage(
496 !command_line.HasSwitch(switches::kDisableSessionStorage));
497
[email protected]b3796c82012-01-19 08:34:33498 WebRuntimeFeatures::enableIndexedDatabase(true);
[email protected]d1b8fccc2011-08-03 01:20:13499
500 WebRuntimeFeatures::enableGeolocation(
501 !command_line.HasSwitch(switches::kDisableGeolocation));
502
[email protected]6aa03b32011-10-27 21:44:44503 WebKit::WebRuntimeFeatures::enableMediaSource(
504 command_line.HasSwitch(switches::kEnableMediaSource));
505
[email protected]d1b8fccc2011-08-03 01:20:13506 WebKit::WebRuntimeFeatures::enableMediaStream(
507 command_line.HasSwitch(switches::kEnableMediaStream));
508
[email protected]efdc0282011-08-26 00:36:12509 WebKit::WebRuntimeFeatures::enableFullScreenAPI(
[email protected]5e5671a2011-09-08 02:12:21510 !command_line.HasSwitch(switches::kDisableFullScreen));
[email protected]efdc0282011-08-26 00:36:12511
[email protected]e4e68dbb2011-11-18 01:50:22512 WebKit::WebRuntimeFeatures::enablePointerLock(
513 command_line.HasSwitch(switches::kEnablePointerLock));
514
[email protected]f5da41d2011-10-08 17:40:07515 WebKit::WebRuntimeFeatures::enableVideoTrack(
516 command_line.HasSwitch(switches::kEnableVideoTrack));
517
[email protected]d1b8fccc2011-08-03 01:20:13518#if defined(OS_CHROMEOS)
519 // TODO(crogers): enable once Web Audio has been tested and optimized.
520 WebRuntimeFeatures::enableWebAudio(false);
521#else
522 WebRuntimeFeatures::enableWebAudio(
523 !command_line.HasSwitch(switches::kDisableWebAudio));
524#endif
525
526 WebRuntimeFeatures::enablePushState(true);
527
[email protected]d1b8fccc2011-08-03 01:20:13528 WebRuntimeFeatures::enableTouch(false);
[email protected]d1b8fccc2011-08-03 01:20:13529
530 WebRuntimeFeatures::enableDeviceMotion(
531 command_line.HasSwitch(switches::kEnableDeviceMotion));
532
533 WebRuntimeFeatures::enableDeviceOrientation(
534 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
535
536 WebRuntimeFeatures::enableSpeechInput(
537 !command_line.HasSwitch(switches::kDisableSpeechInput));
538
539 WebRuntimeFeatures::enableFileSystem(
540 !command_line.HasSwitch(switches::kDisableFileSystem));
541
542 WebRuntimeFeatures::enableJavaScriptI18NAPI(
543 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI));
544
[email protected]0205fbf2011-11-30 21:51:36545 WebRuntimeFeatures::enableGamepad(
546 command_line.HasSwitch(switches::kEnableGamepad));
547
[email protected]d1b8fccc2011-08-03 01:20:13548 WebRuntimeFeatures::enableQuota(true);
549
550 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized());
[email protected]1784b2f2011-11-24 10:53:48551
552 if (content::GetContentClient()->renderer()->
553 RunIdleHandlerWhenWidgetsHidden()) {
554 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
555 }
[email protected]d1b8fccc2011-08-03 01:20:13556}
557
[email protected]f1a29a02011-10-06 23:08:44558void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
[email protected]526476902011-10-06 20:34:06559 Send(new ViewHostMsg_UserMetricsRecordAction(action));
560}
561
[email protected]00614a82011-10-07 22:39:31562base::SharedMemoryHandle RenderThreadImpl::HostAllocateSharedMemoryBuffer(
[email protected]bdae9812011-10-15 00:33:03563 uint32 buffer_size) {
[email protected]00614a82011-10-07 22:39:31564 base::SharedMemoryHandle mem_handle;
[email protected]bdae9812011-10-15 00:33:03565 Send(new ChildProcessHostMsg_SyncAllocateSharedMemory(
566 buffer_size, &mem_handle));
[email protected]00614a82011-10-07 22:39:31567 return mem_handle;
568}
569
[email protected]f1a29a02011-10-06 23:08:44570void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:06571 WebScriptController::registerExtension(extension);
572 v8_extensions_.insert(extension->name());
573}
574
[email protected]f1a29a02011-10-06 23:08:44575bool RenderThreadImpl::IsRegisteredExtension(
[email protected]526476902011-10-06 20:34:06576 const std::string& v8_extension_name) const {
577 return v8_extensions_.find(v8_extension_name) != v8_extensions_.end();
578}
579
[email protected]6593ae12011-11-14 12:09:44580void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
581 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:06582 idle_timer_.Stop();
583 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:44584 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:44585 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:06586}
587
[email protected]f1a29a02011-10-06 23:08:44588void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:48589 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
590 content::GetContentClient()->renderer()->
591 RunIdleHandlerWhenWidgetsHidden();
592 if (run_in_foreground_tab) {
593 IdleHandlerInForegroundTab();
594 return;
595 }
596#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
[email protected]526476902011-10-06 20:34:06597 MallocExtension::instance()->ReleaseFreeMemory();
598#endif
599
600 v8::V8::IdleNotification();
601
602 // Schedule next invocation.
[email protected]6593ae12011-11-14 12:09:44603 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:06604 // delay = delay + 1 / (delay + 2)
605 // Using floor(delay) has a dampening effect such as:
606 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
[email protected]6593ae12011-11-14 12:09:44607 // If the delay is in milliseconds, the above formula is equivalent to:
608 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
609 // which is equivalent to
610 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
611 // Note that idle_notification_delay_in_ms_ would be reset to
612 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
613 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
614 1000000 / (idle_notification_delay_in_ms_ + 2000));
[email protected]526476902011-10-06 20:34:06615
616 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
617}
618
[email protected]1784b2f2011-11-24 10:53:48619void RenderThreadImpl::IdleHandlerInForegroundTab() {
620 // Increase the delay in the same way as in IdleHandler,
621 // but make it periodic by reseting it once it is too big.
622 int64 new_delay_ms = idle_notification_delay_in_ms_ +
623 1000000 / (idle_notification_delay_in_ms_ + 2000);
624 if (new_delay_ms >= kLongIdleHandlerDelayMs)
625 new_delay_ms = kShortIdleHandlerDelayMs;
626
[email protected]1784b2f2011-11-24 10:53:48627 if (idle_notifications_to_skip_ > 0) {
628 idle_notifications_to_skip_--;
[email protected]7e967f82011-12-01 09:35:14629 } else {
[email protected]a47105c832011-12-07 17:24:30630 int cpu_usage = 0;
[email protected]7e967f82011-12-01 09:35:14631 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
632 if (cpu_usage < kIdleCPUUsageThresholdInPercents &&
633 v8::V8::IdleNotification()) {
[email protected]1784b2f2011-11-24 10:53:48634 // V8 finished collecting garbage.
635 new_delay_ms = kLongIdleHandlerDelayMs;
636 }
637 }
[email protected]1784b2f2011-11-24 10:53:48638 ScheduleIdleHandler(new_delay_ms);
639}
640
[email protected]6593ae12011-11-14 12:09:44641int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
642 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:06643}
644
[email protected]6593ae12011-11-14 12:09:44645void RenderThreadImpl::SetIdleNotificationDelayInMs(
646 int64 idle_notification_delay_in_ms) {
647 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:08648}
649
[email protected]1784b2f2011-11-24 10:53:48650void RenderThreadImpl::PostponeIdleNotification() {
651 idle_notifications_to_skip_ = 2;
652}
653
[email protected]4a7d6392011-09-19 20:55:08654#if defined(OS_WIN)
[email protected]f1a29a02011-10-06 23:08:44655void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
[email protected]526476902011-10-06 20:34:06656 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
[email protected]79fff822011-09-20 03:33:21657}
658
[email protected]f1a29a02011-10-06 23:08:44659void RenderThreadImpl::ReleaseCachedFonts() {
[email protected]526476902011-10-06 20:34:06660 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
[email protected]4a7d6392011-09-19 20:55:08661}
[email protected]526476902011-10-06 20:34:06662
[email protected]4a7d6392011-09-19 20:55:08663#endif // OS_WIN
664
[email protected]f1a29a02011-10-06 23:08:44665int32 RenderThreadImpl::RoutingIDForCurrentContext() {
[email protected]526476902011-10-06 20:34:06666 int32 routing_id = MSG_ROUTING_CONTROL;
667 if (v8::Context::InContext()) {
668 WebFrame* frame = WebFrame::frameForCurrentContext();
669 if (frame) {
[email protected]310ebd6302011-10-10 19:06:28670 RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view());
[email protected]526476902011-10-06 20:34:06671 if (view)
672 routing_id = view->routing_id();
673 }
674 } else {
675 DLOG(WARNING) << "Not called within a script context!";
676 }
677 return routing_id;
678}
679
[email protected]f1a29a02011-10-06 23:08:44680void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
[email protected]526476902011-10-06 20:34:06681 suspend_webkit_shared_timer_ = false;
682}
683
[email protected]f1a29a02011-10-06 23:08:44684void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
[email protected]526476902011-10-06 20:34:06685 notify_webkit_of_modal_loop_ = false;
686}
687
[email protected]4e2a25a2012-01-27 00:42:08688void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& host,
[email protected]f1a29a02011-10-06 23:08:44689 double zoom_level) {
[email protected]4e2a25a2012-01-27 00:42:08690 RenderViewZoomer zoomer(host, zoom_level);
[email protected]310ebd6302011-10-10 19:06:28691 content::RenderView::ForEach(&zoomer);
[email protected]526476902011-10-06 20:34:06692}
693
[email protected]f1a29a02011-10-06 23:08:44694void RenderThreadImpl::OnDOMStorageEvent(
[email protected]526476902011-10-06 20:34:06695 const DOMStorageMsg_Event_Params& params) {
[email protected]0654cc82011-11-17 09:20:59696 if (!dom_storage_event_dispatcher_.get()) {
697 EnsureWebKitInitialized();
[email protected]526476902011-10-06 20:34:06698 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
[email protected]0654cc82011-11-17 09:20:59699 }
[email protected]526476902011-10-06 20:34:06700 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key,
701 params.old_value, params.new_value, params.origin, params.url,
702 params.storage_type == DOM_STORAGE_LOCAL);
703}
704
[email protected]f1a29a02011-10-06 23:08:44705bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]1223d6ef2011-03-28 16:47:50706 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
707 RenderProcessObserver* observer;
708 while ((observer = it.GetNext()) != NULL) {
709 if (observer->OnControlMessageReceived(msg))
710 return true;
711 }
712
[email protected]70c19a932010-05-14 12:59:11713 // Some messages are handled by delegates.
[email protected]f430b5712009-08-21 21:46:31714 if (appcache_dispatcher_->OnMessageReceived(msg))
[email protected]a95986a82010-12-24 06:19:28715 return true;
[email protected]1edc16b82009-04-07 17:45:54716
[email protected]a95986a82010-12-24 06:19:28717 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:44718 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]9d797f32010-04-23 07:17:54719 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
720 OnSetZoomLevelForCurrentURL)
[email protected]b9ab10c2009-08-07 18:09:55721 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
[email protected]8930d472009-02-21 08:05:28722 // TODO(port): removed from render_messages_internal.h;
723 // is there a new non-windows message I should add here?
724 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
[email protected]3e267192011-03-25 01:55:45725 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
[email protected]6eac57a2011-07-12 21:15:09726 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]3e267192011-03-25 01:55:45727 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent)
[email protected]b69934e2011-10-29 02:51:52728 IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData)
[email protected]a95986a82010-12-24 06:19:28729 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:28730 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28731 return handled;
initial.commit09911bf2008-07-26 23:55:29732}
733
[email protected]b9ab10c2009-08-07 18:09:55734// Called when to register CSS Color name->system color mappings.
735// We update the colors one by one and then tell WebKit to refresh all render
736// views.
[email protected]f1a29a02011-10-06 23:08:44737void RenderThreadImpl::OnSetCSSColors(
[email protected]b9ab10c2009-08-07 18:09:55738 const std::vector<CSSColors::CSSColorMapping>& colors) {
[email protected]f5e4b9bf2009-10-08 00:59:59739 EnsureWebKitInitialized();
[email protected]b9ab10c2009-08-07 18:09:55740 size_t num_colors = colors.size();
741 scoped_array<WebKit::WebColorName> color_names(
742 new WebKit::WebColorName[num_colors]);
743 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]);
744 size_t i = 0;
745 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it =
746 colors.begin();
747 it != colors.end();
748 ++it, ++i) {
749 color_names[i] = it->first;
750 web_colors[i] = it->second;
751 }
752 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors);
753}
754
[email protected]f1a29a02011-10-06 23:08:44755void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:47756 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:33757 // When bringing in render_view, also bring in webkit's glue and jsbindings.
[email protected]310ebd6302011-10-10 19:06:28758 RenderViewImpl::Create(
[email protected]8ab04652010-06-12 02:47:26759 params.parent_window,
760 MSG_ROUTING_NONE,
761 params.renderer_preferences,
762 params.web_preferences,
763 new SharedRenderViewCounter(0),
764 params.view_id,
[email protected]9f4f3322012-01-18 22:29:56765 params.surface_id,
[email protected]8ab04652010-06-12 02:47:26766 params.session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46767 params.frame_name,
768 params.next_page_id);
[email protected]7f874dec2009-02-06 01:48:27769}
[email protected]4274e582009-01-27 22:09:56770
[email protected]f1a29a02011-10-06 23:08:44771GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
[email protected]7f3a2cf2011-04-06 00:10:50772 content::CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]6217d392010-03-25 22:08:35773 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:22774 // Do nothing if we already have a GPU channel or are already
775 // establishing one.
[email protected]e09cee42010-11-09 01:50:08776 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
777 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]b42a9f62011-06-08 20:36:04778 return GetGpuChannel();
[email protected]6217d392010-03-25 22:08:35779
780 // Recreate the channel if it has been lost.
[email protected]e09cee42010-11-09 01:50:08781 if (gpu_channel_->state() == GpuChannelHost::kLost)
[email protected]6217d392010-03-25 22:08:35782 gpu_channel_ = NULL;
783 }
784
785 if (!gpu_channel_.get())
786 gpu_channel_ = new GpuChannelHost;
787
788 // Ask the browser for the channel name.
[email protected]b42a9f62011-06-08 20:36:04789 IPC::ChannelHandle channel_handle;
790 base::ProcessHandle renderer_process_for_gpu;
[email protected]a80f5ece2011-10-20 23:56:55791 content::GPUInfo gpu_info;
[email protected]b42a9f62011-06-08 20:36:04792 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch,
793 &channel_handle,
794 &renderer_process_for_gpu,
795 &gpu_info)) ||
796 channel_handle.name.empty() ||
797 renderer_process_for_gpu == base::kNullProcessHandle) {
798 // Otherwise cancel the connection.
799 gpu_channel_ = NULL;
800 return NULL;
801 }
[email protected]6217d392010-03-25 22:08:35802
[email protected]1749d142011-12-02 07:27:04803#if defined(OS_POSIX)
804 // Check the validity of fd for bug investigation. Replace with normal error
805 // handling (see above) after bug fixed. See for details: crbug.com/95732.
806 CHECK_NE(-1, channel_handle.socket.fd);
807#endif
808
[email protected]b42a9f62011-06-08 20:36:04809 gpu_channel_->set_gpu_info(gpu_info);
810 content::GetContentClient()->SetGpuInfo(gpu_info);
811
812 // Connect to the GPU process if a channel name was received.
813 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu);
814
[email protected]f9a2b2fe2010-07-15 21:13:23815 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:34816}
817
[email protected]f1a29a02011-10-06 23:08:44818GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
[email protected]6217d392010-03-25 22:08:35819 if (!gpu_channel_.get())
820 return NULL;
821
[email protected]e09cee42010-11-09 01:50:08822 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:35823 return NULL;
824
825 return gpu_channel_.get();
826}
827
[email protected]f1a29a02011-10-06 23:08:44828void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:59829 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:27830 // The call below will cause a GetPlugins call with refresh=true, but at this
831 // point we already know that the browser has refreshed its list, so disable
832 // refresh temporarily to prevent each renderer process causing the list to be
833 // regenerated.
834 plugin_refresh_allowed_ = false;
[email protected]b78e168b2009-09-21 22:05:45835 WebKit::resetPluginCache(reload_pages);
[email protected]b547fd42009-04-23 23:16:27836 plugin_refresh_allowed_ = true;
[email protected]3b48dbc2012-01-06 16:34:17837
838 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:27839}
[email protected]85c55dc2009-11-06 03:05:46840
[email protected]f1a29a02011-10-06 23:08:44841void RenderThreadImpl::OnNetworkStateChanged(bool online) {
[email protected]6eac57a2011-07-12 21:15:09842 EnsureWebKitInitialized();
843 WebNetworkStateNotifier::setOnLine(online);
844}
845
[email protected]b69934e2011-10-29 02:51:52846void RenderThreadImpl::OnTempCrashWithData(const GURL& data) {
[email protected]74ce1ad2011-12-16 21:51:46847 content::GetContentClient()->SetActiveURL(data);
[email protected]b69934e2011-10-29 02:51:52848 CHECK(false);
849}
850
[email protected]c6a7b862010-08-20 22:19:38851scoped_refptr<base::MessageLoopProxy>
[email protected]f1a29a02011-10-06 23:08:44852RenderThreadImpl::GetFileThreadMessageLoopProxy() {
[email protected]c6a7b862010-08-20 22:19:38853 DCHECK(message_loop() == MessageLoop::current());
854 if (!file_thread_.get()) {
855 file_thread_.reset(new base::Thread("Renderer::FILE"));
856 file_thread_->Start();
857 }
858 return file_thread_->message_loop_proxy();
859}