| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/chromeos/printing/printer_configurer.h" | 14 #include "chrome/browser/chromeos/printing/printer_configurer.h" |
| 15 #include "chrome/browser/chromeos/printing/printer_discoverer.h" | 15 #include "chrome/browser/chromeos/printing/printer_detector.h" |
| 16 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" | 16 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" |
| 17 #include "chromeos/printing/ppd_provider.h" | 17 #include "chromeos/printing/ppd_provider.h" |
| 18 #include "chromeos/printing/printer_configuration.h" | 18 #include "chromeos/printing/printer_configuration.h" |
| 19 #include "ui/shell_dialogs/select_file_dialog.h" | 19 #include "ui/shell_dialogs/select_file_dialog.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class ListValue; | 22 class ListValue; |
| 23 } // namespace base | 23 } // namespace base |
| 24 | 24 |
| 25 class Profile; | 25 class Profile; |
| 26 | 26 |
| 27 namespace chromeos { | 27 namespace chromeos { |
| 28 namespace printing { | 28 namespace printing { |
| 29 class PpdProvider; | 29 class PpdProvider; |
| 30 } | 30 } |
| 31 |
| 32 class CombiningPrinterDetector; |
| 33 |
| 31 namespace settings { | 34 namespace settings { |
| 32 | 35 |
| 33 // Chrome OS CUPS printing settings page UI handler. | 36 // Chrome OS CUPS printing settings page UI handler. |
| 34 class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, | 37 class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, |
| 35 public ui::SelectFileDialog::Listener, | 38 public ui::SelectFileDialog::Listener, |
| 36 public chromeos::PrinterDiscoverer::Observer { | 39 public PrinterDetector::Observer { |
| 37 public: | 40 public: |
| 38 explicit CupsPrintersHandler(content::WebUI* webui); | 41 explicit CupsPrintersHandler(content::WebUI* webui); |
| 39 ~CupsPrintersHandler() override; | 42 ~CupsPrintersHandler() override; |
| 40 | 43 |
| 41 // SettingsPageUIHandler overrides: | 44 // SettingsPageUIHandler overrides: |
| 42 void RegisterMessages() override; | 45 void RegisterMessages() override; |
| 43 void OnJavascriptAllowed() override {} | 46 void OnJavascriptAllowed() override {} |
| 44 void OnJavascriptDisallowed() override {} | 47 void OnJavascriptDisallowed() override {} |
| 45 | 48 |
| 46 private: | 49 private: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 // false, the values of |make|, |model| and |ipp_everywhere| are not | 64 // false, the values of |make|, |model| and |ipp_everywhere| are not |
| 62 // specified. | 65 // specified. |
| 63 void OnPrinterInfo(const std::string& callback_id, | 66 void OnPrinterInfo(const std::string& callback_id, |
| 64 bool success, | 67 bool success, |
| 65 const std::string& make, | 68 const std::string& make, |
| 66 const std::string& model, | 69 const std::string& model, |
| 67 bool ipp_everywhere); | 70 bool ipp_everywhere); |
| 68 | 71 |
| 69 void HandleAddCupsPrinter(const base::ListValue* args); | 72 void HandleAddCupsPrinter(const base::ListValue* args); |
| 70 void OnAddedPrinter(std::unique_ptr<Printer> printer, | 73 void OnAddedPrinter(std::unique_ptr<Printer> printer, |
| 71 chromeos::PrinterSetupResult result); | 74 PrinterSetupResult result); |
| 72 void OnAddPrinterError(); | 75 void OnAddPrinterError(); |
| 73 | 76 |
| 74 // Get a list of all manufacturers for which we have at least one model of | 77 // Get a list of all manufacturers for which we have at least one model of |
| 75 // printer supported. Takes one argument, the callback id for the result. | 78 // printer supported. Takes one argument, the callback id for the result. |
| 76 // The callback will be invoked with {success: <boolean>, models: | 79 // The callback will be invoked with {success: <boolean>, models: |
| 77 // <Array<string>>}. | 80 // <Array<string>>}. |
| 78 void HandleGetCupsPrinterManufacturers(const base::ListValue* args); | 81 void HandleGetCupsPrinterManufacturers(const base::ListValue* args); |
| 79 | 82 |
| 80 // Given a manufacturer, get a list of all models of printers for which we can | 83 // Given a manufacturer, get a list of all models of printers for which we can |
| 81 // get drivers. Takes two arguments - the callback id and the manufacturer | 84 // get drivers. Takes two arguments - the callback id and the manufacturer |
| 82 // name for which we want to list models. The callback will be called with | 85 // name for which we want to list models. The callback will be called with |
| 83 // {success: <boolean>, models: Array<string>}. | 86 // {success: <boolean>, models: Array<string>}. |
| 84 void HandleGetCupsPrinterModels(const base::ListValue* args); | 87 void HandleGetCupsPrinterModels(const base::ListValue* args); |
| 85 | 88 |
| 86 void HandleSelectPPDFile(const base::ListValue* args); | 89 void HandleSelectPPDFile(const base::ListValue* args); |
| 87 | 90 |
| 88 // PpdProvider callback handlers. | 91 // PpdProvider callback handlers. |
| 89 void ResolveManufacturersDone( | 92 void ResolveManufacturersDone( |
| 90 const std::string& js_callback, | 93 const std::string& js_callback, |
| 91 chromeos::printing::PpdProvider::CallbackResultCode result_code, | 94 printing::PpdProvider::CallbackResultCode result_code, |
| 92 const std::vector<std::string>& available); | 95 const std::vector<std::string>& available); |
| 93 void ResolvePrintersDone( | 96 void ResolvePrintersDone( |
| 94 const std::string& js_callback, | 97 const std::string& js_callback, |
| 95 chromeos::printing::PpdProvider::CallbackResultCode result_code, | 98 printing::PpdProvider::CallbackResultCode result_code, |
| 96 const std::vector<std::string>& available); | 99 const std::vector<std::string>& available); |
| 97 | 100 |
| 98 // ui::SelectFileDialog::Listener override: | 101 // ui::SelectFileDialog::Listener override: |
| 99 void FileSelected(const base::FilePath& path, | 102 void FileSelected(const base::FilePath& path, |
| 100 int index, | 103 int index, |
| 101 void* params) override; | 104 void* params) override; |
| 102 | 105 |
| 103 void HandleStartDiscovery(const base::ListValue* args); | 106 void HandleStartDiscovery(const base::ListValue* args); |
| 104 void HandleStopDiscovery(const base::ListValue* args); | 107 void HandleStopDiscovery(const base::ListValue* args); |
| 105 | 108 |
| 106 // chromeos::PrinterDiscoverer::Observer override: | 109 // PrinterDetector::Observer implementations: |
| 107 void OnPrintersFound(const std::vector<Printer>& printers) override; | 110 void OnPrintersFound(const std::vector<Printer>& printers) override; |
| 108 void OnDiscoveryInitialScanDone(int printer_count) override; | 111 void OnPrinterScanComplete() override; |
| 109 | 112 |
| 110 // Invokes debugd to add the printer to CUPS. If |ipp_everywhere| is true, | 113 // Invokes debugd to add the printer to CUPS. If |ipp_everywhere| is true, |
| 111 // automatic configuration will be attempted and |ppd_path| is ignored. | 114 // automatic configuration will be attempted and |ppd_path| is ignored. |
| 112 // |ppd_path| is the path to a Postscript Printer Description file that will | 115 // |ppd_path| is the path to a Postscript Printer Description file that will |
| 113 // be used to configure the printer capabilities. This file must be in | 116 // be used to configure the printer capabilities. This file must be in |
| 114 // Downloads or the PPD Cache. | 117 // Downloads or the PPD Cache. |
| 115 void AddPrinterToCups(std::unique_ptr<Printer> printer, | 118 void AddPrinterToCups(std::unique_ptr<Printer> printer, |
| 116 const base::FilePath& ppd_path, | 119 const base::FilePath& ppd_path, |
| 117 bool ipp_everywhere); | 120 bool ipp_everywhere); |
| 118 | 121 |
| 119 std::unique_ptr<chromeos::PrinterDiscoverer> printer_discoverer_; | 122 std::unique_ptr<CombiningPrinterDetector> printer_detector_; |
| 120 scoped_refptr<chromeos::printing::PpdProvider> ppd_provider_; | 123 scoped_refptr<printing::PpdProvider> ppd_provider_; |
| 121 std::unique_ptr<chromeos::PrinterConfigurer> printer_configurer_; | 124 std::unique_ptr<PrinterConfigurer> printer_configurer_; |
| 122 | 125 |
| 123 Profile* profile_; | 126 Profile* profile_; |
| 124 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | 127 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
| 125 std::string webui_callback_id_; | 128 std::string webui_callback_id_; |
| 126 | 129 |
| 127 base::WeakPtrFactory<CupsPrintersHandler> weak_factory_; | 130 base::WeakPtrFactory<CupsPrintersHandler> weak_factory_; |
| 128 | 131 |
| 129 DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler); | 132 DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler); |
| 130 }; | 133 }; |
| 131 | 134 |
| 132 } // namespace settings | 135 } // namespace settings |
| 133 } // namespace chromeos | 136 } // namespace chromeos |
| 134 | 137 |
| 135 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ | 138 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ |
| OLD | NEW |