diff options
-rw-r--r-- | chrome/browser/browser_main.cc | 10 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_cloud.cc | 81 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_cloud.h | 14 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_cloud_internal.h | 17 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_cloud_uitest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_cloud_unittest.cc | 12 | ||||
-rw-r--r-- | chrome/browser/printing/printing_message_filter.cc | 2 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
9 files changed, 94 insertions, 49 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index f8a6726..02ec8dd 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1741,12 +1741,18 @@ int BrowserMain(const MainFunctionParams& parameters) { switches::kCloudPrintJobTitle); print_job_title = string16(native_job_title); #elif defined(OS_POSIX) - // TODO(abodenha@google.com) Implement this for OS_POSIX + // TODO(abodenha@chromium.org) Implement this for OS_POSIX // Command line string types are different #endif } - PrintDialogCloud::CreatePrintDialogForPdf(cloud_print_file, + std::string file_type = "application/pdf"; + if (parsed_command_line.HasSwitch(switches::kCloudPrintFileType)) { + file_type = parsed_command_line.GetSwitchValueASCII( + switches::kCloudPrintFileType); + } + PrintDialogCloud::CreatePrintDialogForFile(cloud_print_file, print_job_title, + file_type, false); } } diff --git a/chrome/browser/printing/print_dialog_cloud.cc b/chrome/browser/printing/print_dialog_cloud.cc index 279ea45..6d8c847 100644 --- a/chrome/browser/printing/print_dialog_cloud.cc +++ b/chrome/browser/printing/print_dialog_cloud.cc @@ -36,14 +36,14 @@ // This means hosting a dialog containing HTML/JavaScript and using // the published cloud print user interface integration APIs to get // page setup settings from the dialog contents and provide the -// generated print PDF to the dialog contents for uploading to the +// generated print data to the dialog contents for uploading to the // cloud print service. // Currently, the flow between these classes is as follows: -// PrintDialogCloud::CreatePrintDialogForPdf is called from +// PrintDialogCloud::CreatePrintDialogForFile is called from // resource_message_filter_gtk.cc once the renderer has informed the -// renderer host that PDF generation into the renderer host provided +// renderer host that print data generation into the renderer host provided // temp file has been completed. That call is on the FILE thread. // That, in turn, hops over to the UI thread to create an instance of // PrintDialogCloud. @@ -57,7 +57,7 @@ // CloudPrintHtmlDialogDelegate also temporarily owns a // CloudPrintFlowHandler, a class which is responsible for the actual -// interactions with the dialog contents, including handing in the PDF +// interactions with the dialog contents, including handing in the // print data and getting any page setup parameters that the dialog // contents provides. As part of bringing up the dialog, // HtmlDialogUI::RenderViewCreated is called (an override of @@ -75,11 +75,11 @@ // the window. In addition, the pending URL is redirected to the // actual cloud print service URL. The flow controller also registers // for notification of when the dialog contents finish loading, which -// is currently used to send the PDF data to the dialog contents. +// is currently used to send the data to the dialog contents. -// In order to send the PDF data to the dialog contents, the flow +// In order to send the data to the dialog contents, the flow // handler uses a CloudPrintDataSender. It creates one, letting it -// know the name of the temporary file containing the PDF data, and +// know the name of the temporary file containing the data, and // posts the task of reading the file // (CloudPrintDataSender::ReadPrintDataFile) to the file thread. That // routine reads in the file, and then hops over to the IO thread to @@ -92,7 +92,7 @@ // TODO(scottbyer): // http://code.google.com/p/chromium/issues/detail?id=44093 The -// high-level flow (where the PDF data is generated before even +// high-level flow (where the data is generated before even // bringing up the dialog) isn't what we want. namespace internal_cloud_print_helpers { @@ -155,32 +155,36 @@ void CloudPrintDataSender::CancelPrintDataFile() { } CloudPrintDataSender::CloudPrintDataSender(CloudPrintDataSenderHelper* helper, - const string16& print_job_title) + const string16& print_job_title, + const std::string& file_type) : helper_(helper), - print_job_title_(print_job_title) { + print_job_title_(print_job_title), + file_type_(file_type) { } CloudPrintDataSender::~CloudPrintDataSender() {} -// Grab the raw PDF file contents and massage them into shape for +// Grab the raw file contents and massage them into shape for // sending to the dialog contents (and up to the cloud print server) // by encoding it and prefixing it with the appropriate mime type. // Once that is done, kick off the next part of the task on the IO // thread. -void CloudPrintDataSender::ReadPrintDataFile(const FilePath& path_to_pdf) { +void CloudPrintDataSender::ReadPrintDataFile(const FilePath& path_to_file) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); int64 file_size = 0; - if (file_util::GetFileSize(path_to_pdf, &file_size) && file_size != 0) { + if (file_util::GetFileSize(path_to_file, &file_size) && file_size != 0) { std::string file_data; if (file_size < kuint32max) { file_data.reserve(static_cast<unsigned int>(file_size)); } else { DLOG(WARNING) << " print data file too large to reserve space"; } - if (helper_ && file_util::ReadFileToString(path_to_pdf, &file_data)) { + if (helper_ && file_util::ReadFileToString(path_to_file, &file_data)) { std::string base64_data; base::Base64Encode(file_data, &base64_data); - std::string header("data:application/pdf;base64,"); + std::string header("data:"); + header.append(file_type_); + header.append(";base64,"); base64_data.insert(0, header); scoped_ptr<StringValue> new_data(new StringValue(base64_data)); print_data_.swap(new_data); @@ -215,10 +219,12 @@ void CloudPrintDataSender::SendPrintDataFile() { } -CloudPrintFlowHandler::CloudPrintFlowHandler(const FilePath& path_to_pdf, - const string16& print_job_title) - : path_to_pdf_(path_to_pdf), - print_job_title_(print_job_title) { +CloudPrintFlowHandler::CloudPrintFlowHandler(const FilePath& path_to_file, + const string16& print_job_title, + const std::string& file_type) + : path_to_file_(path_to_file), + print_job_title_(print_job_title), + file_type_(file_type) { } CloudPrintFlowHandler::~CloudPrintFlowHandler() { @@ -319,7 +325,9 @@ scoped_refptr<CloudPrintDataSender> CloudPrintFlowHandler::CreateCloudPrintDataSender() { DCHECK(web_ui_); print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui_)); - return new CloudPrintDataSender(print_data_helper_.get(), print_job_title_); + return new CloudPrintDataSender(print_data_helper_.get(), + print_job_title_, + file_type_); } void CloudPrintFlowHandler::HandleSendPrintData(const ListValue* args) { @@ -335,7 +343,7 @@ void CloudPrintFlowHandler::HandleSendPrintData(const ListValue* args) { NewRunnableMethod( print_data_sender_.get(), &CloudPrintDataSender::ReadPrintDataFile, - path_to_pdf_)); + path_to_file_)); } } @@ -377,7 +385,7 @@ void CloudPrintFlowHandler::HandleSetPageParameters(const ListValue* args) { // TODO(scottbyer) - Here is where we would kick the originating // renderer thread with these new parameters in order to get it to - // re-generate the PDF and hand it back to us. window.print() is + // re-generate the PDF data and hand it back to us. window.print() is // currently synchronous, so there's a lot of work to do to get to // that point. } @@ -393,12 +401,15 @@ void CloudPrintFlowHandler::StoreDialogClientSize() const { } CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( - const FilePath& path_to_pdf, + const FilePath& path_to_file, int width, int height, const std::string& json_arguments, const string16& print_job_title, + const std::string& file_type, bool modal) - : flow_handler_(new CloudPrintFlowHandler(path_to_pdf, print_job_title)), + : flow_handler_(new CloudPrintFlowHandler(path_to_file, + print_job_title, + file_type)), modal_(modal), owns_flow_handler_(true) { Init(width, height, json_arguments); @@ -501,8 +512,9 @@ bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const { // TODO(scottbyer): The signature here will need to change as the // workflow through the printing code changes to allow for dynamically // changing page setup parameters while the dialog is active. -void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf, +void PrintDialogCloud::CreatePrintDialogForFile(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) || BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -510,32 +522,36 @@ void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf, BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, - path_to_pdf, + path_to_file, print_job_title, + file_type, modal)); } // static, called from the UI thread. -void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf, +void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - new PrintDialogCloud(path_to_pdf, print_job_title, modal); + new PrintDialogCloud(path_to_file, print_job_title, file_type, modal); } // Initialize the print dialog. Called on the UI thread. -PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf, +PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal) : browser_(BrowserList::GetLastActive()) { - Init(path_to_pdf, print_job_title, modal); + Init(path_to_file, print_job_title, file_type, modal); } PrintDialogCloud::~PrintDialogCloud() { } -void PrintDialogCloud::Init(const FilePath& path_to_pdf, +void PrintDialogCloud::Init(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal) { // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should // be distilled out of bookmark sync.) @@ -568,7 +584,8 @@ void PrintDialogCloud::Init(const FilePath& path_to_pdf, HtmlDialogUIDelegate* dialog_delegate = new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate( - path_to_pdf, width, height, std::string(), job_title, modal); + path_to_file, width, height, std::string(), job_title, file_type, + modal); if (modal) { DCHECK(browser_); browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); diff --git a/chrome/browser/printing/print_dialog_cloud.h b/chrome/browser/printing/print_dialog_cloud.h index 01fc5c9..0dde6b5 100644 --- a/chrome/browser/printing/print_dialog_cloud.h +++ b/chrome/browser/printing/print_dialog_cloud.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_PRINTING_PRINT_DIALOG_CLOUD_H_ #pragma once +#include <string> + #include "base/basictypes.h" #include "base/string16.h" @@ -19,26 +21,30 @@ class Message; class PrintDialogCloud { public: // Called on the IO or UI thread. - static void CreatePrintDialogForPdf(const FilePath& path_to_pdf, + static void CreatePrintDialogForFile(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal); private: friend class PrintDialogCloudTest; - explicit PrintDialogCloud(const FilePath& path_to_pdf, + explicit PrintDialogCloud(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal); ~PrintDialogCloud(); - void Init(const FilePath& path_to_pdf, + void Init(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal); // Called as a task from the UI thread, creates an object instance // to run the HTML/JS based print dialog for printing through the cloud. - static void CreateDialogImpl(const FilePath& path_to_pdf, + static void CreateDialogImpl(const FilePath& path_to_file, const string16& print_job_title, + const std::string& file_type, bool modal); Browser* browser_; diff --git a/chrome/browser/printing/print_dialog_cloud_internal.h b/chrome/browser/printing/print_dialog_cloud_internal.h index d64831f..02e4d50 100644 --- a/chrome/browser/printing/print_dialog_cloud_internal.h +++ b/chrome/browser/printing/print_dialog_cloud_internal.h @@ -53,13 +53,14 @@ class CloudPrintDataSender // The owner of this object is also expected to own and control the // lifetime of the helper. CloudPrintDataSender(CloudPrintDataSenderHelper* helper, - const string16& print_job_title); + const string16& print_job_title, + const std::string& file_type); // Calls to read in the PDF file (on the FILE thread) then send that // information to the dialog renderer (on the IO thread). We know // that the WebUI pointer lifetime will outlast us, so we should be // good. - void ReadPrintDataFile(const FilePath& path_to_pdf); + void ReadPrintDataFile(const FilePath& path_to_file); void SendPrintDataFile(); // Cancels any ramining part of the task by clearing out the WebUI @@ -74,6 +75,7 @@ class CloudPrintDataSender CloudPrintDataSenderHelper* volatile helper_; scoped_ptr<StringValue> print_data_; string16 print_job_title_; + std::string file_type_; DISALLOW_COPY_AND_ASSIGN(CloudPrintDataSender); }; @@ -90,8 +92,9 @@ class CloudPrintHtmlDialogDelegate; class CloudPrintFlowHandler : public WebUIMessageHandler, public NotificationObserver { public: - explicit CloudPrintFlowHandler(const FilePath& path_to_pdf, - const string16& print_job_title); + explicit CloudPrintFlowHandler(const FilePath& path_to_file, + const string16& print_job_title, + const std::string& file_type); virtual ~CloudPrintFlowHandler(); // WebUIMessageHandler implementation. @@ -122,8 +125,9 @@ class CloudPrintFlowHandler : public WebUIMessageHandler, CloudPrintHtmlDialogDelegate* dialog_delegate_; NotificationRegistrar registrar_; - FilePath path_to_pdf_; + FilePath path_to_file_; string16 print_job_title_; + std::string file_type_; scoped_refptr<CloudPrintDataSender> print_data_sender_; scoped_ptr<CloudPrintDataSenderHelper> print_data_helper_; @@ -135,10 +139,11 @@ class CloudPrintFlowHandler : public WebUIMessageHandler, // is closed. class CloudPrintHtmlDialogDelegate : public HtmlDialogUIDelegate { public: - CloudPrintHtmlDialogDelegate(const FilePath& path_to_pdf, + CloudPrintHtmlDialogDelegate(const FilePath& path_to_file, int width, int height, const std::string& json_arguments, const string16& print_job_title, + const std::string& file_type, bool modal); virtual ~CloudPrintHtmlDialogDelegate(); diff --git a/chrome/browser/printing/print_dialog_cloud_uitest.cc b/chrome/browser/printing/print_dialog_cloud_uitest.cc index 454f706..b852c72 100644 --- a/chrome/browser/printing/print_dialog_cloud_uitest.cc +++ b/chrome/browser/printing/print_dialog_cloud_uitest.cc @@ -202,6 +202,7 @@ class PrintDialogCloudTest : public InProcessBrowserTest { NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, path_to_pdf, string16(), + std::string("application/pdf"), true)); } diff --git a/chrome/browser/printing/print_dialog_cloud_unittest.cc b/chrome/browser/printing/print_dialog_cloud_unittest.cc index edeb061..f3dd510 100644 --- a/chrome/browser/printing/print_dialog_cloud_unittest.cc +++ b/chrome/browser/printing/print_dialog_cloud_unittest.cc @@ -82,8 +82,9 @@ class MockCloudPrintFlowHandler public base::SupportsWeakPtr<MockCloudPrintFlowHandler> { public: explicit MockCloudPrintFlowHandler(const FilePath& path, - const string16& title) - : CloudPrintFlowHandler(path, title) {} + const string16& title, + const std::string& file_type) + : CloudPrintFlowHandler(path, title, file_type) {} MOCK_METHOD0(DestructorCalled, void()); MOCK_METHOD0(RegisterMessages, void()); MOCK_METHOD3(Observe, @@ -217,7 +218,9 @@ class CloudPrintDataSenderTest : public testing::Test { string16 mock_job_title(ASCIIToUTF16(kMockJobTitle)); mock_helper_.reset(new MockCloudPrintDataSenderHelper); print_data_sender_ = - new CloudPrintDataSender(mock_helper_.get(), mock_job_title); + new CloudPrintDataSender(mock_helper_.get(), + mock_job_title, + std::string("application/pdf")); } scoped_refptr<CloudPrintDataSender> print_data_sender_; @@ -292,8 +295,9 @@ class CloudPrintHtmlDialogDelegateTest : public testing::Test { virtual void SetUp() { FilePath mock_path; string16 mock_title; + std::string mock_file_type; MockCloudPrintFlowHandler* handler = - new MockCloudPrintFlowHandler(mock_path, mock_title); + new MockCloudPrintFlowHandler(mock_path, mock_title, mock_file_type); mock_flow_handler_ = handler->AsWeakPtr(); EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(_)); EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(NULL)); diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc index 47f74ee..4971627 100644 --- a/chrome/browser/printing/printing_message_filter.cc +++ b/chrome/browser/printing/printing_message_filter.cc @@ -155,7 +155,7 @@ void PrintingMessageFilter::OnTempFileForPrintingWritten(int sequence_number) { } if (cloud_print_enabled_) - PrintDialogCloud::CreatePrintDialogForPdf(it->second, string16(), true); + PrintDialogCloud::CreatePrintDialogForFile(it->second, string16(), true); else NOTIMPLEMENTED(); diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index d33b8af..ea8c178 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -117,6 +117,11 @@ const char kCloudPrintFile[] = "cloud-print-file"; // job. const char kCloudPrintJobTitle[] = "cloud-print-job-title"; +// Specifies the mime type to be used when uploading data from the +// file referenced by cloud-print-file. +// Defaults to "application/pdf" if unspecified. +const char kCloudPrintFileType[] = "cloud-print-file-type"; + // The URL of the cloud print service to use, overrides any value // stored in preferences, and the default. Only used if the cloud // print service has been enabled (see enable-cloud-print). diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index eab7efd..a8d9fea 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -48,6 +48,7 @@ extern const char kChromeFrame[]; extern const char kChromeVersion[]; extern const char kCloudPrintFile[]; extern const char kCloudPrintJobTitle[]; +extern const char kCloudPrintFileType[]; extern const char kCloudPrintProxyId[]; extern const char kCloudPrintServiceURL[]; extern const char kConflictingModulesCheck[]; |