blob: 5e298e18b3bc3abb19c76e3aea0aa36eef720c8d [file] [log] [blame]
[email protected]27c483892012-02-09 15:59:101// 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.
4
[email protected]0f5e57f52012-09-20 20:53:185#ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_
6#define CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_
[email protected]27c483892012-02-09 15:59:107
8#include "base/callback.h"
[email protected]4a8adfa02013-03-19 22:37:469#include "chrome/browser/infobars/confirm_infobar_delegate.h"
[email protected]27c483892012-02-09 15:59:1010#include "googleurl/src/gurl.h"
11
12#if defined(ENABLE_PLUGIN_INSTALLATION)
[email protected]0f5e57f52012-09-20 20:53:1813#include "chrome/browser/plugins/plugin_installer_observer.h"
[email protected]27c483892012-02-09 15:59:1014#endif // defined(ENABLE_PLUGIN_INSTALLATION)
15
[email protected]33f84f982012-08-30 00:39:4416class InfoBarService;
[email protected]27c483892012-02-09 15:59:1017class HostContentSettingsMap;
[email protected]fb745cf2012-10-02 15:33:4818class PluginMetadata;
[email protected]56b83362012-09-25 22:01:2019
20namespace content {
21class WebContents;
22}
[email protected]27c483892012-02-09 15:59:1023
24// Base class for blocked plug-in infobars.
25class PluginInfoBarDelegate : public ConfirmInfoBarDelegate {
26 public:
[email protected]33f84f982012-08-30 00:39:4427 PluginInfoBarDelegate(InfoBarService* infobar_service,
[email protected]51ffaf72012-05-09 21:00:4928 const string16& name,
29 const std::string& identifier);
[email protected]27c483892012-02-09 15:59:1030
31 protected:
32 virtual ~PluginInfoBarDelegate();
33
34 // ConfirmInfoBarDelegate:
35 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
36
37 virtual std::string GetLearnMoreURL() const = 0;
38
39 void LoadBlockedPlugins();
40
41 string16 name_;
42
43 private:
44 // ConfirmInfoBarDelegate:
45 virtual gfx::Image* GetIcon() const OVERRIDE;
46 virtual string16 GetLinkText() const OVERRIDE;
47
[email protected]51ffaf72012-05-09 21:00:4948 std::string identifier_;
49
[email protected]27c483892012-02-09 15:59:1050 DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate);
51};
52
53// Infobar that's shown when a plug-in requires user authorization to run.
54class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate {
55 public:
[email protected]0be09932013-01-08 02:03:5056 // Creates an unauthorized plugin delegate and adds it to |infobar_service|.
57 static void Create(InfoBarService* infobar_service,
58 HostContentSettingsMap* content_settings,
59 const string16& name,
60 const std::string& identifier);
61
62 private:
[email protected]33f84f982012-08-30 00:39:4463 UnauthorizedPluginInfoBarDelegate(InfoBarService* infobar_service,
[email protected]51ffaf72012-05-09 21:00:4964 HostContentSettingsMap* content_settings,
65 const string16& name,
66 const std::string& identifier);
[email protected]27c483892012-02-09 15:59:1067 virtual ~UnauthorizedPluginInfoBarDelegate();
68
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;
77
78 HostContentSettingsMap* content_settings_;
79
80 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarDelegate);
81};
82
83#if defined(ENABLE_PLUGIN_INSTALLATION)
84// Infobar that's shown when a plug-in is out of date.
85class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate,
86 public WeakPluginInstallerObserver {
87 public:
[email protected]0be09932013-01-08 02:03:5088 // 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);
[email protected]27c483892012-02-09 15:59:1092
93 private:
[email protected]0be09932013-01-08 02:03:5094 OutdatedPluginInfoBarDelegate(InfoBarService* infobar_service,
[email protected]27c483892012-02-09 15:59:1095 PluginInstaller* installer,
[email protected]fb745cf2012-10-02 15:33:4896 scoped_ptr<PluginMetadata> metadata,
[email protected]27c483892012-02-09 15:59:1097 const string16& message);
98 virtual ~OutdatedPluginInfoBarDelegate();
99
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;
108
109 // PluginInstallerObserver:
[email protected]1a86f752012-02-10 13:20:36110 virtual void DownloadStarted() OVERRIDE;
[email protected]27c483892012-02-09 15:59:10111 virtual void DownloadError(const std::string& message) OVERRIDE;
[email protected]1a86f752012-02-10 13:20:36112 virtual void DownloadCancelled() OVERRIDE;
113 virtual void DownloadFinished() OVERRIDE;
[email protected]27c483892012-02-09 15:59:10114
115 // WeakPluginInstallerObserver:
116 virtual void OnlyWeakObserversLeft() OVERRIDE;
117
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);
121
[email protected]fb745cf2012-10-02 15:33:48122 scoped_ptr<PluginMetadata> plugin_metadata_;
123
[email protected]27c483892012-02-09 15:59:10124 string16 message_;
125
126 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate);
127};
128
129// The main purpose for this class is to popup/close the infobar when there is
130// a missing plugin.
131class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate,
132 public WeakPluginInstallerObserver {
133 public:
[email protected]039cb732012-11-03 01:28:38134 typedef base::Callback<void(const PluginMetadata*)> InstallCallback;
135
[email protected]27c483892012-02-09 15:59:10136 // 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.
[email protected]0be09932013-01-08 02:03:50140 static void Create(InfoBarService* infobar_service,
141 PluginInstaller* installer,
142 scoped_ptr<PluginMetadata> plugin_metadata,
143 const InstallCallback& callback);
144
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,
150 bool new_install,
151 const string16& message);
[email protected]27c483892012-02-09 15:59:10152
153 private:
[email protected]33f84f982012-08-30 00:39:44154 PluginInstallerInfoBarDelegate(InfoBarService* infobar_service,
[email protected]27c483892012-02-09 15:59:10155 PluginInstaller* installer,
[email protected]fb745cf2012-10-02 15:33:48156 scoped_ptr<PluginMetadata> plugin_metadata,
[email protected]039cb732012-11-03 01:28:38157 const InstallCallback& callback,
[email protected]27c483892012-02-09 15:59:10158 bool new_install,
159 const string16& message);
160 virtual ~PluginInstallerInfoBarDelegate();
161
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;
170
171 // PluginInstallerObserver:
[email protected]1a86f752012-02-10 13:20:36172 virtual void DownloadStarted() OVERRIDE;
[email protected]27c483892012-02-09 15:59:10173 virtual void DownloadError(const std::string& message) OVERRIDE;
[email protected]1a86f752012-02-10 13:20:36174 virtual void DownloadCancelled() OVERRIDE;
175 virtual void DownloadFinished() OVERRIDE;
[email protected]27c483892012-02-09 15:59:10176
177 // WeakPluginInstallerObserver:
178 virtual void OnlyWeakObserversLeft() OVERRIDE;
179
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);
183
[email protected]fb745cf2012-10-02 15:33:48184 scoped_ptr<PluginMetadata> plugin_metadata_;
185
[email protected]039cb732012-11-03 01:28:38186 InstallCallback callback_;
[email protected]27c483892012-02-09 15:59:10187
188 // True iff the plug-in isn't installed yet.
189 bool new_install_;
190
191 string16 message_;
192
193 DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate);
194};
195#endif // defined(ENABLE_PLUGIN_INSTALLATION)
196
[email protected]74c7eaa22012-06-21 21:43:49197#if defined(OS_WIN)
198class PluginMetroModeInfoBarDelegate : public ConfirmInfoBarDelegate {
199 public:
[email protected]eac6fef2012-12-26 22:45:11200 // 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.
203 enum Mode {
204 MISSING_PLUGIN,
205 DESKTOP_MODE_REQUIRED,
206 };
207
[email protected]0be09932013-01-08 02:03:50208 // Creates a metro mode infobar and delegate and adds the infobar to
209 // |infobar_service|.
210 static void Create(InfoBarService* infobar_service,
211 Mode mode,
212 const string16& name);
213
214 private:
[email protected]33f84f982012-08-30 00:39:44215 PluginMetroModeInfoBarDelegate(InfoBarService* infobar_service,
[email protected]eac6fef2012-12-26 22:45:11216 Mode mode,
217 const string16& name);
[email protected]74c7eaa22012-06-21 21:43:49218 virtual ~PluginMetroModeInfoBarDelegate();
219
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;
[email protected]b5057db2012-12-07 06:51:10226 virtual bool Cancel() OVERRIDE;
[email protected]74c7eaa22012-06-21 21:43:49227 virtual string16 GetLinkText() const OVERRIDE;
228 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
229
[email protected]eac6fef2012-12-26 22:45:11230 const Mode mode_;
231 const string16 name_;
[email protected]74c7eaa22012-06-21 21:43:49232
233 DISALLOW_COPY_AND_ASSIGN(PluginMetroModeInfoBarDelegate);
234};
235#endif // defined(OS_WIN)
236
[email protected]0f5e57f52012-09-20 20:53:18237#endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_