Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 struct WebIntentServiceData; | 38 struct WebIntentServiceData; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Controls the creation of the WebIntentPicker UI and forwards the user's | 41 // Controls the creation of the WebIntentPicker UI and forwards the user's |
| 42 // intent handler choice back to the WebContents object. | 42 // intent handler choice back to the WebContents object. |
| 43 class WebIntentPickerController | 43 class WebIntentPickerController |
| 44 : public content::NotificationObserver, | 44 : public content::NotificationObserver, |
| 45 public WebIntentPickerDelegate, | 45 public WebIntentPickerDelegate, |
| 46 public extensions::WebstoreInstaller::Delegate { | 46 public extensions::WebstoreInstaller::Delegate { |
| 47 public: | 47 public: |
| 48 | |
| 49 // The various states that the UI may be in. Public for testing. | |
| 50 enum WebIntentPickerState { | |
| 51 kPickerHidden, // Picker not displayed at all. | |
| 52 kPickerSetup, // Initial setup. Acquires data, keeps picker hidden. | |
| 53 kPickerWaiting, // Displaying "waiting for CWS". | |
| 54 kPickerWaitLong, // "waiting" has displayed for longer than min. time. | |
| 55 kPickerMain, // Displaying main picker dialog. | |
| 56 }; | |
| 57 | |
| 58 // Events that happen during picker life time. Drive state machine. | |
| 59 enum WebIntentPickerEvent { | |
| 60 kPickerEventHiddenSetupTimeout, // Time for hidden setup exired. | |
| 61 kPickerEventMaxWaitTimeExceeded, // Exceeded max wait time for CWS results. | |
| 62 kPickerEventRegistryData, // Data from the registry has arrived. | |
| 63 kPickerEventDataComplete, // Data from registry and CWS has arrived. | |
|
Greg Billock
2012/08/08 23:47:11
Better to just have discrete events and figure out
groby-ooo-7-16
2012/08/09 21:59:56
CWS data by itself does _never_ cause any transiti
| |
| 64 }; | |
| 65 | |
| 48 explicit WebIntentPickerController(TabContents* tab_contents); | 66 explicit WebIntentPickerController(TabContents* tab_contents); |
| 49 virtual ~WebIntentPickerController(); | 67 virtual ~WebIntentPickerController(); |
| 50 | 68 |
| 51 // Sets the intent data and return pathway handler object for which | 69 // Sets the intent data and return pathway handler object for which |
| 52 // this picker was created. The picker takes ownership of | 70 // this picker was created. The picker takes ownership of |
| 53 // |intents_dispatcher|. |intents_dispatcher| must not be NULL. | 71 // |intents_dispatcher|. |intents_dispatcher| must not be NULL. |
| 54 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher); | 72 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher); |
| 55 | 73 |
| 56 // Shows the web intent picker given the intent |action| and MIME-type |type|. | 74 // Shows the web intent picker given the intent |action| and MIME-type |type|. |
| 57 void ShowDialog(const string16& action, | 75 void ShowDialog(const string16& action, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 history::FaviconData favicon_data); | 161 history::FaviconData favicon_data); |
| 144 | 162 |
| 145 // Called when IntentExtensionInfo is returned from the CWSIntentsRegistry. | 163 // Called when IntentExtensionInfo is returned from the CWSIntentsRegistry. |
| 146 void OnCWSIntentServicesAvailable( | 164 void OnCWSIntentServicesAvailable( |
| 147 const CWSIntentsRegistry::IntentExtensionList& extensions); | 165 const CWSIntentsRegistry::IntentExtensionList& extensions); |
| 148 | 166 |
| 149 // Called when a suggested extension's icon is fetched. | 167 // Called when a suggested extension's icon is fetched. |
| 150 void OnExtensionIconURLFetchComplete(const string16& extension_id, | 168 void OnExtensionIconURLFetchComplete(const string16& extension_id, |
| 151 const net::URLFetcher* source); | 169 const net::URLFetcher* source); |
| 152 | 170 |
| 171 // Called whenever intent data (both from registry and CWS) arrives. | |
| 172 void OnIntentDataArrived(); | |
| 173 | |
| 153 typedef base::Callback<void(const gfx::Image&)> | 174 typedef base::Callback<void(const gfx::Image&)> |
| 154 ExtensionIconAvailableCallback; | 175 ExtensionIconAvailableCallback; |
| 155 // Called on a worker thread to decode and resize the extension's icon. | 176 // Called on a worker thread to decode and resize the extension's icon. |
| 156 static void DecodeExtensionIconAndResize( | 177 static void DecodeExtensionIconAndResize( |
| 157 scoped_ptr<std::string> icon_response, | 178 scoped_ptr<std::string> icon_response, |
| 158 const ExtensionIconAvailableCallback& callback, | 179 const ExtensionIconAvailableCallback& callback, |
| 159 const base::Closure& unavailable_callback); | 180 const base::Closure& unavailable_callback); |
| 160 | 181 |
| 161 // Called when an extension's icon is successfully decoded and resized. | 182 // Called when an extension's icon is successfully decoded and resized. |
| 162 void OnExtensionIconAvailable(const string16& extension_id, | 183 void OnExtensionIconAvailable(const string16& extension_id, |
| 163 const gfx::Image& icon_image); | 184 const gfx::Image& icon_image); |
| 164 | 185 |
| 165 // Called when an extension's icon failed to be decoded or resized. | 186 // Called when an extension's icon failed to be decoded or resized. |
| 166 void OnExtensionIconUnavailable(const string16& extension_id); | 187 void OnExtensionIconUnavailable(const string16& extension_id); |
| 167 | 188 |
| 168 // When an extension is installed, all that is known is the extension id. | 189 // When an extension is installed, all that is known is the extension id. |
| 169 // This callback receives the intent service data for that extension. | 190 // This callback receives the intent service data for that extension. |
| 170 // |services| must be a non-empty list. | 191 // |services| must be a non-empty list. |
| 171 void OnExtensionInstallServiceAvailable( | 192 void OnExtensionInstallServiceAvailable( |
| 172 const std::vector<webkit_glue::WebIntentServiceData>& services); | 193 const std::vector<webkit_glue::WebIntentServiceData>& services); |
| 173 | 194 |
| 195 // Signals that a picker event has occurred. | |
| 196 void OnPickerEvent(WebIntentPickerEvent event); | |
|
Greg Billock
2012/08/08 23:47:11
Why do we need this? Shouldn't the callbacks thems
groby-ooo-7-16
2012/08/09 21:59:56
OnPickerEvent handles edges of the graph, SetDialo
| |
| 197 | |
| 174 // Decrements the |pending_async_count_| and notifies the picker if it | 198 // Decrements the |pending_async_count_| and notifies the picker if it |
| 175 // reaches zero. | 199 // reaches zero. |
| 176 void AsyncOperationFinished(); | 200 void AsyncOperationFinished(); |
| 177 | 201 |
| 202 // Invoke the specified service at |service_url| with chosen |disposition|. | |
| 203 void InvokeService(const WebIntentPickerModel::InstalledService& service); | |
| 204 | |
| 205 // Sets current dialog state. | |
| 206 void SetDialogState(WebIntentPickerState state); | |
| 207 | |
| 178 // Helper to create picker dialog UI. | 208 // Helper to create picker dialog UI. |
| 179 void CreatePicker(); | 209 void CreatePicker(); |
| 180 | 210 |
| 181 // Closes the currently active picker. | 211 // Closes the currently active picker. |
| 182 void ClosePicker(); | 212 void ClosePicker(); |
| 183 | 213 |
| 214 WebIntentPickerState dialog_state_; // Current state of the dialog. | |
| 215 | |
| 184 // A weak pointer to the tab contents that the picker is displayed on. | 216 // A weak pointer to the tab contents that the picker is displayed on. |
| 185 TabContents* tab_contents_; | 217 TabContents* tab_contents_; |
| 186 | 218 |
| 187 // A notification registrar, listening for notifications when the tab closes | 219 // A notification registrar, listening for notifications when the tab closes |
| 188 // to close the picker ui. | 220 // to close the picker ui. |
| 189 content::NotificationRegistrar registrar_; | 221 content::NotificationRegistrar registrar_; |
| 190 | 222 |
| 191 // A weak pointer to the picker this controller controls. | 223 // A weak pointer to the picker this controller controls. |
| 192 WebIntentPicker* picker_; | 224 WebIntentPicker* picker_; |
| 193 | 225 |
| 194 // The model for the picker. Owned by this controller. It should not be NULL | 226 // The model for the picker. Owned by this controller. It should not be NULL |
| 195 // while this controller exists, even if the picker is not shown. | 227 // while this controller exists, even if the picker is not shown. |
| 196 scoped_ptr<WebIntentPickerModel> picker_model_; | 228 scoped_ptr<WebIntentPickerModel> picker_model_; |
| 197 | 229 |
| 198 // A count of the outstanding asynchronous calls. | 230 // A count of the outstanding asynchronous calls. |
| 199 int pending_async_count_; | 231 int pending_async_count_; |
| 200 | 232 |
| 201 // A count of outstanding WebIntentsRegistry calls. | 233 // A count of outstanding WebIntentsRegistry calls. |
| 202 int pending_registry_calls_count_; | 234 int pending_registry_calls_count_; |
| 203 | 235 |
| 236 // Indicator that there is a pending request for cws data. | |
| 237 bool pending_cws_request_; | |
| 238 | |
| 204 // Is true if the picker is currently visible. | 239 // Is true if the picker is currently visible. |
| 205 // This bool is not equivalent to picker != NULL in a unit test. In that | 240 // This bool is not equivalent to picker != NULL in a unit test. In that |
| 206 // case, a picker may be non-NULL before it is shown. | 241 // case, a picker may be non-NULL before it is shown. |
| 207 bool picker_shown_; | 242 bool picker_shown_; |
| 208 | 243 |
| 209 // Weak pointer to the source WebContents for the intent if the TabContents | 244 // Weak pointer to the source WebContents for the intent if the TabContents |
| 210 // with which this controller is associated is hosting a web intents window | 245 // with which this controller is associated is hosting a web intents window |
| 211 // disposition service. | 246 // disposition service. |
| 212 content::WebContents* window_disposition_source_; | 247 content::WebContents* window_disposition_source_; |
| 213 | 248 |
| 214 // If this tab is hosting a web intents service, a weak pointer to dispatcher | 249 // If this tab is hosting a web intents service, a weak pointer to dispatcher |
| 215 // that invoked us. Weak pointer. | 250 // that invoked us. Weak pointer. |
| 216 content::WebIntentsDispatcher* source_intents_dispatcher_; | 251 content::WebIntentsDispatcher* source_intents_dispatcher_; |
| 217 | 252 |
| 218 // Weak pointer to the routing object for the renderer which launched the | 253 // Weak pointer to the routing object for the renderer which launched the |
| 219 // intent. Contains the intent data and a way to signal back to the | 254 // intent. Contains the intent data and a way to signal back to the |
| 220 // client page. | 255 // client page. |
| 221 content::WebIntentsDispatcher* intents_dispatcher_; | 256 content::WebIntentsDispatcher* intents_dispatcher_; |
| 222 | 257 |
| 223 // Weak pointer to the tab servicing the intent. Remembered in order to | 258 // Weak pointer to the tab servicing the intent. Remembered in order to |
| 224 // close it when a reply is sent. | 259 // close it when a reply is sent. |
| 225 content::WebContents* service_tab_; | 260 content::WebContents* service_tab_; |
| 226 | 261 |
| 227 // Request consumer used when asynchronously loading favicons. | 262 // Request consumer used when asynchronously loading favicons. |
| 228 CancelableRequestConsumerTSimple<size_t> favicon_consumer_; | 263 CancelableRequestConsumerTSimple<size_t> favicon_consumer_; |
| 229 | 264 |
| 230 base::WeakPtrFactory<WebIntentPickerController> weak_ptr_factory_; | 265 base::WeakPtrFactory<WebIntentPickerController> weak_ptr_factory_; |
| 231 | 266 |
| 267 // Timer factory for minimum display time of "waiting" dialog. | |
| 268 base::WeakPtrFactory<WebIntentPickerController> timer_factory_; | |
| 269 | |
| 232 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController); | 270 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController); |
| 233 }; | 271 }; |
| 234 | 272 |
| 235 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ | 273 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ |
| OLD | NEW |