OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/i18n/file_util_icu.h" | 15 #include "base/i18n/file_util_icu.h" |
16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "chrome/browser/browser_process.h" | |
25 #include "chrome/browser/platform_util.h" | 24 #include "chrome/browser/platform_util.h" |
26 #include "chrome/browser/printing/background_printing_manager.h" | |
27 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 25 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
28 #include "chrome/browser/printing/print_dialog_cloud.h" | 26 #include "chrome/browser/printing/print_dialog_cloud.h" |
29 #include "chrome/browser/printing/print_job_manager.h" | 27 #include "chrome/browser/printing/print_job_manager.h" |
30 #include "chrome/browser/printing/print_preview_tab_controller.h" | 28 #include "chrome/browser/printing/print_preview_tab_controller.h" |
31 #include "chrome/browser/printing/print_system_task_proxy.h" | 29 #include "chrome/browser/printing/print_system_task_proxy.h" |
32 #include "chrome/browser/printing/print_view_manager.h" | 30 #include "chrome/browser/printing/print_view_manager.h" |
33 #include "chrome/browser/printing/printer_manager_dialog.h" | 31 #include "chrome/browser/printing/printer_manager_dialog.h" |
34 #include "chrome/browser/sessions/restore_tab_helper.h" | |
35 #include "chrome/browser/tabs/tab_strip_model.h" | |
36 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 33 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
38 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" | 34 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" |
39 #include "chrome/browser/ui/webui/print_preview_ui.h" | 35 #include "chrome/browser/ui/webui/print_preview_ui.h" |
40 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
41 #include "chrome/common/print_messages.h" | 37 #include "chrome/common/print_messages.h" |
42 #include "content/browser/browser_thread.h" | 38 #include "content/browser/browser_thread.h" |
43 #include "content/browser/renderer_host/render_view_host.h" | 39 #include "content/browser/renderer_host/render_view_host.h" |
44 #include "content/browser/tab_contents/tab_contents.h" | 40 #include "content/browser/tab_contents/tab_contents.h" |
45 #include "printing/backend/print_backend.h" | 41 #include "printing/backend/print_backend.h" |
46 #include "printing/metafile.h" | 42 #include "printing/metafile.h" |
47 #include "printing/metafile_impl.h" | 43 #include "printing/metafile_impl.h" |
48 #include "printing/page_range.h" | 44 #include "printing/page_range.h" |
49 #include "printing/print_settings.h" | 45 #include "printing/print_settings.h" |
50 | 46 |
51 #if !defined(OS_CHROMEOS) | 47 #if !defined(OS_CHROMEOS) |
52 #include "base/command_line.h" | 48 #include "base/command_line.h" |
53 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
54 #endif | 50 #endif |
55 | 51 |
56 namespace { | 52 namespace { |
57 | 53 |
58 enum UserActionBuckets { | 54 enum UserActionBuckets { |
59 PRINT_TO_PRINTER, | 55 PRINT_TO_PRINTER, |
60 PRINT_TO_PDF, | 56 PRINT_TO_PDF, |
61 CANCEL, | 57 CANCEL, |
62 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, | 58 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, |
63 PREVIEW_FAILED, | 59 PREVIEW_FAILED, |
64 PREVIEW_STARTED, | 60 PREVIEW_STARTED, |
65 INITIATOR_TAB_CRASHED, | 61 INITIATOR_TAB_CRASHED, // UNUSED |
66 INITIATOR_TAB_CLOSED, | 62 INITIATOR_TAB_CLOSED, |
67 PRINT_WITH_CLOUD_PRINT, | 63 PRINT_WITH_CLOUD_PRINT, |
68 USERACTION_BUCKET_BOUNDARY | 64 USERACTION_BUCKET_BOUNDARY |
69 }; | 65 }; |
70 | 66 |
71 enum PrintSettingsBuckets { | 67 enum PrintSettingsBuckets { |
72 LANDSCAPE, | 68 LANDSCAPE, |
73 PORTRAIT, | 69 PORTRAIT, |
74 COLOR, | 70 COLOR, |
75 BLACK_AND_WHITE, | 71 BLACK_AND_WHITE, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) | 146 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) |
151 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); | 147 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); |
152 | 148 |
153 int color_mode; | 149 int color_mode; |
154 if (settings.GetInteger(printing::kSettingColor, &color_mode)) { | 150 if (settings.GetInteger(printing::kSettingColor, &color_mode)) { |
155 ReportPrintSettingHistogram( | 151 ReportPrintSettingHistogram( |
156 printing::isColorModelSelected(color_mode) ? COLOR : BLACK_AND_WHITE); | 152 printing::isColorModelSelected(color_mode) ? COLOR : BLACK_AND_WHITE); |
157 } | 153 } |
158 } | 154 } |
159 | 155 |
160 printing::BackgroundPrintingManager* GetBackgroundPrintingManager() { | |
161 return g_browser_process->background_printing_manager(); | |
162 } | |
163 | |
164 } // namespace | 156 } // namespace |
165 | 157 |
166 // A Task implementation that stores a PDF file on disk. | 158 // A Task implementation that stores a PDF file on disk. |
167 class PrintToPdfTask : public Task { | 159 class PrintToPdfTask : public Task { |
168 public: | 160 public: |
169 // Takes ownership of |metafile|. | 161 // Takes ownership of |metafile|. |
170 PrintToPdfTask(printing::Metafile* metafile, const FilePath& path) | 162 PrintToPdfTask(printing::Metafile* metafile, const FilePath& path) |
171 : metafile_(metafile), path_(path) { | 163 : metafile_(metafile), path_(path) { |
172 DCHECK(metafile); | 164 DCHECK(metafile); |
173 } | 165 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 base::Unretained(this))); | 225 base::Unretained(this))); |
234 web_ui_->RegisterMessageCallback("signIn", | 226 web_ui_->RegisterMessageCallback("signIn", |
235 base::Bind(&PrintPreviewHandler::HandleSignin, | 227 base::Bind(&PrintPreviewHandler::HandleSignin, |
236 base::Unretained(this))); | 228 base::Unretained(this))); |
237 web_ui_->RegisterMessageCallback("manageCloudPrinters", | 229 web_ui_->RegisterMessageCallback("manageCloudPrinters", |
238 base::Bind(&PrintPreviewHandler::HandleManageCloudPrint, | 230 base::Bind(&PrintPreviewHandler::HandleManageCloudPrint, |
239 base::Unretained(this))); | 231 base::Unretained(this))); |
240 web_ui_->RegisterMessageCallback("manageLocalPrinters", | 232 web_ui_->RegisterMessageCallback("manageLocalPrinters", |
241 base::Bind(&PrintPreviewHandler::HandleManagePrinters, | 233 base::Bind(&PrintPreviewHandler::HandleManagePrinters, |
242 base::Unretained(this))); | 234 base::Unretained(this))); |
243 web_ui_->RegisterMessageCallback("reloadCrashedInitiatorTab", | |
244 base::Bind(&PrintPreviewHandler::HandleReloadCrashedInitiatorTab, | |
245 base::Unretained(this))); | |
246 web_ui_->RegisterMessageCallback("closePrintPreviewTab", | 235 web_ui_->RegisterMessageCallback("closePrintPreviewTab", |
247 base::Bind(&PrintPreviewHandler::HandleClosePreviewTab, | 236 base::Bind(&PrintPreviewHandler::HandleClosePreviewTab, |
248 base::Unretained(this))); | 237 base::Unretained(this))); |
249 web_ui_->RegisterMessageCallback("hidePreview", | 238 web_ui_->RegisterMessageCallback("hidePreview", |
250 base::Bind(&PrintPreviewHandler::HandleHidePreview, | 239 base::Bind(&PrintPreviewHandler::HandleHidePreview, |
251 base::Unretained(this))); | 240 base::Unretained(this))); |
252 web_ui_->RegisterMessageCallback("cancelPendingPrintRequest", | 241 web_ui_->RegisterMessageCallback("cancelPendingPrintRequest", |
253 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, | 242 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, |
254 base::Unretained(this))); | 243 base::Unretained(this))); |
255 web_ui_->RegisterMessageCallback("saveLastPrinter", | 244 web_ui_->RegisterMessageCallback("saveLastPrinter", |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 // thread. | 294 // thread. |
306 settings->SetString(printing::kPreviewUIAddr, | 295 settings->SetString(printing::kPreviewUIAddr, |
307 print_preview_ui->GetPrintPreviewUIAddress()); | 296 print_preview_ui->GetPrintPreviewUIAddress()); |
308 | 297 |
309 // Increment request count. | 298 // Increment request count. |
310 ++regenerate_preview_request_count_; | 299 ++regenerate_preview_request_count_; |
311 | 300 |
312 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 301 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
313 if (!initiator_tab) { | 302 if (!initiator_tab) { |
314 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); | 303 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); |
315 print_preview_ui->OnInitiatorTabClosed(); | 304 print_preview_ui->OnClosePrintPreviewTab(); |
316 return; | 305 return; |
317 } | 306 } |
318 | 307 |
319 // Retrieve the page title and url and send it to the renderer process if | 308 // Retrieve the page title and url and send it to the renderer process if |
320 // headers and footers are to be displayed. | 309 // headers and footers are to be displayed. |
321 bool display_header_footer = false; | 310 bool display_header_footer = false; |
322 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, | 311 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, |
323 &display_header_footer)) { | 312 &display_header_footer)) { |
324 NOTREACHED(); | 313 NOTREACHED(); |
325 } | 314 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 } else if (is_cloud_dialog) { | 389 } else if (is_cloud_dialog) { |
401 HandlePrintWithCloudPrint(); | 390 HandlePrintWithCloudPrint(); |
402 } else { | 391 } else { |
403 ReportPrintSettingsStats(*settings); | 392 ReportPrintSettingsStats(*settings); |
404 ReportUserActionHistogram(PRINT_TO_PRINTER); | 393 ReportUserActionHistogram(PRINT_TO_PRINTER); |
405 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", | 394 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", |
406 GetPageCountFromSettingsDictionary(*settings)); | 395 GetPageCountFromSettingsDictionary(*settings)); |
407 | 396 |
408 // This tries to activate the initiator tab as well, so do not clear the | 397 // This tries to activate the initiator tab as well, so do not clear the |
409 // association with the initiator tab yet. | 398 // association with the initiator tab yet. |
410 HidePreviewTab(); | 399 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
400 print_preview_ui->OnHidePreviewTab(); | |
411 | 401 |
412 // Do this so the initiator tab can open a new print preview tab. | 402 // Do this so the initiator tab can open a new print preview tab. |
413 ClearInitiatorTabDetails(); | 403 ClearInitiatorTabDetails(); |
414 | 404 |
415 // The PDF being printed contains only the pages that the user selected, | 405 // The PDF being printed contains only the pages that the user selected, |
416 // so ignore the page range and print all pages. | 406 // so ignore the page range and print all pages. |
417 settings->Remove(printing::kSettingPageRange, NULL); | 407 settings->Remove(printing::kSettingPageRange, NULL); |
418 RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); | 408 RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); |
419 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); | 409 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
410 if (initiator_tab) | |
411 initiator_tab->print_view_manager()->PrintPreviewDone(); | |
kmadhusu
2011/10/14 22:48:13
How do you exit the nested loop in other cases?
Lei Zhang
2011/10/14 23:22:07
The other cases all close the print preview dialog
| |
420 } | 412 } |
421 } | 413 } |
422 | 414 |
423 void PrintPreviewHandler::HandlePrintToPdf( | 415 void PrintPreviewHandler::HandlePrintToPdf( |
424 const base::DictionaryValue& settings) { | 416 const base::DictionaryValue& settings) { |
425 if (print_to_pdf_path_.get()) { | 417 if (print_to_pdf_path_.get()) { |
426 // User has already selected a path, no need to show the dialog again. | 418 // User has already selected a path, no need to show the dialog again. |
427 PostPrintToPdfTask(); | 419 PostPrintToPdfTask(); |
428 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( | 420 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( |
429 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { | 421 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { |
(...skipping 14 matching lines...) Expand all Loading... | |
444 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); | 436 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
445 FilePath default_filename(print_job_title); | 437 FilePath default_filename(print_job_title); |
446 default_filename = | 438 default_filename = |
447 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 439 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
448 | 440 |
449 SelectFile(default_filename); | 441 SelectFile(default_filename); |
450 } | 442 } |
451 } | 443 } |
452 | 444 |
453 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { | 445 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { |
454 HidePreviewTab(); | 446 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
447 print_preview_ui->OnHidePreviewTab(); | |
455 } | 448 } |
456 | 449 |
457 void PrintPreviewHandler::HandleCancelPendingPrintRequest( | 450 void PrintPreviewHandler::HandleCancelPendingPrintRequest( |
458 const ListValue* /*args*/) { | 451 const ListValue* /*args*/) { |
459 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 452 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
460 if (initiator_tab) { | 453 if (initiator_tab) { |
461 ClearInitiatorTabDetails(); | 454 ClearInitiatorTabDetails(); |
462 } else { | 455 } else { |
463 // Initiator tab does not exists. Get the wrapper contents of current tab. | 456 // Initiator tab does not exists. Get the wrapper contents of current tab. |
464 Browser* browser = BrowserList::GetLastActive(); | 457 Browser* browser = BrowserList::GetLastActive(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 // Cancel the pending preview request if exists. | 548 // Cancel the pending preview request if exists. |
556 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 549 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
557 print_preview_ui->OnCancelPendingPreviewRequest(); | 550 print_preview_ui->OnCancelPendingPreviewRequest(); |
558 } | 551 } |
559 | 552 |
560 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { | 553 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { |
561 ++manage_printers_dialog_request_count_; | 554 ++manage_printers_dialog_request_count_; |
562 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 555 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
563 } | 556 } |
564 | 557 |
565 void PrintPreviewHandler::HandleReloadCrashedInitiatorTab( | |
566 const ListValue* /*args*/) { | |
567 ReportStats(); | |
568 ReportUserActionHistogram(INITIATOR_TAB_CRASHED); | |
569 | |
570 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | |
571 if (!initiator_tab) | |
572 return; | |
573 | |
574 TabContents* contents = initiator_tab->tab_contents(); | |
575 contents->OpenURL(contents->GetURL(), GURL(), CURRENT_TAB, | |
576 content::PAGE_TRANSITION_RELOAD); | |
577 ActivateInitiatorTabAndClosePreviewTab(); | |
578 } | |
579 | |
580 void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* /*args*/) { | 558 void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* /*args*/) { |
581 ReportStats(); | 559 ReportStats(); |
582 ReportUserActionHistogram(CANCEL); | 560 ReportUserActionHistogram(CANCEL); |
583 | 561 |
584 // Record the number of times the user requests to regenerate preview data | 562 // Record the number of times the user requests to regenerate preview data |
585 // before cancelling. | 563 // before cancelling. |
586 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", | 564 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", |
587 regenerate_preview_request_count_); | 565 regenerate_preview_request_count_); |
588 | |
589 ActivateInitiatorTabAndClosePreviewTab(); | |
590 } | 566 } |
591 | 567 |
592 void PrintPreviewHandler::ReportStats() { | 568 void PrintPreviewHandler::ReportStats() { |
593 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters", | 569 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters", |
594 manage_printers_dialog_request_count_); | 570 manage_printers_dialog_request_count_); |
595 } | 571 } |
596 | 572 |
597 void PrintPreviewHandler::HandleGetInitiatorTabTitle( | 573 void PrintPreviewHandler::HandleGetInitiatorTabTitle( |
598 const ListValue* /*args*/) { | 574 const ListValue* /*args*/) { |
599 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 575 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
600 base::StringValue tab_title(print_preview_ui->initiator_tab_title()); | 576 base::StringValue tab_title(print_preview_ui->initiator_tab_title()); |
601 web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title); | 577 web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title); |
602 } | 578 } |
603 | 579 |
604 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 580 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
605 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 581 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
606 if (initiator_tab) { | 582 if (initiator_tab) { |
607 static_cast<RenderViewHostDelegate*>( | 583 static_cast<RenderViewHostDelegate*>( |
608 initiator_tab->tab_contents())->Activate(); | 584 initiator_tab->tab_contents())->Activate(); |
609 } | 585 } |
610 ClosePrintPreviewTab(); | 586 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
587 print_preview_ui->OnClosePrintPreviewTab(); | |
611 } | 588 } |
612 | 589 |
613 void PrintPreviewHandler::SendPrinterCapabilities( | 590 void PrintPreviewHandler::SendPrinterCapabilities( |
614 const DictionaryValue& settings_info) { | 591 const DictionaryValue& settings_info) { |
615 VLOG(1) << "Get printer capabilities finished"; | 592 VLOG(1) << "Get printer capabilities finished"; |
616 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", | 593 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", |
617 settings_info); | 594 settings_info); |
618 } | 595 } |
619 | 596 |
620 void PrintPreviewHandler::SendDefaultPrinter( | 597 void PrintPreviewHandler::SendDefaultPrinter( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 } | 673 } |
697 | 674 |
698 TabContentsWrapper* PrintPreviewHandler::GetInitiatorTab() const { | 675 TabContentsWrapper* PrintPreviewHandler::GetInitiatorTab() const { |
699 printing::PrintPreviewTabController* tab_controller = | 676 printing::PrintPreviewTabController* tab_controller = |
700 printing::PrintPreviewTabController::GetInstance(); | 677 printing::PrintPreviewTabController::GetInstance(); |
701 if (!tab_controller) | 678 if (!tab_controller) |
702 return NULL; | 679 return NULL; |
703 return tab_controller->GetInitiatorTab(preview_tab_wrapper()); | 680 return tab_controller->GetInitiatorTab(preview_tab_wrapper()); |
704 } | 681 } |
705 | 682 |
706 void PrintPreviewHandler::ClosePrintPreviewTab() { | |
707 TabContentsWrapper* tab = | |
708 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | |
709 if (!tab) | |
710 return; | |
711 Browser* preview_tab_browser = BrowserList::FindBrowserWithID( | |
712 tab->restore_tab_helper()->window_id().id()); | |
713 if (!preview_tab_browser) | |
714 return; | |
715 TabStripModel* tabstrip = preview_tab_browser->tabstrip_model(); | |
716 int index = tabstrip->GetIndexOfTabContents(tab); | |
717 if (index == TabStripModel::kNoTab) | |
718 return; | |
719 | |
720 // Keep print preview tab out of the recently closed tab list, because | |
721 // re-opening that page will just display a non-functional print preview page. | |
722 tabstrip->CloseTabContentsAt(index, TabStripModel::CLOSE_NONE); | |
723 } | |
724 | |
725 void PrintPreviewHandler::OnPrintDialogShown() { | 683 void PrintPreviewHandler::OnPrintDialogShown() { |
726 ActivateInitiatorTabAndClosePreviewTab(); | 684 ActivateInitiatorTabAndClosePreviewTab(); |
727 } | 685 } |
728 | 686 |
729 void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { | 687 void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { |
730 SelectFileDialog::FileTypeInfo file_type_info; | 688 SelectFileDialog::FileTypeInfo file_type_info; |
731 file_type_info.extensions.resize(1); | 689 file_type_info.extensions.resize(1); |
732 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); | 690 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); |
733 | 691 |
734 // Initializing last_saved_path_ if it is not already initialized. | 692 // Initializing last_saved_path_ if it is not already initialized. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 761 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
804 print_to_pdf_path_.reset(); | 762 print_to_pdf_path_.reset(); |
805 ActivateInitiatorTabAndClosePreviewTab(); | 763 ActivateInitiatorTabAndClosePreviewTab(); |
806 } | 764 } |
807 | 765 |
808 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 766 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
809 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 767 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
810 print_preview_ui->OnFileSelectionCancelled(); | 768 print_preview_ui->OnFileSelectionCancelled(); |
811 } | 769 } |
812 | 770 |
813 void PrintPreviewHandler::HidePreviewTab() { | |
814 if (GetBackgroundPrintingManager()->HasPrintPreviewTab(preview_tab_wrapper())) | |
815 return; | |
816 GetBackgroundPrintingManager()->OwnPrintPreviewTab(preview_tab_wrapper()); | |
817 } | |
818 | |
819 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 771 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
820 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 772 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
821 if (!initiator_tab) | 773 if (!initiator_tab) |
822 return; | 774 return; |
823 | 775 |
824 // We no longer require the initiator tab details. Remove those details | 776 // We no longer require the initiator tab details. Remove those details |
825 // associated with the preview tab to allow the initiator tab to create | 777 // associated with the preview tab to allow the initiator tab to create |
826 // another preview tab. | 778 // another preview tab. |
827 printing::PrintPreviewTabController* tab_controller = | 779 printing::PrintPreviewTabController* tab_controller = |
828 printing::PrintPreviewTabController::GetInstance(); | 780 printing::PrintPreviewTabController::GetInstance(); |
829 if (tab_controller) | 781 if (tab_controller) |
830 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 782 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
831 } | 783 } |
OLD | NEW |