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