diff options
Diffstat (limited to 'chrome/browser/printing/print_dialog_cloud.cc')
| -rw-r--r-- | chrome/browser/printing/print_dialog_cloud.cc | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/chrome/browser/printing/print_dialog_cloud.cc b/chrome/browser/printing/print_dialog_cloud.cc index 6fd43f4..1af016e 100644 --- a/chrome/browser/printing/print_dialog_cloud.cc +++ b/chrome/browser/printing/print_dialog_cloud.cc @@ -15,14 +15,17 @@ #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/browser/dom_ui/dom_ui_util.h" -#include "chrome/browser/dom_ui/html_dialog_ui.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_url.h" +#include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" +#include "chrome/common/pref_names.h" #include "chrome/common/render_messages_params.h" #include "chrome/common/url_constants.h" #include "webkit/glue/webpreferences.h" @@ -92,7 +95,6 @@ // high-level flow (where the PDF data is generated before even // bringing up the dialog) isn't what we want. - namespace internal_cloud_print_helpers { bool GetRealOrInt(const DictionaryValue& dictionary, @@ -152,6 +154,14 @@ void CloudPrintDataSender::CancelPrintDataFile() { helper_ = NULL; } +CloudPrintDataSender::CloudPrintDataSender(CloudPrintDataSenderHelper* helper, + const string16& print_job_title) + : helper_(helper), + print_job_title_(print_job_title) { +} + +CloudPrintDataSender::~CloudPrintDataSender() {} + // Grab the raw PDF 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. @@ -205,6 +215,18 @@ 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() { + // This will also cancel any task in flight. + CancelAnyRunningTask(); +} + + void CloudPrintFlowHandler::SetDialogDelegate( CloudPrintHtmlDialogDelegate* delegate) { // Even if setting a new dom_ui, it means any previous task needs @@ -225,7 +247,6 @@ void CloudPrintFlowHandler::CancelAnyRunningTask() { } } - void CloudPrintFlowHandler::RegisterMessages() { if (!dom_ui_) return; @@ -358,6 +379,16 @@ void CloudPrintFlowHandler::HandleSetPageParameters(const ListValue* args) { // that point. } +void CloudPrintFlowHandler::StoreDialogClientSize() const { + if (dom_ui_ && dom_ui_->tab_contents() && dom_ui_->tab_contents()->view()) { + gfx::Size size = dom_ui_->tab_contents()->view()->GetContainerSize(); + dom_ui_->GetProfile()->GetPrefs()->SetInteger( + prefs::kCloudPrintDialogWidth, size.width()); + dom_ui_->GetProfile()->GetPrefs()->SetInteger( + prefs::kCloudPrintDialogHeight, size.height()); + } +} + CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( const FilePath& path_to_pdf, int width, int height, @@ -405,7 +436,7 @@ bool CloudPrintHtmlDialogDelegate::IsDialogModal() const { } std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const { - return l10n_util::GetString(IDS_CLOUD_PRINT_TITLE); + return std::wstring(); } GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const { @@ -432,6 +463,8 @@ std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const { void CloudPrintHtmlDialogDelegate::OnDialogClosed( const std::string& json_retval) { + // Get the final dialog size and store it. + flow_handler_->StoreDialogClientSize(); delete this; } @@ -441,6 +474,10 @@ void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source, *out_close_dialog = true; } +bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const { + return false; +} + } // end of namespace internal_cloud_print_helpers // static, called on the IO thread. This is the main entry point into @@ -473,11 +510,25 @@ PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf) if (browser_ && browser_->GetSelectedTabContents()) print_job_title = browser_->GetSelectedTabContents()->GetTitle(); - // TODO(scottbyer): Get the dialog width, height from the dialog - // contents, and take the screen size into account. + const int kDefaultWidth = 497; + const int kDefaultHeight = 332; + + PrefService* pref_service = browser_->GetProfile()->GetPrefs(); + DCHECK(pref_service); + if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) { + pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth, + kDefaultWidth); + } + if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) { + pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, + kDefaultHeight); + } + + int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth); + int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight); HtmlDialogUIDelegate* dialog_delegate = new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate( - path_to_pdf, 500, 400, std::string(), print_job_title); + path_to_pdf, width, height, std::string(), print_job_title); browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); } |
