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 "chrome/browser/infobars/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 virtual ~PluginInfoBarDelegate();
30 // ConfirmInfoBarDelegate:
31 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
33 virtual std::string
GetLearnMoreURL() const = 0;
35 void LoadBlockedPlugins();
38 // ConfirmInfoBarDelegate:
39 virtual int GetIconID() const OVERRIDE
;
40 virtual 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 virtual ~UnauthorizedPluginInfoBarDelegate();
63 // PluginInfoBarDelegate:
64 virtual base::string16
GetMessageText() const OVERRIDE
;
65 virtual base::string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
66 virtual bool Accept() OVERRIDE
;
67 virtual bool Cancel() OVERRIDE
;
68 virtual void InfoBarDismissed() OVERRIDE
;
69 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
70 virtual 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 virtual ~OutdatedPluginInfoBarDelegate();
95 // PluginInfoBarDelegate:
96 virtual base::string16
GetMessageText() const OVERRIDE
;
97 virtual base::string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
98 virtual bool Accept() OVERRIDE
;
99 virtual bool Cancel() OVERRIDE
;
100 virtual void InfoBarDismissed() OVERRIDE
;
101 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
102 virtual std::string
GetLearnMoreURL() const OVERRIDE
;
104 // PluginInstallerObserver:
105 virtual void DownloadStarted() OVERRIDE
;
106 virtual void DownloadError(const std::string
& message
) OVERRIDE
;
107 virtual void DownloadCancelled() OVERRIDE
;
108 virtual void DownloadFinished() OVERRIDE
;
110 // WeakPluginInstallerObserver:
111 virtual 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 virtual ~PluginInstallerInfoBarDelegate();
156 // ConfirmInfoBarDelegate:
157 virtual int GetIconID() const OVERRIDE
;
158 virtual base::string16
GetMessageText() const OVERRIDE
;
159 virtual int GetButtons() const OVERRIDE
;
160 virtual base::string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
161 virtual bool Accept() OVERRIDE
;
162 virtual base::string16
GetLinkText() const OVERRIDE
;
163 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
165 // PluginInstallerObserver:
166 virtual void DownloadStarted() OVERRIDE
;
167 virtual void DownloadError(const std::string
& message
) OVERRIDE
;
168 virtual void DownloadCancelled() OVERRIDE
;
169 virtual void DownloadFinished() OVERRIDE
;
171 // WeakPluginInstallerObserver:
172 virtual 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_