| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/clipboard.h" | 7 #include "base/clipboard.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/gfx/native_widget_types.h" | 9 #include "base/gfx/native_widget_types.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 OnGetMimeTypeFromExtension) | 327 OnGetMimeTypeFromExtension) |
| 328 IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromFile, | 328 IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromFile, |
| 329 OnGetMimeTypeFromFile) | 329 OnGetMimeTypeFromFile) |
| 330 IPC_MESSAGE_HANDLER(ViewHostMsg_GetPreferredExtensionForMimeType, | 330 IPC_MESSAGE_HANDLER(ViewHostMsg_GetPreferredExtensionForMimeType, |
| 331 OnGetPreferredExtensionForMimeType) | 331 OnGetPreferredExtensionForMimeType) |
| 332 IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPBrowsingContext, | 332 IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPBrowsingContext, |
| 333 OnGetCPBrowsingContext) | 333 OnGetCPBrowsingContext) |
| 334 #if defined(OS_WIN) | 334 #if defined(OS_WIN) |
| 335 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) | 335 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) |
| 336 #endif | 336 #endif |
| 337 #if defined(OS_LINUX) | 337 #if defined(USE_X11) |
| 338 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateShareMemory, | 338 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateShareMemory, |
| 339 OnAllocateShareMemory) | 339 OnAllocateShareMemory) |
| 340 #endif | 340 #endif |
| 341 IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats) | 341 IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats) |
| 342 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy) | 342 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy) |
| 343 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings, | 343 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings, |
| 344 OnGetDefaultPrintSettings) | 344 OnGetDefaultPrintSettings) |
| 345 #if defined(OS_WIN) | 345 #if defined(OS_WIN) |
| 346 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, | 346 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, |
| 347 OnScriptedPrint) | 347 OnScriptedPrint) |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // memory objects. handle() is a handle to the process that would | 613 // memory objects. handle() is a handle to the process that would |
| 614 // own any shared memory that might be in the object list. We only do this | 614 // own any shared memory that might be in the object list. We only do this |
| 615 // on Windows and it only applies to bitmaps. (On Linux, bitmaps | 615 // on Windows and it only applies to bitmaps. (On Linux, bitmaps |
| 616 // are copied pixel by pixel rather than using shared memory.) | 616 // are copied pixel by pixel rather than using shared memory.) |
| 617 Clipboard::DuplicateRemoteHandles(handle(), long_living_objects); | 617 Clipboard::DuplicateRemoteHandles(handle(), long_living_objects); |
| 618 #endif | 618 #endif |
| 619 | 619 |
| 620 ui_loop()->PostTask(FROM_HERE, new WriteClipboardTask(long_living_objects)); | 620 ui_loop()->PostTask(FROM_HERE, new WriteClipboardTask(long_living_objects)); |
| 621 } | 621 } |
| 622 | 622 |
| 623 #if !defined(OS_LINUX) | 623 #if !defined(USE_X11) |
| 624 // On non-Linux platforms, clipboard actions can be performed on the IO thread. | 624 // On non-X/11 platforms, clipboard actions can be performed on the IO thread. |
| 625 // On Linux, since the clipboard is linked with GTK, we either have to do this | 625 // On X/11, since the clipboard is linked with GTK, we either have to do this |
| 626 // with GTK on the UI thread, or with Xlib on the BACKGROUND_X11 thread. In an | 626 // with GTK on the UI thread, or with Xlib on the BACKGROUND_X11 thread. In an |
| 627 // ideal world, we would do the latter. However, for now we're going to | 627 // ideal world, we would do the latter. However, for now we're going to |
| 628 // terminate these calls on the UI thread. This risks deadlock in the case of | 628 // terminate these calls on the UI thread. This risks deadlock in the case of |
| 629 // plugins, but it's better than crashing which is what doing on the IO thread | 629 // plugins, but it's better than crashing which is what doing on the IO thread |
| 630 // gives us. | 630 // gives us. |
| 631 // | 631 // |
| 632 // See resource_message_filter_gtk.cc for the Linux implementation of these | 632 // See resource_message_filter_gtk.cc for the Linux implementation of these |
| 633 // functions. | 633 // functions. |
| 634 | 634 |
| 635 void ResourceMessageFilter::OnClipboardIsFormatAvailable( | 635 void ResourceMessageFilter::OnClipboardIsFormatAvailable( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 void ResourceMessageFilter::OnDuplicateSection( | 695 void ResourceMessageFilter::OnDuplicateSection( |
| 696 base::SharedMemoryHandle renderer_handle, | 696 base::SharedMemoryHandle renderer_handle, |
| 697 base::SharedMemoryHandle* browser_handle) { | 697 base::SharedMemoryHandle* browser_handle) { |
| 698 // Duplicate the handle in this process right now so the memory is kept alive | 698 // Duplicate the handle in this process right now so the memory is kept alive |
| 699 // (even if it is not mapped) | 699 // (even if it is not mapped) |
| 700 base::SharedMemory shared_buf(renderer_handle, true, handle()); | 700 base::SharedMemory shared_buf(renderer_handle, true, handle()); |
| 701 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle); | 701 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle); |
| 702 } | 702 } |
| 703 #endif | 703 #endif |
| 704 | 704 |
| 705 #if defined(OS_LINUX) | 705 #if defined(USE_X11) |
| 706 void ResourceMessageFilter::OnAllocateShareMemory( | 706 void ResourceMessageFilter::OnAllocateShareMemory( |
| 707 size_t buffer_size, | 707 size_t buffer_size, |
| 708 base::SharedMemoryHandle* browser_handle) { | 708 base::SharedMemoryHandle* browser_handle) { |
| 709 // We don't want to allocate a super big chunk of memory. | 709 // We don't want to allocate a super big chunk of memory. |
| 710 // 32MB should be large enough for printing on Linux. | 710 // 32MB should be large enough for printing on Linux. |
| 711 if (buffer_size > 32 * 1024 * 1024) { | 711 if (buffer_size > 32 * 1024 * 1024) { |
| 712 *browser_handle = base::SharedMemory::NULLHandle(); | 712 *browser_handle = base::SharedMemory::NULLHandle(); |
| 713 NOTREACHED() << "Buffer too large: " << buffer_size; | 713 NOTREACHED() << "Buffer too large: " << buffer_size; |
| 714 return; | 714 return; |
| 715 } | 715 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 void ResourceMessageFilter::ReplyGetFileSize(int64 result, void* param) { | 1037 void ResourceMessageFilter::ReplyGetFileSize(int64 result, void* param) { |
| 1038 IPC::Message* reply_msg = static_cast<IPC::Message*>(param); | 1038 IPC::Message* reply_msg = static_cast<IPC::Message*>(param); |
| 1039 ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, result); | 1039 ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, result); |
| 1040 Send(reply_msg); | 1040 Send(reply_msg); |
| 1041 | 1041 |
| 1042 // Getting file size callback done, decrease the ref count. | 1042 // Getting file size callback done, decrease the ref count. |
| 1043 Release(); | 1043 Release(); |
| 1044 } | 1044 } |
| OLD | NEW |