| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "app/clipboard/clipboard.h" | 10 #include "app/clipboard/clipboard.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Called on the BACKGROUND_X11 thread. | 49 // Called on the BACKGROUND_X11 thread. |
| 50 void ResourceMessageFilter::DoOnGetScreenInfo(gfx::NativeViewId view, | 50 void ResourceMessageFilter::DoOnGetScreenInfo(gfx::NativeViewId view, |
| 51 IPC::Message* reply_msg) { | 51 IPC::Message* reply_msg) { |
| 52 Display* display = x11_util::GetSecondaryDisplay(); | 52 Display* display = x11_util::GetSecondaryDisplay(); |
| 53 int screen = x11_util::GetDefaultScreen(display); | 53 int screen = x11_util::GetDefaultScreen(display); |
| 54 WebScreenInfo results = WebScreenInfoFactory::screenInfo(display, screen); | 54 WebScreenInfo results = WebScreenInfoFactory::screenInfo(display, screen); |
| 55 ViewHostMsg_GetScreenInfo::WriteReplyParams(reply_msg, results); | 55 ViewHostMsg_GetScreenInfo::WriteReplyParams(reply_msg, results); |
| 56 | 56 |
| 57 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 57 ChromeThread::PostTask( |
| 58 FROM_HERE, NewRunnableMethod( | 58 ChromeThread::IO, FROM_HERE, |
| 59 NewRunnableMethod( |
| 59 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 60 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Called on the BACKGROUND_X11 thread. | 63 // Called on the BACKGROUND_X11 thread. |
| 63 void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view, | 64 void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view, |
| 64 IPC::Message* reply_msg) { | 65 IPC::Message* reply_msg) { |
| 65 // This is called to get the x, y offset (in screen coordinates) of the given | 66 // This is called to get the x, y offset (in screen coordinates) of the given |
| 66 // view and its width and height. | 67 // view and its width and height. |
| 67 gfx::Rect rect; | 68 gfx::Rect rect; |
| 68 XID window; | 69 XID window; |
| 69 | 70 |
| 70 if (Singleton<GtkNativeViewManager>()->GetXIDForId(&window, view)) { | 71 if (Singleton<GtkNativeViewManager>()->GetXIDForId(&window, view)) { |
| 71 if (window) { | 72 if (window) { |
| 72 int x, y; | 73 int x, y; |
| 73 unsigned width, height; | 74 unsigned width, height; |
| 74 if (x11_util::GetWindowGeometry(&x, &y, &width, &height, window)) | 75 if (x11_util::GetWindowGeometry(&x, &y, &width, &height, window)) |
| 75 rect = gfx::Rect(x, y, width, height); | 76 rect = gfx::Rect(x, y, width, height); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 ViewHostMsg_GetWindowRect::WriteReplyParams(reply_msg, rect); | 80 ViewHostMsg_GetWindowRect::WriteReplyParams(reply_msg, rect); |
| 80 | 81 |
| 81 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 82 ChromeThread::PostTask( |
| 82 FROM_HERE, NewRunnableMethod( | 83 ChromeThread::IO, FROM_HERE, |
| 84 NewRunnableMethod( |
| 83 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 85 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Return the top-level parent of the given window. Called on the | 88 // Return the top-level parent of the given window. Called on the |
| 87 // BACKGROUND_X11 thread. | 89 // BACKGROUND_X11 thread. |
| 88 static XID GetTopLevelWindow(XID window) { | 90 static XID GetTopLevelWindow(XID window) { |
| 89 bool parent_is_root; | 91 bool parent_is_root; |
| 90 XID parent_window; | 92 XID parent_window; |
| 91 | 93 |
| 92 if (!x11_util::GetWindowParent(&parent_window, &parent_is_root, window)) | 94 if (!x11_util::GetWindowParent(&parent_window, &parent_is_root, window)) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 110 const XID toplevel = GetTopLevelWindow(window); | 112 const XID toplevel = GetTopLevelWindow(window); |
| 111 int x, y; | 113 int x, y; |
| 112 unsigned width, height; | 114 unsigned width, height; |
| 113 if (x11_util::GetWindowGeometry(&x, &y, &width, &height, toplevel)) | 115 if (x11_util::GetWindowGeometry(&x, &y, &width, &height, toplevel)) |
| 114 rect = gfx::Rect(x, y, width, height); | 116 rect = gfx::Rect(x, y, width, height); |
| 115 } | 117 } |
| 116 } | 118 } |
| 117 | 119 |
| 118 ViewHostMsg_GetRootWindowRect::WriteReplyParams(reply_msg, rect); | 120 ViewHostMsg_GetRootWindowRect::WriteReplyParams(reply_msg, rect); |
| 119 | 121 |
| 120 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 122 ChromeThread::PostTask( |
| 121 FROM_HERE, NewRunnableMethod( | 123 ChromeThread::IO, FROM_HERE, |
| 124 NewRunnableMethod( |
| 122 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 125 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 123 } | 126 } |
| 124 | 127 |
| 125 // Called on the UI thread. | 128 // Called on the UI thread. |
| 126 void ResourceMessageFilter::DoOnClipboardIsFormatAvailable( | 129 void ResourceMessageFilter::DoOnClipboardIsFormatAvailable( |
| 127 Clipboard::FormatType format, Clipboard::Buffer buffer, | 130 Clipboard::FormatType format, Clipboard::Buffer buffer, |
| 128 IPC::Message* reply_msg) { | 131 IPC::Message* reply_msg) { |
| 129 const bool result = GetClipboard()->IsFormatAvailable(format, buffer); | 132 const bool result = GetClipboard()->IsFormatAvailable(format, buffer); |
| 130 | 133 |
| 131 ViewHostMsg_ClipboardIsFormatAvailable::WriteReplyParams(reply_msg, result); | 134 ViewHostMsg_ClipboardIsFormatAvailable::WriteReplyParams(reply_msg, result); |
| 132 | 135 |
| 133 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 136 ChromeThread::PostTask( |
| 134 FROM_HERE, NewRunnableMethod( | 137 ChromeThread::IO, FROM_HERE, |
| 138 NewRunnableMethod( |
| 135 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 139 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 136 } | 140 } |
| 137 | 141 |
| 138 // Called on the UI thread. | 142 // Called on the UI thread. |
| 139 void ResourceMessageFilter::DoOnClipboardReadText(Clipboard::Buffer buffer, | 143 void ResourceMessageFilter::DoOnClipboardReadText(Clipboard::Buffer buffer, |
| 140 IPC::Message* reply_msg) { | 144 IPC::Message* reply_msg) { |
| 141 string16 result; | 145 string16 result; |
| 142 GetClipboard()->ReadText(buffer, &result); | 146 GetClipboard()->ReadText(buffer, &result); |
| 143 | 147 |
| 144 ViewHostMsg_ClipboardReadText::WriteReplyParams(reply_msg, result); | 148 ViewHostMsg_ClipboardReadText::WriteReplyParams(reply_msg, result); |
| 145 | 149 |
| 146 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 150 ChromeThread::PostTask( |
| 147 FROM_HERE, NewRunnableMethod( | 151 ChromeThread::IO, FROM_HERE, |
| 152 NewRunnableMethod( |
| 148 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 153 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 149 } | 154 } |
| 150 | 155 |
| 151 // Called on the UI thread. | 156 // Called on the UI thread. |
| 152 void ResourceMessageFilter::DoOnClipboardReadAsciiText( | 157 void ResourceMessageFilter::DoOnClipboardReadAsciiText( |
| 153 Clipboard::Buffer buffer, IPC::Message* reply_msg) { | 158 Clipboard::Buffer buffer, IPC::Message* reply_msg) { |
| 154 std::string result; | 159 std::string result; |
| 155 GetClipboard()->ReadAsciiText(buffer, &result); | 160 GetClipboard()->ReadAsciiText(buffer, &result); |
| 156 | 161 |
| 157 ViewHostMsg_ClipboardReadAsciiText::WriteReplyParams(reply_msg, result); | 162 ViewHostMsg_ClipboardReadAsciiText::WriteReplyParams(reply_msg, result); |
| 158 | 163 |
| 159 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 164 ChromeThread::PostTask( |
| 160 FROM_HERE, NewRunnableMethod( | 165 ChromeThread::IO, FROM_HERE, |
| 166 NewRunnableMethod( |
| 161 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 167 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 162 } | 168 } |
| 163 | 169 |
| 164 // Called on the UI thread. | 170 // Called on the UI thread. |
| 165 void ResourceMessageFilter::DoOnClipboardReadHTML(Clipboard::Buffer buffer, | 171 void ResourceMessageFilter::DoOnClipboardReadHTML(Clipboard::Buffer buffer, |
| 166 IPC::Message* reply_msg) { | 172 IPC::Message* reply_msg) { |
| 167 std::string src_url_str; | 173 std::string src_url_str; |
| 168 string16 markup; | 174 string16 markup; |
| 169 GetClipboard()->ReadHTML(buffer, &markup, &src_url_str); | 175 GetClipboard()->ReadHTML(buffer, &markup, &src_url_str); |
| 170 const GURL src_url = GURL(src_url_str); | 176 const GURL src_url = GURL(src_url_str); |
| 171 | 177 |
| 172 ViewHostMsg_ClipboardReadHTML::WriteReplyParams(reply_msg, markup, src_url); | 178 ViewHostMsg_ClipboardReadHTML::WriteReplyParams(reply_msg, markup, src_url); |
| 173 | 179 |
| 174 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 180 ChromeThread::PostTask( |
| 175 FROM_HERE, NewRunnableMethod( | 181 ChromeThread::IO, FROM_HERE, |
| 182 NewRunnableMethod( |
| 176 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 183 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 177 } | 184 } |
| 178 | 185 |
| 179 // Called on the FILE thread. | 186 // Called on the FILE thread. |
| 180 void ResourceMessageFilter::DoOnAllocateTempFileForPrinting( | 187 void ResourceMessageFilter::DoOnAllocateTempFileForPrinting( |
| 181 IPC::Message* reply_msg) { | 188 IPC::Message* reply_msg) { |
| 182 base::FileDescriptor temp_file_fd; | 189 base::FileDescriptor temp_file_fd; |
| 183 int fd_in_browser; | 190 int fd_in_browser; |
| 184 temp_file_fd.fd = fd_in_browser = -1; | 191 temp_file_fd.fd = fd_in_browser = -1; |
| 185 temp_file_fd.auto_close = false; | 192 temp_file_fd.auto_close = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 (*map)[fd] = path; | 203 (*map)[fd] = path; |
| 197 temp_file_fd.fd = fd_in_browser = fd; | 204 temp_file_fd.fd = fd_in_browser = fd; |
| 198 temp_file_fd.auto_close = true; | 205 temp_file_fd.auto_close = true; |
| 199 } | 206 } |
| 200 } | 207 } |
| 201 } | 208 } |
| 202 | 209 |
| 203 ViewHostMsg_AllocateTempFileForPrinting::WriteReplyParams( | 210 ViewHostMsg_AllocateTempFileForPrinting::WriteReplyParams( |
| 204 reply_msg, temp_file_fd, fd_in_browser); | 211 reply_msg, temp_file_fd, fd_in_browser); |
| 205 | 212 |
| 206 ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask( | 213 ChromeThread::PostTask( |
| 207 FROM_HERE, NewRunnableMethod( | 214 ChromeThread::IO, FROM_HERE, |
| 215 NewRunnableMethod( |
| 208 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); | 216 this, &ResourceMessageFilter::SendDelayedReply, reply_msg)); |
| 209 } | 217 } |
| 210 | 218 |
| 211 // Called on the IO thread. | 219 // Called on the IO thread. |
| 212 void ResourceMessageFilter::OnGetScreenInfo(gfx::NativeViewId view, | 220 void ResourceMessageFilter::OnGetScreenInfo(gfx::NativeViewId view, |
| 213 IPC::Message* reply_msg) { | 221 IPC::Message* reply_msg) { |
| 214 ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask( | 222 ChromeThread::PostTask( |
| 215 FROM_HERE, NewRunnableMethod( | 223 ChromeThread::BACKGROUND_X11, FROM_HERE, |
| 224 NewRunnableMethod( |
| 216 this, &ResourceMessageFilter::DoOnGetScreenInfo, view, reply_msg)); | 225 this, &ResourceMessageFilter::DoOnGetScreenInfo, view, reply_msg)); |
| 217 } | 226 } |
| 218 | 227 |
| 219 // Called on the IO thread. | 228 // Called on the IO thread. |
| 220 void ResourceMessageFilter::OnGetWindowRect(gfx::NativeViewId view, | 229 void ResourceMessageFilter::OnGetWindowRect(gfx::NativeViewId view, |
| 221 IPC::Message* reply_msg) { | 230 IPC::Message* reply_msg) { |
| 222 ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask( | 231 ChromeThread::PostTask( |
| 223 FROM_HERE, NewRunnableMethod( | 232 ChromeThread::BACKGROUND_X11, FROM_HERE, |
| 233 NewRunnableMethod( |
| 224 this, &ResourceMessageFilter::DoOnGetWindowRect, view, reply_msg)); | 234 this, &ResourceMessageFilter::DoOnGetWindowRect, view, reply_msg)); |
| 225 } | 235 } |
| 226 | 236 |
| 227 // Called on the IO thread. | 237 // Called on the IO thread. |
| 228 void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId view, | 238 void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId view, |
| 229 IPC::Message* reply_msg) { | 239 IPC::Message* reply_msg) { |
| 230 ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask( | 240 ChromeThread::PostTask( |
| 231 FROM_HERE, NewRunnableMethod( | 241 ChromeThread::BACKGROUND_X11, FROM_HERE, |
| 242 NewRunnableMethod( |
| 232 this, &ResourceMessageFilter::DoOnGetRootWindowRect, view, | 243 this, &ResourceMessageFilter::DoOnGetRootWindowRect, view, |
| 233 reply_msg)); | 244 reply_msg)); |
| 234 } | 245 } |
| 235 | 246 |
| 236 // Called on the IO thread. | 247 // Called on the IO thread. |
| 237 void ResourceMessageFilter::OnClipboardIsFormatAvailable( | 248 void ResourceMessageFilter::OnClipboardIsFormatAvailable( |
| 238 Clipboard::FormatType format, Clipboard::Buffer buffer, | 249 Clipboard::FormatType format, Clipboard::Buffer buffer, |
| 239 IPC::Message* reply_msg) { | 250 IPC::Message* reply_msg) { |
| 240 ui_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 251 ui_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 241 this, &ResourceMessageFilter::DoOnClipboardIsFormatAvailable, format, | 252 this, &ResourceMessageFilter::DoOnClipboardIsFormatAvailable, format, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 262 void ResourceMessageFilter::OnClipboardReadHTML(Clipboard::Buffer buffer, | 273 void ResourceMessageFilter::OnClipboardReadHTML(Clipboard::Buffer buffer, |
| 263 IPC::Message* reply_msg) { | 274 IPC::Message* reply_msg) { |
| 264 ui_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 275 ui_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 265 this, &ResourceMessageFilter::DoOnClipboardReadHTML, buffer, | 276 this, &ResourceMessageFilter::DoOnClipboardReadHTML, buffer, |
| 266 reply_msg)); | 277 reply_msg)); |
| 267 } | 278 } |
| 268 | 279 |
| 269 // Called on the IO thread. | 280 // Called on the IO thread. |
| 270 void ResourceMessageFilter::OnAllocateTempFileForPrinting( | 281 void ResourceMessageFilter::OnAllocateTempFileForPrinting( |
| 271 IPC::Message* reply_msg) { | 282 IPC::Message* reply_msg) { |
| 272 ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask( | 283 ChromeThread::PostTask( |
| 273 FROM_HERE, NewRunnableMethod( | 284 ChromeThread::FILE, FROM_HERE, |
| 285 NewRunnableMethod( |
| 274 this, &ResourceMessageFilter::DoOnAllocateTempFileForPrinting, | 286 this, &ResourceMessageFilter::DoOnAllocateTempFileForPrinting, |
| 275 reply_msg)); | 287 reply_msg)); |
| 276 } | 288 } |
| 277 | 289 |
| 278 // Called on the IO thread. | 290 // Called on the IO thread. |
| 279 void ResourceMessageFilter::OnTempFileForPrintingWritten(int fd_in_browser) { | 291 void ResourceMessageFilter::OnTempFileForPrintingWritten(int fd_in_browser) { |
| 280 FdMap* map = &Singleton<PrintingFileDescriptorMap>::get()->map; | 292 FdMap* map = &Singleton<PrintingFileDescriptorMap>::get()->map; |
| 281 FdMap::iterator it = map->find(fd_in_browser); | 293 FdMap::iterator it = map->find(fd_in_browser); |
| 282 if (it == map->end()) { | 294 if (it == map->end()) { |
| 283 NOTREACHED() << "Got a file descriptor that we didn't pass to the " | 295 NOTREACHED() << "Got a file descriptor that we didn't pass to the " |
| 284 "renderer: " << fd_in_browser; | 296 "renderer: " << fd_in_browser; |
| 285 return; | 297 return; |
| 286 } | 298 } |
| 287 | 299 |
| 288 #if defined(TOOLKIT_GTK) | 300 #if defined(TOOLKIT_GTK) |
| 289 PrintDialogGtk::CreatePrintDialogForPdf(it->second, ui_loop()); | 301 PrintDialogGtk::CreatePrintDialogForPdf(it->second, ui_loop()); |
| 290 #else | 302 #else |
| 291 NOTIMPLEMENTED(); | 303 NOTIMPLEMENTED(); |
| 292 #endif | 304 #endif |
| 293 | 305 |
| 294 // Erase the entry in the map. | 306 // Erase the entry in the map. |
| 295 map->erase(it); | 307 map->erase(it); |
| 296 } | 308 } |
| OLD | NEW |