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, // UNUSED |
kmadhusu
2011/10/14 00:21:09
Add a todo to fix this later. We need to record th
Lei Zhang
2011/10/14 20:31:27
I put it back to use.
| |
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", | |
247 base::Bind(&PrintPreviewHandler::HandleClosePreviewTab, | |
248 base::Unretained(this))); | |
249 web_ui_->RegisterMessageCallback("hidePreview", | 235 web_ui_->RegisterMessageCallback("hidePreview", |
250 base::Bind(&PrintPreviewHandler::HandleHidePreview, | 236 base::Bind(&PrintPreviewHandler::HandleHidePreview, |
251 base::Unretained(this))); | 237 base::Unretained(this))); |
252 web_ui_->RegisterMessageCallback("cancelPendingPrintRequest", | 238 web_ui_->RegisterMessageCallback("cancelPendingPrintRequest", |
253 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, | 239 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, |
254 base::Unretained(this))); | 240 base::Unretained(this))); |
255 web_ui_->RegisterMessageCallback("saveLastPrinter", | 241 web_ui_->RegisterMessageCallback("saveLastPrinter", |
256 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, | 242 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, |
257 base::Unretained(this))); | 243 base::Unretained(this))); |
258 web_ui_->RegisterMessageCallback("getInitiatorTabTitle", | 244 web_ui_->RegisterMessageCallback("getInitiatorTabTitle", |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 // thread. | 291 // thread. |
306 settings->SetString(printing::kPreviewUIAddr, | 292 settings->SetString(printing::kPreviewUIAddr, |
307 print_preview_ui->GetPrintPreviewUIAddress()); | 293 print_preview_ui->GetPrintPreviewUIAddress()); |
308 | 294 |
309 // Increment request count. | 295 // Increment request count. |
310 ++regenerate_preview_request_count_; | 296 ++regenerate_preview_request_count_; |
311 | 297 |
312 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 298 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
313 if (!initiator_tab) { | 299 if (!initiator_tab) { |
314 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); | 300 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); |
315 print_preview_ui->OnInitiatorTabClosed(); | 301 print_preview_ui->ClosePrintPreviewTab(); |
316 return; | 302 return; |
317 } | 303 } |
318 | 304 |
319 // Retrieve the page title and url and send it to the renderer process if | 305 // Retrieve the page title and url and send it to the renderer process if |
320 // headers and footers are to be displayed. | 306 // headers and footers are to be displayed. |
321 bool display_header_footer = false; | 307 bool display_header_footer = false; |
322 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, | 308 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, |
323 &display_header_footer)) { | 309 &display_header_footer)) { |
324 NOTREACHED(); | 310 NOTREACHED(); |
325 } | 311 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 } else if (is_cloud_dialog) { | 386 } else if (is_cloud_dialog) { |
401 HandlePrintWithCloudPrint(); | 387 HandlePrintWithCloudPrint(); |
402 } else { | 388 } else { |
403 ReportPrintSettingsStats(*settings); | 389 ReportPrintSettingsStats(*settings); |
404 ReportUserActionHistogram(PRINT_TO_PRINTER); | 390 ReportUserActionHistogram(PRINT_TO_PRINTER); |
405 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", | 391 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", |
406 GetPageCountFromSettingsDictionary(*settings)); | 392 GetPageCountFromSettingsDictionary(*settings)); |
407 | 393 |
408 // This tries to activate the initiator tab as well, so do not clear the | 394 // This tries to activate the initiator tab as well, so do not clear the |
409 // association with the initiator tab yet. | 395 // association with the initiator tab yet. |
410 HidePreviewTab(); | 396 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
397 print_preview_ui->HidePreviewTab(); | |
411 | 398 |
412 // Do this so the initiator tab can open a new print preview tab. | 399 // Do this so the initiator tab can open a new print preview tab. |
413 ClearInitiatorTabDetails(); | 400 ClearInitiatorTabDetails(); |
414 | 401 |
415 // The PDF being printed contains only the pages that the user selected, | 402 // The PDF being printed contains only the pages that the user selected, |
416 // so ignore the page range and print all pages. | 403 // so ignore the page range and print all pages. |
417 settings->Remove(printing::kSettingPageRange, NULL); | 404 settings->Remove(printing::kSettingPageRange, NULL); |
418 RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); | 405 RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); |
419 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); | 406 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
420 } | 407 } |
408 if (initiator_tab) | |
409 initiator_tab->print_view_manager()->PrintPreviewDone(); | |
421 } | 410 } |
422 | 411 |
423 void PrintPreviewHandler::HandlePrintToPdf( | 412 void PrintPreviewHandler::HandlePrintToPdf( |
424 const base::DictionaryValue& settings) { | 413 const base::DictionaryValue& settings) { |
425 if (print_to_pdf_path_.get()) { | 414 if (print_to_pdf_path_.get()) { |
426 // User has already selected a path, no need to show the dialog again. | 415 // User has already selected a path, no need to show the dialog again. |
427 PostPrintToPdfTask(); | 416 PostPrintToPdfTask(); |
428 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( | 417 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( |
429 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { | 418 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { |
430 ReportUserActionHistogram(PRINT_TO_PDF); | 419 ReportUserActionHistogram(PRINT_TO_PDF); |
(...skipping 13 matching lines...) Expand all Loading... | |
444 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); | 433 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
445 FilePath default_filename(print_job_title); | 434 FilePath default_filename(print_job_title); |
446 default_filename = | 435 default_filename = |
447 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 436 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
448 | 437 |
449 SelectFile(default_filename); | 438 SelectFile(default_filename); |
450 } | 439 } |
451 } | 440 } |
452 | 441 |
453 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { | 442 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { |
454 HidePreviewTab(); | 443 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
444 print_preview_ui->HidePreviewTab(); | |
455 } | 445 } |
456 | 446 |
457 void PrintPreviewHandler::HandleCancelPendingPrintRequest( | 447 void PrintPreviewHandler::HandleCancelPendingPrintRequest( |
458 const ListValue* /*args*/) { | 448 const ListValue* /*args*/) { |
459 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 449 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
460 if (initiator_tab) { | 450 if (initiator_tab) { |
461 ClearInitiatorTabDetails(); | 451 ClearInitiatorTabDetails(); |
462 } else { | 452 } else { |
463 // Initiator tab does not exists. Get the wrapper contents of current tab. | 453 // Initiator tab does not exists. Get the wrapper contents of current tab. |
464 Browser* browser = BrowserList::GetLastActive(); | 454 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. | 545 // Cancel the pending preview request if exists. |
556 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 546 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
557 print_preview_ui->OnCancelPendingPreviewRequest(); | 547 print_preview_ui->OnCancelPendingPreviewRequest(); |
558 } | 548 } |
559 | 549 |
560 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { | 550 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { |
561 ++manage_printers_dialog_request_count_; | 551 ++manage_printers_dialog_request_count_; |
562 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 552 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
563 } | 553 } |
564 | 554 |
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*/) { | |
581 ReportStats(); | |
582 ReportUserActionHistogram(CANCEL); | |
583 | |
584 // Record the number of times the user requests to regenerate preview data | |
585 // before cancelling. | |
586 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", | |
587 regenerate_preview_request_count_); | |
588 | |
589 ActivateInitiatorTabAndClosePreviewTab(); | |
590 } | |
591 | |
592 void PrintPreviewHandler::ReportStats() { | 555 void PrintPreviewHandler::ReportStats() { |
593 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters", | 556 UMA_HISTOGRAM_COUNTS("PrintPreview.ManagePrinters", |
594 manage_printers_dialog_request_count_); | 557 manage_printers_dialog_request_count_); |
595 } | 558 } |
596 | 559 |
597 void PrintPreviewHandler::HandleGetInitiatorTabTitle( | 560 void PrintPreviewHandler::HandleGetInitiatorTabTitle( |
598 const ListValue* /*args*/) { | 561 const ListValue* /*args*/) { |
599 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 562 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
600 base::StringValue tab_title(print_preview_ui->initiator_tab_title()); | 563 base::StringValue tab_title(print_preview_ui->initiator_tab_title()); |
601 web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title); | 564 web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title); |
602 } | 565 } |
603 | 566 |
604 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 567 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
605 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 568 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
606 if (initiator_tab) { | 569 if (initiator_tab) { |
607 static_cast<RenderViewHostDelegate*>( | 570 static_cast<RenderViewHostDelegate*>( |
608 initiator_tab->tab_contents())->Activate(); | 571 initiator_tab->tab_contents())->Activate(); |
609 } | 572 } |
610 ClosePrintPreviewTab(); | 573 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
574 print_preview_ui->ClosePrintPreviewTab(); | |
611 } | 575 } |
612 | 576 |
613 void PrintPreviewHandler::SendPrinterCapabilities( | 577 void PrintPreviewHandler::SendPrinterCapabilities( |
614 const DictionaryValue& settings_info) { | 578 const DictionaryValue& settings_info) { |
615 VLOG(1) << "Get printer capabilities finished"; | 579 VLOG(1) << "Get printer capabilities finished"; |
616 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", | 580 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", |
617 settings_info); | 581 settings_info); |
618 } | 582 } |
619 | 583 |
620 void PrintPreviewHandler::SendDefaultPrinter( | 584 void PrintPreviewHandler::SendDefaultPrinter( |
621 const StringValue& default_printer, | 585 const StringValue& default_printer, |
622 const StringValue& cloud_print_data) { | 586 const StringValue& cloud_print_data) { |
623 web_ui_->CallJavascriptFunction("setDefaultPrinter", | 587 web_ui_->CallJavascriptFunction("setDefaultPrinter", |
624 default_printer, | 588 default_printer, |
625 cloud_print_data); | 589 cloud_print_data); |
626 } | 590 } |
627 | 591 |
628 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { | 592 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { |
629 SendCloudPrintEnabled(); | 593 SendCloudPrintEnabled(); |
630 web_ui_->CallJavascriptFunction("setPrinters", printers); | 594 web_ui_->CallJavascriptFunction("setPrinters", printers); |
631 } | 595 } |
632 | 596 |
633 void PrintPreviewHandler::SendCloudPrintEnabled() { | 597 void PrintPreviewHandler::SendCloudPrintEnabled() { |
634 #if defined(OS_MACOSX) | |
635 bool enable_cloud_print_integration = | |
636 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableCloudPrint); | |
637 #else | |
638 bool enable_cloud_print_integration = true; | |
639 #endif | |
640 GURL gcp_url(CloudPrintURL(BrowserList::GetLastActive()->profile()). | 598 GURL gcp_url(CloudPrintURL(BrowserList::GetLastActive()->profile()). |
641 GetCloudPrintServiceURL()); | 599 GetCloudPrintServiceURL()); |
642 base::FundamentalValue enable(enable_cloud_print_integration); | |
643 base::StringValue gcp_url_value(gcp_url.spec()); | 600 base::StringValue gcp_url_value(gcp_url.spec()); |
644 web_ui_->CallJavascriptFunction("setUseCloudPrint", enable, gcp_url_value); | 601 web_ui_->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); |
645 } | 602 } |
646 | 603 |
647 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, | 604 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, |
648 std::string print_ticket) { | 605 std::string print_ticket) { |
649 scoped_refptr<RefCountedBytes> data; | 606 scoped_refptr<RefCountedBytes> data; |
650 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 607 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
651 print_preview_ui->GetPrintPreviewDataForIndex( | 608 print_preview_ui->GetPrintPreviewDataForIndex( |
652 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 609 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
653 CHECK(data.get()); | 610 CHECK(data.get()); |
654 DCHECK_GT(data->size(), 0U); | 611 DCHECK_GT(data->size(), 0U); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 } | 660 } |
704 | 661 |
705 TabContentsWrapper* PrintPreviewHandler::GetInitiatorTab() const { | 662 TabContentsWrapper* PrintPreviewHandler::GetInitiatorTab() const { |
706 printing::PrintPreviewTabController* tab_controller = | 663 printing::PrintPreviewTabController* tab_controller = |
707 printing::PrintPreviewTabController::GetInstance(); | 664 printing::PrintPreviewTabController::GetInstance(); |
708 if (!tab_controller) | 665 if (!tab_controller) |
709 return NULL; | 666 return NULL; |
710 return tab_controller->GetInitiatorTab(preview_tab_wrapper()); | 667 return tab_controller->GetInitiatorTab(preview_tab_wrapper()); |
711 } | 668 } |
712 | 669 |
713 void PrintPreviewHandler::ClosePrintPreviewTab() { | |
714 TabContentsWrapper* tab = | |
715 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | |
716 if (!tab) | |
717 return; | |
718 Browser* preview_tab_browser = BrowserList::FindBrowserWithID( | |
719 tab->restore_tab_helper()->window_id().id()); | |
720 if (!preview_tab_browser) | |
721 return; | |
722 TabStripModel* tabstrip = preview_tab_browser->tabstrip_model(); | |
723 int index = tabstrip->GetIndexOfTabContents(tab); | |
724 if (index == TabStripModel::kNoTab) | |
725 return; | |
726 | |
727 // Keep print preview tab out of the recently closed tab list, because | |
728 // re-opening that page will just display a non-functional print preview page. | |
729 tabstrip->CloseTabContentsAt(index, TabStripModel::CLOSE_NONE); | |
730 } | |
731 | |
732 void PrintPreviewHandler::OnPrintDialogShown() { | 670 void PrintPreviewHandler::OnPrintDialogShown() { |
733 ActivateInitiatorTabAndClosePreviewTab(); | 671 ActivateInitiatorTabAndClosePreviewTab(); |
734 } | 672 } |
735 | 673 |
736 void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { | 674 void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { |
737 SelectFileDialog::FileTypeInfo file_type_info; | 675 SelectFileDialog::FileTypeInfo file_type_info; |
738 file_type_info.extensions.resize(1); | 676 file_type_info.extensions.resize(1); |
739 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); | 677 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); |
740 | 678 |
741 // Initializing last_saved_path_ if it is not already initialized. | 679 // Initializing last_saved_path_ if it is not already initialized. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
810 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 748 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
811 print_to_pdf_path_.reset(); | 749 print_to_pdf_path_.reset(); |
812 ActivateInitiatorTabAndClosePreviewTab(); | 750 ActivateInitiatorTabAndClosePreviewTab(); |
813 } | 751 } |
814 | 752 |
815 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 753 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
816 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 754 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
817 print_preview_ui->OnFileSelectionCancelled(); | 755 print_preview_ui->OnFileSelectionCancelled(); |
818 } | 756 } |
819 | 757 |
820 void PrintPreviewHandler::HidePreviewTab() { | |
821 if (GetBackgroundPrintingManager()->HasPrintPreviewTab(preview_tab_wrapper())) | |
822 return; | |
823 GetBackgroundPrintingManager()->OwnPrintPreviewTab(preview_tab_wrapper()); | |
824 } | |
825 | |
826 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 758 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
827 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 759 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
828 if (!initiator_tab) | 760 if (!initiator_tab) |
829 return; | 761 return; |
830 | 762 |
831 // We no longer require the initiator tab details. Remove those details | 763 // We no longer require the initiator tab details. Remove those details |
832 // associated with the preview tab to allow the initiator tab to create | 764 // associated with the preview tab to allow the initiator tab to create |
833 // another preview tab. | 765 // another preview tab. |
834 printing::PrintPreviewTabController* tab_controller = | 766 printing::PrintPreviewTabController* tab_controller = |
835 printing::PrintPreviewTabController::GetInstance(); | 767 printing::PrintPreviewTabController::GetInstance(); |
836 if (tab_controller) | 768 if (tab_controller) |
837 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 769 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
838 } | 770 } |
OLD | NEW |