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

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

Issue 10383225: Revert 136935 - Sometimes data is NULL. I am not sure if it's correct behavior , but it's safe just… (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')
Property Changes:
Deleted: svn:mergeinfo
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.get() && data->size() > 0U && data->front()) { 718 if (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 PostPrintToPdfTask(data); 844 if (data.get())
845 PostPrintToPdfTask(data);
845 } 846 }
846 847
847 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) { 848 void PrintPreviewHandler::PostPrintToPdfTask(
848 if (!data) { 849 scoped_refptr<base::RefCountedBytes> data) {
849 NOTREACHED();
850 return;
851 }
852 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; 850 printing::PreviewMetafile* metafile = new printing::PreviewMetafile;
853 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); 851 metafile->InitFromData(static_cast<const void*>(data->front()), data->size());
854 // PrintToPdfCallback takes ownership of |metafile|. 852 // PrintToPdfCallback takes ownership of |metafile|.
855 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 853 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
856 base::Bind(&PrintToPdfCallback, metafile, 854 base::Bind(&PrintToPdfCallback, metafile,
857 *print_to_pdf_path_)); 855 *print_to_pdf_path_));
858 print_to_pdf_path_.reset(); 856 print_to_pdf_path_.reset();
859 ActivateInitiatorTabAndClosePreviewTab(); 857 ActivateInitiatorTabAndClosePreviewTab();
860 } 858 }
861 859
862 void PrintPreviewHandler::FileSelectionCanceled(void* params) { 860 void PrintPreviewHandler::FileSelectionCanceled(void* params) {
863 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 861 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
864 web_ui()->GetController()); 862 web_ui()->GetController());
865 print_preview_ui->OnFileSelectionCancelled(); 863 print_preview_ui->OnFileSelectionCancelled();
866 } 864 }
867 865
868 void PrintPreviewHandler::ClearInitiatorTabDetails() { 866 void PrintPreviewHandler::ClearInitiatorTabDetails() {
869 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 867 TabContentsWrapper* initiator_tab = GetInitiatorTab();
870 if (!initiator_tab) 868 if (!initiator_tab)
871 return; 869 return;
872 870
873 // We no longer require the initiator tab details. Remove those details 871 // We no longer require the initiator tab details. Remove those details
874 // associated with the preview tab to allow the initiator tab to create 872 // associated with the preview tab to allow the initiator tab to create
875 // another preview tab. 873 // another preview tab.
876 printing::PrintPreviewTabController* tab_controller = 874 printing::PrintPreviewTabController* tab_controller =
877 printing::PrintPreviewTabController::GetInstance(); 875 printing::PrintPreviewTabController::GetInstance();
878 if (tab_controller) 876 if (tab_controller)
879 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 877 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
880 } 878 }
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