Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 #include "chrome/common/worker_messages.h" | 48 #include "chrome/common/worker_messages.h" |
| 49 #include "net/base/mime_util.h" | 49 #include "net/base/mime_util.h" |
| 50 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| 51 #include "net/http/http_cache.h" | 51 #include "net/http/http_cache.h" |
| 52 #include "net/http/http_transaction_factory.h" | 52 #include "net/http/http_transaction_factory.h" |
| 53 #include "net/url_request/url_request_context.h" | 53 #include "net/url_request/url_request_context.h" |
| 54 #include "webkit/glue/plugins/plugin_list.h" | 54 #include "webkit/glue/plugins/plugin_list.h" |
| 55 #include "webkit/glue/webkit_glue.h" | 55 #include "webkit/glue/webkit_glue.h" |
| 56 #include "webkit/glue/webplugin.h" | 56 #include "webkit/glue/webplugin.h" |
| 57 | 57 |
| 58 #if defined(OS_WIN) | 58 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 59 #include "chrome/browser/printing/print_job_manager.h" | 59 #include "chrome/browser/printing/print_job_manager.h" |
| 60 #include "chrome/browser/printing/printer_query.h" | 60 #include "chrome/browser/printing/printer_query.h" |
| 61 #elif defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_FREEBSD) | 61 #elif defined(OS_LINUX) || defined(OS_FREEBSD) |
| 62 // TODO(port) remove this. | 62 // TODO(port) remove this. |
| 63 #include "chrome/common/temp_scaffolding_stubs.h" | 63 #include "chrome/common/temp_scaffolding_stubs.h" |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 using WebKit::WebCache; | 66 using WebKit::WebCache; |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| 69 | 69 |
| 70 // Context menus are somewhat complicated. We need to intercept them here on | 70 // Context menus are somewhat complicated. We need to intercept them here on |
| 71 // the I/O thread to add any spelling suggestions to them. After that's done, | 71 // the I/O thread to add any spelling suggestions to them. After that's done, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 g_browser_process->clipboard()->WriteObjects(*objects_.get()); | 111 g_browser_process->clipboard()->WriteObjects(*objects_.get()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 scoped_ptr<Clipboard::ObjectMap> objects_; | 115 scoped_ptr<Clipboard::ObjectMap> objects_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 void RenderParamsFromPrintSettings(const printing::PrintSettings& settings, | 118 void RenderParamsFromPrintSettings(const printing::PrintSettings& settings, |
| 119 ViewMsg_Print_Params* params) { | 119 ViewMsg_Print_Params* params) { |
| 120 DCHECK(params); | 120 DCHECK(params); |
| 121 #if defined(OS_WIN) | 121 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 122 params->printable_size.SetSize( | 122 params->printable_size.SetSize( |
| 123 settings.page_setup_pixels().content_area().width(), | 123 settings.page_setup_pixels().content_area().width(), |
| 124 settings.page_setup_pixels().content_area().height()); | 124 settings.page_setup_pixels().content_area().height()); |
| 125 params->dpi = settings.dpi(); | 125 params->dpi = settings.dpi(); |
| 126 // Currently hardcoded at 1.25. See PrintSettings' constructor. | 126 // Currently hardcoded at 1.25. See PrintSettings' constructor. |
| 127 params->min_shrink = settings.min_shrink; | 127 params->min_shrink = settings.min_shrink; |
| 128 // Currently hardcoded at 2.0. See PrintSettings' constructor. | 128 // Currently hardcoded at 2.0. See PrintSettings' constructor. |
| 129 params->max_shrink = settings.max_shrink; | 129 params->max_shrink = settings.max_shrink; |
| 130 // Currently hardcoded at 72dpi. See PrintSettings' constructor. | 130 // Currently hardcoded at 72dpi. See PrintSettings' constructor. |
| 131 params->desired_dpi = settings.desired_dpi; | 131 params->desired_dpi = settings.desired_dpi; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPBrowsingContext, | 350 IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPBrowsingContext, |
| 351 OnGetCPBrowsingContext) | 351 OnGetCPBrowsingContext) |
| 352 #if defined(OS_WIN) | 352 #if defined(OS_WIN) |
| 353 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) | 353 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) |
| 354 #endif | 354 #endif |
| 355 #if defined(OS_LINUX) | 355 #if defined(OS_LINUX) |
| 356 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllocateTempFileForPrinting, | 356 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllocateTempFileForPrinting, |
| 357 OnAllocateTempFileForPrinting) | 357 OnAllocateTempFileForPrinting) |
| 358 IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten, | 358 IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten, |
| 359 OnTempFileForPrintingWritten) | 359 OnTempFileForPrintingWritten) |
| 360 #endif | 360 #endif |
|
pink (ping after 24hrs)
2009/10/13 21:04:51
#elif?
stuartmorgan
2009/10/13 22:07:43
Again, I was trying to be consistent with the rest
| |
| 361 #if defined(OS_MACOSX) | |
| 362 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocatePDFTransport, | |
| 363 OnAllocatePDFTransport) | |
| 364 #endif | |
| 361 IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats) | 365 IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats) |
| 362 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy) | 366 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy) |
| 363 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings, | 367 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings, |
| 364 OnGetDefaultPrintSettings) | 368 OnGetDefaultPrintSettings) |
| 365 #if defined(OS_WIN) | 369 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 366 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, | 370 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, |
| 367 OnScriptedPrint) | 371 OnScriptedPrint) |
| 368 #endif | 372 #endif |
| 369 #if defined(OS_MACOSX) | 373 #if defined(OS_MACOSX) |
| 370 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, | 374 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, |
| 371 OnAllocTransportDIB) | 375 OnAllocTransportDIB) |
| 372 IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, | 376 IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, |
| 373 OnFreeTransportDIB) | 377 OnFreeTransportDIB) |
| 374 #endif | 378 #endif |
| 375 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, | 379 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 void ResourceMessageFilter::OnDuplicateSection( | 735 void ResourceMessageFilter::OnDuplicateSection( |
| 732 base::SharedMemoryHandle renderer_handle, | 736 base::SharedMemoryHandle renderer_handle, |
| 733 base::SharedMemoryHandle* browser_handle) { | 737 base::SharedMemoryHandle* browser_handle) { |
| 734 // Duplicate the handle in this process right now so the memory is kept alive | 738 // Duplicate the handle in this process right now so the memory is kept alive |
| 735 // (even if it is not mapped) | 739 // (even if it is not mapped) |
| 736 base::SharedMemory shared_buf(renderer_handle, true, handle()); | 740 base::SharedMemory shared_buf(renderer_handle, true, handle()); |
| 737 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle); | 741 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle); |
| 738 } | 742 } |
| 739 #endif | 743 #endif |
| 740 | 744 |
| 745 #if defined(OS_MACOSX) | |
| 746 void ResourceMessageFilter::OnAllocatePDFTransport( | |
| 747 size_t buffer_size, | |
| 748 base::SharedMemoryHandle* handle) { | |
| 749 base::SharedMemory shared_buf; | |
| 750 shared_buf.Create(L"", false, false, buffer_size); | |
| 751 if (!shared_buf.Map(buffer_size)) { | |
| 752 *handle = base::SharedMemory::NULLHandle(); | |
| 753 NOTREACHED() << "Cannot map PDF transport buffer"; | |
| 754 return; | |
| 755 } | |
| 756 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), handle); | |
| 757 } | |
| 758 #endif | |
| 759 | |
| 741 void ResourceMessageFilter::OnResourceTypeStats( | 760 void ResourceMessageFilter::OnResourceTypeStats( |
| 742 const WebCache::ResourceTypeStats& stats) { | 761 const WebCache::ResourceTypeStats& stats) { |
| 743 HISTOGRAM_COUNTS("WebCoreCache.ImagesSizeKB", | 762 HISTOGRAM_COUNTS("WebCoreCache.ImagesSizeKB", |
| 744 static_cast<int>(stats.images.size / 1024)); | 763 static_cast<int>(stats.images.size / 1024)); |
| 745 HISTOGRAM_COUNTS("WebCoreCache.CSSStylesheetsSizeKB", | 764 HISTOGRAM_COUNTS("WebCoreCache.CSSStylesheetsSizeKB", |
| 746 static_cast<int>(stats.cssStyleSheets.size / 1024)); | 765 static_cast<int>(stats.cssStyleSheets.size / 1024)); |
| 747 HISTOGRAM_COUNTS("WebCoreCache.ScriptsSizeKB", | 766 HISTOGRAM_COUNTS("WebCoreCache.ScriptsSizeKB", |
| 748 static_cast<int>(stats.scripts.size / 1024)); | 767 static_cast<int>(stats.scripts.size / 1024)); |
| 749 HISTOGRAM_COUNTS("WebCoreCache.XSLStylesheetsSizeKB", | 768 HISTOGRAM_COUNTS("WebCoreCache.XSLStylesheetsSizeKB", |
| 750 static_cast<int>(stats.xslStyleSheets.size / 1024)); | 769 static_cast<int>(stats.xslStyleSheets.size / 1024)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 ViewHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params); | 832 ViewHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params); |
| 814 Send(reply_msg); | 833 Send(reply_msg); |
| 815 // If user hasn't cancelled. | 834 // If user hasn't cancelled. |
| 816 if (printer_query->cookie() && printer_query->settings().dpi()) { | 835 if (printer_query->cookie() && printer_query->settings().dpi()) { |
| 817 print_job_manager_->QueuePrinterQuery(printer_query.get()); | 836 print_job_manager_->QueuePrinterQuery(printer_query.get()); |
| 818 } else { | 837 } else { |
| 819 printer_query->StopWorker(); | 838 printer_query->StopWorker(); |
| 820 } | 839 } |
| 821 } | 840 } |
| 822 | 841 |
| 823 #if defined(OS_WIN) | 842 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 824 | 843 |
| 825 void ResourceMessageFilter::OnScriptedPrint( | 844 void ResourceMessageFilter::OnScriptedPrint( |
| 826 const ViewHostMsg_ScriptedPrint_Params& params, | 845 const ViewHostMsg_ScriptedPrint_Params& params, |
| 827 IPC::Message* reply_msg) { | 846 IPC::Message* reply_msg) { |
| 847 #if defined(OS_WIN) | |
| 828 HWND host_window = gfx::NativeViewFromId(params.host_window_id); | 848 HWND host_window = gfx::NativeViewFromId(params.host_window_id); |
| 849 #elif defined(OS_MACOSX) | |
| 850 gfx::NativeWindow host_window = NULL; | |
| 851 // TODO: Get an actually window ref here, to allow a sheet-based print dialog. | |
|
Amanda Walker
2009/10/13 19:35:49
actually -> actual
stuartmorgan
2009/10/13 22:07:43
Done.
| |
| 852 #endif | |
| 829 | 853 |
| 830 scoped_refptr<printing::PrinterQuery> printer_query; | 854 scoped_refptr<printing::PrinterQuery> printer_query; |
| 831 print_job_manager_->PopPrinterQuery(params.cookie, &printer_query); | 855 print_job_manager_->PopPrinterQuery(params.cookie, &printer_query); |
| 832 if (!printer_query.get()) { | 856 if (!printer_query.get()) { |
| 833 printer_query = new printing::PrinterQuery; | 857 printer_query = new printing::PrinterQuery; |
| 834 } | 858 } |
| 835 | 859 |
| 836 CancelableTask* task = NewRunnableMethod( | 860 CancelableTask* task = NewRunnableMethod( |
| 837 this, | 861 this, |
| 838 &ResourceMessageFilter::OnScriptedPrintReply, | 862 &ResourceMessageFilter::OnScriptedPrintReply, |
| 839 printer_query, | 863 printer_query, |
| 840 params.routing_id, | 864 params.routing_id, |
| 841 reply_msg); | 865 reply_msg); |
| 866 #if defined(OS_WIN) | |
| 842 // Shows the Print... dialog box. This is asynchronous, only the IPC message | 867 // Shows the Print... dialog box. This is asynchronous, only the IPC message |
| 843 // sender will hang until the Print dialog is dismissed. | 868 // sender will hang until the Print dialog is dismissed. |
| 844 if (!host_window || !IsWindow(host_window)) { | 869 if (!host_window || !IsWindow(host_window)) { |
| 845 // TODO(maruel): bug 1214347 Get the right browser window instead. | 870 // TODO(maruel): bug 1214347 Get the right browser window instead. |
| 846 host_window = GetDesktopWindow(); | 871 host_window = GetDesktopWindow(); |
| 847 } else { | 872 } else { |
| 848 host_window = GetAncestor(host_window, GA_ROOTOWNER); | 873 host_window = GetAncestor(host_window, GA_ROOTOWNER); |
| 849 } | 874 } |
| 850 DCHECK(host_window); | 875 DCHECK(host_window); |
| 876 #endif | |
| 851 | 877 |
| 852 printer_query->GetSettings(printing::PrinterQuery::ASK_USER, | 878 printer_query->GetSettings(printing::PrinterQuery::ASK_USER, |
| 853 host_window, | 879 host_window, |
| 854 params.expected_pages_count, | 880 params.expected_pages_count, |
| 855 params.has_selection, | 881 params.has_selection, |
| 856 task); | 882 task); |
| 857 } | 883 } |
| 858 | 884 |
| 859 void ResourceMessageFilter::OnScriptedPrintReply( | 885 void ResourceMessageFilter::OnScriptedPrintReply( |
| 860 scoped_refptr<printing::PrinterQuery> printer_query, | 886 scoped_refptr<printing::PrinterQuery> printer_query, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 872 } | 898 } |
| 873 ViewHostMsg_ScriptedPrint::WriteReplyParams(reply_msg, params); | 899 ViewHostMsg_ScriptedPrint::WriteReplyParams(reply_msg, params); |
| 874 Send(reply_msg); | 900 Send(reply_msg); |
| 875 if (params.params.dpi && params.params.document_cookie) { | 901 if (params.params.dpi && params.params.document_cookie) { |
| 876 print_job_manager_->QueuePrinterQuery(printer_query.get()); | 902 print_job_manager_->QueuePrinterQuery(printer_query.get()); |
| 877 } else { | 903 } else { |
| 878 printer_query->StopWorker(); | 904 printer_query->StopWorker(); |
| 879 } | 905 } |
| 880 } | 906 } |
| 881 | 907 |
| 882 #endif // OS_WIN | 908 #endif // OS_WIN || OS_MACOSX |
| 883 | 909 |
| 884 // static | 910 // static |
| 885 Clipboard* ResourceMessageFilter::GetClipboard() { | 911 Clipboard* ResourceMessageFilter::GetClipboard() { |
| 886 // We have a static instance of the clipboard service for use by all message | 912 // We have a static instance of the clipboard service for use by all message |
| 887 // filters. This instance lives for the life of the browser processes. | 913 // filters. This instance lives for the life of the browser processes. |
| 888 static Clipboard* clipboard = new Clipboard; | 914 static Clipboard* clipboard = new Clipboard; |
| 889 | 915 |
| 890 return clipboard; | 916 return clipboard; |
| 891 } | 917 } |
| 892 | 918 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 Release(); | 1095 Release(); |
| 1070 } | 1096 } |
| 1071 | 1097 |
| 1072 #if defined(USE_TCMALLOC) | 1098 #if defined(USE_TCMALLOC) |
| 1073 void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, | 1099 void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, |
| 1074 const std::string& output) { | 1100 const std::string& output) { |
| 1075 ui_loop()->PostTask(FROM_HERE, | 1101 ui_loop()->PostTask(FROM_HERE, |
| 1076 NewRunnableFunction(AboutTcmallocRendererCallback, pid, output)); | 1102 NewRunnableFunction(AboutTcmallocRendererCallback, pid, output)); |
| 1077 } | 1103 } |
| 1078 #endif | 1104 #endif |
| OLD | NEW |