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 5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_ 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_ 7 8 #include "base/callback.h" 9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 10 #include "url/gurl.h" 11 12 #if defined(ENABLE_PLUGIN_INSTALLATION) 13 #include "chrome/browser/plugins/plugin_installer_observer.h" 14 #endif 15 16 class InfoBarService; 17 class HostContentSettingsMap; 18 class PluginMetadata; 19 20 namespace content { 21 class WebContents; 22 } 23 24 // Base class for blocked plug-in infobars. 25 class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { 26 protected: 27 PluginInfoBarDelegate(InfoBarService* infobar_service, 28 const std::string& identifier); 29 virtual ~PluginInfoBarDelegate(); 30 31 // ConfirmInfoBarDelegate: 32 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; 33 34 virtual std::string GetLearnMoreURL() const = 0; 35 36 void LoadBlockedPlugins(); 37 38 private: 39 // ConfirmInfoBarDelegate: 40 virtual int GetIconID() const OVERRIDE; 41 virtual string16 GetLinkText() const OVERRIDE; 42 43 std::string identifier_; 44 45 DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate); 46 }; 47 48 // Infobar that's shown when a plug-in requires user authorization to run. 49 class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate { 50 public: 51 // Creates an unauthorized plugin infobar delegate and adds it to 52 // |infobar_service|. 53 static void Create(InfoBarService* infobar_service, 54 HostContentSettingsMap* content_settings, 55 const string16& name, 56 const std::string& identifier); 57 58 private: 59 UnauthorizedPluginInfoBarDelegate(InfoBarService* infobar_service, 60 HostContentSettingsMap* content_settings, 61 const string16& name, 62 const std::string& identifier); 63 virtual ~UnauthorizedPluginInfoBarDelegate(); 64 65 // PluginInfoBarDelegate: 66 virtual string16 GetMessageText() const OVERRIDE; 67 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 68 virtual bool Accept() OVERRIDE; 69 virtual bool Cancel() OVERRIDE; 70 virtual void InfoBarDismissed() OVERRIDE; 71 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; 72 virtual std::string GetLearnMoreURL() const OVERRIDE; 73 74 HostContentSettingsMap* content_settings_; 75 string16 name_; 76 77 DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarDelegate); 78 }; 79 80 #if defined(ENABLE_PLUGIN_INSTALLATION) 81 // Infobar that's shown when a plug-in is out of date. 82 class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate, 83 public WeakPluginInstallerObserver { 84 public: 85 // Creates an outdated plugin infobar delegate and adds it to 86 // |infobar_service|. 87 static void Create(InfoBarService* infobar_service, 88 PluginInstaller* installer, 89 scoped_ptr<PluginMetadata> metadata); 90 91 private: 92 OutdatedPluginInfoBarDelegate(InfoBarService* infobar_service, 93 PluginInstaller* installer, 94 scoped_ptr<PluginMetadata> metadata, 95 const string16& message); 96 virtual ~OutdatedPluginInfoBarDelegate(); 97 98 // PluginInfoBarDelegate: 99 virtual string16 GetMessageText() const OVERRIDE; 100 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 101 virtual bool Accept() OVERRIDE; 102 virtual bool Cancel() OVERRIDE; 103 virtual void InfoBarDismissed() OVERRIDE; 104 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; 105 virtual std::string GetLearnMoreURL() const OVERRIDE; 106 107 // PluginInstallerObserver: 108 virtual void DownloadStarted() OVERRIDE; 109 virtual void DownloadError(const std::string& message) OVERRIDE; 110 virtual void DownloadCancelled() OVERRIDE; 111 virtual void DownloadFinished() OVERRIDE; 112 113 // WeakPluginInstallerObserver: 114 virtual void OnlyWeakObserversLeft() OVERRIDE; 115 116 // Replaces this infobar with one showing |message|. The new infobar will 117 // not have any buttons (and not call the callback). 118 void ReplaceWithInfoBar(const string16& message); 119 120 scoped_ptr<PluginMetadata> plugin_metadata_; 121 122 string16 message_; 123 124 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate); 125 }; 126 127 // The main purpose for this class is to popup/close the infobar when there is 128 // a missing plugin. 129 class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate, 130 public WeakPluginInstallerObserver { 131 public: 132 typedef base::Callback<void(const PluginMetadata*)> InstallCallback; 133 134 // Shows an infobar asking whether to install the plugin represented by 135 // |installer|. When the user accepts, |callback| is called. 136 // During installation of the plug-in, the infobar will change to reflect the 137 // installation state. 138 static void Create(InfoBarService* infobar_service, 139 PluginInstaller* installer, 140 scoped_ptr<PluginMetadata> plugin_metadata, 141 const InstallCallback& callback); 142 143 // Replaces |infobar|, which must currently be owned, with an infobar asking 144 // the user to install or update a particular plugin. 145 static void Replace(InfoBarDelegate* infobar, 146 PluginInstaller* installer, 147 scoped_ptr<PluginMetadata> plugin_metadata, 148 bool new_install, 149 const string16& message); 150 151 private: 152 PluginInstallerInfoBarDelegate(InfoBarService* infobar_service, 153 PluginInstaller* installer, 154 scoped_ptr<PluginMetadata> plugin_metadata, 155 const InstallCallback& callback, 156 bool new_install, 157 const string16& message); 158 virtual ~PluginInstallerInfoBarDelegate(); 159 160 // ConfirmInfoBarDelegate: 161 virtual int GetIconID() const OVERRIDE; 162 virtual string16 GetMessageText() const OVERRIDE; 163 virtual int GetButtons() const OVERRIDE; 164 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 165 virtual bool Accept() OVERRIDE; 166 virtual string16 GetLinkText() const OVERRIDE; 167 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; 168 169 // PluginInstallerObserver: 170 virtual void DownloadStarted() OVERRIDE; 171 virtual void DownloadError(const std::string& message) OVERRIDE; 172 virtual void DownloadCancelled() OVERRIDE; 173 virtual void DownloadFinished() OVERRIDE; 174 175 // WeakPluginInstallerObserver: 176 virtual void OnlyWeakObserversLeft() OVERRIDE; 177 178 // Replaces this infobar with one showing |message|. The new infobar will 179 // not have any buttons (and not call the callback). 180 void ReplaceWithInfoBar(const string16& message); 181 182 scoped_ptr<PluginMetadata> plugin_metadata_; 183 184 InstallCallback callback_; 185 186 // True iff the plug-in isn't installed yet. 187 bool new_install_; 188 189 string16 message_; 190 191 DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate); 192 }; 193 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 194 195 #if defined(OS_WIN) 196 class PluginMetroModeInfoBarDelegate : public ConfirmInfoBarDelegate { 197 public: 198 // The infobar can be used for two purposes: to inform the user about a 199 // missing plugin or to note that a plugin only works in desktop mode. These 200 // purposes require different messages, buttons, etc. 201 enum Mode { 202 MISSING_PLUGIN, 203 DESKTOP_MODE_REQUIRED, 204 }; 205 206 // Creates a metro mode infobar and delegate and adds the infobar to 207 // |infobar_service|. 208 static void Create(InfoBarService* infobar_service, 209 Mode mode, 210 const string16& name); 211 212 private: 213 PluginMetroModeInfoBarDelegate(InfoBarService* infobar_service, 214 Mode mode, 215 const string16& name); 216 virtual ~PluginMetroModeInfoBarDelegate(); 217 218 // ConfirmInfoBarDelegate: 219 virtual int GetIconID() const OVERRIDE; 220 virtual string16 GetMessageText() const OVERRIDE; 221 virtual int GetButtons() const OVERRIDE; 222 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 223 virtual bool Accept() OVERRIDE; 224 virtual bool Cancel() OVERRIDE; 225 virtual string16 GetLinkText() const OVERRIDE; 226 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; 227 228 const Mode mode_; 229 const string16 name_; 230 231 DISALLOW_COPY_AND_ASSIGN(PluginMetroModeInfoBarDelegate); 232 }; 233 #endif // defined(OS_WIN) 234 235 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFOBAR_DELEGATES_H_ 236