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

Side by Side Diff: chrome/browser/printing/print_view_manager.cc

Issue 10535045: TabContentsWrapper -> TabContents, for printing code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 months 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
OLDNEW
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_error_dialog.h" 15 #include "chrome/browser/printing/print_error_dialog.h"
16 #include "chrome/browser/printing/print_job.h" 16 #include "chrome/browser/printing/print_job.h"
17 #include "chrome/browser/printing/print_job_manager.h" 17 #include "chrome/browser/printing/print_job_manager.h"
18 #include "chrome/browser/printing/print_preview_tab_controller.h" 18 #include "chrome/browser/printing/print_preview_tab_controller.h"
19 #include "chrome/browser/printing/print_view_manager_observer.h" 19 #include "chrome/browser/printing/print_view_manager_observer.h"
20 #include "chrome/browser/printing/printer_query.h" 20 #include "chrome/browser/printing/printer_query.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents.h"
22 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 22 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/print_messages.h" 24 #include "chrome/common/print_messages.h"
25 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/browser/web_contents_view.h" 30 #include "content/public/browser/web_contents_view.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
(...skipping 12 matching lines...) Expand all
44 // No locking, only access on the UI thread. 44 // No locking, only access on the UI thread.
45 typedef std::map<content::RenderProcessHost*, base::Closure> 45 typedef std::map<content::RenderProcessHost*, base::Closure>
46 ScriptedPrintPreviewClosureMap; 46 ScriptedPrintPreviewClosureMap;
47 static base::LazyInstance<ScriptedPrintPreviewClosureMap> 47 static base::LazyInstance<ScriptedPrintPreviewClosureMap>
48 g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER; 48 g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER;
49 49
50 } // namespace 50 } // namespace
51 51
52 namespace printing { 52 namespace printing {
53 53
54 PrintViewManager::PrintViewManager(TabContentsWrapper* tab) 54 PrintViewManager::PrintViewManager(TabContents* tab)
55 : content::WebContentsObserver(tab->web_contents()), 55 : content::WebContentsObserver(tab->web_contents()),
56 tab_(tab), 56 tab_(tab),
57 number_pages_(0), 57 number_pages_(0),
58 printing_succeeded_(false), 58 printing_succeeded_(false),
59 inside_inner_message_loop_(false), 59 inside_inner_message_loop_(false),
60 observer_(NULL), 60 observer_(NULL),
61 cookie_(0), 61 cookie_(0),
62 print_preview_state_(NOT_PREVIEWING), 62 print_preview_state_(NOT_PREVIEWING),
63 scripted_print_preview_rph_(NULL) { 63 scripted_print_preview_rph_(NULL) {
64 #if defined(OS_POSIX) && !defined(OS_MACOSX) 64 #if defined(OS_POSIX) && !defined(OS_MACOSX)
65 expecting_first_page_ = true; 65 expecting_first_page_ = true;
66 #endif 66 #endif
67 registrar_.Add(this, chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED, 67 registrar_.Add(this, chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED,
68 content::Source<TabContentsWrapper>(tab)); 68 content::Source<TabContents>(tab));
69 } 69 }
70 70
71 PrintViewManager::~PrintViewManager() { 71 PrintViewManager::~PrintViewManager() {
72 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); 72 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_);
73 ReleasePrinterQuery(); 73 ReleasePrinterQuery();
74 DisconnectFromCurrentPrintJob(); 74 DisconnectFromCurrentPrintJob();
75 } 75 }
76 76
77 bool PrintViewManager::PrintNow() { 77 bool PrintViewManager::PrintNow() {
78 return PrintNowInternal(new PrintMsg_PrintPages(routing_id())); 78 return PrintNowInternal(new PrintMsg_PrintPages(routing_id()));
79 } 79 }
80 80
81 bool PrintViewManager::PrintForSystemDialogNow() { 81 bool PrintViewManager::PrintForSystemDialogNow() {
82 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); 82 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id()));
83 } 83 }
84 84
85 bool PrintViewManager::AdvancedPrintNow() { 85 bool PrintViewManager::AdvancedPrintNow() {
86 PrintPreviewTabController* tab_controller = 86 PrintPreviewTabController* tab_controller =
87 PrintPreviewTabController::GetInstance(); 87 PrintPreviewTabController::GetInstance();
88 if (!tab_controller) 88 if (!tab_controller)
89 return false; 89 return false;
90 TabContentsWrapper* print_preview_tab = 90 TabContents* print_preview_tab = tab_controller->GetPrintPreviewForTab(tab_);
91 tab_controller->GetPrintPreviewForTab(tab_);
92 if (print_preview_tab) { 91 if (print_preview_tab) {
93 // Preview tab exist for current tab or current tab is preview tab. 92 // Preview tab exist for current tab or current tab is preview tab.
94 if (!print_preview_tab->web_contents()->GetWebUI()) 93 if (!print_preview_tab->web_contents()->GetWebUI())
95 return false; 94 return false;
96 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 95 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
97 print_preview_tab->web_contents()->GetWebUI()->GetController()); 96 print_preview_tab->web_contents()->GetWebUI()->GetController());
98 print_preview_ui->OnShowSystemDialog(); 97 print_preview_ui->OnShowSystemDialog();
99 return true; 98 return true;
100 } else { 99 } else {
101 return PrintNow(); 100 return PrintNow();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return; 253 return;
255 } 254 }
256 255
257 browser::ShowPrintErrorDialog( 256 browser::ShowPrintErrorDialog(
258 tab_->web_contents()->GetView()->GetTopLevelNativeWindow()); 257 tab_->web_contents()->GetView()->GetTopLevelNativeWindow());
259 258
260 ReleasePrinterQuery(); 259 ReleasePrinterQuery();
261 260
262 content::NotificationService::current()->Notify( 261 content::NotificationService::current()->Notify(
263 chrome::NOTIFICATION_PRINT_JOB_RELEASED, 262 chrome::NOTIFICATION_PRINT_JOB_RELEASED,
264 content::Source<TabContentsWrapper>(tab_), 263 content::Source<TabContents>(tab_),
265 content::NotificationService::NoDetails()); 264 content::NotificationService::NoDetails());
266 } 265 }
267 266
268 void PrintViewManager::OnScriptedPrintPreview(bool source_is_modifiable, 267 void PrintViewManager::OnScriptedPrintPreview(bool source_is_modifiable,
269 IPC::Message* reply_msg) { 268 IPC::Message* reply_msg) {
270 BrowserThread::CurrentlyOn(BrowserThread::UI); 269 BrowserThread::CurrentlyOn(BrowserThread::UI);
271 ScriptedPrintPreviewClosureMap& map = 270 ScriptedPrintPreviewClosureMap& map =
272 g_scripted_print_preview_closure_map.Get(); 271 g_scripted_print_preview_closure_map.Get();
273 content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost(); 272 content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost();
274 273
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 348 }
350 349
351 void PrintViewManager::OnNotifyPrintJobEvent( 350 void PrintViewManager::OnNotifyPrintJobEvent(
352 const JobEventDetails& event_details) { 351 const JobEventDetails& event_details) {
353 switch (event_details.type()) { 352 switch (event_details.type()) {
354 case JobEventDetails::FAILED: { 353 case JobEventDetails::FAILED: {
355 TerminatePrintJob(true); 354 TerminatePrintJob(true);
356 355
357 content::NotificationService::current()->Notify( 356 content::NotificationService::current()->Notify(
358 chrome::NOTIFICATION_PRINT_JOB_RELEASED, 357 chrome::NOTIFICATION_PRINT_JOB_RELEASED,
359 content::Source<TabContentsWrapper>(tab_), 358 content::Source<TabContents>(tab_),
360 content::NotificationService::NoDetails()); 359 content::NotificationService::NoDetails());
361 break; 360 break;
362 } 361 }
363 case JobEventDetails::USER_INIT_DONE: 362 case JobEventDetails::USER_INIT_DONE:
364 case JobEventDetails::DEFAULT_INIT_DONE: 363 case JobEventDetails::DEFAULT_INIT_DONE:
365 case JobEventDetails::USER_INIT_CANCELED: { 364 case JobEventDetails::USER_INIT_CANCELED: {
366 NOTREACHED(); 365 NOTREACHED();
367 break; 366 break;
368 } 367 }
369 case JobEventDetails::ALL_PAGES_REQUESTED: { 368 case JobEventDetails::ALL_PAGES_REQUESTED: {
370 ShouldQuitFromInnerMessageLoop(); 369 ShouldQuitFromInnerMessageLoop();
371 break; 370 break;
372 } 371 }
373 case JobEventDetails::NEW_DOC: 372 case JobEventDetails::NEW_DOC:
374 case JobEventDetails::NEW_PAGE: 373 case JobEventDetails::NEW_PAGE:
375 case JobEventDetails::PAGE_DONE: 374 case JobEventDetails::PAGE_DONE:
376 case JobEventDetails::DOC_DONE: { 375 case JobEventDetails::DOC_DONE: {
377 // Don't care about the actual printing process. 376 // Don't care about the actual printing process.
378 break; 377 break;
379 } 378 }
380 case JobEventDetails::JOB_DONE: { 379 case JobEventDetails::JOB_DONE: {
381 // Printing is done, we don't need it anymore. 380 // Printing is done, we don't need it anymore.
382 // print_job_->is_job_pending() may still be true, depending on the order 381 // print_job_->is_job_pending() may still be true, depending on the order
383 // of object registration. 382 // of object registration.
384 printing_succeeded_ = true; 383 printing_succeeded_ = true;
385 ReleasePrintJob(); 384 ReleasePrintJob();
386 385
387 content::NotificationService::current()->Notify( 386 content::NotificationService::current()->Notify(
388 chrome::NOTIFICATION_PRINT_JOB_RELEASED, 387 chrome::NOTIFICATION_PRINT_JOB_RELEASED,
389 content::Source<TabContentsWrapper>(tab_), 388 content::Source<TabContents>(tab_),
390 content::NotificationService::NoDetails()); 389 content::NotificationService::NoDetails());
391 break; 390 break;
392 } 391 }
393 default: { 392 default: {
394 NOTREACHED(); 393 NOTREACHED();
395 break; 394 break;
396 } 395 }
397 } 396 }
398 } 397 }
399 398
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 scoped_refptr<printing::PrinterQuery> printer_query; 623 scoped_refptr<printing::PrinterQuery> printer_query;
625 print_job_manager->PopPrinterQuery(cookie, &printer_query); 624 print_job_manager->PopPrinterQuery(cookie, &printer_query);
626 if (!printer_query.get()) 625 if (!printer_query.get())
627 return; 626 return;
628 BrowserThread::PostTask( 627 BrowserThread::PostTask(
629 BrowserThread::IO, FROM_HERE, 628 BrowserThread::IO, FROM_HERE,
630 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); 629 base::Bind(&PrinterQuery::StopWorker, printer_query.get()));
631 } 630 }
632 631
633 } // namespace printing 632 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_view_manager.h ('k') | chrome/browser/printing/printing_layout_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698