Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/renderer_host/resource_message_filter.cc

Issue 338065: Add the ability for objects which derive from RefCountedThreadSafe to specify... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/renderer_host/resource_message_filter.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h"
10 #include "base/histogram.h" 11 #include "base/histogram.h"
11 #include "base/process_util.h" 12 #include "base/process_util.h"
12 #include "base/thread.h" 13 #include "base/thread.h"
13 #include "chrome/browser/browser_about_handler.h" 14 #include "chrome/browser/browser_about_handler.h"
14 #include "chrome/browser/child_process_security_policy.h" 15 #include "chrome/browser/child_process_security_policy.h"
15 #include "chrome/browser/chrome_plugin_browsing_context.h" 16 #include "chrome/browser/chrome_plugin_browsing_context.h"
16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/browser/extensions/extension_message_service.h" 17 #include "chrome/browser/extensions/extension_message_service.h"
18 #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h" 18 #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h"
19 #include "chrome/browser/nacl_process_host.h" 19 #include "chrome/browser/nacl_process_host.h"
20 #include "chrome/browser/net/chrome_url_request_context.h" 20 #include "chrome/browser/net/chrome_url_request_context.h"
21 #include "chrome/browser/net/dns_global.h" 21 #include "chrome/browser/net/dns_global.h"
22 #include "chrome/browser/notifications/desktop_notification_service.h" 22 #include "chrome/browser/notifications/desktop_notification_service.h"
23 #include "chrome/browser/notifications/notifications_prefs_cache.h" 23 #include "chrome/browser/notifications/notifications_prefs_cache.h"
24 #include "chrome/browser/plugin_service.h" 24 #include "chrome/browser/plugin_service.h"
25 #include "chrome/browser/profile.h" 25 #include "chrome/browser/profile.h"
26 #include "chrome/browser/privacy_blacklist/blacklist.h" 26 #include "chrome/browser/privacy_blacklist/blacklist.h"
27 #include "chrome/browser/privacy_blacklist/blacklist_observer.h" 27 #include "chrome/browser/privacy_blacklist/blacklist_observer.h"
28 #include "chrome/browser/renderer_host/audio_renderer_host.h" 28 #include "chrome/browser/renderer_host/audio_renderer_host.h"
29 #include "chrome/browser/renderer_host/browser_render_process_host.h" 29 #include "chrome/browser/renderer_host/browser_render_process_host.h"
30 #include "chrome/browser/renderer_host/database_dispatcher_host.h" 30 #include "chrome/browser/renderer_host/database_dispatcher_host.h"
31 #include "chrome/browser/renderer_host/file_system_accessor.h"
32 #include "chrome/browser/renderer_host/render_widget_helper.h" 31 #include "chrome/browser/renderer_host/render_widget_helper.h"
33 #include "chrome/browser/renderer_host/socket_stream_dispatcher_host.h" 32 #include "chrome/browser/renderer_host/socket_stream_dispatcher_host.h"
34 #include "chrome/browser/spellchecker.h" 33 #include "chrome/browser/spellchecker.h"
35 #include "chrome/browser/spellchecker_platform_engine.h" 34 #include "chrome/browser/spellchecker_platform_engine.h"
36 #include "chrome/browser/task_manager.h" 35 #include "chrome/browser/task_manager.h"
37 #include "chrome/browser/worker_host/message_port_dispatcher.h" 36 #include "chrome/browser/worker_host/message_port_dispatcher.h"
38 #include "chrome/browser/worker_host/worker_service.h" 37 #include "chrome/browser/worker_host/worker_service.h"
39 #include "chrome/common/appcache/appcache_dispatcher_host.h" 38 #include "chrome/common/appcache/appcache_dispatcher_host.h"
40 #include "chrome/common/chrome_plugin_lib.h" 39 #include "chrome/common/chrome_plugin_lib.h"
41 #include "chrome/common/chrome_plugin_util.h" 40 #include "chrome/common/chrome_plugin_util.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 IPC_END_MESSAGE_MAP_EX() 399 IPC_END_MESSAGE_MAP_EX()
401 } 400 }
402 401
403 if (!msg_is_ok) { 402 if (!msg_is_ok) {
404 BrowserRenderProcessHost::BadMessageTerminateProcess(msg.type(), handle()); 403 BrowserRenderProcessHost::BadMessageTerminateProcess(msg.type(), handle());
405 } 404 }
406 405
407 return handled; 406 return handled;
408 } 407 }
409 408
409 void ResourceMessageFilter::OnDestruct() {
410 ChromeThread::DeleteOnIOThread::Destruct(this);
411 }
412
410 void ResourceMessageFilter::OnReceiveContextMenuMsg(const IPC::Message& msg) { 413 void ResourceMessageFilter::OnReceiveContextMenuMsg(const IPC::Message& msg) {
411 void* iter = NULL; 414 void* iter = NULL;
412 ContextMenuParams params; 415 ContextMenuParams params;
413 if (!IPC::ParamTraits<ContextMenuParams>::Read(&msg, &iter, &params)) 416 if (!IPC::ParamTraits<ContextMenuParams>::Read(&msg, &iter, &params))
414 return; 417 return;
415 418
416 // Fill in the dictionary suggestions if required. 419 // Fill in the dictionary suggestions if required.
417 if (!params.misspelled_word.empty() && 420 if (!params.misspelled_word.empty() &&
418 spellchecker_ != NULL && params.spellcheck_enabled) { 421 spellchecker_ != NULL && params.spellcheck_enabled) {
419 int misspell_location, misspell_length; 422 int misspell_location, misspell_length;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 } 594 }
592 595
593 fonts[font_index] = font_handle; 596 fonts[font_index] = font_handle;
594 hdcs[font_index] = hdc; 597 hdcs[font_index] = hdc;
595 font_index = (font_index + 1) % kFontCacheSize; 598 font_index = (font_index + 1) % kFontCacheSize;
596 } 599 }
597 #endif 600 #endif
598 601
599 void ResourceMessageFilter::OnGetPlugins(bool refresh, 602 void ResourceMessageFilter::OnGetPlugins(bool refresh,
600 IPC::Message* reply_msg) { 603 IPC::Message* reply_msg) {
601 // Schedule plugin loading on the file thread.
602 // Note: it's possible that the only reference to this object is the task. If
603 // If the task executes on the file thread, and before it returns, the task it
604 // posts to the IO thread runs, then this object will get destructed on the
605 // file thread. We need this object to be destructed on the IO thread, so do
606 // the refcounting manually.
607 AddRef();
608 ChromeThread::PostTask( 604 ChromeThread::PostTask(
609 ChromeThread::FILE, FROM_HERE, 605 ChromeThread::FILE, FROM_HERE,
610 NewRunnableFunction(&ResourceMessageFilter::OnGetPluginsOnFileThread, 606 NewRunnableMethod(
611 this, refresh, reply_msg)); 607 this, &ResourceMessageFilter::OnGetPluginsOnFileThread, refresh,
608 reply_msg));
612 } 609 }
613 610
614 void ResourceMessageFilter::OnGetPluginsOnFileThread( 611 void ResourceMessageFilter::OnGetPluginsOnFileThread(
615 ResourceMessageFilter* filter, 612 bool refresh, IPC::Message* reply_msg) {
616 bool refresh, 613 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
617 IPC::Message* reply_msg) {
618 std::vector<WebPluginInfo> plugins; 614 std::vector<WebPluginInfo> plugins;
619 NPAPI::PluginList::Singleton()->GetPlugins(refresh, &plugins); 615 NPAPI::PluginList::Singleton()->GetPlugins(refresh, &plugins);
620 ViewHostMsg_GetPlugins::WriteReplyParams(reply_msg, plugins); 616 ViewHostMsg_GetPlugins::WriteReplyParams(reply_msg, plugins);
621 ChromeThread::PostTask( 617 ChromeThread::PostTask(
622 ChromeThread::IO, FROM_HERE, 618 ChromeThread::IO, FROM_HERE,
623 NewRunnableMethod(filter, &ResourceMessageFilter::OnPluginsLoaded, 619 NewRunnableMethod(this, &ResourceMessageFilter::Send, reply_msg));
624 reply_msg));
625 }
626
627 void ResourceMessageFilter::OnPluginsLoaded(IPC::Message* reply_msg) {
628 Send(reply_msg);
629 Release();
630 } 620 }
631 621
632 void ResourceMessageFilter::OnGetPluginPath(const GURL& url, 622 void ResourceMessageFilter::OnGetPluginPath(const GURL& url,
633 const GURL& policy_url, 623 const GURL& policy_url,
634 const std::string& mime_type, 624 const std::string& mime_type,
635 FilePath* filename, 625 FilePath* filename,
636 std::string* url_mime_type) { 626 std::string* url_mime_type) {
637 *filename = plugin_service_->GetPluginPath( 627 *filename = plugin_service_->GetPluginPath(
638 url, policy_url, mime_type, url_mime_type); 628 url, policy_url, mime_type, url_mime_type);
639 } 629 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 return; 1115 return;
1126 1116
1127 net::HttpCache::Mode mode = enabled ? 1117 net::HttpCache::Mode mode = enabled ?
1128 net::HttpCache::NORMAL : net::HttpCache::DISABLE; 1118 net::HttpCache::NORMAL : net::HttpCache::DISABLE;
1129 request_context_->GetURLRequestContext()-> 1119 request_context_->GetURLRequestContext()->
1130 http_transaction_factory()->GetCache()->set_mode(mode); 1120 http_transaction_factory()->GetCache()->set_mode(mode);
1131 } 1121 }
1132 1122
1133 void ResourceMessageFilter::OnGetFileSize(const FilePath& path, 1123 void ResourceMessageFilter::OnGetFileSize(const FilePath& path,
1134 IPC::Message* reply_msg) { 1124 IPC::Message* reply_msg) {
1135 // Increase the ref count to ensure ResourceMessageFilter won't be destroyed
1136 // before GetFileSize callback is done.
1137 AddRef();
1138
1139 // Get file size only when the child process has been granted permission to 1125 // Get file size only when the child process has been granted permission to
1140 // upload the file. 1126 // upload the file.
1141 if (ChildProcessSecurityPolicy::GetInstance()->CanUploadFile(id(), path)) { 1127 if (!ChildProcessSecurityPolicy::GetInstance()->CanUploadFile(id(), path)) {
1142 FileSystemAccessor::RequestFileSize( 1128 ViewHostMsg_GetFileSize::WriteReplyParams(
1143 path, 1129 reply_msg, static_cast<int64>(-1));
1144 reply_msg, 1130 Send(reply_msg);
1145 NewCallback(this, &ResourceMessageFilter::ReplyGetFileSize)); 1131 return;
1146 } else {
1147 ReplyGetFileSize(-1, reply_msg);
1148 } 1132 }
1133
1134 // Getting file size could take long time if it lives on a network share,
1135 // so run it on FILE thread.
1136 ChromeThread::PostTask(
1137 ChromeThread::FILE, FROM_HERE,
1138 NewRunnableMethod(
1139 this, &ResourceMessageFilter::OnGetFileSizeOnFileThread, path,
1140 reply_msg));
1149 } 1141 }
1150 1142
1151 void ResourceMessageFilter::ReplyGetFileSize(int64 result, void* param) { 1143 void ResourceMessageFilter::OnGetFileSizeOnFileThread(
1152 IPC::Message* reply_msg = static_cast<IPC::Message*>(param); 1144 const FilePath& path, IPC::Message* reply_msg) {
1145 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
1146
1147 int64 result;
1148 if (!file_util::GetFileSize(path, &result))
1149 result = -1;
1153 ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, result); 1150 ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, result);
1154 Send(reply_msg);
1155 1151
1156 // Getting file size callback done, decrease the ref count. 1152 ChromeThread::PostTask(
1157 Release(); 1153 ChromeThread::IO, FROM_HERE,
1154 NewRunnableMethod(this, &ResourceMessageFilter::Send, reply_msg));
1158 } 1155 }
1159 1156
1160 void ResourceMessageFilter::OnKeygen(uint32 key_size_index, 1157 void ResourceMessageFilter::OnKeygen(uint32 key_size_index,
1161 const std::string& challenge_string, 1158 const std::string& challenge_string,
1162 const GURL& url, 1159 const GURL& url,
1163 std::string* signed_public_key) { 1160 std::string* signed_public_key) {
1164 scoped_ptr<net::KeygenHandler> keygen_handler( 1161 scoped_ptr<net::KeygenHandler> keygen_handler(
1165 new net::KeygenHandler(key_size_index, 1162 new net::KeygenHandler(key_size_index,
1166 challenge_string)); 1163 challenge_string));
1167 *signed_public_key = keygen_handler->GenKeyAndSignChallenge(); 1164 *signed_public_key = keygen_handler->GenKeyAndSignChallenge();
1168 } 1165 }
1169 1166
1170 #if defined(USE_TCMALLOC) 1167 #if defined(USE_TCMALLOC)
1171 void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, 1168 void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid,
1172 const std::string& output) { 1169 const std::string& output) {
1173 ui_loop()->PostTask(FROM_HERE, 1170 ui_loop()->PostTask(FROM_HERE,
1174 NewRunnableFunction(AboutTcmallocRendererCallback, pid, output)); 1171 NewRunnableFunction(AboutTcmallocRendererCallback, pid, output));
1175 } 1172 }
1176 #endif 1173 #endif
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/resource_message_filter.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698