| 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_PLUGINS_PLUGIN_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ | 
| 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ | 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ | 
| 7 | 7 | 
| 8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" | 
| 9 #include "base/string16.h" | 9 #include "base/string16.h" | 
| 10 #include "base/version.h" | 10 #include "base/version.h" | 
| 11 #include "googleurl/src/gurl.h" | 11 #include "chrome/browser/plugins/plugin_metadata.h" | 
| 12 #include "content/public/browser/download_id.h" | 12 #include "content/public/browser/download_id.h" | 
| 13 #include "content/public/browser/download_item.h" | 13 #include "content/public/browser/download_item.h" | 
|  | 14 #include "googleurl/src/gurl.h" | 
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" | 
| 15 | 16 | 
| 16 class FilePath; | 17 class FilePath; | 
| 17 class PluginInstallerObserver; | 18 class PluginInstallerObserver; | 
| 18 class TabContents; | 19 class TabContents; | 
| 19 class WeakPluginInstallerObserver; | 20 class WeakPluginInstallerObserver; | 
| 20 | 21 | 
| 21 namespace content { | 22 namespace content { | 
| 22 class WebContents; | 23 class WebContents; | 
| 23 } | 24 } | 
| 24 | 25 | 
| 25 namespace webkit { | 26 namespace webkit { | 
| 26 struct WebPluginInfo; | 27 struct WebPluginInfo; | 
| 27 } | 28 } | 
| 28 | 29 | 
| 29 class PluginInstaller : public content::DownloadItem::Observer { | 30 class PluginInstaller : public content::DownloadItem::Observer { | 
| 30  public: | 31  public: | 
| 31   enum InstallerState { | 32   enum InstallerState { | 
| 32     INSTALLER_STATE_IDLE, | 33     INSTALLER_STATE_IDLE, | 
| 33     INSTALLER_STATE_DOWNLOADING, | 34     INSTALLER_STATE_DOWNLOADING, | 
| 34   }; | 35   }; | 
| 35 | 36 | 
| 36   // Information about a certain version of the plug-in. | 37   explicit PluginInstaller(PluginMetadata* plugin); | 
| 37   enum SecurityStatus { |  | 
| 38     SECURITY_STATUS_UP_TO_DATE, |  | 
| 39     SECURITY_STATUS_OUT_OF_DATE, |  | 
| 40     SECURITY_STATUS_REQUIRES_AUTHORIZATION, |  | 
| 41   }; |  | 
| 42 |  | 
| 43   PluginInstaller(const std::string& identifier, |  | 
| 44                   const string16& name, |  | 
| 45                   bool url_for_display, |  | 
| 46                   const GURL& plugin_url, |  | 
| 47                   const GURL& help_url, |  | 
| 48                   const string16& group_name_matcher); |  | 
| 49   virtual ~PluginInstaller(); | 38   virtual ~PluginInstaller(); | 
| 50 | 39 | 
| 51   virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 40   virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 
| 52   virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; | 41   virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; | 
| 53 | 42 | 
| 54   void AddObserver(PluginInstallerObserver* observer); | 43   void AddObserver(PluginInstallerObserver* observer); | 
| 55   void RemoveObserver(PluginInstallerObserver* observer); | 44   void RemoveObserver(PluginInstallerObserver* observer); | 
| 56 | 45 | 
| 57   void AddWeakObserver(WeakPluginInstallerObserver* observer); | 46   void AddWeakObserver(WeakPluginInstallerObserver* observer); | 
| 58   void RemoveWeakObserver(WeakPluginInstallerObserver* observer); | 47   void RemoveWeakObserver(WeakPluginInstallerObserver* observer); | 
| 59 | 48 | 
| 60   // Unique identifier for the plug-in. | 49   // Unique identifier for the plug-in. | 
| 61   const std::string& identifier() const { return identifier_; } | 50   const std::string& identifier() const { return plugin_->identifier(); } | 
| 62 | 51 | 
| 63   // Human-readable name of the plug-in. | 52   // Human-readable name of the plug-in. | 
| 64   const string16& name() const { return name_; } | 53   const string16& name() const { return plugin_->name(); } | 
| 65 |  | 
| 66   // Checks if the plug-in matches the group matcher. |  | 
| 67   bool MatchesPlugin(const webkit::WebPluginInfo& plugin); |  | 
| 68 | 54 | 
| 69   // If |url_for_display| is false, |plugin_url| is the URL of the download page | 55   // If |url_for_display| is false, |plugin_url| is the URL of the download page | 
| 70   // for the plug-in, which should be opened in a new tab. If it is true, | 56   // for the plug-in, which should be opened in a new tab. If it is true, | 
| 71   // |plugin_url| is the URL of the plug-in installer binary, which can be | 57   // |plugin_url| is the URL of the plug-in installer binary, which can be | 
| 72   // directly downloaded. | 58   // directly downloaded. | 
| 73   bool url_for_display() const { return url_for_display_; } | 59   bool url_for_display() const { return plugin_->url_for_display(); } | 
| 74   const GURL& plugin_url() const { return plugin_url_; } | 60   const GURL& plugin_url() const { return plugin_->plugin_url(); } | 
| 75 | 61 | 
| 76   // URL to open when the user clicks on the "Problems installing?" link. | 62   // URL to open when the user clicks on the "Problems installing?" link. | 
| 77   const GURL& help_url() const { return help_url_; } | 63   const GURL& help_url() const { return plugin_->help_url(); } | 
| 78 | 64 | 
| 79   InstallerState state() const { return state_; } | 65   InstallerState state() const { return state_; } | 
| 80 | 66 | 
| 81   // Adds information about a plug-in version. |  | 
| 82   void AddVersion(const Version& version, SecurityStatus status); |  | 
| 83 |  | 
| 84   // Returns the security status for the given plug-in (i.e. whether it is |  | 
| 85   // considered out-of-date, etc.) |  | 
| 86   SecurityStatus GetSecurityStatus(const webkit::WebPluginInfo& plugin) const; |  | 
| 87 |  | 
| 88   // Opens the download URL in a new tab. This method should only be called if | 67   // Opens the download URL in a new tab. This method should only be called if | 
| 89   // |url_for_display| returns true. | 68   // |url_for_display| returns true. | 
| 90   void OpenDownloadURL(content::WebContents* web_contents); | 69   void OpenDownloadURL(content::WebContents* web_contents); | 
| 91 | 70 | 
| 92   // Starts downloading the download URL and opens the downloaded file | 71   // Starts downloading the download URL and opens the downloaded file | 
| 93   // when finished. This method should only be called if |url_for_display| | 72   // when finished. This method should only be called if |url_for_display| | 
| 94   // returns false. | 73   // returns false. | 
| 95   void StartInstalling(TabContents* tab_contents); | 74   void StartInstalling(TabContents* tab_contents); | 
| 96 | 75 | 
| 97   // If |status_str| describes a valid security status, writes it to |status| |  | 
| 98   // and returns true, else returns false and leaves |status| unchanged. |  | 
| 99   static bool ParseSecurityStatus(const std::string& status_str, |  | 
| 100                                   SecurityStatus* status); |  | 
| 101 |  | 
| 102  private: | 76  private: | 
| 103   struct VersionComparator { |  | 
| 104     bool operator() (const Version& lhs, const Version& rhs) const; |  | 
| 105   }; |  | 
| 106 |  | 
| 107   void DownloadStarted(scoped_refptr<content::DownloadManager> dlm, | 77   void DownloadStarted(scoped_refptr<content::DownloadManager> dlm, | 
| 108                        content::DownloadId download_id, | 78                        content::DownloadId download_id, | 
| 109                        net::Error error); | 79                        net::Error error); | 
| 110   void DownloadError(const std::string& msg); | 80   void DownloadError(const std::string& msg); | 
| 111   void DownloadCancelled(); | 81   void DownloadCancelled(); | 
| 112 | 82 | 
| 113   std::string identifier_; | 83   // Can't be NULL. It is owned by PluginFinder. | 
| 114   string16 name_; | 84   PluginMetadata* plugin_; | 
| 115   string16 group_name_matcher_; |  | 
| 116   bool url_for_display_; |  | 
| 117   GURL plugin_url_; |  | 
| 118   GURL help_url_; |  | 
| 119   std::map<Version, SecurityStatus, VersionComparator> versions_; |  | 
| 120 | 85 | 
| 121   InstallerState state_; | 86   InstallerState state_; | 
| 122   ObserverList<PluginInstallerObserver> observers_; | 87   ObserverList<PluginInstallerObserver> observers_; | 
| 123   ObserverList<WeakPluginInstallerObserver> weak_observers_; | 88   ObserverList<WeakPluginInstallerObserver> weak_observers_; | 
| 124 | 89 | 
| 125   DISALLOW_COPY_AND_ASSIGN(PluginInstaller); | 90   DISALLOW_COPY_AND_ASSIGN(PluginInstaller); | 
| 126 }; | 91 }; | 
| 127 | 92 | 
| 128 #endif  // CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ | 93 #endif  // CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ | 
| OLD | NEW | 
|---|