| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #if !defined(OS_CHROMEOS) | 10 #if !defined(OS_CHROMEOS) |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 BrowserThread::PostTask( | 470 BrowserThread::PostTask( |
| 471 BrowserThread::FILE, FROM_HERE, | 471 BrowserThread::FILE, FROM_HERE, |
| 472 NewRunnableMethod(task.get(), | 472 NewRunnableMethod(task.get(), |
| 473 &PrintSystemTaskProxy::EnumeratePrinters)); | 473 &PrintSystemTaskProxy::EnumeratePrinters)); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { | 476 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { |
| 477 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 477 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
| 478 if (!settings.get()) | 478 if (!settings.get()) |
| 479 return; | 479 return; |
| 480 int request_id = -1; |
| 481 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) |
| 482 return; |
| 483 |
| 484 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 485 print_preview_ui->OnPrintPreviewRequest(request_id); |
| 486 // Add an additional key in order to identify |print_preview_ui| later on |
| 487 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 488 // thread. |
| 489 settings->SetInteger(printing::kPreviewUIId, print_preview_ui->uid()); |
| 480 | 490 |
| 481 // Increment request count. | 491 // Increment request count. |
| 482 ++regenerate_preview_request_count_; | 492 ++regenerate_preview_request_count_; |
| 483 | 493 |
| 484 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | |
| 485 print_preview_ui->OnPrintPreviewRequest(); | |
| 486 | |
| 487 TabContents* initiator_tab = GetInitiatorTab(); | 494 TabContents* initiator_tab = GetInitiatorTab(); |
| 488 if (!initiator_tab) { | 495 if (!initiator_tab) { |
| 489 if (!reported_failed_preview_) { | 496 if (!reported_failed_preview_) { |
| 490 ReportUserActionHistogram(PREVIEW_FAILED); | 497 ReportUserActionHistogram(PREVIEW_FAILED); |
| 491 reported_failed_preview_ = true; | 498 reported_failed_preview_ = true; |
| 492 } | 499 } |
| 493 print_preview_ui->OnPrintPreviewFailed(); | 500 print_preview_ui->OnPrintPreviewFailed(); |
| 494 return; | 501 return; |
| 495 } | 502 } |
| 496 | 503 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 } | 874 } |
| 868 | 875 |
| 869 void PrintPreviewHandler::OnTabDestroyed() { | 876 void PrintPreviewHandler::OnTabDestroyed() { |
| 870 TabContents* initiator_tab = GetInitiatorTab(); | 877 TabContents* initiator_tab = GetInitiatorTab(); |
| 871 if (!initiator_tab) | 878 if (!initiator_tab) |
| 872 return; | 879 return; |
| 873 | 880 |
| 874 TabContentsWrapper* wrapper = | 881 TabContentsWrapper* wrapper = |
| 875 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); | 882 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); |
| 876 wrapper->print_view_manager()->set_observer(NULL); | 883 wrapper->print_view_manager()->set_observer(NULL); |
| 877 | |
| 878 // Tell the initiator tab to stop rendering the print preview, if any, | |
| 879 // since the preview tab is gone. | |
| 880 RenderViewHost* rvh = initiator_tab->render_view_host(); | |
| 881 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); | |
| 882 } | 884 } |
| 883 | 885 |
| 884 void PrintPreviewHandler::FileSelected(const FilePath& path, | 886 void PrintPreviewHandler::FileSelected(const FilePath& path, |
| 885 int index, void* params) { | 887 int index, void* params) { |
| 886 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 888 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 887 scoped_refptr<RefCountedBytes> data; | 889 scoped_refptr<RefCountedBytes> data; |
| 888 print_preview_ui->GetPrintPreviewDataForIndex( | 890 print_preview_ui->GetPrintPreviewDataForIndex( |
| 889 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 891 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 890 if (!data.get()) { | 892 if (!data.get()) { |
| 891 NOTREACHED(); | 893 NOTREACHED(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 return; | 925 return; |
| 924 | 926 |
| 925 // We no longer require the initiator tab details. Remove those details | 927 // We no longer require the initiator tab details. Remove those details |
| 926 // associated with the preview tab to allow the initiator tab to create | 928 // associated with the preview tab to allow the initiator tab to create |
| 927 // another preview tab. | 929 // another preview tab. |
| 928 printing::PrintPreviewTabController* tab_controller = | 930 printing::PrintPreviewTabController* tab_controller = |
| 929 printing::PrintPreviewTabController::GetInstance(); | 931 printing::PrintPreviewTabController::GetInstance(); |
| 930 if (tab_controller) | 932 if (tab_controller) |
| 931 tab_controller->EraseInitiatorTabInfo(preview_tab()); | 933 tab_controller->EraseInitiatorTabInfo(preview_tab()); |
| 932 } | 934 } |
| OLD | NEW |