| OLD | NEW | 
 | (Empty) | 
|    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 |  | 
|    3 // found in the LICENSE file. |  | 
|    4  |  | 
|    5 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_MODEL_H_ |  | 
|    6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_MODEL_H_ |  | 
|    7  |  | 
|    8 #include <vector> |  | 
|    9  |  | 
|   10 #include "base/basictypes.h" |  | 
|   11 #include "base/string16.h" |  | 
|   12 #include "chrome/browser/extensions/extension_install_prompt.h" |  | 
|   13 #include "googleurl/src/gurl.h" |  | 
|   14 #include "ui/gfx/image/image.h" |  | 
|   15 #include "webkit/glue/web_intent_service_data.h" |  | 
|   16  |  | 
|   17 namespace content { |  | 
|   18 class DownloadItem; |  | 
|   19 } |  | 
|   20  |  | 
|   21 class WebIntentPickerModelObserver; |  | 
|   22  |  | 
|   23 // Model for the WebIntentPicker. |  | 
|   24 class WebIntentPickerModel { |  | 
|   25  public: |  | 
|   26   // An intent service to display in the picker. |  | 
|   27   struct InstalledService { |  | 
|   28     InstalledService( |  | 
|   29         const string16& title, |  | 
|   30         const GURL& url, |  | 
|   31         webkit_glue::WebIntentServiceData::Disposition disposition); |  | 
|   32     ~InstalledService(); |  | 
|   33  |  | 
|   34     // The title of this service. |  | 
|   35     string16 title; |  | 
|   36  |  | 
|   37     // The URL of this service. |  | 
|   38     GURL url; |  | 
|   39  |  | 
|   40     // A favicon of this service. |  | 
|   41     gfx::Image favicon; |  | 
|   42  |  | 
|   43     // The disposition to use when displaying this service. |  | 
|   44     webkit_glue::WebIntentServiceData::Disposition disposition; |  | 
|   45   }; |  | 
|   46  |  | 
|   47   // A suggested extension to display in the picker. |  | 
|   48   struct SuggestedExtension { |  | 
|   49     SuggestedExtension(const string16& title, |  | 
|   50                        const std::string& id, |  | 
|   51                        double average_rating); |  | 
|   52     ~SuggestedExtension(); |  | 
|   53  |  | 
|   54     // The title of the intent service. |  | 
|   55     string16 title; |  | 
|   56  |  | 
|   57     // The id of the extension that provides the intent service. |  | 
|   58     std::string id; |  | 
|   59  |  | 
|   60     // The average rating of the extension. |  | 
|   61     double average_rating; |  | 
|   62  |  | 
|   63     // The extension's icon. |  | 
|   64     gfx::Image icon; |  | 
|   65   }; |  | 
|   66  |  | 
|   67   WebIntentPickerModel(); |  | 
|   68   ~WebIntentPickerModel(); |  | 
|   69  |  | 
|   70   void set_observer(WebIntentPickerModelObserver* observer) { |  | 
|   71     observer_ = observer; |  | 
|   72   } |  | 
|   73  |  | 
|   74   const string16& action() const { return action_; } |  | 
|   75   void set_action(const string16& action) { action_ = action; } |  | 
|   76  |  | 
|   77   const string16& type() const { return type_; } |  | 
|   78   void set_type(const string16& type) { type_ = type; } |  | 
|   79  |  | 
|   80   const GURL& default_service_url() const { return default_service_url_; } |  | 
|   81   void set_default_service_url(const GURL& default_url) { |  | 
|   82     default_service_url_ = default_url; |  | 
|   83   } |  | 
|   84  |  | 
|   85   // Add a new installed service with |title|, |url| and |disposition| to the |  | 
|   86   // picker. |  | 
|   87   void AddInstalledService( |  | 
|   88       const string16& title, |  | 
|   89       const GURL& url, |  | 
|   90       webkit_glue::WebIntentServiceData::Disposition disposition); |  | 
|   91  |  | 
|   92   // Remove an installed service from the picker at |index|. |  | 
|   93   void RemoveInstalledServiceAt(size_t index); |  | 
|   94  |  | 
|   95   // Remove all installed services from the picker, and resets to not |  | 
|   96   // displaying inline disposition.  Note that this does not clear the |  | 
|   97   // observer. |  | 
|   98   void Clear(); |  | 
|   99  |  | 
|  100   // Return the intent service installed at |index|. |  | 
|  101   const InstalledService& GetInstalledServiceAt(size_t index) const; |  | 
|  102  |  | 
|  103   // Return the intent service that uses |url| as its service url, or NULL. |  | 
|  104   const InstalledService* GetInstalledServiceWithURL(const GURL& url) const; |  | 
|  105  |  | 
|  106   // Return the number of intent services in the picker. |  | 
|  107   size_t GetInstalledServiceCount() const; |  | 
|  108  |  | 
|  109   // Update favicon for the intent service with service URL |url| to |image|. |  | 
|  110   void UpdateFaviconForServiceWithURL(const GURL& url, const gfx::Image& image); |  | 
|  111  |  | 
|  112   // Add a list of suggested extensions to the model. |  | 
|  113   void AddSuggestedExtensions( |  | 
|  114       const std::vector<SuggestedExtension>& suggestions); |  | 
|  115  |  | 
|  116   // Remove the suggested extension with this id. |  | 
|  117   void RemoveSuggestedExtension(const std::string& id); |  | 
|  118  |  | 
|  119   // Return the suggested extension at |index|. |  | 
|  120   const SuggestedExtension& GetSuggestedExtensionAt(size_t index) const; |  | 
|  121  |  | 
|  122   // Return the suggested extension for the given id or NULL if none. |  | 
|  123   const SuggestedExtension* GetSuggestedExtensionWithId( |  | 
|  124       const std::string& id) const; |  | 
|  125  |  | 
|  126   // Return the number of suggested extensions to be displayed. |  | 
|  127   size_t GetSuggestedExtensionCount() const; |  | 
|  128  |  | 
|  129   // Return the text to use in the "Get more suggestions" link. Returns UTF8. |  | 
|  130   // Will return an empty string if the link should not be shown. |  | 
|  131   string16 GetSuggestionsLinkText() const; |  | 
|  132  |  | 
|  133   // Set the icon image for the suggested extension with |id|. |  | 
|  134   void SetSuggestedExtensionIconWithId(const std::string& id, |  | 
|  135                                        const gfx::Image& image); |  | 
|  136  |  | 
|  137   // Set the picker to display the intent service with |url| inline. |  | 
|  138   // To clear the current inline disposition set |url| to an empty URL. |  | 
|  139   void SetInlineDisposition(const GURL& url); |  | 
|  140  |  | 
|  141   // Returns true if the picker is currently displaying an inline service. |  | 
|  142   bool IsInlineDisposition() const; |  | 
|  143  |  | 
|  144   // Returns true if there is still a pending request for suggestions from CWS. |  | 
|  145   bool IsWaitingForSuggestions() const; |  | 
|  146  |  | 
|  147   // Set the "waiting for suggestions" status to |waiting| |  | 
|  148   void SetWaitingForSuggestions(bool waiting); |  | 
|  149  |  | 
|  150   // Returns the url of the intent service that is being displayed inline, or |  | 
|  151   // GURL::EmptyGURL() if none. |  | 
|  152   const GURL& inline_disposition_url() const { return inline_disposition_url_; } |  | 
|  153  |  | 
|  154   // Sets the ID of the extension currently being installed. |  | 
|  155   void SetPendingExtensionInstallId(const std::string& id); |  | 
|  156  |  | 
|  157   // Gets the ID of the extension currently being installed. |  | 
|  158   const std::string& pending_extension_install_id() const { |  | 
|  159     return pending_extension_install_id_; |  | 
|  160   } |  | 
|  161  |  | 
|  162   // Updates the pending install download state. |  | 
|  163   void UpdateExtensionDownloadState(content::DownloadItem* item); |  | 
|  164  |  | 
|  165   // Sets the download progress of the extension currently being downloaded. |  | 
|  166   void SetPendingExtensionInstallDownloadProgress(int progress); |  | 
|  167  |  | 
|  168   // Gets the download progress of the extension currently being downloaded. |  | 
|  169   // Returns -1 if progress is indeterminate, otherwise a value from 0 to 100. |  | 
|  170   int pending_extension_install_download_progress() const { |  | 
|  171     return pending_extension_install_download_progress_; |  | 
|  172   } |  | 
|  173  |  | 
|  174   // Sets the status of extension install process. |  | 
|  175   void SetPendingExtensionInstallStatusString(const string16& status); |  | 
|  176  |  | 
|  177   // Gets the status of extension install process. |  | 
|  178   const string16& pending_extension_install_status_string() const { |  | 
|  179     return pending_extension_install_status_string_; |  | 
|  180   } |  | 
|  181  |  | 
|  182   // Sets the extension install delegate. |  | 
|  183   void SetPendingExtensionInstallDelegate( |  | 
|  184       ExtensionInstallPrompt::Delegate* delegate); |  | 
|  185  |  | 
|  186   // Gets the extension install delegate. |  | 
|  187   ExtensionInstallPrompt::Delegate* pending_extension_install_delegate() const { |  | 
|  188     return pending_extension_install_delegate_; |  | 
|  189   } |  | 
|  190  |  | 
|  191   // Sets the extension install prompt. |  | 
|  192   void SetPendingExtensionInstallPrompt( |  | 
|  193       const ExtensionInstallPrompt::Prompt& prompt); |  | 
|  194  |  | 
|  195   // Gets the extension install prompt. |  | 
|  196   const ExtensionInstallPrompt::Prompt* pending_extension_install_prompt() |  | 
|  197       const { |  | 
|  198     return pending_extension_install_prompt_.get(); |  | 
|  199   } |  | 
|  200  |  | 
|  201   // Removes any pending extension install state. |  | 
|  202   void ClearPendingExtensionInstall(); |  | 
|  203  |  | 
|  204   // Set whether the picker should be showing the use-another-app control. |  | 
|  205   void set_show_use_another_service(bool show) { |  | 
|  206     show_use_another_service_ = show; |  | 
|  207   } |  | 
|  208  |  | 
|  209   // Whether or not the picker should show the use-another-app control. |  | 
|  210   bool show_use_another_service() const { |  | 
|  211     return show_use_another_service_; |  | 
|  212   } |  | 
|  213  |  | 
|  214  private: |  | 
|  215   // Delete all elements in |installed_services_| and |suggested_extensions_|. |  | 
|  216   // Note that this method does not reset the observer. |  | 
|  217   void DestroyAll(); |  | 
|  218  |  | 
|  219   // A vector of all installed services in the picker. Each installed service |  | 
|  220   // is owned by this model. |  | 
|  221   std::vector<InstalledService*> installed_services_; |  | 
|  222  |  | 
|  223   // A vector of all suggested extensions in the picker. |  | 
|  224   std::vector<SuggestedExtension> suggested_extensions_; |  | 
|  225  |  | 
|  226   // The observer to send notifications to, or NULL if none. Not owned. |  | 
|  227   WebIntentPickerModelObserver* observer_; |  | 
|  228  |  | 
|  229   // The url of the intent service that is being displayed inline, or |  | 
|  230   // GURL::EmptyGURL() if none. |  | 
|  231   GURL inline_disposition_url_; |  | 
|  232  |  | 
|  233   // A cached copy of the action that instantiated the picker. |  | 
|  234   string16 action_; |  | 
|  235  |  | 
|  236   // A cached copy of the type that instantiated the picker. |  | 
|  237   string16 type_; |  | 
|  238  |  | 
|  239   // The non-empty url of the default service if the WebIntentsRegistry |  | 
|  240   // finds a default service matching the intent being dispatched. |  | 
|  241   GURL default_service_url_; |  | 
|  242  |  | 
|  243   // Indicates that there are still open requests to CWS. |  | 
|  244   bool waiting_for_suggestions_; |  | 
|  245  |  | 
|  246   // Information about the pending extension install. |  | 
|  247   std::string pending_extension_install_id_; |  | 
|  248   int pending_extension_install_download_progress_; |  | 
|  249   string16 pending_extension_install_status_string_; |  | 
|  250   ExtensionInstallPrompt::Delegate* pending_extension_install_delegate_; |  | 
|  251   scoped_ptr<ExtensionInstallPrompt::Prompt> pending_extension_install_prompt_; |  | 
|  252  |  | 
|  253   // Indicates the use-another-service control should be shown. |  | 
|  254   bool show_use_another_service_; |  | 
|  255  |  | 
|  256   DISALLOW_COPY_AND_ASSIGN(WebIntentPickerModel); |  | 
|  257 }; |  | 
|  258  |  | 
|  259 #endif  // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_MODEL_H_ |  | 
| OLD | NEW |