OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/renderer_host/resource_message_filter.h" | 5 #include "chrome/browser/renderer_host/resource_message_filter.h" |
6 | 6 |
7 #include "app/clipboard/clipboard.h" | 7 #include "app/clipboard/clipboard.h" |
8 #include "app/gfx/native_widget_types.h" | 8 #include "app/gfx/native_widget_types.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 base::ProcessHandle peer_handle; | 227 base::ProcessHandle peer_handle; |
228 if (!base::OpenProcessHandle(peer_pid, &peer_handle)) { | 228 if (!base::OpenProcessHandle(peer_pid, &peer_handle)) { |
229 NOTREACHED(); | 229 NOTREACHED(); |
230 } | 230 } |
231 set_handle(peer_handle); | 231 set_handle(peer_handle); |
232 | 232 |
233 // Hook AudioRendererHost to this object after channel is connected so it can | 233 // Hook AudioRendererHost to this object after channel is connected so it can |
234 // this object for sending messages. | 234 // this object for sending messages. |
235 audio_renderer_host_->IPCChannelConnected(id(), handle(), this); | 235 audio_renderer_host_->IPCChannelConnected(id(), handle(), this); |
236 | 236 |
237 WorkerService::GetInstance()->Initialize( | 237 WorkerService::GetInstance()->Initialize(resource_dispatcher_host_); |
238 resource_dispatcher_host_, ui_loop()); | |
239 appcache_dispatcher_host_->Initialize(this, id(), handle()); | 238 appcache_dispatcher_host_->Initialize(this, id(), handle()); |
240 socket_stream_dispatcher_host_->Initialize(this, id()); | 239 socket_stream_dispatcher_host_->Initialize(this, id()); |
241 dom_storage_dispatcher_host_->Init(handle()); | 240 dom_storage_dispatcher_host_->Init(handle()); |
242 } | 241 } |
243 | 242 |
244 void ResourceMessageFilter::OnChannelError() { | 243 void ResourceMessageFilter::OnChannelError() { |
245 NotificationService::current()->Notify( | 244 NotificationService::current()->Notify( |
246 NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, | 245 NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, |
247 Source<ResourceMessageFilter>(this), | 246 Source<ResourceMessageFilter>(this), |
248 NotificationService::NoDetails()); | 247 NotificationService::NoDetails()); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 &misspell_location, &misspell_length, | 422 &misspell_location, &misspell_length, |
424 ¶ms.dictionary_suggestions); | 423 ¶ms.dictionary_suggestions); |
425 | 424 |
426 // If not misspelled, make the misspelled_word param empty. | 425 // If not misspelled, make the misspelled_word param empty. |
427 if (!is_misspelled) | 426 if (!is_misspelled) |
428 params.misspelled_word.clear(); | 427 params.misspelled_word.clear(); |
429 } | 428 } |
430 | 429 |
431 // Create a new ViewHostMsg_ContextMenu message. | 430 // Create a new ViewHostMsg_ContextMenu message. |
432 const ViewHostMsg_ContextMenu context_menu_message(msg.routing_id(), params); | 431 const ViewHostMsg_ContextMenu context_menu_message(msg.routing_id(), params); |
433 ui_loop()->PostTask(FROM_HERE, new ContextMenuMessageDispatcher( | 432 ChromeThread::PostTask( |
434 id(), context_menu_message)); | 433 ChromeThread::UI, FROM_HERE, |
| 434 new ContextMenuMessageDispatcher(id(), context_menu_message)); |
435 } | 435 } |
436 | 436 |
437 // Called on the IPC thread: | 437 // Called on the IPC thread: |
438 bool ResourceMessageFilter::Send(IPC::Message* message) { | 438 bool ResourceMessageFilter::Send(IPC::Message* message) { |
439 if (!channel_) { | 439 if (!channel_) { |
440 delete message; | 440 delete message; |
441 return false; | 441 return false; |
442 } | 442 } |
443 | 443 |
444 return channel_->Send(message); | 444 return channel_->Send(message); |
445 } | 445 } |
446 | 446 |
447 URLRequestContext* ResourceMessageFilter::GetRequestContext( | 447 URLRequestContext* ResourceMessageFilter::GetRequestContext( |
448 uint32 request_id, | 448 uint32 request_id, |
449 const ViewHostMsg_Resource_Request& request_data) { | 449 const ViewHostMsg_Resource_Request& request_data) { |
450 URLRequestContextGetter* request_context = request_context_; | 450 URLRequestContextGetter* request_context = request_context_; |
451 // If the request has resource type of ResourceType::MEDIA, we use a request | 451 // If the request has resource type of ResourceType::MEDIA, we use a request |
452 // context specific to media for handling it because these resources have | 452 // context specific to media for handling it because these resources have |
453 // specific needs for caching. | 453 // specific needs for caching. |
454 if (request_data.resource_type == ResourceType::MEDIA) | 454 if (request_data.resource_type == ResourceType::MEDIA) |
455 request_context = media_request_context_; | 455 request_context = media_request_context_; |
456 return request_context->GetURLRequestContext(); | 456 return request_context->GetURLRequestContext(); |
457 } | 457 } |
458 | 458 |
459 MessageLoop* ResourceMessageFilter::ui_loop() { | |
460 return render_widget_helper_->ui_loop(); | |
461 } | |
462 | |
463 void ResourceMessageFilter::OnMsgCreateWindow( | 459 void ResourceMessageFilter::OnMsgCreateWindow( |
464 int opener_id, bool user_gesture, int* route_id) { | 460 int opener_id, bool user_gesture, int* route_id) { |
465 render_widget_helper_->CreateNewWindow(opener_id, | 461 render_widget_helper_->CreateNewWindow(opener_id, |
466 user_gesture, | 462 user_gesture, |
467 handle(), | 463 handle(), |
468 route_id); | 464 route_id); |
469 } | 465 } |
470 | 466 |
471 void ResourceMessageFilter::OnMsgCreateWidget(int opener_id, | 467 void ResourceMessageFilter::OnMsgCreateWidget(int opener_id, |
472 bool activatable, | 468 bool activatable, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 | 693 |
698 #if defined(OS_WIN) | 694 #if defined(OS_WIN) |
699 // We pass the renderer handle to assist the clipboard with using shared | 695 // We pass the renderer handle to assist the clipboard with using shared |
700 // memory objects. handle() is a handle to the process that would | 696 // memory objects. handle() is a handle to the process that would |
701 // own any shared memory that might be in the object list. We only do this | 697 // own any shared memory that might be in the object list. We only do this |
702 // on Windows and it only applies to bitmaps. (On Linux, bitmaps | 698 // on Windows and it only applies to bitmaps. (On Linux, bitmaps |
703 // are copied pixel by pixel rather than using shared memory.) | 699 // are copied pixel by pixel rather than using shared memory.) |
704 Clipboard::DuplicateRemoteHandles(handle(), long_living_objects); | 700 Clipboard::DuplicateRemoteHandles(handle(), long_living_objects); |
705 #endif | 701 #endif |
706 | 702 |
707 ui_loop()->PostTask(FROM_HERE, new WriteClipboardTask(long_living_objects)); | 703 ChromeThread::PostTask( |
| 704 ChromeThread::UI, FROM_HERE, new WriteClipboardTask(long_living_objects)); |
708 } | 705 } |
709 | 706 |
710 #if !defined(OS_LINUX) | 707 #if !defined(OS_LINUX) |
711 // On non-Linux platforms, clipboard actions can be performed on the IO thread. | 708 // On non-Linux platforms, clipboard actions can be performed on the IO thread. |
712 // On Linux, since the clipboard is linked with GTK, we either have to do this | 709 // On Linux, since the clipboard is linked with GTK, we either have to do this |
713 // with GTK on the UI thread, or with Xlib on the BACKGROUND_X11 thread. In an | 710 // with GTK on the UI thread, or with Xlib on the BACKGROUND_X11 thread. In an |
714 // ideal world, we would do the latter. However, for now we're going to | 711 // ideal world, we would do the latter. However, for now we're going to |
715 // terminate these calls on the UI thread. This risks deadlock in the case of | 712 // terminate these calls on the UI thread. This risks deadlock in the case of |
716 // plugins, but it's better than crashing which is what doing on the IO thread | 713 // plugins, but it's better than crashing which is what doing on the IO thread |
717 // gives us. | 714 // gives us. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 HISTOGRAM_COUNTS("WebCoreCache.CSSStylesheetsSizeKB", | 813 HISTOGRAM_COUNTS("WebCoreCache.CSSStylesheetsSizeKB", |
817 static_cast<int>(stats.cssStyleSheets.size / 1024)); | 814 static_cast<int>(stats.cssStyleSheets.size / 1024)); |
818 HISTOGRAM_COUNTS("WebCoreCache.ScriptsSizeKB", | 815 HISTOGRAM_COUNTS("WebCoreCache.ScriptsSizeKB", |
819 static_cast<int>(stats.scripts.size / 1024)); | 816 static_cast<int>(stats.scripts.size / 1024)); |
820 HISTOGRAM_COUNTS("WebCoreCache.XSLStylesheetsSizeKB", | 817 HISTOGRAM_COUNTS("WebCoreCache.XSLStylesheetsSizeKB", |
821 static_cast<int>(stats.xslStyleSheets.size / 1024)); | 818 static_cast<int>(stats.xslStyleSheets.size / 1024)); |
822 HISTOGRAM_COUNTS("WebCoreCache.FontsSizeKB", | 819 HISTOGRAM_COUNTS("WebCoreCache.FontsSizeKB", |
823 static_cast<int>(stats.fonts.size / 1024)); | 820 static_cast<int>(stats.fonts.size / 1024)); |
824 // We need to notify the TaskManager of these statistics from the UI | 821 // We need to notify the TaskManager of these statistics from the UI |
825 // thread. | 822 // thread. |
826 ui_loop()->PostTask( | 823 ChromeThread::PostTask( |
827 FROM_HERE, NewRunnableFunction( | 824 ChromeThread::UI, FROM_HERE, |
| 825 NewRunnableFunction( |
828 &ResourceMessageFilter::OnResourceTypeStatsOnUIThread, | 826 &ResourceMessageFilter::OnResourceTypeStatsOnUIThread, |
829 stats, | 827 stats, |
830 base::GetProcId(handle()))); | 828 base::GetProcId(handle()))); |
831 } | 829 } |
832 | 830 |
833 void ResourceMessageFilter::OnResourceTypeStatsOnUIThread( | 831 void ResourceMessageFilter::OnResourceTypeStatsOnUIThread( |
834 WebCache::ResourceTypeStats stats, base::ProcessId renderer_id) { | 832 WebCache::ResourceTypeStats stats, base::ProcessId renderer_id) { |
835 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 833 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
836 TaskManager::GetInstance()->model()->NotifyResourceTypeStats( | 834 TaskManager::GetInstance()->model()->NotifyResourceTypeStats( |
837 renderer_id, stats); | 835 renderer_id, stats); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 std::string* signed_public_key) { | 1161 std::string* signed_public_key) { |
1164 scoped_ptr<net::KeygenHandler> keygen_handler( | 1162 scoped_ptr<net::KeygenHandler> keygen_handler( |
1165 new net::KeygenHandler(key_size_index, | 1163 new net::KeygenHandler(key_size_index, |
1166 challenge_string)); | 1164 challenge_string)); |
1167 *signed_public_key = keygen_handler->GenKeyAndSignChallenge(); | 1165 *signed_public_key = keygen_handler->GenKeyAndSignChallenge(); |
1168 } | 1166 } |
1169 | 1167 |
1170 #if defined(USE_TCMALLOC) | 1168 #if defined(USE_TCMALLOC) |
1171 void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, | 1169 void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, |
1172 const std::string& output) { | 1170 const std::string& output) { |
1173 ui_loop()->PostTask(FROM_HERE, | 1171 ChromeThread::PostTask( |
| 1172 ChromeThread::UI, FROM_HERE, |
1174 NewRunnableFunction(AboutTcmallocRendererCallback, pid, output)); | 1173 NewRunnableFunction(AboutTcmallocRendererCallback, pid, output)); |
1175 } | 1174 } |
1176 #endif | 1175 #endif |
OLD | NEW |