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

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 "base/base64.h" 8 #include "base/base64.h"
9 #include "base/command_line.h"
9 #include "base/file_util.h" 10 #include "base/file_util.h"
10 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser_thread.h" 14 #include "chrome/browser/browser_thread.h"
14 #include "chrome/browser/debugger/devtools_manager.h" 15 #include "chrome/browser/debugger/devtools_manager.h"
15 #include "chrome/browser/dom_ui/dom_ui.h" 16 #include "chrome/browser/dom_ui/dom_ui.h"
16 #include "chrome/browser/dom_ui/dom_ui_util.h" 17 #include "chrome/browser/dom_ui/dom_ui_util.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/renderer_host/render_view_host.h" 22 #include "chrome/browser/renderer_host/render_view_host.h"
21 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "chrome/browser/tab_contents/tab_contents_view.h" 24 #include "chrome/browser/tab_contents/tab_contents_view.h"
25 #if defined(TOOLKIT_GTK)
26 #include "chrome/browser/ui/gtk/html_dialog_gtk.h"
27 #endif // defined(TOOLKIT_GTK)
28 #if defined(TOOLKIT_VIEWS)
29 #include "chrome/browser/ui/views/browser_dialogs.h"
30 #endif // defined(TOOLKIT_VIEWS)
31 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/notification_observer.h" 32 #include "chrome/common/notification_observer.h"
24 #include "chrome/common/notification_registrar.h" 33 #include "chrome/common/notification_registrar.h"
25 #include "chrome/common/notification_source.h" 34 #include "chrome/common/notification_source.h"
26 #include "chrome/common/notification_type.h" 35 #include "chrome/common/notification_type.h"
27 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
28 #include "chrome/common/render_messages_params.h" 37 #include "chrome/common/render_messages_params.h"
29 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
30 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
31 #include "webkit/glue/webpreferences.h" 40 #include "webkit/glue/webpreferences.h"
32 41
(...skipping 353 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 // If we're not modal we can show the dialog with no browser.
436 // We need this to keep Chrome alive while our dialog is up.
437 if (!modal_)
438 BrowserList::StartKeepAlive();
422 } 439 }
423 440
424 CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() { 441 CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() {
425 // If the flow_handler_ is about to outlive us because we don't own 442 // 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. 443 // it anymore, we need to have it remove it's reference to us.
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
428 flow_handler_->SetDialogDelegate(NULL); 445 flow_handler_->SetDialogDelegate(NULL);
429 if (owns_flow_handler_) { 446 if (owns_flow_handler_) {
430 delete flow_handler_; 447 delete flow_handler_;
431 } 448 }
432 } 449 }
433 450
434 bool CloudPrintHtmlDialogDelegate::IsDialogModal() const { 451 bool CloudPrintHtmlDialogDelegate::IsDialogModal() const {
435 return true; 452 return modal_;
436 } 453 }
437 454
438 std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const { 455 std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const {
439 return std::wstring(); 456 return std::wstring();
440 } 457 }
441 458
442 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const { 459 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const {
443 return params_.url; 460 return params_.url;
444 } 461 }
445 462
(...skipping 12 matching lines...) Expand all
458 } 475 }
459 476
460 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const { 477 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const {
461 return params_.json_input; 478 return params_.json_input;
462 } 479 }
463 480
464 void CloudPrintHtmlDialogDelegate::OnDialogClosed( 481 void CloudPrintHtmlDialogDelegate::OnDialogClosed(
465 const std::string& json_retval) { 482 const std::string& json_retval) {
466 // Get the final dialog size and store it. 483 // Get the final dialog size and store it.
467 flow_handler_->StoreDialogClientSize(); 484 flow_handler_->StoreDialogClientSize();
485 // If we're modal we can show the dialog with no browser.
486 // End the keep-alive so that Chrome can exit.
487 if (!modal_)
488 BrowserList::EndKeepAlive();
468 delete this; 489 delete this;
469 } 490 }
470 491
471 void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source, 492 void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source,
472 bool* out_close_dialog) { 493 bool* out_close_dialog) {
473 if (out_close_dialog) 494 if (out_close_dialog)
474 *out_close_dialog = true; 495 *out_close_dialog = true;
475 } 496 }
476 497
477 bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const { 498 bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const {
478 return false; 499 return false;
479 } 500 }
480 501
481 } // end of namespace internal_cloud_print_helpers 502 } // end of namespace internal_cloud_print_helpers
482 503
483 // static, called on the IO thread. This is the main entry point into 504 // static, called on the IO thread. This is the main entry point into
484 // creating the dialog. 505 // creating the dialog.
485 506
486 // TODO(scottbyer): The signature here will need to change as the 507 // TODO(scottbyer): The signature here will need to change as the
487 // workflow through the printing code changes to allow for dynamically 508 // workflow through the printing code changes to allow for dynamically
488 // changing page setup parameters while the dialog is active. 509 // changing page setup parameters while the dialog is active.
489 void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf) { 510 void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf,
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 511 const string16& print_job_title,
512 bool modal) {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) ||
514 BrowserThread::CurrentlyOn(BrowserThread::UI));
491 515
492 BrowserThread::PostTask( 516 BrowserThread::PostTask(
493 BrowserThread::UI, FROM_HERE, 517 BrowserThread::UI, FROM_HERE,
494 NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl, path_to_pdf)); 518 NewRunnableFunction(&PrintDialogCloud::CreateDialogImpl,
519 path_to_pdf,
520 print_job_title,
521 modal));
495 } 522 }
496 523
497 // static, called from the UI thread. 524 // static, called from the UI thread.
498 void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf) { 525 void PrintDialogCloud::CreateDialogImpl(const FilePath& path_to_pdf,
526 const string16& print_job_title,
527 bool modal) {
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
500 new PrintDialogCloud(path_to_pdf); 529 new PrintDialogCloud(path_to_pdf, print_job_title, modal);
501 } 530 }
502 531
503 // Initialize the print dialog. Called on the UI thread. 532 // Initialize the print dialog. Called on the UI thread.
504 PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf) 533 PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf,
505 : browser_(BrowserList::GetLastActive()) { 534 const string16& print_job_title,
535 bool modal)
536 : browser_(BrowserList::GetLastActive()),
537 print_job_title_(print_job_title),
538 modal_(modal) {
506 539
507 // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should 540 // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should
508 // be distilled out of bookmark sync.) 541 // be distilled out of bookmark sync.)
509 string16 print_job_title;
510 if (browser_ && browser_->GetSelectedTabContents())
511 print_job_title = browser_->GetSelectedTabContents()->GetTitle();
512
513 const int kDefaultWidth = 497; 542 const int kDefaultWidth = 497;
514 const int kDefaultHeight = 332; 543 const int kDefaultHeight = 332;
515 544 Profile* profile = NULL;
516 PrefService* pref_service = browser_->GetProfile()->GetPrefs(); 545 PrefService* pref_service = NULL;
546 if (modal_) {
547 DCHECK(browser_);
548 if (print_job_title_.empty() && browser_->GetSelectedTabContents())
549 print_job_title_ = browser_->GetSelectedTabContents()->GetTitle();
550 profile = browser_->GetProfile();
551 } else {
552 profile = ProfileManager::GetDefaultProfile();
553 }
554 DCHECK(profile);
555 pref_service = profile->GetPrefs();
517 DCHECK(pref_service); 556 DCHECK(pref_service);
518 if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) { 557 if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) {
519 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth, 558 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth,
520 kDefaultWidth); 559 kDefaultWidth);
521 } 560 }
522 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) { 561 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) {
523 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, 562 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight,
524 kDefaultHeight); 563 kDefaultHeight);
525 } 564 }
526 565
527 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth); 566 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth);
528 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight); 567 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight);
568
529 HtmlDialogUIDelegate* dialog_delegate = 569 HtmlDialogUIDelegate* dialog_delegate =
530 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate( 570 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate(
531 path_to_pdf, width, height, std::string(), print_job_title); 571 path_to_pdf, width, height, std::string(), print_job_title_, modal_);
532 browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); 572 if (modal_) {
573 DCHECK(browser_);
574 browser_->BrowserShowHtmlDialog(dialog_delegate, NULL);
575 } else {
576 #if defined(TOOLKIT_VIEWS)
577 browser::ShowHtmlDialogView(NULL, profile, dialog_delegate);
578 #elif defined(TOOLKIT_GTK)
579 HtmlDialogGtk* html_dialog =
580 new HtmlDialogGtk(profile, dialog_delegate, NULL);
581 html_dialog->InitDialog();
582 #endif // defined(TOOLKIT_VIEWS)
583 }
533 } 584 }
534 585
535 PrintDialogCloud::~PrintDialogCloud() { 586 PrintDialogCloud::~PrintDialogCloud() {
536 } 587 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud.h ('k') | chrome/browser/printing/print_dialog_cloud_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698