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

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

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/plugins/plugin_infobar_delegates.h" 5 #include "chrome/browser/plugins/plugin_infobar_delegates.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/api/infobars/infobar_service.h" 8 #include "chrome/browser/api/infobars/infobar_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
24 24
25 #if defined(OS_WIN) 25 #if defined(OS_WIN)
26 #include <shellapi.h> 26 #include <shellapi.h>
27 #include "ui/base/win/shell.h" 27 #include "ui/base/win/shell.h"
28 #endif 28 #endif
29 29
30 #if defined(ENABLE_PLUGIN_INSTALLATION) 30 #if defined(ENABLE_PLUGIN_INSTALLATION)
31 #if defined(OS_WIN)
32 #include "base/win/metro.h"
33 #endif
31 #include "chrome/browser/plugins/plugin_installer.h" 34 #include "chrome/browser/plugins/plugin_installer.h"
32 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 35 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
33 36
34 using content::OpenURLParams; 37 using content::OpenURLParams;
35 using content::Referrer; 38 using content::Referrer;
36 using content::UserMetricsAction; 39 using content::UserMetricsAction;
37 40
38 PluginInfoBarDelegate::PluginInfoBarDelegate(InfoBarService* infobar_service, 41 PluginInfoBarDelegate::PluginInfoBarDelegate(InfoBarService* infobar_service,
39 const string16& name, 42 const string16& name,
40 const std::string& identifier) 43 const std::string& identifier)
(...skipping 27 matching lines...) Expand all
68 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 71 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
69 IDR_INFOBAR_PLUGIN_INSTALL); 72 IDR_INFOBAR_PLUGIN_INSTALL);
70 } 73 }
71 74
72 string16 PluginInfoBarDelegate::GetLinkText() const { 75 string16 PluginInfoBarDelegate::GetLinkText() const {
73 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 76 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
74 } 77 }
75 78
76 // UnauthorizedPluginInfoBarDelegate ------------------------------------------ 79 // UnauthorizedPluginInfoBarDelegate ------------------------------------------
77 80
78 UnauthorizedPluginInfoBarDelegate::UnauthorizedPluginInfoBarDelegate( 81 // static
82 void UnauthorizedPluginInfoBarDelegate::Create(
79 InfoBarService* infobar_service, 83 InfoBarService* infobar_service,
80 HostContentSettingsMap* content_settings, 84 HostContentSettingsMap* content_settings,
81 const string16& utf16_name, 85 const string16& utf16_name,
82 const std::string& identifier) 86 const std::string& identifier) {
83 : PluginInfoBarDelegate(infobar_service, utf16_name, identifier), 87 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
84 content_settings_(content_settings) { 88 new UnauthorizedPluginInfoBarDelegate(infobar_service, content_settings,
89 utf16_name, identifier)));
90
85 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); 91 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown"));
86 std::string name = UTF16ToUTF8(utf16_name); 92 std::string name(UTF16ToUTF8(utf16_name));
87 if (name == PluginMetadata::kJavaGroupName) 93 if (name == PluginMetadata::kJavaGroupName)
88 content::RecordAction( 94 content::RecordAction(
89 UserMetricsAction("BlockedPluginInfobar.Shown.Java")); 95 UserMetricsAction("BlockedPluginInfobar.Shown.Java"));
90 else if (name == PluginMetadata::kQuickTimeGroupName) 96 else if (name == PluginMetadata::kQuickTimeGroupName)
91 content::RecordAction( 97 content::RecordAction(
92 UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime")); 98 UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime"));
93 else if (name == PluginMetadata::kShockwaveGroupName) 99 else if (name == PluginMetadata::kShockwaveGroupName)
94 content::RecordAction( 100 content::RecordAction(
95 UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave")); 101 UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave"));
96 else if (name == PluginMetadata::kRealPlayerGroupName) 102 else if (name == PluginMetadata::kRealPlayerGroupName)
97 content::RecordAction( 103 content::RecordAction(
98 UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer")); 104 UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer"));
99 else if (name == PluginMetadata::kWindowsMediaPlayerGroupName) 105 else if (name == PluginMetadata::kWindowsMediaPlayerGroupName)
100 content::RecordAction( 106 content::RecordAction(
101 UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer")); 107 UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer"));
102 } 108 }
103 109
110 UnauthorizedPluginInfoBarDelegate::UnauthorizedPluginInfoBarDelegate(
111 InfoBarService* infobar_service,
112 HostContentSettingsMap* content_settings,
113 const string16& utf16_name,
114 const std::string& identifier)
115 : PluginInfoBarDelegate(infobar_service, utf16_name, identifier),
116 content_settings_(content_settings) {
117 }
118
104 UnauthorizedPluginInfoBarDelegate::~UnauthorizedPluginInfoBarDelegate() { 119 UnauthorizedPluginInfoBarDelegate::~UnauthorizedPluginInfoBarDelegate() {
105 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); 120 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
106 } 121 }
107 122
108 std::string UnauthorizedPluginInfoBarDelegate::GetLearnMoreURL() const { 123 std::string UnauthorizedPluginInfoBarDelegate::GetLearnMoreURL() const {
109 return chrome::kBlockedPluginLearnMoreURL; 124 return chrome::kBlockedPluginLearnMoreURL;
110 } 125 }
111 126
112 string16 UnauthorizedPluginInfoBarDelegate::GetMessageText() const { 127 string16 UnauthorizedPluginInfoBarDelegate::GetMessageText() const {
113 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); 128 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool UnauthorizedPluginInfoBarDelegate::LinkClicked( 161 bool UnauthorizedPluginInfoBarDelegate::LinkClicked(
147 WindowOpenDisposition disposition) { 162 WindowOpenDisposition disposition) {
148 content::RecordAction( 163 content::RecordAction(
149 UserMetricsAction("BlockedPluginInfobar.LearnMore")); 164 UserMetricsAction("BlockedPluginInfobar.LearnMore"));
150 return PluginInfoBarDelegate::LinkClicked(disposition); 165 return PluginInfoBarDelegate::LinkClicked(disposition);
151 } 166 }
152 167
153 #if defined(ENABLE_PLUGIN_INSTALLATION) 168 #if defined(ENABLE_PLUGIN_INSTALLATION)
154 // OutdatedPluginInfoBarDelegate ---------------------------------------------- 169 // OutdatedPluginInfoBarDelegate ----------------------------------------------
155 170
156 InfoBarDelegate* OutdatedPluginInfoBarDelegate::Create( 171 void OutdatedPluginInfoBarDelegate::Create(
157 content::WebContents* web_contents, 172 InfoBarService* infobar_service,
158 PluginInstaller* installer, 173 PluginInstaller* installer,
159 scoped_ptr<PluginMetadata> plugin_metadata) { 174 scoped_ptr<PluginMetadata> plugin_metadata) {
160 string16 message; 175 string16 message;
161 switch (installer->state()) { 176 switch (installer->state()) {
162 case PluginInstaller::INSTALLER_STATE_IDLE: 177 case PluginInstaller::INSTALLER_STATE_IDLE:
163 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, 178 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT,
164 plugin_metadata->name()); 179 plugin_metadata->name());
165 break; 180 break;
166 case PluginInstaller::INSTALLER_STATE_DOWNLOADING: 181 case PluginInstaller::INSTALLER_STATE_DOWNLOADING:
167 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING, 182 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
168 plugin_metadata->name()); 183 plugin_metadata->name());
169 break; 184 break;
170 } 185 }
171 return new OutdatedPluginInfoBarDelegate( 186 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
172 web_contents, installer, plugin_metadata.Pass(), message); 187 new OutdatedPluginInfoBarDelegate(
188 infobar_service, installer, plugin_metadata.Pass(), message)));
173 } 189 }
174 190
175 OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( 191 OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate(
176 content::WebContents* web_contents, 192 InfoBarService* infobar_service,
177 PluginInstaller* installer, 193 PluginInstaller* installer,
178 scoped_ptr<PluginMetadata> plugin_metadata, 194 scoped_ptr<PluginMetadata> plugin_metadata,
179 const string16& message) 195 const string16& message)
180 : PluginInfoBarDelegate( 196 : PluginInfoBarDelegate(
181 InfoBarService::FromWebContents(web_contents), 197 infobar_service,
182 plugin_metadata->name(), 198 plugin_metadata->name(),
183 plugin_metadata->identifier()), 199 plugin_metadata->identifier()),
184 WeakPluginInstallerObserver(installer), 200 WeakPluginInstallerObserver(installer),
185 plugin_metadata_(plugin_metadata.Pass()), 201 plugin_metadata_(plugin_metadata.Pass()),
186 message_(message) { 202 message_(message) {
187 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); 203 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown"));
188 std::string name = UTF16ToUTF8(plugin_metadata_->name()); 204 std::string name = UTF16ToUTF8(plugin_metadata_->name());
189 if (name == PluginMetadata::kJavaGroupName) 205 if (name == PluginMetadata::kJavaGroupName)
190 content::RecordAction( 206 content::RecordAction(
191 UserMetricsAction("OutdatedPluginInfobar.Shown.Java")); 207 UserMetricsAction("OutdatedPluginInfobar.Shown.Java"));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 308
293 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( 309 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar(
294 const string16& message) { 310 const string16& message) {
295 // Return early if the message doesn't change. This is important in case the 311 // Return early if the message doesn't change. This is important in case the
296 // PluginInstaller is still iterating over its observers (otherwise we would 312 // PluginInstaller is still iterating over its observers (otherwise we would
297 // keep replacing infobar delegates infinitely). 313 // keep replacing infobar delegates infinitely).
298 if (message_ == message) 314 if (message_ == message)
299 return; 315 return;
300 if (!owner()) 316 if (!owner())
301 return; 317 return;
302 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( 318 PluginInstallerInfoBarDelegate::Replace(
303 owner(), installer(), plugin_metadata_->Clone(), 319 this, installer(), plugin_metadata_->Clone(), false, message);
304 PluginInstallerInfoBarDelegate::InstallCallback(), false, message);
305 owner()->ReplaceInfoBar(this, delegate);
306 } 320 }
307 321
308 // PluginInstallerInfoBarDelegate --------------------------------------------- 322 // PluginInstallerInfoBarDelegate ---------------------------------------------
309 323
324 void PluginInstallerInfoBarDelegate::Create(
325 InfoBarService* infobar_service,
326 PluginInstaller* installer,
327 scoped_ptr<PluginMetadata> plugin_metadata,
328 const InstallCallback& callback) {
329 string16 name(plugin_metadata->name());
330 #if defined(OS_WIN)
331 if (base::win::IsMetroProcess()) {
332 PluginMetroModeInfoBarDelegate::Create(
333 infobar_service, PluginMetroModeInfoBarDelegate::MISSING_PLUGIN, name);
334 return;
335 }
336 #endif
337 string16 message;
338 switch (installer->state()) {
339 case PluginInstaller::INSTALLER_STATE_IDLE:
340 message = l10n_util::GetStringFUTF16(
341 IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT, name);
342 break;
343 case PluginInstaller::INSTALLER_STATE_DOWNLOADING:
344 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING, name);
345 break;
346 }
347 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
348 new PluginInstallerInfoBarDelegate(
349 infobar_service, installer, plugin_metadata.Pass(), callback, true,
350 message)));
351 }
352
353 void PluginInstallerInfoBarDelegate::Replace(
354 InfoBarDelegate* infobar,
355 PluginInstaller* installer,
356 scoped_ptr<PluginMetadata> plugin_metadata,
357 bool new_install,
358 const string16& message) {
359 DCHECK(infobar->owner());
360 infobar->owner()->ReplaceInfoBar(infobar, scoped_ptr<InfoBarDelegate>(
361 new PluginInstallerInfoBarDelegate(
362 infobar->owner(), installer, plugin_metadata.Pass(),
363 PluginInstallerInfoBarDelegate::InstallCallback(), new_install,
364 message)));
365 }
366
310 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( 367 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate(
311 InfoBarService* infobar_service, 368 InfoBarService* infobar_service,
312 PluginInstaller* installer, 369 PluginInstaller* installer,
313 scoped_ptr<PluginMetadata> plugin_metadata, 370 scoped_ptr<PluginMetadata> plugin_metadata,
314 const InstallCallback& callback, 371 const InstallCallback& callback,
315 bool new_install, 372 bool new_install,
316 const string16& message) 373 const string16& message)
317 : ConfirmInfoBarDelegate(infobar_service), 374 : ConfirmInfoBarDelegate(infobar_service),
318 WeakPluginInstallerObserver(installer), 375 WeakPluginInstallerObserver(installer),
319 plugin_metadata_(plugin_metadata.Pass()), 376 plugin_metadata_(plugin_metadata.Pass()),
320 callback_(callback), 377 callback_(callback),
321 new_install_(new_install), 378 new_install_(new_install),
322 message_(message) { 379 message_(message) {
323 } 380 }
324 381
325 PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() { 382 PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() {
326 } 383 }
327 384
328 InfoBarDelegate* PluginInstallerInfoBarDelegate::Create(
329 InfoBarService* infobar_service,
330 PluginInstaller* installer,
331 scoped_ptr<PluginMetadata> plugin_metadata,
332 const InstallCallback& callback) {
333 string16 message;
334 switch (installer->state()) {
335 case PluginInstaller::INSTALLER_STATE_IDLE:
336 message = l10n_util::GetStringFUTF16(
337 IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT, plugin_metadata->name());
338 break;
339 case PluginInstaller::INSTALLER_STATE_DOWNLOADING:
340 message = l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
341 plugin_metadata->name());
342 break;
343 }
344 return new PluginInstallerInfoBarDelegate(
345 infobar_service, installer, plugin_metadata.Pass(),
346 callback, true, message);
347 }
348
349 gfx::Image* PluginInstallerInfoBarDelegate::GetIcon() const { 385 gfx::Image* PluginInstallerInfoBarDelegate::GetIcon() const {
350 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 386 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
351 IDR_INFOBAR_PLUGIN_INSTALL); 387 IDR_INFOBAR_PLUGIN_INSTALL);
352 } 388 }
353 389
354 string16 PluginInstallerInfoBarDelegate::GetMessageText() const { 390 string16 PluginInstallerInfoBarDelegate::GetMessageText() const {
355 return message_; 391 return message_;
356 } 392 }
357 393
358 int PluginInstallerInfoBarDelegate::GetButtons() const { 394 int PluginInstallerInfoBarDelegate::GetButtons() const {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 457
422 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( 458 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar(
423 const string16& message) { 459 const string16& message) {
424 // Return early if the message doesn't change. This is important in case the 460 // Return early if the message doesn't change. This is important in case the
425 // PluginInstaller is still iterating over its observers (otherwise we would 461 // PluginInstaller is still iterating over its observers (otherwise we would
426 // keep replacing infobar delegates infinitely). 462 // keep replacing infobar delegates infinitely).
427 if (message_ == message) 463 if (message_ == message)
428 return; 464 return;
429 if (!owner()) 465 if (!owner())
430 return; 466 return;
431 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( 467 Replace(this, installer(), plugin_metadata_->Clone(), new_install_, message);
432 owner(), installer(), plugin_metadata_->Clone(),
433 InstallCallback(), new_install_, message);
434 owner()->ReplaceInfoBar(this, delegate);
435 } 468 }
436 469
437 // PluginMetroModeInfoBarDelegate --------------------------------------------- 470 // PluginMetroModeInfoBarDelegate ---------------------------------------------
438 #if defined(OS_WIN) 471 #if defined(OS_WIN)
472 // static
473 void PluginMetroModeInfoBarDelegate::Create(
474 InfoBarService* infobar_service,
475 PluginMetroModeInfoBarDelegate::Mode mode,
476 const string16& name) {
477 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
478 new PluginMetroModeInfoBarDelegate(infobar_service, mode, name)));
479 }
480
439 PluginMetroModeInfoBarDelegate::PluginMetroModeInfoBarDelegate( 481 PluginMetroModeInfoBarDelegate::PluginMetroModeInfoBarDelegate(
440 InfoBarService* infobar_service, 482 InfoBarService* infobar_service,
441 PluginMetroModeInfoBarDelegate::Mode mode, 483 PluginMetroModeInfoBarDelegate::Mode mode,
442 const string16& name) 484 const string16& name)
443 : ConfirmInfoBarDelegate(infobar_service), 485 : ConfirmInfoBarDelegate(infobar_service),
444 mode_(mode), 486 mode_(mode),
445 name_(name) { 487 name_(name) {
446 } 488 }
447 489
448 PluginMetroModeInfoBarDelegate::~PluginMetroModeInfoBarDelegate() { 490 PluginMetroModeInfoBarDelegate::~PluginMetroModeInfoBarDelegate() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 "https://support.google.com/chrome/?ib_display_in_desktop" : 545 "https://support.google.com/chrome/?ib_display_in_desktop" :
504 "https://support.google.com/chrome/?ib_redirect_to_desktop"), 546 "https://support.google.com/chrome/?ib_redirect_to_desktop"),
505 Referrer(), 547 Referrer(),
506 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 548 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
507 content::PAGE_TRANSITION_LINK, false); 549 content::PAGE_TRANSITION_LINK, false);
508 owner()->GetWebContents()->OpenURL(params); 550 owner()->GetWebContents()->OpenURL(params);
509 return false; 551 return false;
510 } 552 }
511 #endif // defined(OS_WIN) 553 #endif // defined(OS_WIN)
512 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 554 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_infobar_delegates.h ('k') | chrome/browser/plugins/plugin_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698