[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 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. |
| 4 | |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_ |
| 6 | #define CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_ |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 7 | |
| 8 | #include "base/callback.h" |
[email protected] | 4a8adfa0 | 2013-03-19 22:37:46 | [diff] [blame] | 9 | #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 10 | #include "googleurl/src/gurl.h" |
| 11 | |
| 12 | #if defined(ENABLE_PLUGIN_INSTALLATION) |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 13 | #include "chrome/browser/plugins/plugin_installer_observer.h" |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 14 | #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| 15 | |
[email protected] | 33f84f98 | 2012-08-30 00:39:44 | [diff] [blame] | 16 | class InfoBarService; |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 17 | class HostContentSettingsMap; |
[email protected] | fb745cf | 2012-10-02 15:33:48 | [diff] [blame] | 18 | class PluginMetadata; |
[email protected] | 56b8336 | 2012-09-25 22:01:20 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | class WebContents; |
| 22 | } |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 23 | |
| 24 | // Base class for blocked plug-in infobars. |
| 25 | class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 26 | public: |
[email protected] | 33f84f98 | 2012-08-30 00:39:44 | [diff] [blame] | 27 | PluginInfoBarDelegate(InfoBarService* infobar_service, |
[email protected] | 51ffaf7 | 2012-05-09 21:00:49 | [diff] [blame] | 28 | const string16& name, |
| 29 | const std::string& identifier); |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 30 | |
| 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] | 51ffaf7 | 2012-05-09 21:00:49 | [diff] [blame] | 48 | std::string identifier_; |
| 49 | |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 50 | DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate); |
| 51 | }; |
| 52 | |
| 53 | // Infobar that's shown when a plug-in requires user authorization to run. |
| 54 | class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate { |
| 55 | public: |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 56 | // 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] | 33f84f98 | 2012-08-30 00:39:44 | [diff] [blame] | 63 | UnauthorizedPluginInfoBarDelegate(InfoBarService* infobar_service, |
[email protected] | 51ffaf7 | 2012-05-09 21:00:49 | [diff] [blame] | 64 | HostContentSettingsMap* content_settings, |
| 65 | const string16& name, |
| 66 | const std::string& identifier); |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 67 | 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. |
| 85 | class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate, |
| 86 | public WeakPluginInstallerObserver { |
| 87 | public: |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 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); |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 92 | |
| 93 | private: |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 94 | OutdatedPluginInfoBarDelegate(InfoBarService* infobar_service, |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 95 | PluginInstaller* installer, |
[email protected] | fb745cf | 2012-10-02 15:33:48 | [diff] [blame] | 96 | scoped_ptr<PluginMetadata> metadata, |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 97 | 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] | 1a86f75 | 2012-02-10 13:20:36 | [diff] [blame] | 110 | virtual void DownloadStarted() OVERRIDE; |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 111 | virtual void DownloadError(const std::string& message) OVERRIDE; |
[email protected] | 1a86f75 | 2012-02-10 13:20:36 | [diff] [blame] | 112 | virtual void DownloadCancelled() OVERRIDE; |
| 113 | virtual void DownloadFinished() OVERRIDE; |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 114 | |
| 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] | fb745cf | 2012-10-02 15:33:48 | [diff] [blame] | 122 | scoped_ptr<PluginMetadata> plugin_metadata_; |
| 123 | |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 124 | 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. |
| 131 | class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate, |
| 132 | public WeakPluginInstallerObserver { |
| 133 | public: |
[email protected] | 039cb73 | 2012-11-03 01:28:38 | [diff] [blame] | 134 | typedef base::Callback<void(const PluginMetadata*)> InstallCallback; |
| 135 | |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 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. |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 140 | 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] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 152 | |
| 153 | private: |
[email protected] | 33f84f98 | 2012-08-30 00:39:44 | [diff] [blame] | 154 | PluginInstallerInfoBarDelegate(InfoBarService* infobar_service, |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 155 | PluginInstaller* installer, |
[email protected] | fb745cf | 2012-10-02 15:33:48 | [diff] [blame] | 156 | scoped_ptr<PluginMetadata> plugin_metadata, |
[email protected] | 039cb73 | 2012-11-03 01:28:38 | [diff] [blame] | 157 | const InstallCallback& callback, |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 158 | 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] | 1a86f75 | 2012-02-10 13:20:36 | [diff] [blame] | 172 | virtual void DownloadStarted() OVERRIDE; |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 173 | virtual void DownloadError(const std::string& message) OVERRIDE; |
[email protected] | 1a86f75 | 2012-02-10 13:20:36 | [diff] [blame] | 174 | virtual void DownloadCancelled() OVERRIDE; |
| 175 | virtual void DownloadFinished() OVERRIDE; |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 176 | |
| 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] | fb745cf | 2012-10-02 15:33:48 | [diff] [blame] | 184 | scoped_ptr<PluginMetadata> plugin_metadata_; |
| 185 | |
[email protected] | 039cb73 | 2012-11-03 01:28:38 | [diff] [blame] | 186 | InstallCallback callback_; |
[email protected] | 27c48389 | 2012-02-09 15:59:10 | [diff] [blame] | 187 | |
| 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] | 74c7eaa2 | 2012-06-21 21:43:49 | [diff] [blame] | 197 | #if defined(OS_WIN) |
| 198 | class PluginMetroModeInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 199 | public: |
[email protected] | eac6fef | 2012-12-26 22:45:11 | [diff] [blame] | 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. |
| 203 | enum Mode { |
| 204 | MISSING_PLUGIN, |
| 205 | DESKTOP_MODE_REQUIRED, |
| 206 | }; |
| 207 | |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 208 | // 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] | 33f84f98 | 2012-08-30 00:39:44 | [diff] [blame] | 215 | PluginMetroModeInfoBarDelegate(InfoBarService* infobar_service, |
[email protected] | eac6fef | 2012-12-26 22:45:11 | [diff] [blame] | 216 | Mode mode, |
| 217 | const string16& name); |
[email protected] | 74c7eaa2 | 2012-06-21 21:43:49 | [diff] [blame] | 218 | 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] | b5057db | 2012-12-07 06:51:10 | [diff] [blame] | 226 | virtual bool Cancel() OVERRIDE; |
[email protected] | 74c7eaa2 | 2012-06-21 21:43:49 | [diff] [blame] | 227 | virtual string16 GetLinkText() const OVERRIDE; |
| 228 | virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 229 | |
[email protected] | eac6fef | 2012-12-26 22:45:11 | [diff] [blame] | 230 | const Mode mode_; |
| 231 | const string16 name_; |
[email protected] | 74c7eaa2 | 2012-06-21 21:43:49 | [diff] [blame] | 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(PluginMetroModeInfoBarDelegate); |
| 234 | }; |
| 235 | #endif // defined(OS_WIN) |
| 236 | |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 237 | #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_ |