Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / plugins / plugin_infobar_delegates.h
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 "components/infobars/core/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   ~PluginInfoBarDelegate() override;
29
30   // ConfirmInfoBarDelegate:
31   bool LinkClicked(WindowOpenDisposition disposition) override;
32
33   virtual std::string GetLearnMoreURL() const = 0;
34
35   void LoadBlockedPlugins();
36
37  private:
38   // ConfirmInfoBarDelegate:
39   int GetIconID() const override;
40   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   ~UnauthorizedPluginInfoBarDelegate() override;
62
63   // PluginInfoBarDelegate:
64   base::string16 GetMessageText() const override;
65   base::string16 GetButtonLabel(InfoBarButton button) const override;
66   bool Accept() override;
67   bool Cancel() override;
68   void InfoBarDismissed() override;
69   bool LinkClicked(WindowOpenDisposition disposition) override;
70   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   ~OutdatedPluginInfoBarDelegate() override;
94
95   // PluginInfoBarDelegate:
96   base::string16 GetMessageText() const override;
97   base::string16 GetButtonLabel(InfoBarButton button) const override;
98   bool Accept() override;
99   bool Cancel() override;
100   void InfoBarDismissed() override;
101   bool LinkClicked(WindowOpenDisposition disposition) override;
102   std::string GetLearnMoreURL() const override;
103
104   // PluginInstallerObserver:
105   void DownloadStarted() override;
106   void DownloadError(const std::string& message) override;
107   void DownloadCancelled() override;
108   void DownloadFinished() override;
109
110   // WeakPluginInstallerObserver:
111   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(infobars::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   ~PluginInstallerInfoBarDelegate() override;
155
156   // ConfirmInfoBarDelegate:
157   int GetIconID() const override;
158   base::string16 GetMessageText() const override;
159   int GetButtons() const override;
160   base::string16 GetButtonLabel(InfoBarButton button) const override;
161   bool Accept() override;
162   base::string16 GetLinkText() const override;
163   bool LinkClicked(WindowOpenDisposition disposition) override;
164
165   // PluginInstallerObserver:
166   void DownloadStarted() override;
167   void DownloadError(const std::string& message) override;
168   void DownloadCancelled() override;
169   void DownloadFinished() override;
170
171   // WeakPluginInstallerObserver:
172   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_