Chromium Code Reviews| Index: chrome/browser/printing/print_dialog_cloud.cc |
| =================================================================== |
| --- chrome/browser/printing/print_dialog_cloud.cc (revision 71046) |
| +++ chrome/browser/printing/print_dialog_cloud.cc (working copy) |
| @@ -7,6 +7,7 @@ |
| #include "app/l10n_util.h" |
| #include "base/base64.h" |
| +#include "base/command_line.h" |
| #include "base/file_util.h" |
| #include "base/json/json_reader.h" |
| #include "base/values.h" |
| @@ -15,12 +16,20 @@ |
| #include "chrome/browser/debugger/devtools_manager.h" |
| #include "chrome/browser/dom_ui/dom_ui.h" |
| #include "chrome/browser/dom_ui/dom_ui_util.h" |
| +#if defined(TOOLKIT_GTK) |
| +#include "chrome/browser/gtk/html_dialog_gtk.h" |
| +#endif // defined(TOOLKIT_GTK) |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.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" |
| +#if defined(TOOLKIT_VIEWS) |
| +#include "chrome/browser/ui/views/browser_dialogs.h" |
| +#endif // defined(TOOLKIT_VIEWS) |
| +#include "chrome/common/chrome_switches.h" |
| #include "chrome/common/notification_observer.h" |
| #include "chrome/common/notification_registrar.h" |
| #include "chrome/common/notification_source.h" |
| @@ -393,8 +402,10 @@ |
| const FilePath& path_to_pdf, |
| int width, int height, |
| const std::string& json_arguments, |
| - const string16& print_job_title) |
| + const string16& print_job_title, |
| + bool modal) |
| : flow_handler_(new CloudPrintFlowHandler(path_to_pdf, print_job_title)), |
| + modal_(modal), |
| owns_flow_handler_(true) { |
| Init(width, height, json_arguments); |
| } |
| @@ -402,8 +413,10 @@ |
| CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( |
| CloudPrintFlowHandler* flow_handler, |
| int width, int height, |
| - const std::string& json_arguments) |
| + const std::string& json_arguments, |
| + bool modal) |
| : flow_handler_(flow_handler), |
| + modal_(modal), |
| owns_flow_handler_(true) { |
| Init(width, height, json_arguments); |
| } |
| @@ -419,6 +432,9 @@ |
| params_.json_input = json_arguments; |
| flow_handler_->SetDialogDelegate(this); |
| + // We might show the dialog with no browser. |
| + // We need this to keep Chrome alive while our dialog is up. |
| + BrowserList::StartKeepAlive(); |
| } |
| CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() { |
| @@ -432,7 +448,7 @@ |
| } |
| bool CloudPrintHtmlDialogDelegate::IsDialogModal() const { |
| - return true; |
| + return modal_; |
| } |
| std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const { |
| @@ -465,6 +481,9 @@ |
| const std::string& json_retval) { |
| // Get the final dialog size and store it. |
| flow_handler_->StoreDialogClientSize(); |
| + // We might show the dialog with no browser. |
| + // End the keep-alive so that Chrome can exit. |
| + BrowserList::EndKeepAlive(); |
| delete this; |
| } |
| @@ -486,34 +505,52 @@ |
| // 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) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| +void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf, |
| + const string16& print_job_title, |
| + bool modal) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || |
| + BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| BrowserThread::PostTask( |
| BrowserThread::UI, FROM_HERE, |
| - NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, path_to_pdf)); |
| + NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, |
| + path_to_pdf, |
| + print_job_title, |
| + modal)); |
| } |
| // static, called from the UI thread. |
| -void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf) { |
| +void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf, |
| + const string16& print_job_title, |
| + bool modal) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - new PrintDialogCloud(path_to_pdf); |
| + new PrintDialogCloud(path_to_pdf, print_job_title, modal); |
| } |
| // Initialize the print dialog. Called on the UI thread. |
| -PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf) |
| - : browser_(BrowserList::GetLastActive()) { |
| +PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf, |
| + const string16& print_job_title, |
| + bool modal) |
| + : browser_(BrowserList::GetLastActive()), |
| + print_job_title_(print_job_title), |
| + modal_(modal) { |
| // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should |
| // be distilled out of bookmark sync.) |
| - string16 print_job_title; |
| - if (browser_ && browser_->GetSelectedTabContents()) |
| - print_job_title = browser_->GetSelectedTabContents()->GetTitle(); |
| - |
| const int kDefaultWidth = 497; |
| const int kDefaultHeight = 332; |
| - |
| - PrefService* pref_service = browser_->GetProfile()->GetPrefs(); |
| + Profile* profile = NULL; |
| + PrefService* pref_service = NULL; |
| + if (modal_) { |
|
Scott Byer
2011/01/12 23:35:02
When called to print a web page, the dialog should
|
| + profile = ProfileManager::GetDefaultProfile(); |
| + } else { |
| + DCHECK(browser_); |
| + if (print_job_title_.empty() && browser_->GetSelectedTabContents()) |
| + print_job_title_ = browser_->GetSelectedTabContents()->GetTitle(); |
| + profile = browser_->GetProfile(); |
| + } |
| + DCHECK(profile); |
| + pref_service = profile->GetPrefs(); |
| DCHECK(pref_service); |
| if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) { |
| pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth, |
| @@ -526,10 +563,22 @@ |
| 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, width, height, std::string(), print_job_title); |
| - browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); |
| + path_to_pdf, width, height, std::string(), print_job_title_, modal_); |
| + if (modal_) { |
| +#if defined(TOOLKIT_VIEWS) |
| + browser::ShowHtmlDialogView(NULL, profile, dialog_delegate); |
| +#elif defined(TOOLKIT_GTK) |
| + HtmlDialogGtk* html_dialog = |
| + new HtmlDialogGtk(profile, dialog_delegate, NULL); |
| + html_dialog->InitDialog(); |
| +#endif // defined(TOOLKIT_VIEWS) |
| + } else { |
| + DCHECK(browser_); |
| + browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); |
| + } |
| } |
| PrintDialogCloud::~PrintDialogCloud() { |