OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/render_thread.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 using WebKit::WebView; | 98 using WebKit::WebView; |
99 using content::RenderProcessObserver; | 99 using content::RenderProcessObserver; |
100 | 100 |
101 namespace { | 101 namespace { |
102 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; | 102 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; |
103 | 103 |
104 #if defined(TOUCH_UI) | 104 #if defined(TOUCH_UI) |
105 static const int kPopupListBoxMinimumRowHeight = 60; | 105 static const int kPopupListBoxMinimumRowHeight = 60; |
106 #endif | 106 #endif |
107 | 107 |
108 // Keep the global RenderThread in a TLS slot so it is impossible to access | 108 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
109 // incorrectly from the wrong thread. | 109 // incorrectly from the wrong thread. |
110 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( | 110 static base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > lazy_tls( |
111 base::LINKER_INITIALIZED); | 111 base::LINKER_INITIALIZED); |
112 | 112 |
113 class RenderViewZoomer : public content::RenderViewVisitor { | 113 class RenderViewZoomer : public content::RenderViewVisitor { |
114 public: | 114 public: |
115 RenderViewZoomer(const GURL& url, double zoom_level) | 115 RenderViewZoomer(const GURL& url, double zoom_level) |
116 : zoom_level_(zoom_level) { | 116 : zoom_level_(zoom_level) { |
117 host_ = net::GetHostOrSpecFromURL(url); | 117 host_ = net::GetHostOrSpecFromURL(url); |
118 } | 118 } |
119 | 119 |
120 virtual bool Visit(RenderView* render_view) { | 120 virtual bool Visit(RenderView* render_view) { |
(...skipping 12 matching lines...) Expand all Loading... |
133 | 133 |
134 private: | 134 private: |
135 std::string host_; | 135 std::string host_; |
136 double zoom_level_; | 136 double zoom_level_; |
137 | 137 |
138 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); | 138 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
139 }; | 139 }; |
140 | 140 |
141 } // namespace | 141 } // namespace |
142 | 142 |
143 // TODO(jam): move this to content/public/renderer/render_thread.cc once this fi
le is renamed | |
144 namespace content { | |
145 | |
146 // Keep the global RenderThread in a TLS slot so it is impossible to access | |
147 // incorrectly from the wrong thread. | |
148 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( | |
149 base::LINKER_INITIALIZED); | |
150 | |
151 RenderThread* RenderThread::Get() { | |
152 return lazy_tls.Pointer()->Get(); | |
153 } | |
154 | |
155 RenderThread::RenderThread() { | |
156 lazy_tls.Pointer()->Set(this); | |
157 } | |
158 | |
159 RenderThread::~RenderThread() { | |
160 lazy_tls.Pointer()->Set(NULL); | |
161 } | |
162 | |
163 } // namespace content | |
164 | |
165 | |
166 static void* CreateHistogram( | 143 static void* CreateHistogram( |
167 const char *name, int min, int max, size_t buckets) { | 144 const char *name, int min, int max, size_t buckets) { |
168 if (min <= 0) | 145 if (min <= 0) |
169 min = 1; | 146 min = 1; |
170 base::Histogram* histogram = base::Histogram::FactoryGet( | 147 base::Histogram* histogram = base::Histogram::FactoryGet( |
171 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); | 148 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag); |
172 return histogram; | 149 return histogram; |
173 } | 150 } |
174 | 151 |
175 static void AddHistogramSample(void* hist, int sample) { | 152 static void AddHistogramSample(void* hist, int sample) { |
176 base::Histogram* histogram = static_cast<base::Histogram*>(hist); | 153 base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
177 histogram->Add(sample); | 154 histogram->Add(sample); |
178 } | 155 } |
179 | 156 |
180 RenderThread* RenderThread::current() { | 157 RenderThreadImpl* RenderThreadImpl::current() { |
181 return lazy_tls.Pointer()->Get(); | 158 return lazy_tls.Pointer()->Get(); |
182 } | 159 } |
183 | 160 |
184 // When we run plugins in process, we actually run them on the render thread, | 161 // When we run plugins in process, we actually run them on the render thread, |
185 // which means that we need to make the render thread pump UI events. | 162 // which means that we need to make the render thread pump UI events. |
186 RenderThread::RenderThread() { | 163 RenderThreadImpl::RenderThreadImpl() { |
187 Init(); | 164 Init(); |
188 } | 165 } |
189 | 166 |
190 RenderThread::RenderThread(const std::string& channel_name) | 167 RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) |
191 : ChildThread(channel_name) { | 168 : ChildThread(channel_name) { |
192 Init(); | 169 Init(); |
193 } | 170 } |
194 | 171 |
195 void RenderThread::Init() { | 172 void RenderThreadImpl::Init() { |
196 TRACE_EVENT_BEGIN_ETW("RenderThread::Init", 0, ""); | 173 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
197 | 174 |
198 #if defined(OS_MACOSX) | 175 #if defined(OS_MACOSX) |
199 // On Mac, the select popups are rendered by the browser. | 176 // On Mac, the select popups are rendered by the browser. |
200 WebKit::WebView::setUseExternalPopupMenus(true); | 177 WebKit::WebView::setUseExternalPopupMenus(true); |
201 #endif | 178 #endif |
202 | 179 |
203 lazy_tls.Pointer()->Set(this); | 180 lazy_tls.Pointer()->Set(this); |
204 #if defined(OS_WIN) | 181 #if defined(OS_WIN) |
205 // If you are running plugins in this thread you need COM active but in | 182 // If you are running plugins in this thread you need COM active but in |
206 // the normal case you don't. | 183 // the normal case you don't. |
207 if (RenderProcessImpl::InProcessPlugins()) | 184 if (RenderProcessImpl::InProcessPlugins()) |
208 CoInitialize(0); | 185 CoInitialize(0); |
209 #endif | 186 #endif |
210 | 187 |
211 // In single process the single process is all there is. | 188 // In single process the single process is all there is. |
212 suspend_webkit_shared_timer_ = true; | 189 suspend_webkit_shared_timer_ = true; |
213 notify_webkit_of_modal_loop_ = true; | 190 notify_webkit_of_modal_loop_ = true; |
214 plugin_refresh_allowed_ = true; | 191 plugin_refresh_allowed_ = true; |
215 widget_count_ = 0; | 192 widget_count_ = 0; |
216 hidden_widget_count_ = 0; | 193 hidden_widget_count_ = 0; |
217 idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; | 194 idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; |
218 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); | 195 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this)); |
219 | 196 |
220 appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); | 197 appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); |
221 indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); | 198 indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
222 | 199 |
223 db_message_filter_ = new DBMessageFilter(); | 200 db_message_filter_ = new DBMessageFilter(); |
224 AddFilter(db_message_filter_.get()); | 201 AddFilter(db_message_filter_.get()); |
225 | 202 |
226 vc_manager_ = new VideoCaptureImplManager(); | 203 vc_manager_ = new VideoCaptureImplManager(); |
227 AddFilter(vc_manager_->video_capture_message_filter()); | 204 AddFilter(vc_manager_->video_capture_message_filter()); |
228 | 205 |
229 audio_input_message_filter_ = new AudioInputMessageFilter(); | 206 audio_input_message_filter_ = new AudioInputMessageFilter(); |
230 AddFilter(audio_input_message_filter_.get()); | 207 AddFilter(audio_input_message_filter_.get()); |
231 | 208 |
232 audio_message_filter_ = new AudioMessageFilter(); | 209 audio_message_filter_ = new AudioMessageFilter(); |
233 AddFilter(audio_message_filter_.get()); | 210 AddFilter(audio_message_filter_.get()); |
234 | 211 |
235 devtools_agent_message_filter_ = new DevToolsAgentFilter(); | 212 devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
236 AddFilter(devtools_agent_message_filter_.get()); | 213 AddFilter(devtools_agent_message_filter_.get()); |
237 | 214 |
238 content::GetContentClient()->renderer()->RenderThreadStarted(); | 215 content::GetContentClient()->renderer()->RenderThreadStarted(); |
239 | 216 |
240 TRACE_EVENT_END_ETW("RenderThread::Init", 0, ""); | 217 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); |
241 } | 218 } |
242 | 219 |
243 RenderThread::~RenderThread() { | 220 RenderThreadImpl::~RenderThreadImpl() { |
244 FOR_EACH_OBSERVER( | 221 FOR_EACH_OBSERVER( |
245 RenderProcessObserver, observers_, OnRenderProcessShutdown()); | 222 RenderProcessObserver, observers_, OnRenderProcessShutdown()); |
246 | 223 |
247 // Wait for all databases to be closed. | 224 // Wait for all databases to be closed. |
248 if (web_database_observer_impl_.get()) | 225 if (web_database_observer_impl_.get()) |
249 web_database_observer_impl_->WaitForAllDatabasesToClose(); | 226 web_database_observer_impl_->WaitForAllDatabasesToClose(); |
250 | 227 |
251 // Shutdown in reverse of the initialization order. | 228 // Shutdown in reverse of the initialization order. |
252 RemoveFilter(devtools_agent_message_filter_.get()); | 229 RemoveFilter(devtools_agent_message_filter_.get()); |
253 devtools_agent_message_filter_ = NULL; | 230 devtools_agent_message_filter_ = NULL; |
(...skipping 26 matching lines...) Expand all Loading... |
280 // TODO(port) | 257 // TODO(port) |
281 #if defined(OS_WIN) | 258 #if defined(OS_WIN) |
282 // Clean up plugin channels before this thread goes away. | 259 // Clean up plugin channels before this thread goes away. |
283 NPChannelBase::CleanupChannels(); | 260 NPChannelBase::CleanupChannels(); |
284 // Don't call COM if the renderer is in the sandbox. | 261 // Don't call COM if the renderer is in the sandbox. |
285 if (RenderProcessImpl::InProcessPlugins()) | 262 if (RenderProcessImpl::InProcessPlugins()) |
286 CoUninitialize(); | 263 CoUninitialize(); |
287 #endif | 264 #endif |
288 } | 265 } |
289 | 266 |
290 bool RenderThread::Send(IPC::Message* msg) { | 267 bool RenderThreadImpl::Send(IPC::Message* msg) { |
291 // Certain synchronous messages cannot always be processed synchronously by | 268 // Certain synchronous messages cannot always be processed synchronously by |
292 // the browser, e.g., Chrome frame communicating with the embedding browser. | 269 // the browser, e.g., Chrome frame communicating with the embedding browser. |
293 // This could cause a complete hang of Chrome if a windowed plug-in is trying | 270 // This could cause a complete hang of Chrome if a windowed plug-in is trying |
294 // to communicate with the renderer thread since the browser's UI thread | 271 // to communicate with the renderer thread since the browser's UI thread |
295 // could be stuck (within a Windows API call) trying to synchronously | 272 // could be stuck (within a Windows API call) trying to synchronously |
296 // communicate with the plug-in. The remedy is to pump messages on this | 273 // communicate with the plug-in. The remedy is to pump messages on this |
297 // thread while the browser is processing this request. This creates an | 274 // thread while the browser is processing this request. This creates an |
298 // opportunity for re-entrancy into WebKit, so we need to take care to disable | 275 // opportunity for re-entrancy into WebKit, so we need to take care to disable |
299 // callbacks, timers, and pending network loads that could trigger such | 276 // callbacks, timers, and pending network loads that could trigger such |
300 // callbacks. | 277 // callbacks. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 if (notify_webkit_of_modal_loop) | 325 if (notify_webkit_of_modal_loop) |
349 WebView::didExitModalLoop(); | 326 WebView::didExitModalLoop(); |
350 | 327 |
351 if (suspend_webkit_shared_timer) | 328 if (suspend_webkit_shared_timer) |
352 webkit_platform_support_->ResumeSharedTimer(); | 329 webkit_platform_support_->ResumeSharedTimer(); |
353 } | 330 } |
354 | 331 |
355 return rv; | 332 return rv; |
356 } | 333 } |
357 | 334 |
358 MessageLoop* RenderThread::GetMessageLoop() { | 335 MessageLoop* RenderThreadImpl::GetMessageLoop() { |
359 return message_loop(); | 336 return message_loop(); |
360 } | 337 } |
361 | 338 |
362 IPC::SyncChannel* RenderThread::GetChannel() { | 339 IPC::SyncChannel* RenderThreadImpl::GetChannel() { |
363 return channel(); | 340 return channel(); |
364 } | 341 } |
365 | 342 |
366 ResourceDispatcher* RenderThread::GetResourceDispatcher() { | 343 ResourceDispatcher* RenderThreadImpl::GetResourceDispatcher() { |
367 return resource_dispatcher(); | 344 return resource_dispatcher(); |
368 } | 345 } |
369 | 346 |
370 std::string RenderThread::GetLocale() { | 347 std::string RenderThreadImpl::GetLocale() { |
371 // The browser process should have passed the locale to the renderer via the | 348 // The browser process should have passed the locale to the renderer via the |
372 // --lang command line flag. In single process mode, this will return the | 349 // --lang command line flag. In single process mode, this will return the |
373 // wrong value. TODO(tc): Fix this for single process mode. | 350 // wrong value. TODO(tc): Fix this for single process mode. |
374 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 351 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
375 const std::string& lang = | 352 const std::string& lang = |
376 parsed_command_line.GetSwitchValueASCII(switches::kLang); | 353 parsed_command_line.GetSwitchValueASCII(switches::kLang); |
377 DCHECK(!lang.empty() || | 354 DCHECK(!lang.empty() || |
378 (!parsed_command_line.HasSwitch(switches::kRendererProcess) && | 355 (!parsed_command_line.HasSwitch(switches::kRendererProcess) && |
379 !parsed_command_line.HasSwitch(switches::kPluginProcess))); | 356 !parsed_command_line.HasSwitch(switches::kPluginProcess))); |
380 return lang; | 357 return lang; |
381 } | 358 } |
382 | 359 |
383 void RenderThread::AddRoute(int32 routing_id, | 360 void RenderThreadImpl::AddRoute(int32 routing_id, |
384 IPC::Channel::Listener* listener) { | 361 IPC::Channel::Listener* listener) { |
385 widget_count_++; | 362 widget_count_++; |
386 return ChildThread::AddRoute(routing_id, listener); | 363 return ChildThread::AddRoute(routing_id, listener); |
387 } | 364 } |
388 | 365 |
389 void RenderThread::RemoveRoute(int32 routing_id) { | 366 void RenderThreadImpl::RemoveRoute(int32 routing_id) { |
390 widget_count_--; | 367 widget_count_--; |
391 return ChildThread::RemoveRoute(routing_id); | 368 return ChildThread::RemoveRoute(routing_id); |
392 } | 369 } |
393 | 370 |
394 void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { | 371 void RenderThreadImpl::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
395 channel()->AddFilter(filter); | 372 channel()->AddFilter(filter); |
396 } | 373 } |
397 | 374 |
398 void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { | 375 void RenderThreadImpl::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
399 channel()->RemoveFilter(filter); | 376 channel()->RemoveFilter(filter); |
400 } | 377 } |
401 | 378 |
402 void RenderThread::SetOutgoingMessageFilter( | 379 void RenderThreadImpl::SetOutgoingMessageFilter( |
403 IPC::ChannelProxy::OutgoingMessageFilter* filter) { | 380 IPC::ChannelProxy::OutgoingMessageFilter* filter) { |
404 } | 381 } |
405 | 382 |
406 void RenderThread::AddObserver(content::RenderProcessObserver* observer) { | 383 void RenderThreadImpl::AddObserver(content::RenderProcessObserver* observer) { |
407 observers_.AddObserver(observer); | 384 observers_.AddObserver(observer); |
408 } | 385 } |
409 | 386 |
410 void RenderThread::RemoveObserver(content::RenderProcessObserver* observer) { | 387 void RenderThreadImpl::RemoveObserver( |
| 388 content::RenderProcessObserver* observer) { |
411 observers_.RemoveObserver(observer); | 389 observers_.RemoveObserver(observer); |
412 } | 390 } |
413 | 391 |
414 void RenderThread::WidgetHidden() { | 392 void RenderThreadImpl::WidgetHidden() { |
415 DCHECK(hidden_widget_count_ < widget_count_); | 393 DCHECK(hidden_widget_count_ < widget_count_); |
416 hidden_widget_count_++; | 394 hidden_widget_count_++; |
417 | 395 |
418 if (!content::GetContentClient()->renderer()-> | 396 if (!content::GetContentClient()->renderer()-> |
419 RunIdleHandlerWhenWidgetsHidden()) { | 397 RunIdleHandlerWhenWidgetsHidden()) { |
420 return; | 398 return; |
421 } | 399 } |
422 | 400 |
423 if (widget_count_ && hidden_widget_count_ == widget_count_) | 401 if (widget_count_ && hidden_widget_count_ == widget_count_) |
424 ScheduleIdleHandler(kInitialIdleHandlerDelayS); | 402 ScheduleIdleHandler(kInitialIdleHandlerDelayS); |
425 } | 403 } |
426 | 404 |
427 void RenderThread::WidgetRestored() { | 405 void RenderThreadImpl::WidgetRestored() { |
428 DCHECK_GT(hidden_widget_count_, 0); | 406 DCHECK_GT(hidden_widget_count_, 0); |
429 hidden_widget_count_--; | 407 hidden_widget_count_--; |
430 if (!content::GetContentClient()->renderer()-> | 408 if (!content::GetContentClient()->renderer()-> |
431 RunIdleHandlerWhenWidgetsHidden()) { | 409 RunIdleHandlerWhenWidgetsHidden()) { |
432 return; | 410 return; |
433 } | 411 } |
434 | 412 |
435 idle_timer_.Stop(); | 413 idle_timer_.Stop(); |
436 } | 414 } |
437 | 415 |
438 void RenderThread::EnsureWebKitInitialized() { | 416 void RenderThreadImpl::EnsureWebKitInitialized() { |
439 if (webkit_platform_support_.get()) | 417 if (webkit_platform_support_.get()) |
440 return; | 418 return; |
441 | 419 |
442 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); | 420 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
443 v8::V8::SetCreateHistogramFunction(CreateHistogram); | 421 v8::V8::SetCreateHistogramFunction(CreateHistogram); |
444 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); | 422 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample); |
445 | 423 |
446 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); | 424 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
447 WebKit::initialize(webkit_platform_support_.get()); | 425 WebKit::initialize(webkit_platform_support_.get()); |
448 | 426 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 !command_line.HasSwitch(switches::kDisableFileSystem)); | 506 !command_line.HasSwitch(switches::kDisableFileSystem)); |
529 | 507 |
530 WebRuntimeFeatures::enableJavaScriptI18NAPI( | 508 WebRuntimeFeatures::enableJavaScriptI18NAPI( |
531 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)); | 509 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI)); |
532 | 510 |
533 WebRuntimeFeatures::enableQuota(true); | 511 WebRuntimeFeatures::enableQuota(true); |
534 | 512 |
535 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized()); | 513 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, WebKitInitialized()); |
536 } | 514 } |
537 | 515 |
538 void RenderThread::RecordUserMetrics(const std::string& action) { | 516 void RenderThreadImpl::RecordUserMetrics(const std::string& action) { |
539 Send(new ViewHostMsg_UserMetricsRecordAction(action)); | 517 Send(new ViewHostMsg_UserMetricsRecordAction(action)); |
540 } | 518 } |
541 | 519 |
542 void RenderThread::RegisterExtension(v8::Extension* extension) { | 520 void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
543 WebScriptController::registerExtension(extension); | 521 WebScriptController::registerExtension(extension); |
544 v8_extensions_.insert(extension->name()); | 522 v8_extensions_.insert(extension->name()); |
545 } | 523 } |
546 | 524 |
547 bool RenderThread::IsRegisteredExtension( | 525 bool RenderThreadImpl::IsRegisteredExtension( |
548 const std::string& v8_extension_name) const { | 526 const std::string& v8_extension_name) const { |
549 return v8_extensions_.find(v8_extension_name) != v8_extensions_.end(); | 527 return v8_extensions_.find(v8_extension_name) != v8_extensions_.end(); |
550 } | 528 } |
551 | 529 |
552 void RenderThread::ScheduleIdleHandler(double initial_delay_s) { | 530 void RenderThreadImpl::ScheduleIdleHandler(double initial_delay_s) { |
553 idle_notification_delay_in_s_ = initial_delay_s; | 531 idle_notification_delay_in_s_ = initial_delay_s; |
554 idle_timer_.Stop(); | 532 idle_timer_.Stop(); |
555 idle_timer_.Start(FROM_HERE, | 533 idle_timer_.Start(FROM_HERE, |
556 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), | 534 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), |
557 this, &RenderThread::IdleHandler); | 535 this, &RenderThreadImpl::IdleHandler); |
558 } | 536 } |
559 | 537 |
560 void RenderThread::IdleHandler() { | 538 void RenderThreadImpl::IdleHandler() { |
561 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 539 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
562 MallocExtension::instance()->ReleaseFreeMemory(); | 540 MallocExtension::instance()->ReleaseFreeMemory(); |
563 #endif | 541 #endif |
564 | 542 |
565 v8::V8::IdleNotification(); | 543 v8::V8::IdleNotification(); |
566 | 544 |
567 // Schedule next invocation. | 545 // Schedule next invocation. |
568 // Dampen the delay using the algorithm: | 546 // Dampen the delay using the algorithm: |
569 // delay = delay + 1 / (delay + 2) | 547 // delay = delay + 1 / (delay + 2) |
570 // Using floor(delay) has a dampening effect such as: | 548 // Using floor(delay) has a dampening effect such as: |
571 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... | 549 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
572 // Note that idle_notification_delay_in_s_ would be reset to | 550 // Note that idle_notification_delay_in_s_ would be reset to |
573 // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden. | 551 // kInitialIdleHandlerDelayS in RenderThreadImpl::WidgetHidden. |
574 ScheduleIdleHandler(idle_notification_delay_in_s_ + | 552 ScheduleIdleHandler(idle_notification_delay_in_s_ + |
575 1.0 / (idle_notification_delay_in_s_ + 2.0)); | 553 1.0 / (idle_notification_delay_in_s_ + 2.0)); |
576 | 554 |
577 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); | 555 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
578 } | 556 } |
579 | 557 |
580 double RenderThread::GetIdleNotificationDelayInS() const { | 558 double RenderThreadImpl::GetIdleNotificationDelayInS() const { |
581 return idle_notification_delay_in_s_; | 559 return idle_notification_delay_in_s_; |
582 } | 560 } |
583 | 561 |
584 void RenderThread::SetIdleNotificationDelayInS( | 562 void RenderThreadImpl::SetIdleNotificationDelayInS( |
585 double idle_notification_delay_in_s) { | 563 double idle_notification_delay_in_s) { |
586 idle_notification_delay_in_s_ = idle_notification_delay_in_s; | 564 idle_notification_delay_in_s_ = idle_notification_delay_in_s; |
587 } | 565 } |
588 | 566 |
589 #if defined(OS_WIN) | 567 #if defined(OS_WIN) |
590 void RenderThread::PreCacheFont(const LOGFONT& log_font) { | 568 void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
591 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); | 569 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
592 } | 570 } |
593 | 571 |
594 void RenderThread::ReleaseCachedFonts() { | 572 void RenderThreadImpl::ReleaseCachedFonts() { |
595 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); | 573 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
596 } | 574 } |
597 | 575 |
598 #endif // OS_WIN | 576 #endif // OS_WIN |
599 | 577 |
600 int32 RenderThread::RoutingIDForCurrentContext() { | 578 int32 RenderThreadImpl::RoutingIDForCurrentContext() { |
601 int32 routing_id = MSG_ROUTING_CONTROL; | 579 int32 routing_id = MSG_ROUTING_CONTROL; |
602 if (v8::Context::InContext()) { | 580 if (v8::Context::InContext()) { |
603 WebFrame* frame = WebFrame::frameForCurrentContext(); | 581 WebFrame* frame = WebFrame::frameForCurrentContext(); |
604 if (frame) { | 582 if (frame) { |
605 RenderView* view = RenderView::FromWebView(frame->view()); | 583 RenderView* view = RenderView::FromWebView(frame->view()); |
606 if (view) | 584 if (view) |
607 routing_id = view->routing_id(); | 585 routing_id = view->routing_id(); |
608 } | 586 } |
609 } else { | 587 } else { |
610 DLOG(WARNING) << "Not called within a script context!"; | 588 DLOG(WARNING) << "Not called within a script context!"; |
611 } | 589 } |
612 return routing_id; | 590 return routing_id; |
613 } | 591 } |
614 | 592 |
615 void RenderThread::DoNotSuspendWebKitSharedTimer() { | 593 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
616 suspend_webkit_shared_timer_ = false; | 594 suspend_webkit_shared_timer_ = false; |
617 } | 595 } |
618 | 596 |
619 void RenderThread::DoNotNotifyWebKitOfModalLoop() { | 597 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
620 notify_webkit_of_modal_loop_ = false; | 598 notify_webkit_of_modal_loop_ = false; |
621 } | 599 } |
622 | 600 |
623 void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url, | 601 void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const GURL& url, |
624 double zoom_level) { | 602 double zoom_level) { |
625 RenderViewZoomer zoomer(url, zoom_level); | 603 RenderViewZoomer zoomer(url, zoom_level); |
626 RenderView::ForEach(&zoomer); | 604 RenderView::ForEach(&zoomer); |
627 } | 605 } |
628 | 606 |
629 void RenderThread::OnDOMStorageEvent( | 607 void RenderThreadImpl::OnDOMStorageEvent( |
630 const DOMStorageMsg_Event_Params& params) { | 608 const DOMStorageMsg_Event_Params& params) { |
631 if (!dom_storage_event_dispatcher_.get()) | 609 if (!dom_storage_event_dispatcher_.get()) |
632 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); | 610 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); |
633 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key, | 611 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key, |
634 params.old_value, params.new_value, params.origin, params.url, | 612 params.old_value, params.new_value, params.origin, params.url, |
635 params.storage_type == DOM_STORAGE_LOCAL); | 613 params.storage_type == DOM_STORAGE_LOCAL); |
636 } | 614 } |
637 | 615 |
638 bool RenderThread::OnControlMessageReceived(const IPC::Message& msg) { | 616 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
639 ObserverListBase<RenderProcessObserver>::Iterator it(observers_); | 617 ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |
640 RenderProcessObserver* observer; | 618 RenderProcessObserver* observer; |
641 while ((observer = it.GetNext()) != NULL) { | 619 while ((observer = it.GetNext()) != NULL) { |
642 if (observer->OnControlMessageReceived(msg)) | 620 if (observer->OnControlMessageReceived(msg)) |
643 return true; | 621 return true; |
644 } | 622 } |
645 | 623 |
646 // Some messages are handled by delegates. | 624 // Some messages are handled by delegates. |
647 if (appcache_dispatcher_->OnMessageReceived(msg)) | 625 if (appcache_dispatcher_->OnMessageReceived(msg)) |
648 return true; | 626 return true; |
649 if (indexed_db_dispatcher_->OnMessageReceived(msg)) | 627 if (indexed_db_dispatcher_->OnMessageReceived(msg)) |
650 return true; | 628 return true; |
651 | 629 |
652 bool handled = true; | 630 bool handled = true; |
653 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) | 631 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |
654 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, | 632 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |
655 OnSetZoomLevelForCurrentURL) | 633 OnSetZoomLevelForCurrentURL) |
656 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) | 634 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) |
657 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) | 635 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |
658 // TODO(port): removed from render_messages_internal.h; | 636 // TODO(port): removed from render_messages_internal.h; |
659 // is there a new non-windows message I should add here? | 637 // is there a new non-windows message I should add here? |
660 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) | 638 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
661 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) | 639 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |
662 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) | 640 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) |
663 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) | 641 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) |
664 IPC_MESSAGE_UNHANDLED(handled = false) | 642 IPC_MESSAGE_UNHANDLED(handled = false) |
665 IPC_END_MESSAGE_MAP() | 643 IPC_END_MESSAGE_MAP() |
666 return handled; | 644 return handled; |
667 } | 645 } |
668 | 646 |
669 void RenderThread::OnSetNextPageID(int32 next_page_id) { | 647 void RenderThreadImpl::OnSetNextPageID(int32 next_page_id) { |
670 // This should only be called at process initialization time, so we shouldn't | 648 // This should only be called at process initialization time, so we shouldn't |
671 // have to worry about thread-safety. | 649 // have to worry about thread-safety. |
672 RenderView::SetNextPageID(next_page_id); | 650 RenderView::SetNextPageID(next_page_id); |
673 } | 651 } |
674 | 652 |
675 // Called when to register CSS Color name->system color mappings. | 653 // Called when to register CSS Color name->system color mappings. |
676 // We update the colors one by one and then tell WebKit to refresh all render | 654 // We update the colors one by one and then tell WebKit to refresh all render |
677 // views. | 655 // views. |
678 void RenderThread::OnSetCSSColors( | 656 void RenderThreadImpl::OnSetCSSColors( |
679 const std::vector<CSSColors::CSSColorMapping>& colors) { | 657 const std::vector<CSSColors::CSSColorMapping>& colors) { |
680 EnsureWebKitInitialized(); | 658 EnsureWebKitInitialized(); |
681 size_t num_colors = colors.size(); | 659 size_t num_colors = colors.size(); |
682 scoped_array<WebKit::WebColorName> color_names( | 660 scoped_array<WebKit::WebColorName> color_names( |
683 new WebKit::WebColorName[num_colors]); | 661 new WebKit::WebColorName[num_colors]); |
684 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); | 662 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]); |
685 size_t i = 0; | 663 size_t i = 0; |
686 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = | 664 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it = |
687 colors.begin(); | 665 colors.begin(); |
688 it != colors.end(); | 666 it != colors.end(); |
689 ++it, ++i) { | 667 ++it, ++i) { |
690 color_names[i] = it->first; | 668 color_names[i] = it->first; |
691 web_colors[i] = it->second; | 669 web_colors[i] = it->second; |
692 } | 670 } |
693 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); | 671 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors); |
694 } | 672 } |
695 | 673 |
696 void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) { | 674 void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) { |
697 EnsureWebKitInitialized(); | 675 EnsureWebKitInitialized(); |
698 // When bringing in render_view, also bring in webkit's glue and jsbindings. | 676 // When bringing in render_view, also bring in webkit's glue and jsbindings. |
699 RenderView::Create( | 677 RenderView::Create( |
700 this, | 678 this, |
701 params.parent_window, | 679 params.parent_window, |
702 MSG_ROUTING_NONE, | 680 MSG_ROUTING_NONE, |
703 params.renderer_preferences, | 681 params.renderer_preferences, |
704 params.web_preferences, | 682 params.web_preferences, |
705 new SharedRenderViewCounter(0), | 683 new SharedRenderViewCounter(0), |
706 params.view_id, | 684 params.view_id, |
707 params.session_storage_namespace_id, | 685 params.session_storage_namespace_id, |
708 params.frame_name); | 686 params.frame_name); |
709 } | 687 } |
710 | 688 |
711 GpuChannelHost* RenderThread::EstablishGpuChannelSync( | 689 GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync( |
712 content::CauseForGpuLaunch cause_for_gpu_launch) { | 690 content::CauseForGpuLaunch cause_for_gpu_launch) { |
713 if (gpu_channel_.get()) { | 691 if (gpu_channel_.get()) { |
714 // Do nothing if we already have a GPU channel or are already | 692 // Do nothing if we already have a GPU channel or are already |
715 // establishing one. | 693 // establishing one. |
716 if (gpu_channel_->state() == GpuChannelHost::kUnconnected || | 694 if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
717 gpu_channel_->state() == GpuChannelHost::kConnected) | 695 gpu_channel_->state() == GpuChannelHost::kConnected) |
718 return GetGpuChannel(); | 696 return GetGpuChannel(); |
719 | 697 |
720 // Recreate the channel if it has been lost. | 698 // Recreate the channel if it has been lost. |
721 if (gpu_channel_->state() == GpuChannelHost::kLost) | 699 if (gpu_channel_->state() == GpuChannelHost::kLost) |
(...skipping 20 matching lines...) Expand all Loading... |
742 | 720 |
743 gpu_channel_->set_gpu_info(gpu_info); | 721 gpu_channel_->set_gpu_info(gpu_info); |
744 content::GetContentClient()->SetGpuInfo(gpu_info); | 722 content::GetContentClient()->SetGpuInfo(gpu_info); |
745 | 723 |
746 // Connect to the GPU process if a channel name was received. | 724 // Connect to the GPU process if a channel name was received. |
747 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); | 725 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); |
748 | 726 |
749 return GetGpuChannel(); | 727 return GetGpuChannel(); |
750 } | 728 } |
751 | 729 |
752 GpuChannelHost* RenderThread::GetGpuChannel() { | 730 GpuChannelHost* RenderThreadImpl::GetGpuChannel() { |
753 if (!gpu_channel_.get()) | 731 if (!gpu_channel_.get()) |
754 return NULL; | 732 return NULL; |
755 | 733 |
756 if (gpu_channel_->state() != GpuChannelHost::kConnected) | 734 if (gpu_channel_->state() != GpuChannelHost::kConnected) |
757 return NULL; | 735 return NULL; |
758 | 736 |
759 return gpu_channel_.get(); | 737 return gpu_channel_.get(); |
760 } | 738 } |
761 | 739 |
762 void RenderThread::OnPurgePluginListCache(bool reload_pages) { | 740 void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) { |
763 EnsureWebKitInitialized(); | 741 EnsureWebKitInitialized(); |
764 // The call below will cause a GetPlugins call with refresh=true, but at this | 742 // The call below will cause a GetPlugins call with refresh=true, but at this |
765 // point we already know that the browser has refreshed its list, so disable | 743 // point we already know that the browser has refreshed its list, so disable |
766 // refresh temporarily to prevent each renderer process causing the list to be | 744 // refresh temporarily to prevent each renderer process causing the list to be |
767 // regenerated. | 745 // regenerated. |
768 plugin_refresh_allowed_ = false; | 746 plugin_refresh_allowed_ = false; |
769 WebKit::resetPluginCache(reload_pages); | 747 WebKit::resetPluginCache(reload_pages); |
770 plugin_refresh_allowed_ = true; | 748 plugin_refresh_allowed_ = true; |
771 } | 749 } |
772 | 750 |
773 void RenderThread::OnNetworkStateChanged(bool online) { | 751 void RenderThreadImpl::OnNetworkStateChanged(bool online) { |
774 EnsureWebKitInitialized(); | 752 EnsureWebKitInitialized(); |
775 WebNetworkStateNotifier::setOnLine(online); | 753 WebNetworkStateNotifier::setOnLine(online); |
776 } | 754 } |
777 | 755 |
778 scoped_refptr<base::MessageLoopProxy> | 756 scoped_refptr<base::MessageLoopProxy> |
779 RenderThread::GetFileThreadMessageLoopProxy() { | 757 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
780 DCHECK(message_loop() == MessageLoop::current()); | 758 DCHECK(message_loop() == MessageLoop::current()); |
781 if (!file_thread_.get()) { | 759 if (!file_thread_.get()) { |
782 file_thread_.reset(new base::Thread("Renderer::FILE")); | 760 file_thread_.reset(new base::Thread("Renderer::FILE")); |
783 file_thread_->Start(); | 761 file_thread_->Start(); |
784 } | 762 } |
785 return file_thread_->message_loop_proxy(); | 763 return file_thread_->message_loop_proxy(); |
786 } | 764 } |
OLD | NEW |