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 #if defined(ENABLE_PLUGIN_INSTALLATION)
48 // Infobar that's shown when a plug-in is out of date.
49 class OutdatedPluginInfoBarDelegate
: public PluginInfoBarDelegate
,
50 public WeakPluginInstallerObserver
{
52 // Creates an outdated plugin infobar and delegate and adds the infobar to
54 static void Create(InfoBarService
* infobar_service
,
55 PluginInstaller
* installer
,
56 scoped_ptr
<PluginMetadata
> metadata
);
59 OutdatedPluginInfoBarDelegate(PluginInstaller
* installer
,
60 scoped_ptr
<PluginMetadata
> metadata
,
61 const base::string16
& message
);
62 ~OutdatedPluginInfoBarDelegate() override
;
64 // PluginInfoBarDelegate:
65 base::string16
GetMessageText() const override
;
66 base::string16
GetButtonLabel(InfoBarButton button
) const override
;
67 bool Accept() override
;
68 bool Cancel() override
;
69 void InfoBarDismissed() override
;
70 bool LinkClicked(WindowOpenDisposition disposition
) override
;
71 std::string
GetLearnMoreURL() const override
;
73 // PluginInstallerObserver:
74 void DownloadStarted() override
;
75 void DownloadError(const std::string
& message
) override
;
76 void DownloadCancelled() override
;
77 void DownloadFinished() override
;
79 // WeakPluginInstallerObserver:
80 void OnlyWeakObserversLeft() override
;
82 // Replaces this infobar with one showing |message|. The new infobar will
83 // not have any buttons (and not call the callback).
84 void ReplaceWithInfoBar(const base::string16
& message
);
86 scoped_ptr
<PluginMetadata
> plugin_metadata_
;
88 base::string16 message_
;
90 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate
);
93 // The main purpose for this class is to popup/close the infobar when there is
95 class PluginInstallerInfoBarDelegate
: public ConfirmInfoBarDelegate
,
96 public WeakPluginInstallerObserver
{
98 typedef base::Callback
<void(const PluginMetadata
*)> InstallCallback
;
100 // Shows an infobar asking whether to install the plugin represented by
101 // |installer|. When the user accepts, |callback| is called.
102 // During installation of the plug-in, the infobar will change to reflect the
103 // installation state.
104 static void Create(InfoBarService
* infobar_service
,
105 PluginInstaller
* installer
,
106 scoped_ptr
<PluginMetadata
> plugin_metadata
,
107 const InstallCallback
& callback
);
109 // Replaces |infobar|, which must currently be owned, with an infobar asking
110 // the user to install or update a particular plugin.
111 static void Replace(infobars::InfoBar
* infobar
,
112 PluginInstaller
* installer
,
113 scoped_ptr
<PluginMetadata
> plugin_metadata
,
115 const base::string16
& message
);
118 PluginInstallerInfoBarDelegate(PluginInstaller
* installer
,
119 scoped_ptr
<PluginMetadata
> metadata
,
120 const InstallCallback
& callback
,
122 const base::string16
& message
);
123 ~PluginInstallerInfoBarDelegate() override
;
125 // ConfirmInfoBarDelegate:
126 int GetIconID() const override
;
127 base::string16
GetMessageText() const override
;
128 int GetButtons() const override
;
129 base::string16
GetButtonLabel(InfoBarButton button
) const override
;
130 bool Accept() override
;
131 base::string16
GetLinkText() const override
;
132 bool LinkClicked(WindowOpenDisposition disposition
) override
;
134 // PluginInstallerObserver:
135 void DownloadStarted() override
;
136 void DownloadError(const std::string
& message
) override
;
137 void DownloadCancelled() override
;
138 void DownloadFinished() override
;
140 // WeakPluginInstallerObserver:
141 void OnlyWeakObserversLeft() override
;
143 // Replaces this infobar with one showing |message|. The new infobar will
144 // not have any buttons (and not call the callback).
145 void ReplaceWithInfoBar(const base::string16
& message
);
147 scoped_ptr
<PluginMetadata
> plugin_metadata_
;
149 InstallCallback callback_
;
151 // True iff the plug-in isn't installed yet.
154 base::string16 message_
;
156 DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate
);
158 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
161 class PluginMetroModeInfoBarDelegate
: public ConfirmInfoBarDelegate
{
163 // The infobar can be used for two purposes: to inform the user about a
164 // missing plugin or to note that a plugin only works in desktop mode. These
165 // purposes require different messages, buttons, etc.
168 DESKTOP_MODE_REQUIRED
,
171 // Creates a metro mode infobar and delegate and adds the infobar to
172 // |infobar_service|.
173 static void Create(InfoBarService
* infobar_service
,
175 const base::string16
& name
);
178 PluginMetroModeInfoBarDelegate(Mode mode
, const base::string16
& name
);
179 virtual ~PluginMetroModeInfoBarDelegate();
181 // ConfirmInfoBarDelegate:
182 virtual int GetIconID() const override
;
183 virtual base::string16
GetMessageText() const override
;
184 virtual int GetButtons() const override
;
185 virtual base::string16
GetButtonLabel(InfoBarButton button
) const override
;
186 virtual bool Accept() override
;
187 virtual base::string16
GetLinkText() const override
;
188 virtual bool LinkClicked(WindowOpenDisposition disposition
) override
;
191 const base::string16 name_
;
193 DISALLOW_COPY_AND_ASSIGN(PluginMetroModeInfoBarDelegate
);
195 #endif // defined(OS_WIN)
197 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_