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

Unified Diff: chrome/browser/printing/print_dialog_cloud.cc

Issue 6038008: Modify chrome to accept a pdf file on the command line and upload it to Cloud... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/print_dialog_cloud.cc
===================================================================
--- chrome/browser/printing/print_dialog_cloud.cc (revision 70951)
+++ 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,8 @@
params_.json_input = json_arguments;
flow_handler_->SetDialogDelegate(this);
+ // Keep the browser alive while we are showing the notification.
sanjeevr 2011/01/11 21:39:55 Nit: Change comment, this is not a notification. A
abodenha 2011/01/12 01:30:50 Done.
+ BrowserList::StartKeepAlive();
}
CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() {
@@ -432,7 +447,7 @@
}
bool CloudPrintHtmlDialogDelegate::IsDialogModal() const {
- return true;
+ return modal_;
}
std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const {
@@ -465,6 +480,8 @@
const std::string& json_retval) {
// Get the final dialog size and store it.
flow_handler_->StoreDialogClientSize();
+ // Keep the browser alive while we are showing the notification.
sanjeevr 2011/01/11 21:39:55 Same here.
abodenha 2011/01/12 01:30:50 Done.
+ BrowserList::EndKeepAlive();
delete this;
}
@@ -487,7 +504,8 @@
// 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));
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) ||
+ BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
@@ -507,13 +525,31 @@
// 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;
+ bool modal = true;
+ if (browser_) {
+ if (browser_->GetSelectedTabContents())
+ print_job_title = browser_->GetSelectedTabContents()->GetTitle();
+ profile = browser_->GetProfile();
+ modal = true;
+ } else {
+#ifdef OS_WIN
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kCloudPrintJobTitle)) {
+ CommandLine::StringType native_job_title;
+ native_job_title = CommandLine::ForCurrentProcess()->GetSwitchValueNative(
+ switches::kCloudPrintJobTitle);
sanjeevr 2011/01/11 21:39:55 We should probably refactor this and have the titl
abodenha 2011/01/12 01:30:50 Good call. Refactoring makes the code much cleane
+ print_job_title = string16(native_job_title);
+ }
+#endif
+ profile = ProfileManager::GetDefaultProfile();
+ modal = false;
+ }
+ DCHECK(profile);
+ pref_service = profile->GetPrefs();
DCHECK(pref_service);
if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) {
pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth,
@@ -526,10 +562,21 @@
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 (browser_) {
Scott Byer 2011/01/11 21:46:31 I'd be surprised if this pattern wasn't elsewhere
abodenha 2011/01/12 01:30:50 Done. See comment about refactoring for modal and
+ browser_->BrowserShowHtmlDialog(dialog_delegate, NULL);
+ } else {
+#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)
+ }
}
PrintDialogCloud::~PrintDialogCloud() {

Powered by Google App Engine
This is Rietveld 408576698