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 kPickerEventRegistryDataComplete, // Data from the registry has arrived. |
| 63 kPickerEventAsyncDataComplete, // Data from registry and CWS has arrived. |
| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 history::FaviconData favicon_data); | 167 history::FaviconData favicon_data); |
150 | 168 |
151 // Called when IntentExtensionInfo is returned from the CWSIntentsRegistry. | 169 // Called when IntentExtensionInfo is returned from the CWSIntentsRegistry. |
152 void OnCWSIntentServicesAvailable( | 170 void OnCWSIntentServicesAvailable( |
153 const CWSIntentsRegistry::IntentExtensionList& extensions); | 171 const CWSIntentsRegistry::IntentExtensionList& extensions); |
154 | 172 |
155 // Called when a suggested extension's icon is fetched. | 173 // Called when a suggested extension's icon is fetched. |
156 void OnExtensionIconURLFetchComplete(const string16& extension_id, | 174 void OnExtensionIconURLFetchComplete(const string16& extension_id, |
157 const net::URLFetcher* source); | 175 const net::URLFetcher* source); |
158 | 176 |
| 177 // Called whenever intent data (both from registry and CWS) arrives. |
| 178 void OnIntentDataArrived(); |
| 179 |
159 typedef base::Callback<void(const gfx::Image&)> | 180 typedef base::Callback<void(const gfx::Image&)> |
160 ExtensionIconAvailableCallback; | 181 ExtensionIconAvailableCallback; |
161 // Called on a worker thread to decode and resize the extension's icon. | 182 // Called on a worker thread to decode and resize the extension's icon. |
162 static void DecodeExtensionIconAndResize( | 183 static void DecodeExtensionIconAndResize( |
163 scoped_ptr<std::string> icon_response, | 184 scoped_ptr<std::string> icon_response, |
164 const ExtensionIconAvailableCallback& callback, | 185 const ExtensionIconAvailableCallback& callback, |
165 const base::Closure& unavailable_callback); | 186 const base::Closure& unavailable_callback); |
166 | 187 |
167 // Called when an extension's icon is successfully decoded and resized. | 188 // Called when an extension's icon is successfully decoded and resized. |
168 void OnExtensionIconAvailable(const string16& extension_id, | 189 void OnExtensionIconAvailable(const string16& extension_id, |
169 const gfx::Image& icon_image); | 190 const gfx::Image& icon_image); |
170 | 191 |
171 // Called when an extension's icon failed to be decoded or resized. | 192 // Called when an extension's icon failed to be decoded or resized. |
172 void OnExtensionIconUnavailable(const string16& extension_id); | 193 void OnExtensionIconUnavailable(const string16& extension_id); |
173 | 194 |
| 195 // Signals that a picker event has occurred. |
| 196 void OnPickerEvent(WebIntentPickerEvent event); |
| 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 |