| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/printing/print_view_manager.h" | 5 #include "chrome/browser/printing/print_view_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/printing/print_job.h" | 15 #include "chrome/browser/printing/print_job.h" |
| 16 #include "chrome/browser/printing/print_job_manager.h" | 16 #include "chrome/browser/printing/print_job_manager.h" |
| 17 #include "chrome/browser/printing/print_preview_tab_controller.h" | 17 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 18 #include "chrome/browser/printing/print_view_manager_observer.h" | 18 #include "chrome/browser/printing/print_view_manager_observer.h" |
| 19 #include "chrome/browser/printing/printer_query.h" | 19 #include "chrome/browser/printing/printer_query.h" |
| 20 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 21 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 22 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/print_messages.h" | 24 #include "chrome/common/print_messages.h" |
| 24 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 27 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 return; | 253 return; |
| 253 } | 254 } |
| 254 ReleasePrinterQuery(); | 255 ReleasePrinterQuery(); |
| 255 | 256 |
| 256 content::NotificationService::current()->Notify( | 257 content::NotificationService::current()->Notify( |
| 257 chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 258 chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
| 258 content::Source<TabContentsWrapper>(tab_), | 259 content::Source<TabContentsWrapper>(tab_), |
| 259 content::NotificationService::NoDetails()); | 260 content::NotificationService::NoDetails()); |
| 260 } | 261 } |
| 261 | 262 |
| 263 void PrintViewManager::OnCheckScriptedPrintAllowed(bool* allowed) { |
| 264 // If our tab isn't isn't in the browser list, printing shouldn't |
| 265 // be allowed. Most likely case is a blocked popup. |
| 266 *allowed = BrowserList::FindBrowserWithWebContents(web_contents()) != NULL; |
| 267 } |
| 268 |
| 262 void PrintViewManager::OnScriptedPrintPreview(bool source_is_modifiable, | 269 void PrintViewManager::OnScriptedPrintPreview(bool source_is_modifiable, |
| 263 IPC::Message* reply_msg) { | 270 IPC::Message* reply_msg) { |
| 264 BrowserThread::CurrentlyOn(BrowserThread::UI); | 271 BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 265 ScriptedPrintPreviewClosureMap& map = | 272 ScriptedPrintPreviewClosureMap& map = |
| 266 g_scripted_print_preview_closure_map.Get(); | 273 g_scripted_print_preview_closure_map.Get(); |
| 267 content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost(); | 274 content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost(); |
| 268 | 275 |
| 269 // This should always be 0 once we get modal window.print(). | 276 // This should always be 0 once we get modal window.print(). |
| 270 if (map.count(rph) != 0) { | 277 if (map.count(rph) != 0) { |
| 271 // Renderer already handling window.print() in another View. | 278 // Renderer already handling window.print() in another View. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { | 316 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
| 310 bool handled = true; | 317 bool handled = true; |
| 311 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) | 318 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
| 312 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 319 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
| 313 OnDidGetPrintedPagesCount) | 320 OnDidGetPrintedPagesCount) |
| 314 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, | 321 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, |
| 315 OnDidGetDocumentCookie) | 322 OnDidGetDocumentCookie) |
| 316 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) | 323 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) |
| 317 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 324 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
| 318 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) | 325 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) |
| 326 IPC_MESSAGE_HANDLER(PrintHostMsg_CheckScriptedPrintAllowed, |
| 327 OnCheckScriptedPrintAllowed) |
| 319 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrintPreview, | 328 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrintPreview, |
| 320 OnScriptedPrintPreview) | 329 OnScriptedPrintPreview) |
| 321 IPC_MESSAGE_UNHANDLED(handled = false) | 330 IPC_MESSAGE_UNHANDLED(handled = false) |
| 322 IPC_END_MESSAGE_MAP() | 331 IPC_END_MESSAGE_MAP() |
| 323 return handled; | 332 return handled; |
| 324 } | 333 } |
| 325 | 334 |
| 326 void PrintViewManager::Observe(int type, | 335 void PrintViewManager::Observe(int type, |
| 327 const content::NotificationSource& source, | 336 const content::NotificationSource& source, |
| 328 const content::NotificationDetails& details) { | 337 const content::NotificationDetails& details) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 scoped_refptr<printing::PrinterQuery> printer_query; | 623 scoped_refptr<printing::PrinterQuery> printer_query; |
| 615 print_job_manager->PopPrinterQuery(cookie, &printer_query); | 624 print_job_manager->PopPrinterQuery(cookie, &printer_query); |
| 616 if (!printer_query.get()) | 625 if (!printer_query.get()) |
| 617 return; | 626 return; |
| 618 BrowserThread::PostTask( | 627 BrowserThread::PostTask( |
| 619 BrowserThread::IO, FROM_HERE, | 628 BrowserThread::IO, FROM_HERE, |
| 620 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 629 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
| 621 } | 630 } |
| 622 | 631 |
| 623 } // namespace printing | 632 } // namespace printing |
| OLD | NEW |