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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/printing/print_dialog_cloud.h" 5 #include "chrome/browser/printing/print_dialog_cloud.h"
6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" 6 #include "chrome/browser/printing/print_dialog_cloud_internal.h"
7 7
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/command_line.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/browser_thread.h" 15 #include "chrome/browser/browser_thread.h"
15 #include "chrome/browser/debugger/devtools_manager.h" 16 #include "chrome/browser/debugger/devtools_manager.h"
16 #include "chrome/browser/dom_ui/dom_ui.h" 17 #include "chrome/browser/dom_ui/dom_ui.h"
17 #include "chrome/browser/dom_ui/dom_ui_util.h" 18 #include "chrome/browser/dom_ui/dom_ui_util.h"
19 #if defined(TOOLKIT_GTK)
20 #include "chrome/browser/gtk/html_dialog_gtk.h"
21 #endif // defined(TOOLKIT_GTK)
18 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 23 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
20 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/renderer_host/render_view_host.h" 26 #include "chrome/browser/renderer_host/render_view_host.h"
22 #include "chrome/browser/tab_contents/tab_contents.h" 27 #include "chrome/browser/tab_contents/tab_contents.h"
23 #include "chrome/browser/tab_contents/tab_contents_view.h" 28 #include "chrome/browser/tab_contents/tab_contents_view.h"
29 #if defined(TOOLKIT_VIEWS)
30 #include "chrome/browser/ui/views/browser_dialogs.h"
31 #endif // defined(TOOLKIT_VIEWS)
32 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/notification_observer.h" 33 #include "chrome/common/notification_observer.h"
25 #include "chrome/common/notification_registrar.h" 34 #include "chrome/common/notification_registrar.h"
26 #include "chrome/common/notification_source.h" 35 #include "chrome/common/notification_source.h"
27 #include "chrome/common/notification_type.h" 36 #include "chrome/common/notification_type.h"
28 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
29 #include "chrome/common/render_messages_params.h" 38 #include "chrome/common/render_messages_params.h"
30 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
31 #include "webkit/glue/webpreferences.h" 40 #include "webkit/glue/webpreferences.h"
32 41
33 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 prefs::kCloudPrintDialogWidth, size.width()); 395 prefs::kCloudPrintDialogWidth, size.width());
387 dom_ui_->GetProfile()->GetPrefs()->SetInteger( 396 dom_ui_->GetProfile()->GetPrefs()->SetInteger(
388 prefs::kCloudPrintDialogHeight, size.height()); 397 prefs::kCloudPrintDialogHeight, size.height());
389 } 398 }
390 } 399 }
391 400
392 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( 401 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate(
393 const FilePath& path_to_pdf, 402 const FilePath& path_to_pdf,
394 int width, int height, 403 int width, int height,
395 const std::string& json_arguments, 404 const std::string& json_arguments,
396 const string16& print_job_title) 405 const string16& print_job_title,
406 bool modal)
397 : flow_handler_(new CloudPrintFlowHandler(path_to_pdf, print_job_title)), 407 : flow_handler_(new CloudPrintFlowHandler(path_to_pdf, print_job_title)),
408 modal_(modal),
398 owns_flow_handler_(true) { 409 owns_flow_handler_(true) {
399 Init(width, height, json_arguments); 410 Init(width, height, json_arguments);
400 } 411 }
401 412
402 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( 413 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate(
403 CloudPrintFlowHandler* flow_handler, 414 CloudPrintFlowHandler* flow_handler,
404 int width, int height, 415 int width, int height,
405 const std::string& json_arguments) 416 const std::string& json_arguments,
417 bool modal)
406 : flow_handler_(flow_handler), 418 : flow_handler_(flow_handler),
419 modal_(modal),
407 owns_flow_handler_(true) { 420 owns_flow_handler_(true) {
408 Init(width, height, json_arguments); 421 Init(width, height, json_arguments);
409 } 422 }
410 423
411 void CloudPrintHtmlDialogDelegate::Init( 424 void CloudPrintHtmlDialogDelegate::Init(
412 int width, int height, const std::string& json_arguments) { 425 int width, int height, const std::string& json_arguments) {
413 // This information is needed to show the dialog HTML content. 426 // This information is needed to show the dialog HTML content.
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
415 std::string cloud_print_url(chrome::kCloudPrintResourcesURL); 428 std::string cloud_print_url(chrome::kCloudPrintResourcesURL);
416 params_.url = GURL(cloud_print_url); 429 params_.url = GURL(cloud_print_url);
417 params_.height = height; 430 params_.height = height;
418 params_.width = width; 431 params_.width = width;
419 params_.json_input = json_arguments; 432 params_.json_input = json_arguments;
420 433
421 flow_handler_->SetDialogDelegate(this); 434 flow_handler_->SetDialogDelegate(this);
435 // 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.
436 BrowserList::StartKeepAlive();
422 } 437 }
423 438
424 CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() { 439 CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() {
425 // If the flow_handler_ is about to outlive us because we don't own 440 // If the flow_handler_ is about to outlive us because we don't own
426 // it anymore, we need to have it remove it's reference to us. 441 // it anymore, we need to have it remove it's reference to us.
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
428 flow_handler_->SetDialogDelegate(NULL); 443 flow_handler_->SetDialogDelegate(NULL);
429 if (owns_flow_handler_) { 444 if (owns_flow_handler_) {
430 delete flow_handler_; 445 delete flow_handler_;
431 } 446 }
432 } 447 }
433 448
434 bool CloudPrintHtmlDialogDelegate::IsDialogModal() const { 449 bool CloudPrintHtmlDialogDelegate::IsDialogModal() const {
435 return true; 450 return modal_;
436 } 451 }
437 452
438 std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const { 453 std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const {
439 return std::wstring(); 454 return std::wstring();
440 } 455 }
441 456
442 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const { 457 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const {
443 return params_.url; 458 return params_.url;
444 } 459 }
445 460
(...skipping 12 matching lines...) Expand all
458 } 473 }
459 474
460 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const { 475 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const {
461 return params_.json_input; 476 return params_.json_input;
462 } 477 }
463 478
464 void CloudPrintHtmlDialogDelegate::OnDialogClosed( 479 void CloudPrintHtmlDialogDelegate::OnDialogClosed(
465 const std::string& json_retval) { 480 const std::string& json_retval) {
466 // Get the final dialog size and store it. 481 // Get the final dialog size and store it.
467 flow_handler_->StoreDialogClientSize(); 482 flow_handler_->StoreDialogClientSize();
483 // 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.
484 BrowserList::EndKeepAlive();
468 delete this; 485 delete this;
469 } 486 }
470 487
471 void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source, 488 void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source,
472 bool* out_close_dialog) { 489 bool* out_close_dialog) {
473 if (out_close_dialog) 490 if (out_close_dialog)
474 *out_close_dialog = true; 491 *out_close_dialog = true;
475 } 492 }
476 493
477 bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const { 494 bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const {
478 return false; 495 return false;
479 } 496 }
480 497
481 } // end of namespace internal_cloud_print_helpers 498 } // end of namespace internal_cloud_print_helpers
482 499
483 // static, called on the IO thread. This is the main entry point into 500 // static, called on the IO thread. This is the main entry point into
484 // creating the dialog. 501 // creating the dialog.
485 502
486 // TODO(scottbyer): The signature here will need to change as the 503 // TODO(scottbyer): The signature here will need to change as the
487 // workflow through the printing code changes to allow for dynamically 504 // workflow through the printing code changes to allow for dynamically
488 // changing page setup parameters while the dialog is active. 505 // changing page setup parameters while the dialog is active.
489 void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf) { 506 void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) ||
508 BrowserThread::CurrentlyOn(BrowserThread::UI));
491 509
492 BrowserThread::PostTask( 510 BrowserThread::PostTask(
493 BrowserThread::UI, FROM_HERE, 511 BrowserThread::UI, FROM_HERE,
494 NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, path_to_pdf)); 512 NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, path_to_pdf));
495 } 513 }
496 514
497 // static, called from the UI thread. 515 // static, called from the UI thread.
498 void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf) { 516 void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf) {
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
500 new PrintDialogCloud(path_to_pdf); 518 new PrintDialogCloud(path_to_pdf);
501 } 519 }
502 520
503 // Initialize the print dialog. Called on the UI thread. 521 // Initialize the print dialog. Called on the UI thread.
504 PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf) 522 PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf)
505 : browser_(BrowserList::GetLastActive()) { 523 : browser_(BrowserList::GetLastActive()) {
506 524
507 // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should 525 // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should
508 // be distilled out of bookmark sync.) 526 // be distilled out of bookmark sync.)
509 string16 print_job_title; 527 string16 print_job_title;
510 if (browser_ && browser_->GetSelectedTabContents())
511 print_job_title = browser_->GetSelectedTabContents()->GetTitle();
512
513 const int kDefaultWidth = 497; 528 const int kDefaultWidth = 497;
514 const int kDefaultHeight = 332; 529 const int kDefaultHeight = 332;
515 530 Profile* profile = NULL;
516 PrefService* pref_service = browser_->GetProfile()->GetPrefs(); 531 PrefService* pref_service = NULL;
532 bool modal = true;
533 if (browser_) {
534 if (browser_->GetSelectedTabContents())
535 print_job_title = browser_->GetSelectedTabContents()->GetTitle();
536 profile = browser_->GetProfile();
537 modal = true;
538 } else {
539 #ifdef OS_WIN
540 if (CommandLine::ForCurrentProcess()->HasSwitch(
541 switches::kCloudPrintJobTitle)) {
542 CommandLine::StringType native_job_title;
543 native_job_title = CommandLine::ForCurrentProcess()->GetSwitchValueNative(
544 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
545 print_job_title = string16(native_job_title);
546 }
547 #endif
548 profile = ProfileManager::GetDefaultProfile();
549 modal = false;
550 }
551 DCHECK(profile);
552 pref_service = profile->GetPrefs();
517 DCHECK(pref_service); 553 DCHECK(pref_service);
518 if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) { 554 if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) {
519 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth, 555 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth,
520 kDefaultWidth); 556 kDefaultWidth);
521 } 557 }
522 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) { 558 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) {
523 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, 559 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight,
524 kDefaultHeight); 560 kDefaultHeight);
525 } 561 }
526 562
527 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth); 563 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth);
528 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight); 564 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight);
565
529 HtmlDialogUIDelegate* dialog_delegate = 566 HtmlDialogUIDelegate* dialog_delegate =
530 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate( 567 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate(
531 path_to_pdf, width, height, std::string(), print_job_title); 568 path_to_pdf, width, height, std::string(), print_job_title, modal);
532 browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); 569 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
570 browser_->BrowserShowHtmlDialog(dialog_delegate, NULL);
571 } else {
572 #if defined(TOOLKIT_VIEWS)
573 browser::ShowHtmlDialogView(NULL, profile, dialog_delegate);
574 #elif defined(TOOLKIT_GTK)
575 HtmlDialogGtk* html_dialog =
576 new HtmlDialogGtk(profile, dialog_delegate, NULL);
577 html_dialog->InitDialog();
578 #endif // defined(TOOLKIT_VIEWS)
579 }
533 } 580 }
534 581
535 PrintDialogCloud::~PrintDialogCloud() { 582 PrintDialogCloud::~PrintDialogCloud() {
536 } 583 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698