| 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> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 8 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 9 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" | 13 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" |
| 14 #include "chromeos/printing/ppd_provider.h" |
| 10 #include "chromeos/printing/printer_configuration.h" | 15 #include "chromeos/printing/printer_configuration.h" |
| 11 #include "chromeos/printing/printer_discoverer.h" | 16 #include "chromeos/printing/printer_discoverer.h" |
| 12 #include "ui/shell_dialogs/select_file_dialog.h" | 17 #include "ui/shell_dialogs/select_file_dialog.h" |
| 13 | 18 |
| 14 namespace base { | 19 namespace base { |
| 15 class ListValue; | 20 class ListValue; |
| 16 } // namespace base | 21 } // namespace base |
| 17 | 22 |
| 18 class Profile; | 23 class Profile; |
| 19 | 24 |
| 20 namespace chromeos { | 25 namespace chromeos { |
| 26 namespace printing { |
| 27 class PpdProvider; |
| 28 } |
| 21 namespace settings { | 29 namespace settings { |
| 22 | 30 |
| 23 // Chrome OS CUPS printing settings page UI handler. | 31 // Chrome OS CUPS printing settings page UI handler. |
| 24 class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, | 32 class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, |
| 25 public ui::SelectFileDialog::Listener, | 33 public ui::SelectFileDialog::Listener, |
| 26 public chromeos::PrinterDiscoverer::Observer { | 34 public chromeos::PrinterDiscoverer::Observer { |
| 27 public: | 35 public: |
| 28 explicit CupsPrintersHandler(content::WebUI* webui); | 36 explicit CupsPrintersHandler(content::WebUI* webui); |
| 29 ~CupsPrintersHandler() override; | 37 ~CupsPrintersHandler() override; |
| 30 | 38 |
| 31 // SettingsPageUIHandler overrides: | 39 // SettingsPageUIHandler overrides: |
| 32 void RegisterMessages() override; | 40 void RegisterMessages() override; |
| 33 void OnJavascriptAllowed() override {} | 41 void OnJavascriptAllowed() override {} |
| 34 void OnJavascriptDisallowed() override {} | 42 void OnJavascriptDisallowed() override {} |
| 35 | 43 |
| 36 private: | 44 private: |
| 37 // Gets all CUPS printers and return it to WebUI. | 45 // Gets all CUPS printers and return it to WebUI. |
| 38 void HandleGetCupsPrintersList(const base::ListValue* args); | 46 void HandleGetCupsPrintersList(const base::ListValue* args); |
| 39 void HandleUpdateCupsPrinter(const base::ListValue* args); | 47 void HandleUpdateCupsPrinter(const base::ListValue* args); |
| 40 void HandleRemoveCupsPrinter(const base::ListValue* args); | 48 void HandleRemoveCupsPrinter(const base::ListValue* args); |
| 41 | 49 |
| 42 void HandleAddCupsPrinter(const base::ListValue* args); | 50 void HandleAddCupsPrinter(const base::ListValue* args); |
| 43 void OnAddedPrinter(std::unique_ptr<Printer> printer, bool success); | 51 void OnAddedPrinter(std::unique_ptr<Printer> printer, bool success); |
| 44 void OnAddPrinterError(); | 52 void OnAddPrinterError(); |
| 45 | 53 |
| 54 // Get a list of all manufacturers for which we have at least one model of |
| 55 // printer supported. Takes one argument, the callback id for the result. |
| 56 // The callback will be invoked with {success: <boolean>, models: |
| 57 // <Array<string>>}. |
| 58 void HandleGetCupsPrinterManufacturers(const base::ListValue* args); |
| 59 |
| 60 // Given a manufacturer, get a list of all models of printers for which we can |
| 61 // get drivers. Takes two arguments - the callback id and the manufacturer |
| 62 // name for which we want to list models. The callback will be called with |
| 63 // {success: <boolean>, models: Array<string>}. |
| 64 void HandleGetCupsPrinterModels(const base::ListValue* args); |
| 65 |
| 46 void HandleSelectPPDFile(const base::ListValue* args); | 66 void HandleSelectPPDFile(const base::ListValue* args); |
| 47 | 67 |
| 68 // PpdProvider callback handlers. |
| 69 void QueryAvailableManufacturersDone( |
| 70 const std::string& js_callback, |
| 71 chromeos::printing::PpdProvider::CallbackResultCode result_code, |
| 72 const chromeos::printing::PpdProvider::AvailablePrintersMap& available); |
| 73 void QueryAvailableModelsDone( |
| 74 const std::string& js_callback, |
| 75 const std::string& manufacturer, |
| 76 chromeos::printing::PpdProvider::CallbackResultCode result_code, |
| 77 const chromeos::printing::PpdProvider::AvailablePrintersMap& available); |
| 78 |
| 48 // ui::SelectFileDialog::Listener override: | 79 // ui::SelectFileDialog::Listener override: |
| 49 void FileSelected(const base::FilePath& path, | 80 void FileSelected(const base::FilePath& path, |
| 50 int index, | 81 int index, |
| 51 void* params) override; | 82 void* params) override; |
| 52 | 83 |
| 53 void HandleStartDiscovery(const base::ListValue* args); | 84 void HandleStartDiscovery(const base::ListValue* args); |
| 54 void HandleStopDiscovery(const base::ListValue* args); | 85 void HandleStopDiscovery(const base::ListValue* args); |
| 55 | 86 |
| 56 // chromeos::PrinterDiscoverer::Observer override: | 87 // chromeos::PrinterDiscoverer::Observer override: |
| 57 void OnPrintersFound(const std::vector<Printer>& printers) override; | 88 void OnPrintersFound(const std::vector<Printer>& printers) override; |
| 58 void OnDiscoveryDone() override; | 89 void OnDiscoveryDone() override; |
| 59 | 90 |
| 60 std::unique_ptr<chromeos::PrinterDiscoverer> printer_discoverer_; | 91 std::unique_ptr<chromeos::PrinterDiscoverer> printer_discoverer_; |
| 92 std::unique_ptr<chromeos::printing::PpdProvider> ppd_provider_; |
| 61 | 93 |
| 62 Profile* profile_; | 94 Profile* profile_; |
| 63 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | 95 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
| 64 std::string webui_callback_id_; | 96 std::string webui_callback_id_; |
| 65 | 97 |
| 66 base::WeakPtrFactory<CupsPrintersHandler> weak_factory_; | 98 base::WeakPtrFactory<CupsPrintersHandler> weak_factory_; |
| 67 | 99 |
| 68 DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler); | 100 DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler); |
| 69 }; | 101 }; |
| 70 | 102 |
| 71 } // namespace settings | 103 } // namespace settings |
| 72 } // namespace chromeos | 104 } // namespace chromeos |
| 73 | 105 |
| 74 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ | 106 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CUPS_PRINTERS_HANDLER_H_ |
| OLD | NEW |