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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
44 #include "ui/base/win/foreground_helper.h" | 44 #include "ui/base/win/foreground_helper.h" |
45 #endif | 45 #endif |
46 | 46 |
47 #include "webkit/glue/webpreferences.h" | 47 #include "webkit/glue/webpreferences.h" |
48 | 48 |
49 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
50 | 50 |
51 #if defined(USE_AURA) | 51 #if defined(USE_AURA) |
52 #include "chrome/browser/ui/browser_window.h" | 52 #include "chrome/browser/ui/browser_window.h" |
53 #include "chrome/browser/ui/views/html_dialog_view.h" | 53 #include "chrome/browser/ui/views/web_dialog_view.h" |
54 #include "ui/aura/root_window.h" | 54 #include "ui/aura/root_window.h" |
55 #include "ui/views/widget/widget.h" | 55 #include "ui/views/widget/widget.h" |
56 #endif | 56 #endif |
57 | 57 |
58 // This module implements the UI support in Chrome for cloud printing. | 58 // This module implements the UI support in Chrome for cloud printing. |
59 // This means hosting a dialog containing HTML/JavaScript and using | 59 // This means hosting a dialog containing HTML/JavaScript and using |
60 // the published cloud print user interface integration APIs to get | 60 // the published cloud print user interface integration APIs to get |
61 // page setup settings from the dialog contents and provide the | 61 // page setup settings from the dialog contents and provide the |
62 // generated print data to the dialog contents for uploading to the | 62 // generated print data to the dialog contents for uploading to the |
63 // cloud print service. | 63 // cloud print service. |
64 | 64 |
65 // Currently, the flow between these classes is as follows: | 65 // Currently, the flow between these classes is as follows: |
66 | 66 |
67 // PrintDialogCloud::CreatePrintDialogForFile is called from | 67 // PrintDialogCloud::CreatePrintDialogForFile is called from |
68 // resource_message_filter_gtk.cc once the renderer has informed the | 68 // resource_message_filter_gtk.cc once the renderer has informed the |
69 // renderer host that print data generation into the renderer host provided | 69 // renderer host that print data generation into the renderer host provided |
70 // temp file has been completed. That call is on the FILE thread. | 70 // temp file has been completed. That call is on the FILE thread. |
71 // That, in turn, hops over to the UI thread to create an instance of | 71 // That, in turn, hops over to the UI thread to create an instance of |
72 // PrintDialogCloud. | 72 // PrintDialogCloud. |
73 | 73 |
74 // The constructor for PrintDialogCloud creates a | 74 // The constructor for PrintDialogCloud creates a |
75 // CloudPrintHtmlDialogDelegate and asks the current active browser to | 75 // CloudPrintWebDialogDelegate and asks the current active browser to |
76 // show an HTML dialog using that class as the delegate. That class | 76 // show an HTML dialog using that class as the delegate. That class |
77 // hands in the kChromeUICloudPrintResourcesURL as the URL to visit. That is | 77 // hands in the kChromeUICloudPrintResourcesURL as the URL to visit. That is |
78 // recognized by the GetWebUIFactoryFunction as a signal to create an | 78 // recognized by the GetWebUIFactoryFunction as a signal to create an |
79 // ExternalHtmlDialogUI. | 79 // ExternalHtmlDialogUI. |
80 | 80 |
81 // CloudPrintHtmlDialogDelegate also temporarily owns a | 81 // CloudPrintWebDialogDelegate also temporarily owns a |
82 // CloudPrintFlowHandler, a class which is responsible for the actual | 82 // CloudPrintFlowHandler, a class which is responsible for the actual |
83 // interactions with the dialog contents, including handing in the | 83 // interactions with the dialog contents, including handing in the |
84 // print data and getting any page setup parameters that the dialog | 84 // print data and getting any page setup parameters that the dialog |
85 // contents provides. As part of bringing up the dialog, | 85 // contents provides. As part of bringing up the dialog, |
86 // HtmlDialogUI::RenderViewCreated is called (an override of | 86 // HtmlDialogUI::RenderViewCreated is called (an override of |
87 // WebUI::RenderViewCreated). That routine, in turn, calls the | 87 // WebUI::RenderViewCreated). That routine, in turn, calls the |
88 // delegate's GetWebUIMessageHandlers routine, at which point the | 88 // delegate's GetWebUIMessageHandlers routine, at which point the |
89 // ownership of the CloudPrintFlowHandler is handed over. A pointer | 89 // ownership of the CloudPrintFlowHandler is handed over. A pointer |
90 // to the flow handler is kept to facilitate communication back and | 90 // to the flow handler is kept to facilitate communication back and |
91 // forth between the two classes. | 91 // forth between the two classes. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 callback_(callback) { | 280 callback_(callback) { |
281 } | 281 } |
282 | 282 |
283 CloudPrintFlowHandler::~CloudPrintFlowHandler() { | 283 CloudPrintFlowHandler::~CloudPrintFlowHandler() { |
284 // This will also cancel any task in flight. | 284 // This will also cancel any task in flight. |
285 CancelAnyRunningTask(); | 285 CancelAnyRunningTask(); |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 void CloudPrintFlowHandler::SetDialogDelegate( | 289 void CloudPrintFlowHandler::SetDialogDelegate( |
290 CloudPrintHtmlDialogDelegate* delegate) { | 290 CloudPrintWebDialogDelegate* delegate) { |
291 // Even if setting a new WebUI, it means any previous task needs | 291 // Even if setting a new WebUI, it means any previous task needs |
292 // to be canceled, its now invalid. | 292 // to be canceled, its now invalid. |
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
294 CancelAnyRunningTask(); | 294 CancelAnyRunningTask(); |
295 dialog_delegate_ = delegate; | 295 dialog_delegate_ = delegate; |
296 } | 296 } |
297 | 297 |
298 // Cancels any print data sender we have in flight and removes our | 298 // Cancels any print data sender we have in flight and removes our |
299 // reference to it, so when the task that is calling it finishes and | 299 // reference to it, so when the task that is calling it finishes and |
300 // removes its reference, it goes away. | 300 // removes its reference, it goes away. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 web_ui()->GetWebContents()->GetView()) { | 480 web_ui()->GetWebContents()->GetView()) { |
481 gfx::Size size = web_ui()->GetWebContents()->GetView()->GetContainerSize(); | 481 gfx::Size size = web_ui()->GetWebContents()->GetView()->GetContainerSize(); |
482 Profile* profile = Profile::FromWebUI(web_ui()); | 482 Profile* profile = Profile::FromWebUI(web_ui()); |
483 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, | 483 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, |
484 size.width()); | 484 size.width()); |
485 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, | 485 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, |
486 size.height()); | 486 size.height()); |
487 } | 487 } |
488 } | 488 } |
489 | 489 |
490 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( | 490 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( |
491 const FilePath& path_to_file, | 491 const FilePath& path_to_file, |
492 int width, int height, | 492 int width, int height, |
493 const std::string& json_arguments, | 493 const std::string& json_arguments, |
494 const string16& print_job_title, | 494 const string16& print_job_title, |
495 const string16& print_ticket, | 495 const string16& print_ticket, |
496 const std::string& file_type, | 496 const std::string& file_type, |
497 bool modal, | 497 bool modal, |
498 bool delete_on_close, | 498 bool delete_on_close, |
499 bool close_after_signin, | 499 bool close_after_signin, |
500 const base::Closure& callback) | 500 const base::Closure& callback) |
501 : delete_on_close_(delete_on_close), | 501 : delete_on_close_(delete_on_close), |
502 flow_handler_(new CloudPrintFlowHandler(path_to_file, | 502 flow_handler_(new CloudPrintFlowHandler(path_to_file, |
503 print_job_title, | 503 print_job_title, |
504 print_ticket, | 504 print_ticket, |
505 file_type, | 505 file_type, |
506 close_after_signin, | 506 close_after_signin, |
507 callback)), | 507 callback)), |
508 modal_(modal), | 508 modal_(modal), |
509 owns_flow_handler_(true), | 509 owns_flow_handler_(true), |
510 path_to_file_(path_to_file) { | 510 path_to_file_(path_to_file) { |
511 Init(width, height, json_arguments); | 511 Init(width, height, json_arguments); |
512 } | 512 } |
513 | 513 |
514 // For unit testing. | 514 // For unit testing. |
515 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( | 515 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( |
516 CloudPrintFlowHandler* flow_handler, | 516 CloudPrintFlowHandler* flow_handler, |
517 int width, int height, | 517 int width, int height, |
518 const std::string& json_arguments, | 518 const std::string& json_arguments, |
519 bool modal, | 519 bool modal, |
520 bool delete_on_close) | 520 bool delete_on_close) |
521 : delete_on_close_(delete_on_close), | 521 : delete_on_close_(delete_on_close), |
522 flow_handler_(flow_handler), | 522 flow_handler_(flow_handler), |
523 modal_(modal), | 523 modal_(modal), |
524 owns_flow_handler_(true) { | 524 owns_flow_handler_(true) { |
525 Init(width, height, json_arguments); | 525 Init(width, height, json_arguments); |
526 } | 526 } |
527 | 527 |
528 void CloudPrintHtmlDialogDelegate::Init(int width, int height, | 528 void CloudPrintWebDialogDelegate::Init(int width, int height, |
529 const std::string& json_arguments) { | 529 const std::string& json_arguments) { |
530 // This information is needed to show the dialog HTML content. | 530 // This information is needed to show the dialog HTML content. |
531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
532 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL); | 532 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL); |
533 params_.height = height; | 533 params_.height = height; |
534 params_.width = width; | 534 params_.width = width; |
535 params_.json_input = json_arguments; | 535 params_.json_input = json_arguments; |
536 | 536 |
537 flow_handler_->SetDialogDelegate(this); | 537 flow_handler_->SetDialogDelegate(this); |
538 // If we're not modal we can show the dialog with no browser. | 538 // If we're not modal we can show the dialog with no browser. |
539 // We need this to keep Chrome alive while our dialog is up. | 539 // We need this to keep Chrome alive while our dialog is up. |
540 if (!modal_) | 540 if (!modal_) |
541 BrowserList::StartKeepAlive(); | 541 BrowserList::StartKeepAlive(); |
542 } | 542 } |
543 | 543 |
544 CloudPrintHtmlDialogDelegate::~CloudPrintHtmlDialogDelegate() { | 544 CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() { |
545 // If the flow_handler_ is about to outlive us because we don't own | 545 // If the flow_handler_ is about to outlive us because we don't own |
546 // it anymore, we need to have it remove its reference to us. | 546 // it anymore, we need to have it remove its reference to us. |
547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
548 flow_handler_->SetDialogDelegate(NULL); | 548 flow_handler_->SetDialogDelegate(NULL); |
549 if (owns_flow_handler_) { | 549 if (owns_flow_handler_) { |
550 delete flow_handler_; | 550 delete flow_handler_; |
551 } | 551 } |
552 } | 552 } |
553 | 553 |
554 ui::ModalType CloudPrintHtmlDialogDelegate::GetDialogModalType() const { | 554 ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const { |
555 return modal_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE; | 555 return modal_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE; |
556 } | 556 } |
557 | 557 |
558 string16 CloudPrintHtmlDialogDelegate::GetDialogTitle() const { | 558 string16 CloudPrintWebDialogDelegate::GetDialogTitle() const { |
559 return string16(); | 559 return string16(); |
560 } | 560 } |
561 | 561 |
562 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const { | 562 GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const { |
563 return params_.url; | 563 return params_.url; |
564 } | 564 } |
565 | 565 |
566 void CloudPrintHtmlDialogDelegate::GetWebUIMessageHandlers( | 566 void CloudPrintWebDialogDelegate::GetWebUIMessageHandlers( |
567 std::vector<WebUIMessageHandler*>* handlers) const { | 567 std::vector<WebUIMessageHandler*>* handlers) const { |
568 handlers->push_back(flow_handler_); | 568 handlers->push_back(flow_handler_); |
569 // We don't own flow_handler_ anymore, but it sticks around until at | 569 // We don't own flow_handler_ anymore, but it sticks around until at |
570 // least right after OnDialogClosed() is called (and this object is | 570 // least right after OnDialogClosed() is called (and this object is |
571 // destroyed). | 571 // destroyed). |
572 owns_flow_handler_ = false; | 572 owns_flow_handler_ = false; |
573 } | 573 } |
574 | 574 |
575 void CloudPrintHtmlDialogDelegate::GetDialogSize(gfx::Size* size) const { | 575 void CloudPrintWebDialogDelegate::GetDialogSize(gfx::Size* size) const { |
576 size->set_width(params_.width); | 576 size->set_width(params_.width); |
577 size->set_height(params_.height); | 577 size->set_height(params_.height); |
578 } | 578 } |
579 | 579 |
580 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const { | 580 std::string CloudPrintWebDialogDelegate::GetDialogArgs() const { |
581 return params_.json_input; | 581 return params_.json_input; |
582 } | 582 } |
583 | 583 |
584 void CloudPrintHtmlDialogDelegate::OnDialogClosed( | 584 void CloudPrintWebDialogDelegate::OnDialogClosed( |
585 const std::string& json_retval) { | 585 const std::string& json_retval) { |
586 // Get the final dialog size and store it. | 586 // Get the final dialog size and store it. |
587 flow_handler_->StoreDialogClientSize(); | 587 flow_handler_->StoreDialogClientSize(); |
588 | 588 |
589 if (delete_on_close_) { | 589 if (delete_on_close_) { |
590 BrowserThread::PostTask( | 590 BrowserThread::PostTask( |
591 BrowserThread::FILE, FROM_HERE, | 591 BrowserThread::FILE, FROM_HERE, |
592 base::Bind(&internal_cloud_print_helpers::Delete, path_to_file_)); | 592 base::Bind(&internal_cloud_print_helpers::Delete, path_to_file_)); |
593 } | 593 } |
594 | 594 |
595 // If we're modal we can show the dialog with no browser. | 595 // If we're modal we can show the dialog with no browser. |
596 // End the keep-alive so that Chrome can exit. | 596 // End the keep-alive so that Chrome can exit. |
597 if (!modal_) | 597 if (!modal_) |
598 BrowserList::EndKeepAlive(); | 598 BrowserList::EndKeepAlive(); |
599 delete this; | 599 delete this; |
600 } | 600 } |
601 | 601 |
602 void CloudPrintHtmlDialogDelegate::OnCloseContents(WebContents* source, | 602 void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source, |
603 bool* out_close_dialog) { | 603 bool* out_close_dialog) { |
604 if (out_close_dialog) | 604 if (out_close_dialog) |
605 *out_close_dialog = true; | 605 *out_close_dialog = true; |
606 } | 606 } |
607 | 607 |
608 bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const { | 608 bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const { |
609 return false; | 609 return false; |
610 } | 610 } |
611 | 611 |
612 bool CloudPrintHtmlDialogDelegate::HandleContextMenu( | 612 bool CloudPrintWebDialogDelegate::HandleContextMenu( |
613 const content::ContextMenuParams& params) { | 613 const content::ContextMenuParams& params) { |
614 return true; | 614 return true; |
615 } | 615 } |
616 | 616 |
617 void CreatePrintDialogForBytesImpl(scoped_refptr<base::RefCountedBytes> data, | 617 void CreatePrintDialogForBytesImpl(scoped_refptr<base::RefCountedBytes> data, |
618 const string16& print_job_title, | 618 const string16& print_job_title, |
619 const string16& print_ticket, | 619 const string16& print_ticket, |
620 const std::string& file_type, | 620 const std::string& file_type, |
621 bool modal) { | 621 bool modal) { |
622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 } | 677 } |
678 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) { | 678 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) { |
679 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, | 679 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight, |
680 kDefaultHeight, | 680 kDefaultHeight, |
681 PrefService::UNSYNCABLE_PREF); | 681 PrefService::UNSYNCABLE_PREF); |
682 } | 682 } |
683 | 683 |
684 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth); | 684 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth); |
685 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight); | 685 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight); |
686 | 686 |
687 HtmlDialogUIDelegate* dialog_delegate = | 687 WebDialogDelegate* dialog_delegate = |
688 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate( | 688 new internal_cloud_print_helpers::CloudPrintWebDialogDelegate( |
689 path_to_file, width, height, std::string(), job_title, print_ticket, | 689 path_to_file, width, height, std::string(), job_title, print_ticket, |
690 file_type, modal, delete_on_close, close_after_signin, | 690 file_type, modal, delete_on_close, close_after_signin, |
691 callback); | 691 callback); |
692 browser::ShowHtmlDialog(modal ? browser->window()->GetNativeHandle() : NULL, | 692 browser::ShowWebDialog(modal ? browser->window()->GetNativeHandle() : NULL, |
693 profile, | 693 profile, |
694 browser, | 694 browser, |
695 dialog_delegate, | 695 dialog_delegate, |
696 STYLE_GENERIC); | 696 STYLE_GENERIC); |
697 } | 697 } |
698 | 698 |
699 void CreateDialogSigninImpl(const base::Closure& callback) { | 699 void CreateDialogSigninImpl(const base::Closure& callback) { |
700 CreateDialogImpl(FilePath(), string16(), string16(), std::string(), | 700 CreateDialogImpl(FilePath(), string16(), string16(), std::string(), |
701 true, false, true, callback); | 701 true, false, true, callback); |
702 } | 702 } |
703 | 703 |
704 void CreateDialogFullImpl(const FilePath& path_to_file, | 704 void CreateDialogFullImpl(const FilePath& path_to_file, |
705 const string16& print_job_title, | 705 const string16& print_job_title, |
706 const string16& print_ticket, | 706 const string16& print_ticket, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 file_type, | 803 file_type, |
804 false, | 804 false, |
805 delete_on_close); | 805 delete_on_close); |
806 return true; | 806 return true; |
807 } | 807 } |
808 } | 808 } |
809 return false; | 809 return false; |
810 } | 810 } |
811 | 811 |
812 } // end namespace | 812 } // end namespace |
OLD | NEW |