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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 10389186: Revert 137558 - Revert 136935 - Sometimes data is NULL. I am not sure if it's correct behavior , bu… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/webui/print_preview/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/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>
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 708 }
709 } 709 }
710 710
711 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, 711 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings,
712 std::string print_ticket) { 712 std::string print_ticket) {
713 scoped_refptr<base::RefCountedBytes> data; 713 scoped_refptr<base::RefCountedBytes> data;
714 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 714 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
715 web_ui()->GetController()); 715 web_ui()->GetController());
716 print_preview_ui->GetPrintPreviewDataForIndex( 716 print_preview_ui->GetPrintPreviewDataForIndex(
717 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 717 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
718 if (data->size() > 0U && data->front()) { 718 if (data.get() && data->size() > 0U && data->front()) {
719 string16 print_job_title_utf16 = 719 string16 print_job_title_utf16 =
720 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); 720 preview_tab_wrapper()->print_view_manager()->RenderSourceName();
721 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); 721 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16);
722 std::string printer_id; 722 std::string printer_id;
723 settings.GetString(printing::kSettingCloudPrintId, &printer_id); 723 settings.GetString(printing::kSettingCloudPrintId, &printer_id);
724 // BASE64 encode the job data. 724 // BASE64 encode the job data.
725 std::string raw_data(reinterpret_cast<const char*>(data->front()), 725 std::string raw_data(reinterpret_cast<const char*>(data->front()),
726 data->size()); 726 data->size());
727 std::string base64_data; 727 std::string base64_data;
728 if (!base::Base64Encode(raw_data, &base64_data)) { 728 if (!base::Base64Encode(raw_data, &base64_data)) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 // Updating |save_path_| to the newly selected folder. 834 // Updating |save_path_| to the newly selected folder.
835 GetStickySettings()->StoreSavePath(path.DirName()); 835 GetStickySettings()->StoreSavePath(path.DirName());
836 836
837 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 837 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
838 web_ui()->GetController()); 838 web_ui()->GetController());
839 print_preview_ui->web_ui()->CallJavascriptFunction("fileSelectionCompleted"); 839 print_preview_ui->web_ui()->CallJavascriptFunction("fileSelectionCompleted");
840 scoped_refptr<base::RefCountedBytes> data; 840 scoped_refptr<base::RefCountedBytes> data;
841 print_preview_ui->GetPrintPreviewDataForIndex( 841 print_preview_ui->GetPrintPreviewDataForIndex(
842 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 842 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
843 print_to_pdf_path_.reset(new FilePath(path)); 843 print_to_pdf_path_.reset(new FilePath(path));
844 if (data.get()) 844 PostPrintToPdfTask(data);
845 PostPrintToPdfTask(data);
846 } 845 }
847 846
848 void PrintPreviewHandler::PostPrintToPdfTask( 847 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) {
849 scoped_refptr<base::RefCountedBytes> data) { 848 if (!data) {
849 NOTREACHED();
850 return;
851 }
850 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; 852 printing::PreviewMetafile* metafile = new printing::PreviewMetafile;
851 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); 853 metafile->InitFromData(static_cast<const void*>(data->front()), data->size());
852 // PrintToPdfCallback takes ownership of |metafile|. 854 // PrintToPdfCallback takes ownership of |metafile|.
853 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 855 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
854 base::Bind(&PrintToPdfCallback, metafile, 856 base::Bind(&PrintToPdfCallback, metafile,
855 *print_to_pdf_path_)); 857 *print_to_pdf_path_));
856 print_to_pdf_path_.reset(); 858 print_to_pdf_path_.reset();
857 ActivateInitiatorTabAndClosePreviewTab(); 859 ActivateInitiatorTabAndClosePreviewTab();
858 } 860 }
859 861
860 void PrintPreviewHandler::FileSelectionCanceled(void* params) { 862 void PrintPreviewHandler::FileSelectionCanceled(void* params) {
861 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 863 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
862 web_ui()->GetController()); 864 web_ui()->GetController());
863 print_preview_ui->OnFileSelectionCancelled(); 865 print_preview_ui->OnFileSelectionCancelled();
864 } 866 }
865 867
866 void PrintPreviewHandler::ClearInitiatorTabDetails() { 868 void PrintPreviewHandler::ClearInitiatorTabDetails() {
867 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 869 TabContentsWrapper* initiator_tab = GetInitiatorTab();
868 if (!initiator_tab) 870 if (!initiator_tab)
869 return; 871 return;
870 872
871 // We no longer require the initiator tab details. Remove those details 873 // We no longer require the initiator tab details. Remove those details
872 // associated with the preview tab to allow the initiator tab to create 874 // associated with the preview tab to allow the initiator tab to create
873 // another preview tab. 875 // another preview tab.
874 printing::PrintPreviewTabController* tab_controller = 876 printing::PrintPreviewTabController* tab_controller =
875 printing::PrintPreviewTabController::GetInstance(); 877 printing::PrintPreviewTabController::GetInstance();
876 if (tab_controller) 878 if (tab_controller)
877 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 879 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
878 } 880 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698