| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
| 13 #include "base/prefs/pref_member.h" | 13 #include "base/prefs/pref_member.h" |
| 14 #include "chrome/browser/local_discovery/cloud_device_list.h" |
| 14 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" | 15 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" |
| 15 #include "chrome/browser/local_discovery/privet_device_lister.h" | 16 #include "chrome/browser/local_discovery/privet_device_lister.h" |
| 16 #include "chrome/browser/local_discovery/privet_http.h" | 17 #include "chrome/browser/local_discovery/privet_http.h" |
| 17 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "content/public/browser/web_ui_message_handler.h" | 19 #include "content/public/browser/web_ui_message_handler.h" |
| 19 | 20 |
| 20 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) | 21 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) |
| 21 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE | 22 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 // TODO(noamsml): Factor out full registration flow into single class | 25 // TODO(noamsml): Factor out full registration flow into single class |
| 25 namespace local_discovery { | 26 namespace local_discovery { |
| 26 | 27 |
| 27 class PrivetConfirmApiCallFlow; | 28 class PrivetConfirmApiCallFlow; |
| 28 class PrivetHTTPAsynchronousFactory; | 29 class PrivetHTTPAsynchronousFactory; |
| 29 class PrivetHTTPResolution; | 30 class PrivetHTTPResolution; |
| 30 class ServiceDiscoverySharedClient; | 31 class ServiceDiscoverySharedClient; |
| 31 | 32 |
| 32 // UI Handler for chrome://devices/ | 33 // UI Handler for chrome://devices/ |
| 33 // It listens to local discovery notifications and passes those notifications | 34 // It listens to local discovery notifications and passes those notifications |
| 34 // into the Javascript to update the page. | 35 // into the Javascript to update the page. |
| 35 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, | 36 class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, |
| 36 public PrivetRegisterOperation::Delegate, | 37 public PrivetRegisterOperation::Delegate, |
| 37 public PrivetDeviceLister::Delegate, | 38 public PrivetDeviceLister::Delegate, |
| 38 public CloudPrintPrinterList::Delegate, | 39 public CloudPrintPrinterList::Delegate, |
| 40 public CloudDeviceList::Delegate, |
| 39 public SigninManagerBase::Observer { | 41 public SigninManagerBase::Observer { |
| 40 public: | 42 public: |
| 41 LocalDiscoveryUIHandler(); | 43 LocalDiscoveryUIHandler(); |
| 42 virtual ~LocalDiscoveryUIHandler(); | 44 virtual ~LocalDiscoveryUIHandler(); |
| 43 | 45 |
| 44 static bool GetHasVisible(); | 46 static bool GetHasVisible(); |
| 45 | 47 |
| 46 // WebUIMessageHandler implementation. | 48 // WebUIMessageHandler implementation. |
| 47 virtual void RegisterMessages() OVERRIDE; | 49 virtual void RegisterMessages() OVERRIDE; |
| 48 | 50 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 virtual void DeviceChanged(bool added, | 69 virtual void DeviceChanged(bool added, |
| 68 const std::string& name, | 70 const std::string& name, |
| 69 const DeviceDescription& description) OVERRIDE; | 71 const DeviceDescription& description) OVERRIDE; |
| 70 | 72 |
| 71 virtual void DeviceRemoved(const std::string& name) OVERRIDE; | 73 virtual void DeviceRemoved(const std::string& name) OVERRIDE; |
| 72 | 74 |
| 73 virtual void DeviceCacheFlushed() OVERRIDE; | 75 virtual void DeviceCacheFlushed() OVERRIDE; |
| 74 | 76 |
| 75 // CloudPrintPrinterList::Delegate implementation. | 77 // CloudPrintPrinterList::Delegate implementation. |
| 76 virtual void OnCloudPrintPrinterListReady() OVERRIDE; | 78 virtual void OnCloudPrintPrinterListReady() OVERRIDE; |
| 79 virtual void OnCloudPrintPrinterListUnavailable() OVERRIDE; |
| 77 | 80 |
| 78 virtual void OnCloudPrintPrinterListUnavailable() OVERRIDE; | 81 // CloudDeviceList::Delegate implementation. |
| 82 virtual void OnCloudDeviceListReady() OVERRIDE; |
| 83 virtual void OnCloudDeviceListUnavailable() OVERRIDE; |
| 79 | 84 |
| 80 // SigninManagerBase::Observer implementation. | 85 // SigninManagerBase::Observer implementation. |
| 81 virtual void GoogleSigninSucceeded(const std::string& username, | 86 virtual void GoogleSigninSucceeded(const std::string& username, |
| 82 const std::string& password) OVERRIDE; | 87 const std::string& password) OVERRIDE; |
| 83 | 88 |
| 84 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 89 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; |
| 85 | 90 |
| 86 private: | 91 private: |
| 87 typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap; | 92 typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap; |
| 88 | 93 |
| 89 // Message handlers: | 94 // Message handlers: |
| 90 // For when the page is ready to receive device notifications. | 95 // For when the page is ready to receive device notifications. |
| 91 void HandleStart(const base::ListValue* args); | 96 void HandleStart(const base::ListValue* args); |
| 92 | 97 |
| 93 // For when a visibility change occurs. | 98 // For when a visibility change occurs. |
| 94 void HandleIsVisible(const base::ListValue* args); | 99 void HandleIsVisible(const base::ListValue* args); |
| 95 | 100 |
| 96 // For when a user choice is made. | 101 // For when a user choice is made. |
| 97 void HandleRegisterDevice(const base::ListValue* args); | 102 void HandleRegisterDevice(const base::ListValue* args); |
| 98 | 103 |
| 99 // For when a cancelation is made. | 104 // For when a cancellation is made. |
| 100 void HandleCancelRegistration(const base::ListValue* args); | 105 void HandleCancelRegistration(const base::ListValue* args); |
| 101 | 106 |
| 102 // For requesting the printer list. | 107 // For requesting the device list. |
| 103 void HandleRequestPrinterList(const base::ListValue* args); | 108 void HandleRequestDeviceList(const base::ListValue* args); |
| 104 | 109 |
| 105 // For opening URLs (relative to the Google Cloud Print base URL) in a new | 110 // For opening URLs (relative to the Google Cloud Print base URL) in a new |
| 106 // tab. | 111 // tab. |
| 107 void HandleOpenCloudPrintURL(const base::ListValue* args); | 112 void HandleOpenCloudPrintURL(const base::ListValue* args); |
| 108 | 113 |
| 109 // For showing sync login UI. | 114 // For showing sync login UI. |
| 110 void HandleShowSyncUI(const base::ListValue* args); | 115 void HandleShowSyncUI(const base::ListValue* args); |
| 111 | 116 |
| 112 // For when the IP address of the printer has been resolved for registration. | 117 // For when the IP address of the printer has been resolved for registration. |
| 113 void StartRegisterHTTP( | 118 void StartRegisterHTTP( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 128 void SetIsVisible(bool visible); | 133 void SetIsVisible(bool visible); |
| 129 | 134 |
| 130 // Get the sync account email. | 135 // Get the sync account email. |
| 131 std::string GetSyncAccount(); | 136 std::string GetSyncAccount(); |
| 132 | 137 |
| 133 // Reset and cancel the current registration. | 138 // Reset and cancel the current registration. |
| 134 void ResetCurrentRegistration(); | 139 void ResetCurrentRegistration(); |
| 135 | 140 |
| 136 scoped_ptr<base::DictionaryValue> CreatePrinterInfo( | 141 scoped_ptr<base::DictionaryValue> CreatePrinterInfo( |
| 137 const CloudPrintPrinterList::PrinterDetails& description); | 142 const CloudPrintPrinterList::PrinterDetails& description); |
| 143 scoped_ptr<base::DictionaryValue> CreateDeviceInfo( |
| 144 const CloudDeviceList::DeviceDetails& description); |
| 138 | 145 |
| 139 // Announcement hasn't been sent for a certain time after registration | 146 // Announcement hasn't been sent for a certain time after registration |
| 140 // finished. Consider it failed. | 147 // finished. Consider it failed. |
| 141 // TODO(noamsml): Re-resolve service first. | 148 // TODO(noamsml): Re-resolve service first. |
| 142 void OnAnnouncementTimeoutReached(); | 149 void OnAnnouncementTimeoutReached(); |
| 143 | 150 |
| 144 void CheckUserLoggedIn(); | 151 void CheckUserLoggedIn(); |
| 145 | 152 |
| 153 void CheckListingDone(); |
| 154 |
| 146 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 155 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
| 147 void StartCloudPrintConnector(); | 156 void StartCloudPrintConnector(); |
| 148 void OnCloudPrintPrefsChanged(); | 157 void OnCloudPrintPrefsChanged(); |
| 149 void ShowCloudPrintSetupDialog(const base::ListValue* args); | 158 void ShowCloudPrintSetupDialog(const base::ListValue* args); |
| 150 void HandleDisableCloudPrintConnector(const base::ListValue* args); | 159 void HandleDisableCloudPrintConnector(const base::ListValue* args); |
| 151 void SetupCloudPrintConnectorSection(); | 160 void SetupCloudPrintConnectorSection(); |
| 152 void RemoveCloudPrintConnectorSection(); | 161 void RemoveCloudPrintConnectorSection(); |
| 153 void RefreshCloudPrintStatusFromService(); | 162 void RefreshCloudPrintStatusFromService(); |
| 154 #endif | 163 #endif |
| 155 | 164 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 175 scoped_ptr<PrivetHTTPResolution> privet_resolution_; | 184 scoped_ptr<PrivetHTTPResolution> privet_resolution_; |
| 176 | 185 |
| 177 // A map of current device descriptions provided by the PrivetDeviceLister. | 186 // A map of current device descriptions provided by the PrivetDeviceLister. |
| 178 DeviceDescriptionMap device_descriptions_; | 187 DeviceDescriptionMap device_descriptions_; |
| 179 | 188 |
| 180 // Whether or not the page is marked as visible. | 189 // Whether or not the page is marked as visible. |
| 181 bool is_visible_; | 190 bool is_visible_; |
| 182 | 191 |
| 183 // List of printers from cloud print. | 192 // List of printers from cloud print. |
| 184 scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_; | 193 scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_; |
| 194 scoped_ptr<CloudDeviceList> cloud_device_list_; |
| 195 scoped_ptr<base::ListValue> devices_list_; |
| 185 | 196 |
| 186 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 197 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
| 187 StringPrefMember cloud_print_connector_email_; | 198 StringPrefMember cloud_print_connector_email_; |
| 188 BooleanPrefMember cloud_print_connector_enabled_; | 199 BooleanPrefMember cloud_print_connector_enabled_; |
| 189 bool cloud_print_connector_ui_enabled_; | 200 bool cloud_print_connector_ui_enabled_; |
| 190 #endif | 201 #endif |
| 191 | 202 |
| 192 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); | 203 DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); |
| 193 }; | 204 }; |
| 194 | 205 |
| 195 #undef CLOUD_PRINT_CONNECTOR_UI_AVAILABLE | 206 #undef CLOUD_PRINT_CONNECTOR_UI_AVAILABLE |
| 196 | 207 |
| 197 } // namespace local_discovery | 208 } // namespace local_discovery |
| 198 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ | 209 #endif // CHROME_BROWSER_UI_WEBUI_LOCAL_DISCOVERY_LOCAL_DISCOVERY_UI_HANDLER_H_ |
| OLD | NEW |