| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process_impl.h" | 16 #include "chrome/browser/browser_process_impl.h" |
| 17 #include "chrome/browser/debugger/devtools_window.h" | 17 #include "chrome/browser/debugger/devtools_window.h" |
| 18 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 20 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/ui/browser.h" | |
| 24 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | |
| 26 #include "chrome/browser/ui/browser_list.h" | |
| 27 #include "chrome/browser/ui/browser_window.h" | |
| 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 29 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/print_messages.h" | 26 #include "chrome/common/print_messages.h" |
| 32 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 33 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 35 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
| 36 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
| 37 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 38 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 gfx::Size size = web_ui()->GetWebContents()->GetView()->GetContainerSize(); | 469 gfx::Size size = web_ui()->GetWebContents()->GetView()->GetContainerSize(); |
| 475 Profile* profile = Profile::FromWebUI(web_ui()); | 470 Profile* profile = Profile::FromWebUI(web_ui()); |
| 476 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, | 471 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, |
| 477 size.width()); | 472 size.width()); |
| 478 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, | 473 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, |
| 479 size.height()); | 474 size.height()); |
| 480 } | 475 } |
| 481 } | 476 } |
| 482 | 477 |
| 483 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( | 478 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( |
| 479 content::BrowserContext* browser_context, |
| 480 gfx::NativeWindow modal_parent, |
| 484 const FilePath& path_to_file, | 481 const FilePath& path_to_file, |
| 485 int width, int height, | |
| 486 const std::string& json_arguments, | 482 const std::string& json_arguments, |
| 487 const string16& print_job_title, | 483 const string16& print_job_title, |
| 488 const string16& print_ticket, | 484 const string16& print_ticket, |
| 489 const std::string& file_type, | 485 const std::string& file_type, |
| 490 bool modal, | |
| 491 bool delete_on_close, | 486 bool delete_on_close, |
| 492 bool close_after_signin, | 487 bool close_after_signin, |
| 493 const base::Closure& callback) | 488 const base::Closure& callback) |
| 494 : delete_on_close_(delete_on_close), | 489 : delete_on_close_(delete_on_close), |
| 495 flow_handler_(new CloudPrintFlowHandler(path_to_file, | 490 flow_handler_(new CloudPrintFlowHandler(path_to_file, |
| 496 print_job_title, | 491 print_job_title, |
| 497 print_ticket, | 492 print_ticket, |
| 498 file_type, | 493 file_type, |
| 499 close_after_signin, | 494 close_after_signin, |
| 500 callback)), | 495 callback)), |
| 501 modal_(modal), | 496 modal_parent_(modal_parent), |
| 502 owns_flow_handler_(true), | 497 owns_flow_handler_(true), |
| 503 path_to_file_(path_to_file) { | 498 path_to_file_(path_to_file), |
| 504 Init(width, height, json_arguments); | 499 keep_alive_when_non_modal_(true) { |
| 500 Init(browser_context, json_arguments); |
| 505 } | 501 } |
| 506 | 502 |
| 507 // For unit testing. | 503 // For unit testing. |
| 508 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( | 504 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( |
| 505 const FilePath& path_to_file, |
| 509 CloudPrintFlowHandler* flow_handler, | 506 CloudPrintFlowHandler* flow_handler, |
| 510 int width, int height, | |
| 511 const std::string& json_arguments, | 507 const std::string& json_arguments, |
| 512 bool modal, | |
| 513 bool delete_on_close) | 508 bool delete_on_close) |
| 514 : delete_on_close_(delete_on_close), | 509 : delete_on_close_(delete_on_close), |
| 515 flow_handler_(flow_handler), | 510 flow_handler_(flow_handler), |
| 516 modal_(modal), | 511 modal_parent_(NULL), |
| 517 owns_flow_handler_(true) { | 512 owns_flow_handler_(true), |
| 518 Init(width, height, json_arguments); | 513 keep_alive_when_non_modal_(false) { |
| 514 Init(NULL, json_arguments); |
| 519 } | 515 } |
| 520 | 516 |
| 521 void CloudPrintWebDialogDelegate::Init(int width, int height, | 517 // Returns the persisted width/height for the print dialog. |
| 518 void GetDialogWidthAndHeightFromPrefs(content::BrowserContext* browser_context, |
| 519 int* width, |
| 520 int* height) { |
| 521 const int kDefaultWidth = 912; |
| 522 const int kDefaultHeight = 633; |
| 523 if (!browser_context) { |
| 524 *width = kDefaultWidth; |
| 525 *height = kDefaultHeight; |
| 526 return; |
| 527 } |
| 528 |
| 529 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 530 if (!profile->GetPrefs()->FindPreference(prefs::kCloudPrintDialogWidth)) { |
| 531 profile->GetPrefs()->RegisterIntegerPref(prefs::kCloudPrintDialogWidth, |
| 532 kDefaultWidth, |
| 533 PrefService::UNSYNCABLE_PREF); |
| 534 } |
| 535 if (!profile->GetPrefs()->FindPreference(prefs::kCloudPrintDialogHeight)) { |
| 536 profile->GetPrefs()->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, |
| 537 kDefaultHeight, |
| 538 PrefService::UNSYNCABLE_PREF); |
| 539 } |
| 540 |
| 541 *width = profile->GetPrefs()->GetInteger(prefs::kCloudPrintDialogWidth); |
| 542 *height = profile->GetPrefs()->GetInteger(prefs::kCloudPrintDialogHeight); |
| 543 } |
| 544 |
| 545 void CloudPrintWebDialogDelegate::Init(content::BrowserContext* browser_context, |
| 522 const std::string& json_arguments) { | 546 const std::string& json_arguments) { |
| 523 // This information is needed to show the dialog HTML content. | 547 // This information is needed to show the dialog HTML content. |
| 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 549 |
| 525 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL); | 550 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL); |
| 526 params_.height = height; | 551 GetDialogWidthAndHeightFromPrefs(browser_context, |
| 527 params_.width = width; | 552 ¶ms_.width, |
| 553 ¶ms_.height); |
| 528 params_.json_input = json_arguments; | 554 params_.json_input = json_arguments; |
| 529 | 555 |
| 530 flow_handler_->SetDialogDelegate(this); | 556 flow_handler_->SetDialogDelegate(this); |
| 531 // If we're not modal we can show the dialog with no browser. | 557 // If we're not modal we can show the dialog with no browser. |
| 532 // We need this to keep Chrome alive while our dialog is up. | 558 // We need this to keep Chrome alive while our dialog is up. |
| 533 if (!modal_) | 559 if (!modal_parent_ && keep_alive_when_non_modal_) |
| 534 browser::StartKeepAlive(); | 560 browser::StartKeepAlive(); |
| 535 } | 561 } |
| 536 | 562 |
| 537 CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() { | 563 CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() { |
| 538 // If the flow_handler_ is about to outlive us because we don't own | 564 // If the flow_handler_ is about to outlive us because we don't own |
| 539 // it anymore, we need to have it remove its reference to us. | 565 // it anymore, we need to have it remove its reference to us. |
| 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 541 flow_handler_->SetDialogDelegate(NULL); | 567 flow_handler_->SetDialogDelegate(NULL); |
| 542 if (owns_flow_handler_) { | 568 if (owns_flow_handler_) { |
| 543 delete flow_handler_; | 569 delete flow_handler_; |
| 544 } | 570 } |
| 545 } | 571 } |
| 546 | 572 |
| 547 ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const { | 573 ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const { |
| 548 return modal_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE; | 574 return modal_parent_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE; |
| 549 } | 575 } |
| 550 | 576 |
| 551 string16 CloudPrintWebDialogDelegate::GetDialogTitle() const { | 577 string16 CloudPrintWebDialogDelegate::GetDialogTitle() const { |
| 552 return string16(); | 578 return string16(); |
| 553 } | 579 } |
| 554 | 580 |
| 555 GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const { | 581 GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const { |
| 556 return params_.url; | 582 return params_.url; |
| 557 } | 583 } |
| 558 | 584 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 580 flow_handler_->StoreDialogClientSize(); | 606 flow_handler_->StoreDialogClientSize(); |
| 581 | 607 |
| 582 if (delete_on_close_) { | 608 if (delete_on_close_) { |
| 583 BrowserThread::PostTask( | 609 BrowserThread::PostTask( |
| 584 BrowserThread::FILE, FROM_HERE, | 610 BrowserThread::FILE, FROM_HERE, |
| 585 base::Bind(&internal_cloud_print_helpers::Delete, path_to_file_)); | 611 base::Bind(&internal_cloud_print_helpers::Delete, path_to_file_)); |
| 586 } | 612 } |
| 587 | 613 |
| 588 // If we're modal we can show the dialog with no browser. | 614 // If we're modal we can show the dialog with no browser. |
| 589 // End the keep-alive so that Chrome can exit. | 615 // End the keep-alive so that Chrome can exit. |
| 590 if (!modal_) | 616 if (!modal_parent_ && keep_alive_when_non_modal_) |
| 591 browser::EndKeepAlive(); | 617 browser::EndKeepAlive(); |
| 592 delete this; | 618 delete this; |
| 593 } | 619 } |
| 594 | 620 |
| 595 void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source, | 621 void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source, |
| 596 bool* out_close_dialog) { | 622 bool* out_close_dialog) { |
| 597 if (out_close_dialog) | 623 if (out_close_dialog) |
| 598 *out_close_dialog = true; | 624 *out_close_dialog = true; |
| 599 } | 625 } |
| 600 | 626 |
| 601 bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const { | 627 bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const { |
| 602 return false; | 628 return false; |
| 603 } | 629 } |
| 604 | 630 |
| 605 bool CloudPrintWebDialogDelegate::HandleContextMenu( | 631 bool CloudPrintWebDialogDelegate::HandleContextMenu( |
| 606 const content::ContextMenuParams& params) { | 632 const content::ContextMenuParams& params) { |
| 607 return true; | 633 return true; |
| 608 } | 634 } |
| 609 | 635 |
| 610 void CreatePrintDialogForBytesImpl(scoped_refptr<base::RefCountedBytes> data, | 636 void CreatePrintDialogForBytesImpl(content::BrowserContext* browser_context, |
| 637 gfx::NativeWindow modal_parent, |
| 638 scoped_refptr<base::RefCountedBytes> data, |
| 611 const string16& print_job_title, | 639 const string16& print_job_title, |
| 612 const string16& print_ticket, | 640 const string16& print_ticket, |
| 613 const std::string& file_type, | 641 const std::string& file_type) { |
| 614 bool modal) { | |
| 615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 616 // TODO(abodenha@chromium.org) Writing the PDF to a file before printing | 643 // TODO(abodenha@chromium.org) Writing the PDF to a file before printing |
| 617 // is wasteful. Modify the dialog flow to pull PDF data from memory. | 644 // is wasteful. Modify the dialog flow to pull PDF data from memory. |
| 618 // See http://code.google.com/p/chromium/issues/detail?id=44093 | 645 // See http://code.google.com/p/chromium/issues/detail?id=44093 |
| 619 FilePath path; | 646 FilePath path; |
| 620 if (file_util::CreateTemporaryFile(&path)) { | 647 if (file_util::CreateTemporaryFile(&path)) { |
| 621 file_util::WriteFile(path, | 648 file_util::WriteFile(path, |
| 622 reinterpret_cast<const char*>(data->front()), | 649 reinterpret_cast<const char*>(data->front()), |
| 623 data->size()); | 650 data->size()); |
| 624 } | 651 } |
| 625 print_dialog_cloud::CreatePrintDialogForFile(path, | 652 print_dialog_cloud::CreatePrintDialogForFile(browser_context, |
| 653 modal_parent, |
| 654 path, |
| 626 print_job_title, | 655 print_job_title, |
| 627 print_ticket, | 656 print_ticket, |
| 628 file_type, | 657 file_type, |
| 629 modal, | |
| 630 true); | 658 true); |
| 631 } | 659 } |
| 632 | 660 |
| 633 // Called from the UI thread, starts up the dialog. | 661 // Called from the UI thread, starts up the dialog. |
| 634 void CreateDialogImpl(const FilePath& path_to_file, | 662 void CreateDialogImpl(content::BrowserContext* browser_context, |
| 663 gfx::NativeWindow modal_parent, |
| 664 const FilePath& path_to_file, |
| 635 const string16& print_job_title, | 665 const string16& print_job_title, |
| 636 const string16& print_ticket, | 666 const string16& print_ticket, |
| 637 const std::string& file_type, | 667 const std::string& file_type, |
| 638 bool modal, | |
| 639 bool delete_on_close, | 668 bool delete_on_close, |
| 640 bool close_after_signin, | 669 bool close_after_signin, |
| 641 const base::Closure& callback) { | 670 const base::Closure& callback) { |
| 642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 643 Browser* browser = BrowserList::GetLastActive(); | |
| 644 | |
| 645 const int kDefaultWidth = 912; | |
| 646 const int kDefaultHeight = 633; | |
| 647 string16 job_title = print_job_title; | |
| 648 Profile* profile = NULL; | |
| 649 if (modal) { | |
| 650 if (job_title.empty()) { | |
| 651 WebContents* web_contents = browser->GetSelectedWebContents(); | |
| 652 if (web_contents) | |
| 653 job_title = web_contents->GetTitle(); | |
| 654 } | |
| 655 profile = browser->profile(); | |
| 656 } else { | |
| 657 std::vector<Profile*> loaded_profiles = | |
| 658 g_browser_process->profile_manager()->GetLoadedProfiles(); | |
| 659 DCHECK_GT(loaded_profiles.size(), 0U); | |
| 660 profile = loaded_profiles[0]; | |
| 661 browser = browser::FindLastActiveWithProfile(profile); | |
| 662 } | |
| 663 DCHECK(profile); | |
| 664 PrefService* pref_service = profile->GetPrefs(); | |
| 665 DCHECK(pref_service); | |
| 666 if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) { | |
| 667 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth, | |
| 668 kDefaultWidth, | |
| 669 PrefService::UNSYNCABLE_PREF); | |
| 670 } | |
| 671 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) { | |
| 672 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, | |
| 673 kDefaultHeight, | |
| 674 PrefService::UNSYNCABLE_PREF); | |
| 675 } | |
| 676 | |
| 677 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth); | |
| 678 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight); | |
| 679 | |
| 680 WebDialogDelegate* dialog_delegate = | 672 WebDialogDelegate* dialog_delegate = |
| 681 new internal_cloud_print_helpers::CloudPrintWebDialogDelegate( | 673 new internal_cloud_print_helpers::CloudPrintWebDialogDelegate( |
| 682 path_to_file, width, height, std::string(), job_title, print_ticket, | 674 browser_context, |
| 683 file_type, modal, delete_on_close, close_after_signin, | 675 modal_parent, |
| 676 path_to_file, |
| 677 std::string(), |
| 678 print_job_title, |
| 679 print_ticket, |
| 680 file_type, |
| 681 delete_on_close, |
| 682 close_after_signin, |
| 684 callback); | 683 callback); |
| 685 browser::ShowWebDialog(modal ? browser->window()->GetNativeHandle() : NULL, | 684 browser::ShowWebDialog(modal_parent, |
| 686 profile, browser, dialog_delegate); | 685 Profile::FromBrowserContext(browser_context), |
| 686 NULL, |
| 687 dialog_delegate); |
| 687 } | 688 } |
| 688 | 689 |
| 689 void CreateDialogSigninImpl(const base::Closure& callback) { | 690 void CreateDialogSigninImpl(content::BrowserContext* browser_context, |
| 690 CreateDialogImpl(FilePath(), string16(), string16(), std::string(), | 691 gfx::NativeWindow modal_parent, |
| 691 true, false, true, callback); | 692 const base::Closure& callback) { |
| 693 CreateDialogImpl(browser_context, modal_parent, FilePath(), string16(), |
| 694 string16(), std::string(), false, true, callback); |
| 692 } | 695 } |
| 693 | 696 |
| 694 void CreateDialogFullImpl(const FilePath& path_to_file, | 697 void CreateDialogFullImpl(content::BrowserContext* browser_context, |
| 695 const string16& print_job_title, | 698 gfx::NativeWindow modal_parent, |
| 696 const string16& print_ticket, | 699 const FilePath& path_to_file, |
| 697 const std::string& file_type, | 700 const string16& print_job_title, |
| 698 bool modal, | 701 const string16& print_ticket, |
| 699 bool delete_on_close) { | 702 const std::string& file_type, |
| 700 CreateDialogImpl(path_to_file, print_job_title, print_ticket, file_type, | 703 bool delete_on_close) { |
| 701 modal, delete_on_close, false, base::Closure()); | 704 CreateDialogImpl(browser_context, modal_parent, path_to_file, print_job_title, |
| 705 print_ticket, file_type, delete_on_close, false, |
| 706 base::Closure()); |
| 702 } | 707 } |
| 703 | 708 |
| 704 | 709 |
| 705 | 710 |
| 706 // Provides a runnable function to delete a file. | 711 // Provides a runnable function to delete a file. |
| 707 void Delete(const FilePath& file_path) { | 712 void Delete(const FilePath& file_path) { |
| 708 file_util::Delete(file_path, false); | 713 file_util::Delete(file_path, false); |
| 709 } | 714 } |
| 710 | 715 |
| 711 } // namespace internal_cloud_print_helpers | 716 } // namespace internal_cloud_print_helpers |
| 712 | 717 |
| 713 namespace print_dialog_cloud { | 718 namespace print_dialog_cloud { |
| 714 | 719 |
| 715 // Called on the FILE or UI thread. This is the main entry point into creating | 720 // Called on the FILE or UI thread. This is the main entry point into creating |
| 716 // the dialog. | 721 // the dialog. |
| 717 | 722 |
| 718 // TODO(scottbyer): The signature here will need to change as the | 723 // TODO(scottbyer): The signature here will need to change as the |
| 719 // workflow through the printing code changes to allow for dynamically | 724 // workflow through the printing code changes to allow for dynamically |
| 720 // changing page setup parameters while the dialog is active. | 725 // changing page setup parameters while the dialog is active. |
| 721 void CreatePrintDialogForFile(const FilePath& path_to_file, | 726 void CreatePrintDialogForFile(content::BrowserContext* browser_context, |
| 727 gfx::NativeWindow modal_parent, |
| 728 const FilePath& path_to_file, |
| 722 const string16& print_job_title, | 729 const string16& print_job_title, |
| 723 const string16& print_ticket, | 730 const string16& print_ticket, |
| 724 const std::string& file_type, | 731 const std::string& file_type, |
| 725 bool modal, | |
| 726 bool delete_on_close) { | 732 bool delete_on_close) { |
| 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) || | 733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) || |
| 728 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 734 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 729 | |
| 730 BrowserThread::PostTask( | 735 BrowserThread::PostTask( |
| 731 BrowserThread::UI, FROM_HERE, | 736 BrowserThread::UI, FROM_HERE, |
| 732 base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, | 737 base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, |
| 733 path_to_file, print_job_title, print_ticket, file_type, modal, | 738 browser_context, modal_parent, path_to_file, print_job_title, |
| 734 delete_on_close)); | 739 print_ticket, file_type, delete_on_close)); |
| 735 } | 740 } |
| 736 | 741 |
| 737 void CreateCloudPrintSigninDialog(const base::Closure& callback) { | 742 void CreateCloudPrintSigninDialog(content::BrowserContext* browser_context, |
| 743 gfx::NativeWindow modal_parent, |
| 744 const base::Closure& callback) { |
| 738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 739 | 746 |
| 740 BrowserThread::PostTask( | 747 BrowserThread::PostTask( |
| 741 BrowserThread::UI, FROM_HERE, | 748 BrowserThread::UI, FROM_HERE, |
| 742 base::Bind(&internal_cloud_print_helpers::CreateDialogSigninImpl, | 749 base::Bind(&internal_cloud_print_helpers::CreateDialogSigninImpl, |
| 750 browser_context, |
| 751 modal_parent, |
| 743 callback)); | 752 callback)); |
| 744 } | 753 } |
| 745 | 754 |
| 746 void CreatePrintDialogForBytes(scoped_refptr<base::RefCountedBytes> data, | 755 void CreatePrintDialogForBytes(content::BrowserContext* browser_context, |
| 756 gfx::NativeWindow modal_parent, |
| 757 scoped_refptr<base::RefCountedBytes> data, |
| 747 const string16& print_job_title, | 758 const string16& print_job_title, |
| 748 const string16& print_ticket, | 759 const string16& print_ticket, |
| 749 const std::string& file_type, | 760 const std::string& file_type) { |
| 750 bool modal) { | |
| 751 // TODO(abodenha@chromium.org) Avoid cloning the PDF data. Make use of a | 761 // TODO(abodenha@chromium.org) Avoid cloning the PDF data. Make use of a |
| 752 // shared memory object instead. | 762 // shared memory object instead. |
| 753 // http://code.google.com/p/chromium/issues/detail?id=44093 | 763 // http://code.google.com/p/chromium/issues/detail?id=44093 |
| 754 scoped_refptr<base::RefCountedBytes> cloned_data = | 764 scoped_refptr<base::RefCountedBytes> cloned_data = |
| 755 new base::RefCountedBytes(data->data()); | 765 new base::RefCountedBytes(data->data()); |
| 756 BrowserThread::PostTask( | 766 BrowserThread::PostTask( |
| 757 BrowserThread::FILE, FROM_HERE, | 767 BrowserThread::FILE, FROM_HERE, |
| 758 base::Bind(&internal_cloud_print_helpers::CreatePrintDialogForBytesImpl, | 768 base::Bind(&internal_cloud_print_helpers::CreatePrintDialogForBytesImpl, |
| 759 cloned_data, print_job_title, print_ticket, file_type, modal)); | 769 browser_context, modal_parent, cloned_data, print_job_title, |
| 770 print_ticket, file_type)); |
| 760 } | 771 } |
| 761 | 772 |
| 762 bool CreatePrintDialogFromCommandLine(const CommandLine& command_line) { | 773 bool CreatePrintDialogFromCommandLine(const CommandLine& command_line) { |
| 763 DCHECK(command_line.HasSwitch(switches::kCloudPrintFile)); | 774 DCHECK(command_line.HasSwitch(switches::kCloudPrintFile)); |
| 764 if (!command_line.GetSwitchValuePath(switches::kCloudPrintFile).empty()) { | 775 if (!command_line.GetSwitchValuePath(switches::kCloudPrintFile).empty()) { |
| 765 FilePath cloud_print_file; | 776 FilePath cloud_print_file; |
| 766 cloud_print_file = | 777 cloud_print_file = |
| 767 command_line.GetSwitchValuePath(switches::kCloudPrintFile); | 778 command_line.GetSwitchValuePath(switches::kCloudPrintFile); |
| 768 if (!cloud_print_file.empty()) { | 779 if (!cloud_print_file.empty()) { |
| 769 string16 print_job_title; | 780 string16 print_job_title; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 780 } | 791 } |
| 781 std::string file_type = "application/pdf"; | 792 std::string file_type = "application/pdf"; |
| 782 if (command_line.HasSwitch(switches::kCloudPrintFileType)) { | 793 if (command_line.HasSwitch(switches::kCloudPrintFileType)) { |
| 783 file_type = command_line.GetSwitchValueASCII( | 794 file_type = command_line.GetSwitchValueASCII( |
| 784 switches::kCloudPrintFileType); | 795 switches::kCloudPrintFileType); |
| 785 } | 796 } |
| 786 | 797 |
| 787 bool delete_on_close = CommandLine::ForCurrentProcess()->HasSwitch( | 798 bool delete_on_close = CommandLine::ForCurrentProcess()->HasSwitch( |
| 788 switches::kCloudPrintDeleteFile); | 799 switches::kCloudPrintDeleteFile); |
| 789 | 800 |
| 790 print_dialog_cloud::CreatePrintDialogForFile(cloud_print_file, | 801 print_dialog_cloud::CreatePrintDialogForFile( |
| 791 print_job_title, | 802 ProfileManager::GetDefaultProfile(), |
| 792 print_job_print_ticket, | 803 NULL, |
| 793 file_type, | 804 cloud_print_file, |
| 794 false, | 805 print_job_title, |
| 795 delete_on_close); | 806 print_job_print_ticket, |
| 807 file_type, |
| 808 delete_on_close); |
| 796 return true; | 809 return true; |
| 797 } | 810 } |
| 798 } | 811 } |
| 799 return false; | 812 return false; |
| 800 } | 813 } |
| 801 | 814 |
| 802 } // end namespace | 815 } // end namespace |
| OLD | NEW |