| OLD | NEW |
| 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" | 14 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "webkit/glue/web_intent_data.h" | 17 #include "webkit/glue/web_intent_data.h" |
| 18 | 18 |
| 19 class Browser; | 19 class Browser; |
| 20 class GURL; | 20 class GURL; |
| 21 class SkBitmap; | 21 class TabContents; |
| 22 class TabContentsWrapper; | 22 class TabContentsWrapper; |
| 23 class WebIntentPicker; | 23 class WebIntentPicker; |
| 24 class WebIntentPickerFactory; | 24 class WebIntentPickerModel; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 class WebContents; | 27 class WebContents; |
| 28 class WebIntentsDispatcher; | 28 class WebIntentsDispatcher; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace gfx { |
| 32 class Image; |
| 33 } |
| 34 |
| 31 namespace webkit_glue { | 35 namespace webkit_glue { |
| 32 struct WebIntentServiceData; | 36 struct WebIntentServiceData; |
| 33 } | 37 } |
| 34 | 38 |
| 35 // Controls the creation of the WebIntentPicker UI and forwards the user's | 39 // Controls the creation of the WebIntentPicker UI and forwards the user's |
| 36 // intent handler choice back to the TabContents object. | 40 // intent handler choice back to the TabContents object. |
| 37 class WebIntentPickerController : public content::NotificationObserver, | 41 class WebIntentPickerController : public content::NotificationObserver, |
| 38 public WebIntentPickerDelegate { | 42 public WebIntentPickerDelegate { |
| 39 public: | 43 public: |
| 40 // Takes ownership of |factory|. | 44 // Takes ownership of |factory|. |
| 41 WebIntentPickerController(TabContentsWrapper* wrapper, | 45 explicit WebIntentPickerController(TabContentsWrapper* wrapper); |
| 42 WebIntentPickerFactory* factory); | |
| 43 virtual ~WebIntentPickerController(); | 46 virtual ~WebIntentPickerController(); |
| 44 | 47 |
| 45 // Sets the intent data and return pathway handler object for which | 48 // Sets the intent data and return pathway handler object for which |
| 46 // this picker was created. The picker takes ownership of | 49 // this picker was created. The picker takes ownership of |
| 47 // |intents_dispatcher|. |intents_dispatcher| must not be NULL. | 50 // |intents_dispatcher|. |intents_dispatcher| must not be NULL. |
| 48 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher); | 51 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher); |
| 49 | 52 |
| 50 // Shows the web intent picker for |browser|, given the intent | 53 // Shows the web intent picker for |browser|, given the intent |
| 51 // |action| and MIME-type |type|. | 54 // |action| and MIME-type |type|. |
| 52 void ShowDialog(Browser* browser, | 55 void ShowDialog(Browser* browser, |
| 53 const string16& action, | 56 const string16& action, |
| 54 const string16& type); | 57 const string16& type); |
| 55 | 58 |
| 56 protected: | 59 protected: |
| 57 // content::NotificationObserver implementation. | 60 // content::NotificationObserver implementation. |
| 58 virtual void Observe(int type, | 61 virtual void Observe(int type, |
| 59 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) OVERRIDE; | 63 const content::NotificationDetails& details) OVERRIDE; |
| 61 | 64 |
| 62 // WebIntentPickerDelegate implementation. | 65 // WebIntentPickerDelegate implementation. |
| 63 virtual void OnServiceChosen(size_t index) OVERRIDE; | 66 virtual void OnServiceChosen(size_t index, Disposition disposition) OVERRIDE; |
| 67 virtual void OnInlineDispositionWebContentsCreated( |
| 68 content::WebContents* web_contents) OVERRIDE; |
| 64 virtual void OnCancelled() OVERRIDE; | 69 virtual void OnCancelled() OVERRIDE; |
| 65 virtual void OnClosing() OVERRIDE; | 70 virtual void OnClosing() OVERRIDE; |
| 66 | 71 |
| 67 private: | 72 private: |
| 68 // Gets a notification when the return message is sent to the source tab, | |
| 69 // so we can close the picker dialog or service tab. | |
| 70 void OnSendReturnMessage(); | |
| 71 | |
| 72 friend class WebIntentPickerControllerTest; | |
| 73 friend class WebIntentPickerControllerBrowserTest; | 73 friend class WebIntentPickerControllerBrowserTest; |
| 74 friend class InvokingTabObserver; | 74 friend class InvokingTabObserver; |
| 75 class WebIntentDataFetcher; | 75 class WebIntentDataFetcher; |
| 76 class FaviconFetcher; | 76 class FaviconFetcher; |
| 77 | 77 |
| 78 int pending_async_count() const { return pending_async_count_; } | 78 // Gets a notification when the return message is sent to the source tab, |
| 79 // so we can close the picker dialog or service tab. |
| 80 void OnSendReturnMessage(); |
| 81 |
| 82 // Exposed for tests only. |
| 83 void set_picker(WebIntentPicker* picker) { picker_ = picker; } |
| 84 |
| 85 // Exposed for tests only. |
| 86 void set_model_observer(WebIntentPickerModelObserver* observer) { |
| 87 picker_model_->set_observer(observer); |
| 88 } |
| 79 | 89 |
| 80 // Called from the WebIntentDataFetcher when intent data is available. | 90 // Called from the WebIntentDataFetcher when intent data is available. |
| 81 void OnWebIntentDataAvailable( | 91 void OnWebIntentDataAvailable( |
| 82 const std::vector<webkit_glue::WebIntentServiceData>& services); | 92 const std::vector<webkit_glue::WebIntentServiceData>& services); |
| 83 | 93 |
| 84 // Called from the FaviconDataFetcher when a favicon is available. | 94 // Called from the FaviconDataFetcher when a favicon is available. |
| 85 void OnFaviconDataAvailable(size_t index, const SkBitmap& icon_bitmap); | 95 void OnFaviconDataAvailable(size_t index, const gfx::Image& icon); |
| 86 | 96 |
| 87 // Called from the FaviconDataFetcher when a favicon is not available. | 97 // Called from the FaviconDataFetcher when a favicon is not available. |
| 88 void OnFaviconDataUnavailable(size_t index); | 98 void OnFaviconDataUnavailable(size_t index); |
| 89 | 99 |
| 100 // Decrements the |pending_async_count_| and notifies the picker if it |
| 101 // reaches zero. |
| 102 void AsyncOperationFinished(); |
| 103 |
| 90 // Closes the currently active picker. | 104 // Closes the currently active picker. |
| 91 void ClosePicker(); | 105 void ClosePicker(); |
| 92 | 106 |
| 93 // A weak pointer to the tab contents that the picker is displayed on. | 107 // A weak pointer to the tab contents that the picker is displayed on. |
| 94 TabContentsWrapper* wrapper_; | 108 TabContentsWrapper* wrapper_; |
| 95 | 109 |
| 96 // A notification registrar, listening for notifications when the tab closes | 110 // A notification registrar, listening for notifications when the tab closes |
| 97 // to close the picker ui. | 111 // to close the picker ui. |
| 98 content::NotificationRegistrar registrar_; | 112 content::NotificationRegistrar registrar_; |
| 99 | 113 |
| 100 // A factory to create a new picker. | |
| 101 scoped_ptr<WebIntentPickerFactory> picker_factory_; | |
| 102 | |
| 103 // A helper class to fetch web intent data asynchronously. | 114 // A helper class to fetch web intent data asynchronously. |
| 104 scoped_ptr<WebIntentDataFetcher> web_intent_data_fetcher_; | 115 scoped_ptr<WebIntentDataFetcher> web_intent_data_fetcher_; |
| 105 | 116 |
| 106 // A helper class to fetch favicon data asynchronously. | 117 // A helper class to fetch favicon data asynchronously. |
| 107 scoped_ptr<FaviconFetcher> favicon_fetcher_; | 118 scoped_ptr<FaviconFetcher> favicon_fetcher_; |
| 108 | 119 |
| 109 // A weak pointer to the picker this controller controls. | 120 // A weak pointer to the picker this controller controls. |
| 110 WebIntentPicker* picker_; | 121 WebIntentPicker* picker_; |
| 111 | 122 |
| 112 // A list of URLs to display in the UI. | 123 // The model for the picker. Owned by this controller. It should not be NULL |
| 113 std::vector<GURL> urls_; | 124 // while this controller exists, even if the picker is not shown. |
| 114 | 125 scoped_ptr<WebIntentPickerModel> picker_model_; |
| 115 // A list of the service data on display in the UI. | |
| 116 std::vector<webkit_glue::WebIntentServiceData> service_data_; | |
| 117 | 126 |
| 118 // A count of the outstanding asynchronous calls. | 127 // A count of the outstanding asynchronous calls. |
| 119 int pending_async_count_; | 128 int pending_async_count_; |
| 120 | 129 |
| 130 // Is true if the picker is currently visible. |
| 131 // This bool is not equivalent to picker != NULL in a unit test. In that |
| 132 // case, a picker may be non-NULL before it is shown. |
| 133 bool picker_shown_; |
| 134 |
| 121 // The routing object for the renderer which launched the intent. | 135 // The routing object for the renderer which launched the intent. |
| 122 // Contains the intent data and a way to signal back to the client page. | 136 // Contains the intent data and a way to signal back to the client page. |
| 123 scoped_ptr<content::WebIntentsDispatcher> intents_dispatcher_; | 137 scoped_ptr<content::WebIntentsDispatcher> intents_dispatcher_; |
| 124 | 138 |
| 125 // Weak pointer to the tab servicing the intent. Remembered in order to | 139 // Weak pointer to the tab servicing the intent. Remembered in order to |
| 126 // close it when a reply is sent. | 140 // close it when a reply is sent. |
| 127 content::WebContents* service_tab_; | 141 content::WebContents* service_tab_; |
| 128 | 142 |
| 129 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController); | 143 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController); |
| 130 }; | 144 }; |
| 131 | 145 |
| 132 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ | 146 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ |
| OLD | NEW |