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"
10 #include "googleurl/src/gurl.h"
12 #if defined(ENABLE_PLUGIN_INSTALLATION)
13 #include "chrome/browser/plugins/plugin_installer_observer.h"
14 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
17 class HostContentSettingsMap
;
24 // Base class for blocked plug-in infobars.
25 class PluginInfoBarDelegate
: public ConfirmInfoBarDelegate
{
27 PluginInfoBarDelegate(InfoBarService
* infobar_service
,
29 const std::string
& identifier
);
32 virtual ~PluginInfoBarDelegate();
34 // ConfirmInfoBarDelegate:
35 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
37 virtual std::string
GetLearnMoreURL() const = 0;
39 void LoadBlockedPlugins();
44 // ConfirmInfoBarDelegate:
45 virtual gfx::Image
* GetIcon() const OVERRIDE
;
46 virtual string16
GetLinkText() const OVERRIDE
;
48 std::string identifier_
;
50 DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate
);
53 // Infobar that's shown when a plug-in requires user authorization to run.
54 class UnauthorizedPluginInfoBarDelegate
: public PluginInfoBarDelegate
{
56 // Creates an unauthorized plugin delegate and adds it to |infobar_service|.
57 static void Create(InfoBarService
* infobar_service
,
58 HostContentSettingsMap
* content_settings
,
60 const std::string
& identifier
);
63 UnauthorizedPluginInfoBarDelegate(InfoBarService
* infobar_service
,
64 HostContentSettingsMap
* content_settings
,
66 const std::string
& identifier
);
67 virtual ~UnauthorizedPluginInfoBarDelegate();
69 // PluginInfoBarDelegate:
70 virtual string16
GetMessageText() const OVERRIDE
;
71 virtual string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
72 virtual bool Accept() OVERRIDE
;
73 virtual bool Cancel() OVERRIDE
;
74 virtual void InfoBarDismissed() OVERRIDE
;
75 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
76 virtual std::string
GetLearnMoreURL() const OVERRIDE
;
78 HostContentSettingsMap
* content_settings_
;
80 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarDelegate
);
83 #if defined(ENABLE_PLUGIN_INSTALLATION)
84 // Infobar that's shown when a plug-in is out of date.
85 class OutdatedPluginInfoBarDelegate
: public PluginInfoBarDelegate
,
86 public WeakPluginInstallerObserver
{
88 // Creates an outdated plugin delegate and adds it to |infobar_service|.
89 static void Create(InfoBarService
* infobar_service
,
90 PluginInstaller
* installer
,
91 scoped_ptr
<PluginMetadata
> metadata
);
94 OutdatedPluginInfoBarDelegate(InfoBarService
* infobar_service
,
95 PluginInstaller
* installer
,
96 scoped_ptr
<PluginMetadata
> metadata
,
97 const string16
& message
);
98 virtual ~OutdatedPluginInfoBarDelegate();
100 // PluginInfoBarDelegate:
101 virtual string16
GetMessageText() const OVERRIDE
;
102 virtual string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
103 virtual bool Accept() OVERRIDE
;
104 virtual bool Cancel() OVERRIDE
;
105 virtual void InfoBarDismissed() OVERRIDE
;
106 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
107 virtual std::string
GetLearnMoreURL() const OVERRIDE
;
109 // PluginInstallerObserver:
110 virtual void DownloadStarted() OVERRIDE
;
111 virtual void DownloadError(const std::string
& message
) OVERRIDE
;
112 virtual void DownloadCancelled() OVERRIDE
;
113 virtual void DownloadFinished() OVERRIDE
;
115 // WeakPluginInstallerObserver:
116 virtual void OnlyWeakObserversLeft() OVERRIDE
;
118 // Replaces this infobar with one showing |message|. The new infobar will
119 // not have any buttons (and not call the callback).
120 void ReplaceWithInfoBar(const string16
& message
);
122 scoped_ptr
<PluginMetadata
> plugin_metadata_
;
126 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate
);
129 // The main purpose for this class is to popup/close the infobar when there is
131 class PluginInstallerInfoBarDelegate
: public ConfirmInfoBarDelegate
,
132 public WeakPluginInstallerObserver
{
134 typedef base::Callback
<void(const PluginMetadata
*)> InstallCallback
;
136 // Shows an infobar asking whether to install the plugin represented by
137 // |installer|. When the user accepts, |callback| is called.
138 // During installation of the plug-in, the infobar will change to reflect the
139 // installation state.
140 static void Create(InfoBarService
* infobar_service
,
141 PluginInstaller
* installer
,
142 scoped_ptr
<PluginMetadata
> plugin_metadata
,
143 const InstallCallback
& callback
);
145 // Replaces |infobar|, which must currently be owned, with an infobar asking
146 // the user to install or update a particular plugin.
147 static void Replace(InfoBarDelegate
* infobar
,
148 PluginInstaller
* installer
,
149 scoped_ptr
<PluginMetadata
> metadata
,
151 const string16
& message
);
154 PluginInstallerInfoBarDelegate(InfoBarService
* infobar_service
,
155 PluginInstaller
* installer
,
156 scoped_ptr
<PluginMetadata
> plugin_metadata
,
157 const InstallCallback
& callback
,
159 const string16
& message
);
160 virtual ~PluginInstallerInfoBarDelegate();
162 // ConfirmInfoBarDelegate:
163 virtual gfx::Image
* GetIcon() const OVERRIDE
;
164 virtual string16
GetMessageText() const OVERRIDE
;
165 virtual int GetButtons() const OVERRIDE
;
166 virtual string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
167 virtual bool Accept() OVERRIDE
;
168 virtual string16
GetLinkText() const OVERRIDE
;
169 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
171 // PluginInstallerObserver:
172 virtual void DownloadStarted() OVERRIDE
;
173 virtual void DownloadError(const std::string
& message
) OVERRIDE
;
174 virtual void DownloadCancelled() OVERRIDE
;
175 virtual void DownloadFinished() OVERRIDE
;
177 // WeakPluginInstallerObserver:
178 virtual void OnlyWeakObserversLeft() OVERRIDE
;
180 // Replaces this infobar with one showing |message|. The new infobar will
181 // not have any buttons (and not call the callback).
182 void ReplaceWithInfoBar(const string16
& message
);
184 scoped_ptr
<PluginMetadata
> plugin_metadata_
;
186 InstallCallback callback_
;
188 // True iff the plug-in isn't installed yet.
193 DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate
);
195 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
198 class PluginMetroModeInfoBarDelegate
: public ConfirmInfoBarDelegate
{
200 // The infobar can be used for two purposes: to inform the user about a
201 // missing plugin or to note that a plugin only works in desktop mode. These
202 // purposes require different messages, buttons, etc.
205 DESKTOP_MODE_REQUIRED
,
208 // Creates a metro mode infobar and delegate and adds the infobar to
209 // |infobar_service|.
210 static void Create(InfoBarService
* infobar_service
,
212 const string16
& name
);
215 PluginMetroModeInfoBarDelegate(InfoBarService
* infobar_service
,
217 const string16
& name
);
218 virtual ~PluginMetroModeInfoBarDelegate();
220 // ConfirmInfoBarDelegate:
221 virtual gfx::Image
* GetIcon() const OVERRIDE
;
222 virtual string16
GetMessageText() const OVERRIDE
;
223 virtual int GetButtons() const OVERRIDE
;
224 virtual string16
GetButtonLabel(InfoBarButton button
) const OVERRIDE
;
225 virtual bool Accept() OVERRIDE
;
226 virtual bool Cancel() OVERRIDE
;
227 virtual string16
GetLinkText() const OVERRIDE
;
228 virtual bool LinkClicked(WindowOpenDisposition disposition
) OVERRIDE
;
231 const string16 name_
;
233 DISALLOW_COPY_AND_ASSIGN(PluginMetroModeInfoBarDelegate
);
235 #endif // defined(OS_WIN)
237 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_