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