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.
5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_
6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_
8 #include "base/callback.h"
9 #include "components/infobars/core/confirm_infobar_delegate.h"
12 #if defined(ENABLE_PLUGIN_INSTALLATION)
13 #include "chrome/browser/plugins/plugin_installer_observer.h"
17 class HostContentSettingsMap;
24 // Base class for blocked plug-in infobars.
25 class PluginInfoBarDelegate : public ConfirmInfoBarDelegate {
27 explicit PluginInfoBarDelegate(const std::string& identifier);
28 ~PluginInfoBarDelegate() override;
30 // ConfirmInfoBarDelegate:
31 bool LinkClicked(WindowOpenDisposition disposition) override;
33 virtual std::string GetLearnMoreURL() const = 0;
35 void LoadBlockedPlugins();
38 // ConfirmInfoBarDelegate:
39 int GetIconID() const override;
40 base::string16 GetLinkText() const override;
42 std::string identifier_;
44 DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate);
47 // Infobar that's shown when a plug-in requires user authorization to run.
48 class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate {
50 // Creates an unauthorized plugin infobar and delegate and adds the infobar to
52 static void Create(InfoBarService* infobar_service,
53 HostContentSettingsMap* content_settings,
54 const base::string16& name,
55 const std::string& identifier);
58 UnauthorizedPluginInfoBarDelegate(HostContentSettingsMap* content_settings,
59 const base::string16& name,
60 const std::string& identifier);
61 ~UnauthorizedPluginInfoBarDelegate() override;
63 // PluginInfoBarDelegate:
64 base::string16 GetMessageText() const override;
65 base::string16 GetButtonLabel(InfoBarButton button) const override;
66 bool Accept() override;
67 bool Cancel() override;
68 void InfoBarDismissed() override;
69 bool LinkClicked(WindowOpenDisposition disposition) override;
70 std::string GetLearnMoreURL() const override;
72 HostContentSettingsMap* content_settings_;
75 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarDelegate);
78 #if defined(ENABLE_PLUGIN_INSTALLATION)
79 // Infobar that's shown when a plug-in is out of date.
80 class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate,
81 public WeakPluginInstallerObserver {
83 // Creates an outdated plugin infobar and delegate and adds the infobar to
85 static void Create(InfoBarService* infobar_service,
86 PluginInstaller* installer,
87 scoped_ptr<PluginMetadata> metadata);
90 OutdatedPluginInfoBarDelegate(PluginInstaller* installer,
91 scoped_ptr<PluginMetadata> metadata,
92 const base::string16& message);
93 ~OutdatedPluginInfoBarDelegate() override;
95 // PluginInfoBarDelegate:
96 base::string16 GetMessageText() const override;
97 base::string16 GetButtonLabel(InfoBarButton button) const override;
98 bool Accept() override;
99 bool Cancel() override;
100 void InfoBarDismissed() override;
101 bool LinkClicked(WindowOpenDisposition disposition) override;
102 std::string GetLearnMoreURL() const override;
104 // PluginInstallerObserver:
105 void DownloadStarted() override;
106 void DownloadError(const std::string& message) override;
107 void DownloadCancelled() override;
108 void DownloadFinished() override;
110 // WeakPluginInstallerObserver:
111 void OnlyWeakObserversLeft() override;
113 // Replaces this infobar with one showing |message|. The new infobar will
114 // not have any buttons (and not call the callback).
115 void ReplaceWithInfoBar(const base::string16& message);
117 scoped_ptr<PluginMetadata> plugin_metadata_;
119 base::string16 message_;
121 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate);
124 // The main purpose for this class is to popup/close the infobar when there is
126 class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate,
127 public WeakPluginInstallerObserver {
129 typedef base::Callback<void(const PluginMetadata*)> InstallCallback;
131 // Shows an infobar asking whether to install the plugin represented by
132 // |installer|. When the user accepts, |callback| is called.
133 // During installation of the plug-in, the infobar will change to reflect the
134 // installation state.
135 static void Create(InfoBarService* infobar_service,
136 PluginInstaller* installer,
137 scoped_ptr<PluginMetadata> plugin_metadata,
138 const InstallCallback& callback);
140 // Replaces |infobar|, which must currently be owned, with an infobar asking
141 // the user to install or update a particular plugin.
142 static void Replace(infobars::InfoBar* infobar,
143 PluginInstaller* installer,
144 scoped_ptr<PluginMetadata> plugin_metadata,
146 const base::string16& message);
149 PluginInstallerInfoBarDelegate(PluginInstaller* installer,
150 scoped_ptr<PluginMetadata> metadata,
151 const InstallCallback& callback,
153 const base::string16& message);
154 ~PluginInstallerInfoBarDelegate() override;
156 // ConfirmInfoBarDelegate:
157 int GetIconID() const override;
158 base::string16 GetMessageText() const override;
159 int GetButtons() const override;
160 base::string16 GetButtonLabel(InfoBarButton button) const override;
161 bool Accept() override;
162 base::string16 GetLinkText() const override;
163 bool LinkClicked(WindowOpenDisposition disposition) override;
165 // PluginInstallerObserver:
166 void DownloadStarted() override;
167 void DownloadError(const std::string& message) override;
168 void DownloadCancelled() override;
169 void DownloadFinished() override;
171 // WeakPluginInstallerObserver:
172 void OnlyWeakObserversLeft() override;
174 // Replaces this infobar with one showing |message|. The new infobar will
175 // not have any buttons (and not call the callback).
176 void ReplaceWithInfoBar(const base::string16& message);
178 scoped_ptr<PluginMetadata> plugin_metadata_;
180 InstallCallback callback_;
182 // True iff the plug-in isn't installed yet.
185 base::string16 message_;
187 DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate);
189 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
192 class PluginMetroModeInfoBarDelegate : public ConfirmInfoBarDelegate {
194 // The infobar can be used for two purposes: to inform the user about a
195 // missing plugin or to note that a plugin only works in desktop mode. These
196 // purposes require different messages, buttons, etc.
199 DESKTOP_MODE_REQUIRED,
202 // Creates a metro mode infobar and delegate and adds the infobar to
203 // |infobar_service|.
204 static void Create(InfoBarService* infobar_service,
206 const base::string16& name);
209 PluginMetroModeInfoBarDelegate(Mode mode, const base::string16& name);
210 virtual ~PluginMetroModeInfoBarDelegate();
212 // ConfirmInfoBarDelegate:
213 virtual int GetIconID() const override;
214 virtual base::string16 GetMessageText() const override;
215 virtual int GetButtons() const override;
216 virtual base::string16 GetButtonLabel(InfoBarButton button) const override;
217 virtual bool Accept() override;
218 virtual base::string16 GetLinkText() const override;
219 virtual bool LinkClicked(WindowOpenDisposition disposition) override;
222 const base::string16 name_;
224 DISALLOW_COPY_AND_ASSIGN(PluginMetroModeInfoBarDelegate);
226 #endif // defined(OS_WIN)
228 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_