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