Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/plugin_infobar_delegates.cc

Issue 10933044: Move chrome/browser/plugin_* to chrome/browser/plugins/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@remove_plugin_group
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/plugin_infobar_delegates.h ('k') | chrome/browser/plugin_installer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "chrome/browser/plugin_infobar_delegates.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/api/infobars/infobar_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/google/google_util.h"
11 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/plugin_observer.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/common/render_messages.h"
15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/user_metrics.h"
18 #include "content/public/browser/web_contents.h"
19 #include "grit/generated_resources.h"
20 #include "grit/locale_settings.h"
21 #include "grit/theme_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h"
24 #include "webkit/plugins/npapi/plugin_group.h"
25
26 #if defined(OS_WIN)
27 #include <shellapi.h>
28 #include "ui/base/win/shell.h"
29 #endif
30
31 #if defined(ENABLE_PLUGIN_INSTALLATION)
32 #include "chrome/browser/plugin_installer.h"
33 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
34
35 using content::OpenURLParams;
36 using content::Referrer;
37 using content::UserMetricsAction;
38
39 PluginInfoBarDelegate::PluginInfoBarDelegate(InfoBarService* infobar_service,
40 const string16& name,
41 const std::string& identifier)
42 : ConfirmInfoBarDelegate(infobar_service),
43 name_(name),
44 identifier_(identifier) {
45 }
46
47 PluginInfoBarDelegate::~PluginInfoBarDelegate() {
48 }
49
50 bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
51 OpenURLParams params(
52 GURL(GetLearnMoreURL()), Referrer(),
53 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
54 content::PAGE_TRANSITION_LINK,
55 false);
56 owner()->GetWebContents()->OpenURL(params);
57 return false;
58 }
59
60 void PluginInfoBarDelegate::LoadBlockedPlugins() {
61 content::WebContents* web_contents = owner()->GetWebContents();
62 if (web_contents) {
63 web_contents->Send(new ChromeViewMsg_LoadBlockedPlugins(
64 web_contents->GetRoutingID(), identifier_));
65 }
66 }
67
68 gfx::Image* PluginInfoBarDelegate::GetIcon() const {
69 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
70 IDR_INFOBAR_PLUGIN_INSTALL);
71 }
72
73 string16 PluginInfoBarDelegate::GetLinkText() const {
74 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
75 }
76
77 // UnauthorizedPluginInfoBarDelegate ------------------------------------------
78
79 UnauthorizedPluginInfoBarDelegate::UnauthorizedPluginInfoBarDelegate(
80 InfoBarService* infobar_service,
81 HostContentSettingsMap* content_settings,
82 const string16& utf16_name,
83 const std::string& identifier)
84 : PluginInfoBarDelegate(infobar_service, utf16_name, identifier),
85 content_settings_(content_settings) {
86 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown"));
87 std::string name = UTF16ToUTF8(utf16_name);
88 if (name == webkit::npapi::PluginGroup::kJavaGroupName)
89 content::RecordAction(
90 UserMetricsAction("BlockedPluginInfobar.Shown.Java"));
91 else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName)
92 content::RecordAction(
93 UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime"));
94 else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName)
95 content::RecordAction(
96 UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave"));
97 else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName)
98 content::RecordAction(
99 UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer"));
100 else if (name == webkit::npapi::PluginGroup::kWindowsMediaPlayerGroupName)
101 content::RecordAction(
102 UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer"));
103 }
104
105 UnauthorizedPluginInfoBarDelegate::~UnauthorizedPluginInfoBarDelegate() {
106 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
107 }
108
109 std::string UnauthorizedPluginInfoBarDelegate::GetLearnMoreURL() const {
110 return chrome::kBlockedPluginLearnMoreURL;
111 }
112
113 string16 UnauthorizedPluginInfoBarDelegate::GetMessageText() const {
114 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_);
115 }
116
117 string16 UnauthorizedPluginInfoBarDelegate::GetButtonLabel(
118 InfoBarButton button) const {
119 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
120 IDS_PLUGIN_ENABLE_TEMPORARILY : IDS_PLUGIN_ENABLE_ALWAYS);
121 }
122
123 bool UnauthorizedPluginInfoBarDelegate::Accept() {
124 content::RecordAction(
125 UserMetricsAction("BlockedPluginInfobar.AllowThisTime"));
126 LoadBlockedPlugins();
127 return true;
128 }
129
130 bool UnauthorizedPluginInfoBarDelegate::Cancel() {
131 content::RecordAction(
132 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow"));
133 content_settings_->AddExceptionForURL(owner()->GetWebContents()->GetURL(),
134 owner()->GetWebContents()->GetURL(),
135 CONTENT_SETTINGS_TYPE_PLUGINS,
136 std::string(),
137 CONTENT_SETTING_ALLOW);
138 LoadBlockedPlugins();
139 return true;
140 }
141
142 void UnauthorizedPluginInfoBarDelegate::InfoBarDismissed() {
143 content::RecordAction(
144 UserMetricsAction("BlockedPluginInfobar.Dismissed"));
145 }
146
147 bool UnauthorizedPluginInfoBarDelegate::LinkClicked(
148 WindowOpenDisposition disposition) {
149 content::RecordAction(
150 UserMetricsAction("BlockedPluginInfobar.LearnMore"));
151 return PluginInfoBarDelegate::LinkClicked(disposition);
152 }
153
154 #if defined(ENABLE_PLUGIN_INSTALLATION)
155 // OutdatedPluginInfoBarDelegate ----------------------------------------------
156
157 InfoBarDelegate* OutdatedPluginInfoBarDelegate::Create(
158 PluginObserver* observer,
159 PluginInstaller* installer) {
160 string16 message;
161 switch (installer->state()) {
162 case PluginInstaller::INSTALLER_STATE_IDLE:
163 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT,
164 installer->name());
165 break;
166 case PluginInstaller::INSTALLER_STATE_DOWNLOADING:
167 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
168 installer->name());
169 break;
170 }
171 return new OutdatedPluginInfoBarDelegate(
172 observer, installer, message);
173 }
174
175 OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate(
176 PluginObserver* observer,
177 PluginInstaller* installer,
178 const string16& message)
179 : PluginInfoBarDelegate(InfoBarService::ForTab(observer->tab_contents()),
180 installer->name(),
181 installer->identifier()),
182 WeakPluginInstallerObserver(installer),
183 observer_(observer),
184 message_(message) {
185 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown"));
186 std::string name = UTF16ToUTF8(installer->name());
187 if (name == webkit::npapi::PluginGroup::kJavaGroupName)
188 content::RecordAction(
189 UserMetricsAction("OutdatedPluginInfobar.Shown.Java"));
190 else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName)
191 content::RecordAction(
192 UserMetricsAction("OutdatedPluginInfobar.Shown.QuickTime"));
193 else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName)
194 content::RecordAction(
195 UserMetricsAction("OutdatedPluginInfobar.Shown.Shockwave"));
196 else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName)
197 content::RecordAction(
198 UserMetricsAction("OutdatedPluginInfobar.Shown.RealPlayer"));
199 else if (name == webkit::npapi::PluginGroup::kSilverlightGroupName)
200 content::RecordAction(
201 UserMetricsAction("OutdatedPluginInfobar.Shown.Silverlight"));
202 else if (name == webkit::npapi::PluginGroup::kAdobeReaderGroupName)
203 content::RecordAction(
204 UserMetricsAction("OutdatedPluginInfobar.Shown.Reader"));
205 }
206
207 OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() {
208 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed"));
209 }
210
211 std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const {
212 return chrome::kOutdatedPluginLearnMoreURL;
213 }
214
215 string16 OutdatedPluginInfoBarDelegate::GetMessageText() const {
216 return message_;
217 }
218
219 string16 OutdatedPluginInfoBarDelegate::GetButtonLabel(
220 InfoBarButton button) const {
221 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
222 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY);
223 }
224
225 bool OutdatedPluginInfoBarDelegate::Accept() {
226 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update"));
227 if (installer()->state() != PluginInstaller::INSTALLER_STATE_IDLE) {
228 NOTREACHED();
229 return false;
230 }
231
232 content::WebContents* web_contents = owner()->GetWebContents();
233 if (installer()->url_for_display()) {
234 installer()->OpenDownloadURL(web_contents);
235 } else {
236 installer()->StartInstalling(observer_->tab_contents());
237 }
238 return false;
239 }
240
241 bool OutdatedPluginInfoBarDelegate::Cancel() {
242 content::RecordAction(
243 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime"));
244 LoadBlockedPlugins();
245 return true;
246 }
247
248 void OutdatedPluginInfoBarDelegate::InfoBarDismissed() {
249 content::RecordAction(
250 UserMetricsAction("OutdatedPluginInfobar.Dismissed"));
251 }
252
253 bool OutdatedPluginInfoBarDelegate::LinkClicked(
254 WindowOpenDisposition disposition) {
255 content::RecordAction(
256 UserMetricsAction("OutdatedPluginInfobar.LearnMore"));
257 return PluginInfoBarDelegate::LinkClicked(disposition);
258 }
259
260 void OutdatedPluginInfoBarDelegate::DownloadStarted() {
261 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
262 installer()->name()));
263 }
264
265 void OutdatedPluginInfoBarDelegate::DownloadError(const std::string& message) {
266 ReplaceWithInfoBar(
267 l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT,
268 installer()->name()));
269 }
270
271 void OutdatedPluginInfoBarDelegate::DownloadCancelled() {
272 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED,
273 installer()->name()));
274 }
275
276 void OutdatedPluginInfoBarDelegate::DownloadFinished() {
277 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_UPDATING,
278 installer()->name()));
279 }
280
281 void OutdatedPluginInfoBarDelegate::OnlyWeakObserversLeft() {
282 if (owner())
283 owner()->RemoveInfoBar(this);
284 }
285
286 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar(
287 const string16& message) {
288 // Return early if the message doesn't change. This is important in case the
289 // PluginInstaller is still iterating over its observers (otherwise we would
290 // keep replacing infobar delegates infinitely).
291 if (message_ == message)
292 return;
293 if (!owner())
294 return;
295 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate(
296 owner(), installer(), base::Closure(), false, message);
297 owner()->ReplaceInfoBar(this, delegate);
298 }
299
300 // PluginInstallerInfoBarDelegate ---------------------------------------------
301
302 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate(
303 InfoBarService* infobar_service,
304 PluginInstaller* installer,
305 const base::Closure& callback,
306 bool new_install,
307 const string16& message)
308 : ConfirmInfoBarDelegate(infobar_service),
309 WeakPluginInstallerObserver(installer),
310 callback_(callback),
311 new_install_(new_install),
312 message_(message) {
313 }
314
315 PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() {
316 }
317
318 InfoBarDelegate* PluginInstallerInfoBarDelegate::Create(
319 InfoBarService* infobar_service,
320 PluginInstaller* installer,
321 const base::Closure& callback) {
322 string16 message;
323 const string16& plugin_name = installer->name();
324 switch (installer->state()) {
325 case PluginInstaller::INSTALLER_STATE_IDLE:
326 message = l10n_util::GetStringFUTF16(
327 IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT, plugin_name);
328 break;
329 case PluginInstaller::INSTALLER_STATE_DOWNLOADING:
330 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING, plugin_name);
331 break;
332 }
333 return new PluginInstallerInfoBarDelegate(
334 infobar_service, installer, callback, true, message);
335 }
336
337 gfx::Image* PluginInstallerInfoBarDelegate::GetIcon() const {
338 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
339 IDR_INFOBAR_PLUGIN_INSTALL);
340 }
341
342 string16 PluginInstallerInfoBarDelegate::GetMessageText() const {
343 return message_;
344 }
345
346 int PluginInstallerInfoBarDelegate::GetButtons() const {
347 return callback_.is_null() ? BUTTON_NONE : BUTTON_OK;
348 }
349
350 string16 PluginInstallerInfoBarDelegate::GetButtonLabel(
351 InfoBarButton button) const {
352 DCHECK_EQ(BUTTON_OK, button);
353 return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_INSTALLPLUGIN_BUTTON);
354 }
355
356 bool PluginInstallerInfoBarDelegate::Accept() {
357 callback_.Run();
358 return false;
359 }
360
361 string16 PluginInstallerInfoBarDelegate::GetLinkText() const {
362 return l10n_util::GetStringUTF16(
363 new_install_ ? IDS_PLUGININSTALLER_PROBLEMSINSTALLING
364 : IDS_PLUGININSTALLER_PROBLEMSUPDATING);
365 }
366
367 bool PluginInstallerInfoBarDelegate::LinkClicked(
368 WindowOpenDisposition disposition) {
369 GURL url(installer()->help_url());
370 if (url.is_empty()) {
371 url = google_util::AppendGoogleLocaleParam(GURL(
372 "https://www.google.com/support/chrome/bin/answer.py?answer=142064"));
373 }
374
375 OpenURLParams params(
376 url, Referrer(),
377 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
378 content::PAGE_TRANSITION_LINK, false);
379 owner()->GetWebContents()->OpenURL(params);
380 return false;
381 }
382
383 void PluginInstallerInfoBarDelegate::DownloadStarted() {
384 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
385 installer()->name()));
386 }
387
388 void PluginInstallerInfoBarDelegate::DownloadCancelled() {
389 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED,
390 installer()->name()));
391 }
392
393 void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) {
394 ReplaceWithInfoBar(
395 l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT,
396 installer()->name()));
397 }
398
399 void PluginInstallerInfoBarDelegate::DownloadFinished() {
400 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(
401 new_install_ ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING,
402 installer()->name()));
403 }
404
405 void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() {
406 if (owner())
407 owner()->RemoveInfoBar(this);
408 }
409
410 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar(
411 const string16& message) {
412 // Return early if the message doesn't change. This is important in case the
413 // PluginInstaller is still iterating over its observers (otherwise we would
414 // keep replacing infobar delegates infinitely).
415 if (message_ == message)
416 return;
417 if (!owner())
418 return;
419 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate(
420 owner(), installer(), base::Closure(), new_install_, message);
421 owner()->ReplaceInfoBar(this, delegate);
422 }
423
424 // PluginMetroModeInfoBarDelegate ---------------------------------------------
425 #if defined(OS_WIN)
426 InfoBarDelegate* PluginMetroModeInfoBarDelegate::Create(
427 InfoBarService* infobar_service, const string16& plugin_name) {
428 string16 message = l10n_util::GetStringFUTF16(
429 IDS_METRO_MISSING_PLUGIN_PROMPT, plugin_name);
430 return new PluginMetroModeInfoBarDelegate(
431 infobar_service, message);
432 }
433
434 PluginMetroModeInfoBarDelegate::PluginMetroModeInfoBarDelegate(
435 InfoBarService* infobar_service, const string16& message)
436 : ConfirmInfoBarDelegate(infobar_service),
437 message_(message) {
438 }
439
440 PluginMetroModeInfoBarDelegate::~PluginMetroModeInfoBarDelegate() {
441 }
442
443 gfx::Image* PluginMetroModeInfoBarDelegate::GetIcon() const {
444 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
445 IDR_INFOBAR_PLUGIN_INSTALL);
446 }
447
448 string16 PluginMetroModeInfoBarDelegate::GetMessageText() const {
449 return message_;
450 }
451
452 int PluginMetroModeInfoBarDelegate::GetButtons() const {
453 return BUTTON_OK;
454 }
455
456 string16 PluginMetroModeInfoBarDelegate::GetButtonLabel(
457 InfoBarButton button) const {
458 DCHECK_EQ(BUTTON_OK, button);
459 return l10n_util::GetStringUTF16(IDS_WIN8_DESKTOP_RESTART);
460 }
461
462 bool PluginMetroModeInfoBarDelegate::Accept() {
463 content::WebContents* web_contents = owner()->GetWebContents();
464 if (!web_contents)
465 return false;
466 // Note that empty urls are not valid.
467 if (!web_contents->GetURL().is_valid())
468 return false;
469 std::string url(web_contents->GetURL().spec());
470 browser::AttemptRestartWithModeSwitch();
471 return true;
472 }
473
474 string16 PluginMetroModeInfoBarDelegate::GetLinkText() const {
475 return l10n_util::GetStringUTF16(IDS_METRO_SWITCH_WHY_LINK);
476 }
477
478 bool PluginMetroModeInfoBarDelegate::LinkClicked(
479 WindowOpenDisposition disposition) {
480 // TODO(cpu): replace with the final url.
481 GURL url = google_util::AppendGoogleLocaleParam(GURL(
482 "https://support.google.com/chrome/?ib_display_in_desktop"));
483 OpenURLParams params(
484 url, Referrer(),
485 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
486 content::PAGE_TRANSITION_LINK, false);
487 owner()->GetWebContents()->OpenURL(params);
488 return false;
489 }
490 #endif // defined(OS_WIN)
491 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
OLDNEW
« no previous file with comments | « chrome/browser/plugin_infobar_delegates.h ('k') | chrome/browser/plugin_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698