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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 900503002: List printers managed by extensions in print preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 10 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
OLDNEW
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/ui/webui/print_preview/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 #if defined(OS_CHROMEOS) 83 #if defined(OS_CHROMEOS)
84 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 84 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
85 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 85 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
86 #endif 86 #endif
87 87
88 #if defined(ENABLE_SERVICE_DISCOVERY) 88 #if defined(ENABLE_SERVICE_DISCOVERY)
89 #include "chrome/browser/local_discovery/privet_constants.h" 89 #include "chrome/browser/local_discovery/privet_constants.h"
90 #endif 90 #endif
91 91
92 #if defined(ENABLE_EXTENSIONS)
93 #include "extensions/browser/api/printer_provider/printer_provider_api.h"
94 #endif
95
92 using content::BrowserThread; 96 using content::BrowserThread;
93 using content::RenderViewHost; 97 using content::RenderViewHost;
94 using content::WebContents; 98 using content::WebContents;
95 99
96 namespace { 100 namespace {
97 101
98 enum UserActionBuckets { 102 enum UserActionBuckets {
99 PRINT_TO_PRINTER, 103 PRINT_TO_PRINTER,
100 PRINT_TO_PDF, 104 PRINT_TO_PDF,
101 CANCEL, 105 CANCEL,
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 base::Unretained(this))); 644 base::Unretained(this)));
641 web_ui()->RegisterMessageCallback("getPrivetPrinters", 645 web_ui()->RegisterMessageCallback("getPrivetPrinters",
642 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinters, 646 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinters,
643 base::Unretained(this))); 647 base::Unretained(this)));
644 web_ui()->RegisterMessageCallback("stopGetPrivetPrinters", 648 web_ui()->RegisterMessageCallback("stopGetPrivetPrinters",
645 base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters, 649 base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters,
646 base::Unretained(this))); 650 base::Unretained(this)));
647 web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities", 651 web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities",
648 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities, 652 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities,
649 base::Unretained(this))); 653 base::Unretained(this)));
654 web_ui()->RegisterMessageCallback(
655 "getExtensionPrinters",
656 base::Bind(&PrintPreviewHandler::HandleGetExtensionPrinters,
657 base::Unretained(this)));
658 web_ui()->RegisterMessageCallback(
659 "getExtensionPrinterCapabilities",
660 base::Bind(&PrintPreviewHandler::HandleGetExtensionPrinterCapabilities,
661 base::Unretained(this)));
650 RegisterForMergeSession(); 662 RegisterForMergeSession();
651 } 663 }
652 664
653 bool PrintPreviewHandler::PrivetPrintingEnabled() { 665 bool PrintPreviewHandler::PrivetPrintingEnabled() {
654 #if defined(ENABLE_SERVICE_DISCOVERY) 666 #if defined(ENABLE_SERVICE_DISCOVERY)
655 return true; 667 return true;
656 #else 668 #else
657 return false; 669 return false;
658 #endif 670 #endif
659 } 671 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 bool success = args->GetString(0, &name); 711 bool success = args->GetString(0, &name);
700 DCHECK(success); 712 DCHECK(success);
701 713
702 CreatePrivetHTTP( 714 CreatePrivetHTTP(
703 name, 715 name,
704 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient, 716 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient,
705 base::Unretained(this))); 717 base::Unretained(this)));
706 #endif 718 #endif
707 } 719 }
708 720
721 void PrintPreviewHandler::HandleGetExtensionPrinters(
722 const base::ListValue* args) {
723 #if defined(ENABLE_EXTENSIONS)
724 // TODO(tbarzic): Handle case where a new search is initiated before the
725 // previous one finishes. Currently, in this case Web UI layer may get
726 // multiple events with printer list from some extensions, and it may get
727 // fooled by |done| flag from the first search into marking the search
728 // complete.
Aleksey Shlyapnikov 2015/02/03 20:18:24 I'm fine with implementing it later. Just curious,
tbarzic 2015/02/04 02:21:23 Closer to former. I'll probably just end up invali
729 extensions::PrinterProviderAPI::GetFactoryInstance()
730 ->Get(preview_web_contents()->GetBrowserContext())
731 ->DispatchGetPrintersRequested(
732 base::Bind(&PrintPreviewHandler::OnGotPrintersForExtension,
733 weak_factory_.GetWeakPtr()));
734 #else
735 OnGotPrintersForExtension(base::ListValue(), true /* done */);
736 #endif
737 }
738
739 void PrintPreviewHandler::HandleGetExtensionPrinterCapabilities(
740 const base::ListValue* args) {
741 std::string extension_id;
742 std::string printer_id;
743 bool ok = args->GetString(0, &extension_id);
744 DCHECK(ok);
745 ok = args->GetString(1, &printer_id);
746 DCHECK(ok);
747
748 #if defined(ENABLE_EXTENSIONS)
749 extensions::PrinterProviderAPI::GetFactoryInstance()
750 ->Get(preview_web_contents()->GetBrowserContext())
751 ->DispatchGetCapabilityRequested(
752 extension_id, printer_id,
753 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities,
754 weak_factory_.GetWeakPtr(), extension_id, printer_id));
755 #else
756 OnGotExtensionPrinterCapabilities(extension_id, printer_id,
757 base::DictionaryValue());
Aleksey Shlyapnikov 2015/02/03 20:18:24 Empty capabilities are not valid. How do you plan
tbarzic 2015/02/04 02:21:23 Added error handling.
758 #endif
759 }
760
709 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { 761 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) {
710 DCHECK_EQ(3U, args->GetSize()); 762 DCHECK_EQ(3U, args->GetSize());
711 scoped_ptr<base::DictionaryValue> settings(GetSettingsDictionary(args)); 763 scoped_ptr<base::DictionaryValue> settings(GetSettingsDictionary(args));
712 if (!settings.get()) 764 if (!settings.get())
713 return; 765 return;
714 int request_id = -1; 766 int request_id = -1;
715 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) 767 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id))
716 return; 768 return;
717 769
718 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 770 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); 1633 printer_value->SetBoolean("hasLocalPrinting", has_local_printing);
1582 printer_value->SetBoolean( 1634 printer_value->SetBoolean(
1583 "isUnregistered", 1635 "isUnregistered",
1584 description.id.empty() && 1636 description.id.empty() &&
1585 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); 1637 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos));
1586 printer_value->SetString("cloudID", description.id); 1638 printer_value->SetString("cloudID", description.id);
1587 } 1639 }
1588 1640
1589 #endif // defined(ENABLE_SERVICE_DISCOVERY) 1641 #endif // defined(ENABLE_SERVICE_DISCOVERY)
1590 1642
1643 void PrintPreviewHandler::OnGotPrintersForExtension(
1644 const base::ListValue& printers,
1645 bool done) {
1646 web_ui()->CallJavascriptFunction("onExtensionPrintersAdded", printers,
1647 base::FundamentalValue(done));
1648 }
1649
1650 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities(
1651 const std::string& extension_id,
1652 const std::string& printer_id,
1653 const base::DictionaryValue& capabilities) {
1654 web_ui()->CallJavascriptFunction("onExtensionCapabilitiesSet",
1655 base::StringValue(extension_id),
1656 base::StringValue(printer_id),
1657 capabilities);
1658 }
1659
1591 void PrintPreviewHandler::RegisterForMergeSession() { 1660 void PrintPreviewHandler::RegisterForMergeSession() {
1592 DCHECK(!reconcilor_); 1661 DCHECK(!reconcilor_);
1593 Profile* profile = Profile::FromWebUI(web_ui()); 1662 Profile* profile = Profile::FromWebUI(web_ui());
1594 if (switches::IsEnableAccountConsistency() && !profile->IsOffTheRecord()) { 1663 if (switches::IsEnableAccountConsistency() && !profile->IsOffTheRecord()) {
1595 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile); 1664 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile);
1596 if (reconcilor_) 1665 if (reconcilor_)
1597 reconcilor_->AddMergeSessionObserver(this); 1666 reconcilor_->AddMergeSessionObserver(this);
1598 } 1667 }
1599 } 1668 }
1600 1669
1601 void PrintPreviewHandler::UnregisterForMergeSession() { 1670 void PrintPreviewHandler::UnregisterForMergeSession() {
1602 if (reconcilor_) 1671 if (reconcilor_)
1603 reconcilor_->RemoveMergeSessionObserver(this); 1672 reconcilor_->RemoveMergeSessionObserver(this);
1604 } 1673 }
1605 1674
1606 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1675 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1607 const base::Closure& closure) { 1676 const base::Closure& closure) {
1608 pdf_file_saved_closure_ = closure; 1677 pdf_file_saved_closure_ = closure;
1609 } 1678 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698