Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change infobar creation to use a public static Create() method on the…

… infobar delegate classes. Make constructors as private as possible.

This has several purposes:
* By preventing direct instantiation, it prevents callers from leaking if they create an infobar and don't add it to an InfoBarService.
* By moving decision-making about when to show infobars into these Create() functions, there's a pattern for where such code should go, and caller code becomes simpler and easier to read.
* The two bullets above together mean that for infobars which should only be displayed in certain circumstances, code can't accidentally bypass the decision logic.
* It enables us to eliminate a common InfoBarService* temp on the caller side since the caller no longer needs to both pass the pointer to the infobar _and_ call AddInfoBar() on the pointer.  This was also a somewhat redundant-looking pattern.
* It makes it easier to change the ownership model for infobars in the future by limiting the affected callsites to only the Create() functions.

Note that right now, this still feels pretty redundant since we pass all the same args to Create() functions as constructors most times.  In the new ownership model constructors will no longer need to take InfoBarService*s, which will make this better.

Additionally, this makes AddInfoBar()/ReplaceInfoBar() take scoped_ptr<>s to indicate they're receiving ownership.  This sort of change is easy to make since we only need change the create functions.

This change also has a functional effect: it eliminates some cases where we tried to only show infobars when no other infobars were already showing (discussed and approved by Glen).

BUG=none
TEST=none
Review URL: https://codereview.chromium.org/11644059

git-svn-id: http://src.chromium.org/svn/trunk/src/chrome/browser@175467 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
  • Loading branch information...
commit 2c169846785272299e17aaffcfe1fd8cd9c979f8 1 parent 5fb31e0
pkasting@chromium.org authored
Showing with 1,493 additions and 1,379 deletions.
  1. +2 −3 accessibility/accessibility_extension_apitest.cc
  2. +3 −4 alternate_nav_url_fetcher.cc
  3. +3 −3 api/infobars/confirm_infobar_delegate.cc
  4. +2 −1  api/infobars/confirm_infobar_delegate.h
  5. +0 −4 api/infobars/infobar_delegate.cc
  6. +0 −4 api/infobars/infobar_delegate.h
  7. +9 −7 api/infobars/infobar_service.h
  8. +11 −0 api/infobars/simple_alert_infobar_delegate.cc
  9. +8 −3 api/infobars/simple_alert_infobar_delegate.h
  10. +11 −0 autofill/autofill_cc_infobar_delegate.cc
  11. +17 −2 autofill/autofill_cc_infobar_delegate.h
  12. +2 −6 autofill/autofill_manager.cc
  13. +20 −18 autofill/autofill_metrics_unittest.cc
  14. +26 −3 chrome_quota_permission_context.cc
  15. +2 −7 chromeos/login/webui_login_view.cc
  16. +31 −10 custom_handlers/register_protocol_handler_infobar_delegate.cc
  17. +10 −5 custom_handlers/register_protocol_handler_infobar_delegate.h
  18. +13 −5 download/download_request_infobar_delegate.cc
  19. +16 −4 download/download_request_infobar_delegate.h
  20. +10 −19 download/download_request_infobar_delegate_unittest.cc
  21. +1 −2  download/download_request_limiter.cc
  22. +28 −12 extensions/api/debugger/debugger_api.cc
  23. +30 −18 extensions/app_notify_channel_ui_impl.cc
  24. +17 −5 extensions/extension_infobar_delegate.cc
  25. +13 −6 extensions/extension_infobar_delegate.h
  26. +18 −70 extensions/extension_install_ui_default.cc
  27. +0 −15 extensions/extension_install_ui_default.h
  28. +75 −22 extensions/theme_installed_infobar_delegate.cc
  29. +15 −12 extensions/theme_installed_infobar_delegate.h
  30. +13 −13 geolocation/chrome_geolocation_permission_context_unittest.cc
  31. +19 −0 geolocation/geolocation_confirm_infobar_delegate.cc
  32. +9 −1 geolocation/geolocation_confirm_infobar_delegate.h
  33. +0 −26 geolocation/geolocation_confirm_infobar_delegate_factory.cc
  34. +0 −32 geolocation/geolocation_confirm_infobar_delegate_factory.h
  35. +4 −8 geolocation/geolocation_infobar_queue_controller.cc
  36. +1 −19 google/google_url_tracker.cc
  37. +17 −6 google/google_url_tracker_infobar_delegate.cc
  38. +9 −3 google/google_url_tracker_infobar_delegate.h
  39. +29 −8 google/google_url_tracker_unittest.cc
  40. +7 −0 infobars/alternate_nav_infobar_delegate.cc
  41. +7 −3 infobars/alternate_nav_infobar_delegate.h
  42. +1 −1  infobars/infobar.cc
  43. +3 −5 infobars/infobar_extension_api.cc
  44. +24 −40 infobars/infobar_tab_helper.cc
  45. +5 −3 infobars/infobar_tab_helper.h
  46. +26 −3 infobars/insecure_content_infobar_delegate.cc
  47. +9 −5 infobars/insecure_content_infobar_delegate.h
  48. +0 −42 intents/register_intent_handler_helper.cc
  49. +48 −37 intents/register_intent_handler_infobar_delegate.cc
  50. +35 −15 intents/register_intent_handler_infobar_delegate.h
  51. +4 −7 intents/register_intent_handler_infobar_delegate_unittest.cc
  52. +13 −6 managed_mode/managed_mode_navigation_observer.cc
  53. +2 −2 nacl_host/nacl_infobar.cc
  54. +28 −4 notifications/desktop_notification_service.cc
  55. +51 −38 omnibox_search_hint.cc
  56. +0 −9 omnibox_search_hint.h
  57. +33 −22 password_manager/password_manager_delegate_impl.cc
  58. +23 −23 pepper_broker_infobar_delegate.cc
  59. +9 −7 pepper_broker_infobar_delegate.h
  60. +82 −40 plugins/plugin_infobar_delegates.cc
  61. +31 −14 plugins/plugin_infobar_delegates.h
  62. +24 −55 plugins/plugin_observer.cc
  63. +64 −53 ssl/ssl_tab_helper.cc
  64. +16 −4 three_d_api_observer.cc
  65. +42 −39 translate/translate_infobar_delegate.cc
  66. +21 −21 translate/translate_infobar_delegate.h
  67. +29 −90 translate/translate_manager.cc
  68. +0 −12 translate/translate_manager.h
  69. +23 −16 ui/auto_login_info_bar_delegate.cc
  70. +5 −2 ui/auto_login_info_bar_delegate.h
  71. +2 −4 ui/auto_login_prompter.cc
  72. +11 −70 ui/browser.cc
  73. +0 −14 ui/browser.h
  74. +3 −8 ui/chrome_select_file_policy.cc
  75. +2 −4 ui/cocoa/content_settings/collected_cookies_mac.mm
  76. +4 −4 ui/cocoa/infobars/infobar_container_controller.h
  77. +1 −3 ui/cocoa/infobars/infobar_controller.mm
  78. +24 −20 ui/cocoa/keystone_infobar_delegate.mm
  79. +6 −0 ui/collected_cookies_infobar_delegate.cc
  80. +4 −1 ui/collected_cookies_infobar_delegate.h
  81. +2 −4 ui/content_settings/content_setting_bubble_model.cc
  82. +2 −4 ui/gtk/collected_cookies_gtk.cc
  83. +26 −8 ui/hung_plugin_tab_helper.cc
  84. +42 −9 ui/media_stream_infobar_delegate.cc
  85. +14 −5 ui/media_stream_infobar_delegate.h
  86. +17 −11 ui/startup/autolaunch_prompt_win.cc
  87. +5 −9 ui/startup/bad_flags_prompt.cc
  88. +18 −12 ui/startup/default_browser_prompt.cc
  89. +39 −8 ui/startup/obsolete_os_info_bar.cc
  90. +7 −4 ui/startup/obsolete_os_info_bar.h
  91. +0 −15 ui/startup/obsolete_os_prompt.cc
  92. +0 −21 ui/startup/obsolete_os_prompt.h
  93. +0 −41 ui/startup/obsolete_os_prompt_gtk.cc
  94. +16 −58 ui/startup/session_crashed_prompt.cc
  95. +34 −4 ui/startup/session_crashed_prompt.h
  96. +5 −3 ui/startup/startup_browser_creator_impl.cc
  97. +23 −9 ui/sync/one_click_signin_helper.cc
  98. +5 −5 ui/sync/one_click_signin_infobar_delegate.cc
  99. +3 −1 ui/sync/one_click_signin_infobar_delegate.h
  100. +2 −4 ui/views/collected_cookies_views.cc
  101. +5 −3 ui/views/external_tab_container_win.cc
  102. +2 −4 ui/website_settings/website_settings.cc
  103. +6 −0 ui/website_settings/website_settings_infobar_delegate.cc
  104. +4 −1 ui/website_settings/website_settings_infobar_delegate.h
  105. +0 −4 ui/website_settings/website_settings_unittest.cc
View
5 accessibility/accessibility_extension_apitest.cc
@@ -24,11 +24,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_GetAlertsForTab) {
ASSERT_TRUE(infobar_service);
const char kAlertMessage[] = "Simple Alert Infobar.";
- infobar_service->AddInfoBar(
- new SimpleAlertInfoBarDelegate(infobar_service,
+ SimpleAlertInfoBarDelegate::Create(infobar_service,
NULL,
ASCIIToUTF16(kAlertMessage),
- false));
+ false);
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
ASSERT_TRUE(RunExtensionTest("accessibility/get_alerts_for_tab")) << message_;
View
7 alternate_nav_url_fetcher.cc
@@ -142,10 +142,9 @@ void AlternateNavURLFetcher::SetStatusFromURLFetch(
void AlternateNavURLFetcher::ShowInfobarIfPossible() {
if (navigated_to_entry_ && (state_ == SUCCEEDED)) {
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(controller_->GetWebContents());
- infobar_service->AddInfoBar(
- new AlternateNavInfoBarDelegate(infobar_service, alternate_nav_url_));
+ AlternateNavInfoBarDelegate::Create(
+ InfoBarService::FromWebContents(controller_->GetWebContents()),
+ alternate_nav_url_);
} else if (state_ != FAILED) {
return;
}
View
6 api/infobars/confirm_infobar_delegate.cc
@@ -8,6 +8,9 @@
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+ConfirmInfoBarDelegate::~ConfirmInfoBarDelegate() {
+}
+
InfoBarDelegate::InfoBarAutomationType
ConfirmInfoBarDelegate::GetInfoBarAutomationType() const {
return CONFIRM_INFOBAR;
@@ -46,9 +49,6 @@ ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(
: InfoBarDelegate(infobar_service) {
}
-ConfirmInfoBarDelegate::~ConfirmInfoBarDelegate() {
-}
-
bool ConfirmInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
ConfirmInfoBarDelegate* confirm_delegate =
delegate->AsConfirmInfoBarDelegate();
View
3  api/infobars/confirm_infobar_delegate.h
@@ -20,6 +20,8 @@ class ConfirmInfoBarDelegate : public InfoBarDelegate {
BUTTON_CANCEL = 1 << 1,
};
+ virtual ~ConfirmInfoBarDelegate();
+
// Returns the InfoBar type to be displayed for the InfoBar.
virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE;
@@ -59,7 +61,6 @@ class ConfirmInfoBarDelegate : public InfoBarDelegate {
protected:
explicit ConfirmInfoBarDelegate(InfoBarService* infobar_service);
- virtual ~ConfirmInfoBarDelegate();
virtual bool ShouldExpireInternal(
const content::LoadCommittedDetails& details) const OVERRIDE;
View
4 api/infobars/infobar_delegate.cc
@@ -39,10 +39,6 @@ bool InfoBarDelegate::ShouldExpire(
void InfoBarDelegate::InfoBarDismissed() {
}
-void InfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
gfx::Image* InfoBarDelegate::GetIcon() const {
return NULL;
}
View
4 api/infobars/infobar_delegate.h
@@ -84,10 +84,6 @@ class InfoBarDelegate {
// Called when the user clicks on the close button to dismiss the infobar.
virtual void InfoBarDismissed();
- // Called after the InfoBar is closed. Deletes |this|.
- // TODO(pkasting): Get rid of this and delete delegates directly.
- void InfoBarClosed();
-
// Return the icon to be shown for this InfoBar. If the returned Image is
// NULL, no icon is shown.
virtual gfx::Image* GetIcon() const;
View
16 api/infobars/infobar_service.h
@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_API_INFOBARS_INFOBAR_SERVICE_H_
#define CHROME_BROWSER_API_INFOBARS_INFOBAR_SERVICE_H_
-#include <cstddef>
+#include "base/memory/scoped_ptr.h"
namespace content {
class WebContents;
@@ -35,8 +35,8 @@ class InfoBarService {
// which returns true for InfoBarDelegate::EqualsDelegate(delegate),
// |delegate| is closed immediately without being added.
//
- // Returns whether |delegate| was successfully added.
- virtual bool AddInfoBar(InfoBarDelegate* delegate) = 0;
+ // Returns the delegate if it was successfully added.
+ virtual InfoBarDelegate* AddInfoBar(scoped_ptr<InfoBarDelegate> delegate) = 0;
// Removes the InfoBar for the specified |delegate|.
//
@@ -50,16 +50,18 @@ class InfoBarService {
// If infobars are disabled for this tab, |new_delegate| is closed immediately
// without being added, and nothing else happens.
//
- // Returns whether |new_delegate| was successfully added.
+ // Returns the new delegate if it was successfully added.
//
// NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
- virtual bool ReplaceInfoBar(InfoBarDelegate* old_delegate,
- InfoBarDelegate* new_delegate) = 0;
+ virtual InfoBarDelegate* ReplaceInfoBar(
+ InfoBarDelegate* old_delegate,
+ scoped_ptr<InfoBarDelegate> new_delegate) = 0;
// Returns the number of infobars for this tab.
virtual size_t GetInfoBarCount() const = 0;
- // Returns the infobar at the given |index|.
+ // Returns the infobar delegate at the given |index|. The InfoBarService
+ // retains ownership.
//
// Warning: Does not sanity check |index|.
virtual InfoBarDelegate* GetInfoBarDelegateAt(size_t index) = 0;
View
11 api/infobars/simple_alert_infobar_delegate.cc
@@ -4,8 +4,19 @@
#include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h"
+#include "chrome/browser/api/infobars/infobar_service.h"
#include "third_party/skia/include/core/SkBitmap.h"
+// static
+void SimpleAlertInfoBarDelegate::Create(InfoBarService* infobar_service,
+ gfx::Image* icon,
+ const string16& message,
+ bool auto_expire) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new SimpleAlertInfoBarDelegate(infobar_service, icon, message,
+ auto_expire)));
+}
+
SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate(
InfoBarService* infobar_service,
gfx::Image* icon,
View
11 api/infobars/simple_alert_infobar_delegate.h
@@ -12,12 +12,17 @@
class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
+ // Creates a simple alert delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ gfx::Image* icon, // May be NULL.
+ const string16& message,
+ bool auto_expire);
+
+ private:
SimpleAlertInfoBarDelegate(InfoBarService* infobar_service,
- gfx::Image* icon, // May be NULL.
+ gfx::Image* icon,
const string16& message,
bool auto_expire);
-
- private:
virtual ~SimpleAlertInfoBarDelegate();
// ConfirmInfoBarDelegate:
View
11 autofill/autofill_cc_infobar_delegate.cc
@@ -17,6 +17,17 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+// static
+void AutofillCCInfoBarDelegate::Create(
+ InfoBarService* infobar_service,
+ const CreditCard* credit_card,
+ PersonalDataManager* personal_data,
+ const AutofillMetrics* metric_logger) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new AutofillCCInfoBarDelegate(infobar_service, credit_card, personal_data,
+ metric_logger)));
+}
+
AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
InfoBarService* infobar_service,
const CreditCard* credit_card,
View
19 autofill/autofill_cc_infobar_delegate.h
@@ -24,12 +24,27 @@ struct LoadCommittedDetails;
// card information gathered from a form submission.
class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
+ // Creates an autofill credit card delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ const CreditCard* credit_card,
+ PersonalDataManager* personal_data,
+ const AutofillMetrics* metric_logger);
+
+#if defined(UNIT_TEST)
+ static scoped_ptr<ConfirmInfoBarDelegate> Create(
+ const CreditCard* credit_card,
+ PersonalDataManager* personal_data,
+ const AutofillMetrics* metric_logger) {
+ return scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate(
+ NULL, credit_card, personal_data, metric_logger));
+ }
+#endif
+
+ private:
AutofillCCInfoBarDelegate(InfoBarService* infobar_service,
const CreditCard* credit_card,
PersonalDataManager* personal_data,
const AutofillMetrics* metric_logger);
-
- private:
virtual ~AutofillCCInfoBarDelegate();
void LogUserAction(AutofillMetrics::InfoBarMetric user_action);
View
8 autofill/autofill_manager.cc
@@ -869,12 +869,8 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) {
// it.
scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card);
if (imported_credit_card && web_contents()) {
- InfoBarService* infobar_service = manager_delegate_->GetInfoBarService();
- infobar_service->AddInfoBar(
- new AutofillCCInfoBarDelegate(infobar_service,
- scoped_credit_card.release(),
- personal_data_,
- metric_logger_.get()));
+ AutofillCCInfoBarDelegate::Create(manager_delegate_->GetInfoBarService(),
+ scoped_credit_card.release(), personal_data_, metric_logger_.get());
}
}
View
38 autofill/autofill_metrics_unittest.cc
@@ -8,7 +8,6 @@
#include "base/string16.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "chrome/browser/autofill/autofill_common_test.h"
#include "chrome/browser/autofill/autofill_manager.h"
@@ -269,8 +268,9 @@ class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
virtual void TearDown() OVERRIDE;
protected:
- AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger,
- CreditCard** created_card);
+ scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
+ MockAutofillMetrics* metric_logger,
+ CreditCard** created_card);
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
@@ -334,7 +334,7 @@ void AutofillMetricsTest::TearDown() {
ChromeRenderViewHostTestHarness::TearDown();
}
-AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate(
+scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
MockAutofillMetrics* metric_logger,
CreditCard** created_card) {
EXPECT_CALL(*metric_logger,
@@ -343,11 +343,8 @@ AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate(
CreditCard* credit_card = new CreditCard();
if (created_card)
*created_card = credit_card;
- return new AutofillCCInfoBarDelegate(
- InfoBarService::FromWebContents(web_contents()),
- credit_card,
- &personal_data_,
- metric_logger);
+ return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_,
+ metric_logger);
}
// Test that we log quality metrics appropriately.
@@ -1138,37 +1135,40 @@ TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
// Test that credit card infobar metrics are logged correctly.
TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
- InfoBarService::CreateForWebContents(web_contents());
-
MockAutofillMetrics metric_logger;
::testing::InSequence dummy;
// Accept the infobar.
{
CreditCard* credit_card;
- scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger,
- &credit_card));
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
+ &credit_card));
+ ASSERT_TRUE(infobar);
EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card));
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
- EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Accept());
+ EXPECT_TRUE(infobar->Accept());
}
// Cancel the infobar.
{
- scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
+ NULL));
+ ASSERT_TRUE(infobar);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
- EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Cancel());
+ EXPECT_TRUE(infobar->Cancel());
}
// Dismiss the infobar.
{
- scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
+ NULL));
+ ASSERT_TRUE(infobar);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
EXPECT_CALL(metric_logger,
@@ -1178,7 +1178,9 @@ TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
// Ignore the infobar.
{
- scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
+ NULL));
+ ASSERT_TRUE(infobar);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
}
View
29 chrome_quota_permission_context.cc
@@ -38,6 +38,16 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
typedef QuotaPermissionContext::PermissionCallback PermissionCallback;
+ // Creates a request quota infobar delegate and adds it to |infobar_service|.
+ static void Create(
+ InfoBarService* infobar_service,
+ ChromeQuotaPermissionContext* context,
+ const GURL& origin_url,
+ int64 requested_quota,
+ const std::string& display_languages,
+ const PermissionCallback& callback);
+
+ private:
RequestQuotaInfoBarDelegate(
InfoBarService* infobar_service,
ChromeQuotaPermissionContext* context,
@@ -52,7 +62,6 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate {
requested_quota_(requested_quota),
callback_(callback) {}
- private:
virtual ~RequestQuotaInfoBarDelegate() {
if (!callback_.is_null())
context_->DispatchCallbackOnIOThread(
@@ -78,6 +87,20 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate {
DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate);
};
+// static
+void RequestQuotaInfoBarDelegate::Create(
+ InfoBarService* infobar_service,
+ ChromeQuotaPermissionContext* context,
+ const GURL& origin_url,
+ int64 requested_quota,
+ const std::string& display_languages,
+ const QuotaPermissionContext::PermissionCallback& callback) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new RequestQuotaInfoBarDelegate(infobar_service, context, origin_url,
+ requested_quota, display_languages,
+ callback)));
+}
+
string16 RequestQuotaInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(
(requested_quota_ > kRequestLargeQuotaThreshold ?
@@ -148,10 +171,10 @@ void ChromeQuotaPermissionContext::RequestQuotaPermission(
}
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
- infobar_service->AddInfoBar(new RequestQuotaInfoBarDelegate(
+ RequestQuotaInfoBarDelegate::Create(
infobar_service, this, origin_url, requested_quota,
profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
- callback));
+ callback);
}
void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread(
View
9 chromeos/login/webui_login_view.cc
@@ -17,11 +17,11 @@
#include "chrome/browser/chromeos/login/base_login_display_host.h"
#include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
#include "chrome/browser/chromeos/login/webui_login_display.h"
-#include "chrome/browser/media/media_stream_devices_controller.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/password_manager/password_manager_delegate_impl.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/renderer_preferences_util.h"
+#include "chrome/browser/ui/media_stream_infobar_delegate.h"
#include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/common/chrome_notification_types.h"
@@ -350,12 +350,7 @@ void WebUILoginView::RequestMediaAccessPermission(
WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
-
- scoped_ptr<MediaStreamDevicesController> controller(
- new MediaStreamDevicesController(profile, request, callback));
- if (!controller->DismissInfoBarAndTakeActionOnSettings())
+ if (MediaStreamInfoBarDelegate::Create(web_contents, request, callback))
NOTREACHED() << "Media stream not allowed for WebUI";
}
View
41 custom_handlers/register_protocol_handler_infobar_delegate.cc
@@ -17,13 +17,30 @@ using content::OpenURLParams;
using content::Referrer;
using content::UserMetricsAction;
-RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate(
+// static
+void RegisterProtocolHandlerInfoBarDelegate::Create(
InfoBarService* infobar_service,
ProtocolHandlerRegistry* registry,
- const ProtocolHandler& handler)
- : ConfirmInfoBarDelegate(infobar_service),
- registry_(registry),
- handler_(handler) {
+ const ProtocolHandler& handler) {
+ content::RecordAction(
+ content::UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown"));
+
+ scoped_ptr<InfoBarDelegate> infobar(
+ new RegisterProtocolHandlerInfoBarDelegate(infobar_service, registry,
+ handler));
+
+ for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) {
+ RegisterProtocolHandlerInfoBarDelegate* existing_delegate =
+ infobar_service->GetInfoBarDelegateAt(i)->
+ AsRegisterProtocolHandlerInfoBarDelegate();
+ if ((existing_delegate != NULL) &&
+ existing_delegate->handler_.IsEquivalent(handler)) {
+ infobar_service->ReplaceInfoBar(existing_delegate, infobar.Pass());
+ return;
+ }
+ }
+
+ infobar_service->AddInfoBar(infobar.Pass());
}
InfoBarDelegate::InfoBarAutomationType
@@ -47,6 +64,15 @@ string16 RegisterProtocolHandlerInfoBarDelegate::GetMessageText() const {
GetProtocolName(handler_));
}
+RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate(
+ InfoBarService* infobar_service,
+ ProtocolHandlerRegistry* registry,
+ const ProtocolHandler& handler)
+ : ConfirmInfoBarDelegate(infobar_service),
+ registry_(registry),
+ handler_(handler) {
+}
+
string16 RegisterProtocolHandlerInfoBarDelegate::GetProtocolName(
const ProtocolHandler& handler) const {
if (handler.protocol() == "mailto")
@@ -101,11 +127,6 @@ bool RegisterProtocolHandlerInfoBarDelegate::LinkClicked(
return false;
}
-bool RegisterProtocolHandlerInfoBarDelegate::IsReplacedBy(
- RegisterProtocolHandlerInfoBarDelegate* delegate) {
- return handler_.IsEquivalent(delegate->handler_);
-}
-
RegisterProtocolHandlerInfoBarDelegate*
RegisterProtocolHandlerInfoBarDelegate::
AsRegisterProtocolHandlerInfoBarDelegate() {
View
15 custom_handlers/register_protocol_handler_infobar_delegate.h
@@ -16,9 +16,12 @@ class ProtocolHandlerRegistry;
// card information gathered from a form submission.
class RegisterProtocolHandlerInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- RegisterProtocolHandlerInfoBarDelegate(InfoBarService* infobar_service,
- ProtocolHandlerRegistry* registry,
- const ProtocolHandler& handler);
+ // Creates a new RPH delegate. Searches |infobar_service| for an existing
+ // delegate for the same |handler|; replaces it with the new delegate if
+ // found, otherwise adds the new infobar to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ ProtocolHandlerRegistry* registry,
+ const ProtocolHandler& handler);
// ConfirmInfoBarDelegate:
virtual Type GetInfoBarType() const OVERRIDE;
@@ -35,9 +38,11 @@ class RegisterProtocolHandlerInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE;
- bool IsReplacedBy(RegisterProtocolHandlerInfoBarDelegate* delegate);
-
private:
+ RegisterProtocolHandlerInfoBarDelegate(InfoBarService* infobar_service,
+ ProtocolHandlerRegistry* registry,
+ const ProtocolHandler& handler);
+
// Returns a user-friendly name for the protocol of this protocol handler.
string16 GetProtocolName(const ProtocolHandler& handler) const;
ProtocolHandlerRegistry* registry_;
View
18 download/download_request_infobar_delegate.cc
@@ -10,6 +10,19 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() {
+ if (host_)
+ host_->Cancel();
+}
+
+// static
+void DownloadRequestInfoBarDelegate::Create(
+ InfoBarService* infobar_service,
+ DownloadRequestLimiter::TabDownloadState* host) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new DownloadRequestInfoBarDelegate(infobar_service, host)));
+}
+
DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(
InfoBarService* infobar_service,
DownloadRequestLimiter::TabDownloadState* host)
@@ -17,11 +30,6 @@ DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(
host_(host) {
}
-DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() {
- if (host_)
- host_->Cancel();
-}
-
gfx::Image* DownloadRequestInfoBarDelegate::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INFOBAR_MULTIPLE_DOWNLOADS);
View
20 download/download_request_infobar_delegate.h
@@ -17,16 +17,28 @@ class InfoBarService;
// on an unsuspecting user.
class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- DownloadRequestInfoBarDelegate(
- InfoBarService* infobar_service,
- DownloadRequestLimiter::TabDownloadState* host);
+ virtual ~DownloadRequestInfoBarDelegate();
+
+ // Creates a download request delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ DownloadRequestLimiter::TabDownloadState* host);
+
+#if defined(UNIT_TEST)
+ static scoped_ptr<DownloadRequestInfoBarDelegate> Create(
+ DownloadRequestLimiter::TabDownloadState* host) {
+ return scoped_ptr<DownloadRequestInfoBarDelegate>(
+ new DownloadRequestInfoBarDelegate(NULL, host));
+ }
+#endif
void set_host(DownloadRequestLimiter::TabDownloadState* host) {
host_ = host;
}
private:
- virtual ~DownloadRequestInfoBarDelegate();
+ DownloadRequestInfoBarDelegate(
+ InfoBarService* infobar_service,
+ DownloadRequestLimiter::TabDownloadState* host);
// ConfirmInfoBarDelegate:
virtual gfx::Image* GetIcon() const OVERRIDE;
View
29 download/download_request_infobar_delegate_unittest.cc
@@ -18,23 +18,14 @@ class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState {
virtual void Cancel();
virtual void Accept();
- ConfirmInfoBarDelegate* infobar() {
- return infobar_->AsConfirmInfoBarDelegate();
- }
- void close_infobar() {
- // TODO(pkasting): Right now InfoBarDelegates delete themselves via
- // InfoBarClosed(); once InfoBars own their delegates, this can become a
- // simple reset() call and ~MockTabDownloadState() will no longer need to
- // call it.
- if (infobar_ != NULL)
- infobar_.release()->InfoBarClosed();
- }
+ ConfirmInfoBarDelegate* infobar() { return infobar_.get(); }
+ void delete_infobar_delegate() { infobar_.reset(); }
bool responded() const { return responded_; }
bool accepted() const { return accepted_; }
private:
// The actual infobar delegate we're listening to.
- scoped_ptr<InfoBarDelegate> infobar_;
+ scoped_ptr<DownloadRequestInfoBarDelegate> infobar_;
// True if we have gotten some sort of response.
bool responded_;
@@ -45,12 +36,12 @@ class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState {
};
MockTabDownloadState::MockTabDownloadState()
- : responded_(false), accepted_(false) {
- infobar_.reset(new DownloadRequestInfoBarDelegate(NULL, this));
+ : infobar_(DownloadRequestInfoBarDelegate::Create(this)),
+ responded_(false),
+ accepted_(false) {
}
MockTabDownloadState::~MockTabDownloadState() {
- close_infobar();
EXPECT_TRUE(responded_);
}
@@ -64,7 +55,7 @@ void MockTabDownloadState::Accept() {
EXPECT_FALSE(responded_);
responded_ = true;
accepted_ = true;
- static_cast<DownloadRequestInfoBarDelegate*>(infobar_.get())->set_host(NULL);
+ infobar_->set_host(NULL);
}
@@ -73,19 +64,19 @@ void MockTabDownloadState::Accept() {
TEST(DownloadRequestInfobarDelegate, AcceptTest) {
MockTabDownloadState state;
if (state.infobar()->Accept())
- state.close_infobar();
+ state.delete_infobar_delegate();
EXPECT_TRUE(state.accepted());
}
TEST(DownloadRequestInfobarDelegate, CancelTest) {
MockTabDownloadState state;
if (state.infobar()->Cancel())
- state.close_infobar();
+ state.delete_infobar_delegate();
EXPECT_FALSE(state.accepted());
}
TEST(DownloadRequestInfobarDelegate, CloseTest) {
MockTabDownloadState state;
- state.close_infobar();
+ state.delete_infobar_delegate();
EXPECT_FALSE(state.accepted());
}
View
3  download/download_request_limiter.cc
@@ -106,8 +106,7 @@ void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload(
Cancel();
return;
}
- infobar_ = new DownloadRequestInfoBarDelegate(infobar_service, this);
- infobar_service->AddInfoBar(infobar_);
+ DownloadRequestInfoBarDelegate::Create(infobar_service, this);
}
void DownloadRequestLimiter::TabDownloadState::Cancel() {
View
40 extensions/api/debugger/debugger_api.cc
@@ -59,17 +59,24 @@ class ExtensionDevToolsClientHost;
class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- ExtensionDevToolsInfoBarDelegate(
+ // Creates an extension dev tools delegate and adds it to |infobar_service|.
+ // Returns a pointer to the delegate if it was successfully added.
+ static ExtensionDevToolsInfoBarDelegate* Create(
InfoBarService* infobar_service,
const std::string& client_name,
ExtensionDevToolsClientHost* client_host);
- virtual ~ExtensionDevToolsInfoBarDelegate();
// Notifies infobar delegate that associated DevToolsClientHost will be
// destroyed.
void DiscardClientHost();
private:
+ ExtensionDevToolsInfoBarDelegate(
+ InfoBarService* infobar_service,
+ const std::string& client_name,
+ ExtensionDevToolsClientHost* client_host);
+ virtual ~ExtensionDevToolsInfoBarDelegate();
+
// ConfirmInfoBarDelegate:
virtual int GetButtons() const OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
@@ -196,14 +203,12 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost(
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents_);
- infobar_delegate_ = new ExtensionDevToolsInfoBarDelegate(infobar_service,
- extension_name,
- this);
- if (infobar_service->AddInfoBar(infobar_delegate_)) {
+ infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create(infobar_service,
+ extension_name,
+ this);
+ if (infobar_delegate_) {
registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
content::Source<InfoBarService>(infobar_service));
- } else {
- infobar_delegate_ = NULL;
}
}
@@ -347,6 +352,21 @@ void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend(
}
}
+// static
+ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create(
+ InfoBarService* infobar_service,
+ const std::string& client_name,
+ ExtensionDevToolsClientHost* client_host) {
+ return static_cast<ExtensionDevToolsInfoBarDelegate*>(
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name,
+ client_host))));
+}
+
+void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() {
+ client_host_ = NULL;
+}
+
ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate(
InfoBarService* infobar_service,
const std::string& client_name,
@@ -359,10 +379,6 @@ ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate(
ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() {
}
-void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() {
- client_host_ = NULL;
-}
-
int ExtensionDevToolsInfoBarDelegate::GetButtons() const {
return BUTTON_CANCEL;
}
View
48 extensions/app_notify_channel_ui_impl.cc
@@ -33,10 +33,10 @@ namespace {
class AppNotifyChannelUIInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- AppNotifyChannelUIInfoBarDelegate(AppNotifyChannelUIImpl* creator,
- InfoBarService* infobar_service,
- const std::string& app_name);
- virtual ~AppNotifyChannelUIInfoBarDelegate();
+ // Creates an app notify channel UI delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ AppNotifyChannelUIImpl* creator,
+ const std::string& app_name);
// ConfirmInfoBarDelegate.
virtual string16 GetMessageText() const OVERRIDE;
@@ -46,22 +46,24 @@ class AppNotifyChannelUIInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual void InfoBarDismissed() OVERRIDE;
private:
+ AppNotifyChannelUIInfoBarDelegate(AppNotifyChannelUIImpl* creator,
+ InfoBarService* infobar_service,
+ const std::string& app_name);
+ virtual ~AppNotifyChannelUIInfoBarDelegate();
+
AppNotifyChannelUIImpl* creator_;
std::string app_name_;
DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelUIInfoBarDelegate);
};
-AppNotifyChannelUIInfoBarDelegate::AppNotifyChannelUIInfoBarDelegate(
- AppNotifyChannelUIImpl* creator,
- InfoBarService* infobar_service,
- const std::string& app_name)
- : ConfirmInfoBarDelegate(infobar_service),
- creator_(creator),
- app_name_(app_name) {
-}
-
-AppNotifyChannelUIInfoBarDelegate::~AppNotifyChannelUIInfoBarDelegate() {
+// static
+void AppNotifyChannelUIInfoBarDelegate::Create(InfoBarService* infobar_service,
+ AppNotifyChannelUIImpl* creator,
+ const std::string& app_name) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new AppNotifyChannelUIInfoBarDelegate(creator, infobar_service,
+ app_name)));
}
string16 AppNotifyChannelUIInfoBarDelegate::GetMessageText() const {
@@ -95,6 +97,18 @@ void AppNotifyChannelUIInfoBarDelegate::InfoBarDismissed() {
Cancel();
}
+AppNotifyChannelUIInfoBarDelegate::AppNotifyChannelUIInfoBarDelegate(
+ AppNotifyChannelUIImpl* creator,
+ InfoBarService* infobar_service,
+ const std::string& app_name)
+ : ConfirmInfoBarDelegate(infobar_service),
+ creator_(creator),
+ app_name_(app_name) {
+}
+
+AppNotifyChannelUIInfoBarDelegate::~AppNotifyChannelUIInfoBarDelegate() {
+}
+
} // namespace
@@ -142,10 +156,8 @@ void AppNotifyChannelUIImpl::PromptSyncSetup(
return;
}
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(web_contents_);
- infobar_service->AddInfoBar(new AppNotifyChannelUIInfoBarDelegate(
- this, infobar_service, app_name_));
+ AppNotifyChannelUIInfoBarDelegate::Create(
+ InfoBarService::FromWebContents(web_contents_), this, app_name_);
}
void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) {
View
22 extensions/extension_infobar_delegate.cc
@@ -16,6 +16,23 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
+
+ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
+ if (observer_)
+ observer_->OnDelegateDeleted();
+}
+
+// static
+void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service,
+ Browser* browser,
+ const extensions::Extension* extension,
+ const GURL& url,
+ int height) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new ExtensionInfoBarDelegate(browser, infobar_service, extension, url,
+ height)));
+}
+
ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
Browser* browser,
InfoBarService* infobar_service,
@@ -54,11 +71,6 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
height_ = default_height;
}
-ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
- if (observer_)
- observer_->OnDelegateDeleted();
-}
-
bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
ExtensionInfoBarDelegate* extension_delegate =
delegate->AsExtensionInfoBarDelegate();
View
19 extensions/extension_infobar_delegate.h
@@ -33,11 +33,14 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate,
virtual ~DelegateObserver() {}
};
- ExtensionInfoBarDelegate(Browser* browser,
- InfoBarService* infobar_service,
- const extensions::Extension* extension,
- const GURL& url,
- int height);
+ virtual ~ExtensionInfoBarDelegate();
+
+ // Creates an extension delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ Browser* browser,
+ const extensions::Extension* extension,
+ const GURL& url,
+ int height);
const extensions::Extension* extension() { return extension_; }
extensions::ExtensionHost* extension_host() { return extension_host_.get(); }
@@ -48,7 +51,11 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate,
bool closing() const { return closing_; }
private:
- virtual ~ExtensionInfoBarDelegate();
+ ExtensionInfoBarDelegate(Browser* browser,
+ InfoBarService* infobar_service,
+ const extensions::Extension* extension,
+ const GURL& url,
+ int height);
// InfoBarDelegate:
virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE;
View
88 extensions/extension_install_ui_default.cc
@@ -52,6 +52,12 @@ bool disable_failure_ui_for_tests = false;
// Helper class to put up an infobar when installation fails.
class ErrorInfobarDelegate : public ConfirmInfoBarDelegate {
public:
+ // Creates an error delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ Browser* browser,
+ const extensions::CrxInstallerError& error);
+
+ private:
ErrorInfobarDelegate(InfoBarService* infobar_service,
Browser* browser,
const extensions::CrxInstallerError& error)
@@ -60,7 +66,6 @@ class ErrorInfobarDelegate : public ConfirmInfoBarDelegate {
error_(error) {
}
- private:
virtual string16 GetMessageText() const OVERRIDE {
return error_.message();
}
@@ -88,6 +93,14 @@ class ErrorInfobarDelegate : public ConfirmInfoBarDelegate {
extensions::CrxInstallerError error_;
};
+// static
+void ErrorInfobarDelegate::Create(InfoBarService* infobar_service,
+ Browser* browser,
+ const extensions::CrxInstallerError& error) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new ErrorInfobarDelegate(infobar_service, browser, error)));
+}
+
} // namespace
ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile)
@@ -124,8 +137,8 @@ void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension,
}
if (extension->is_theme()) {
- ShowThemeInfoBar(previous_theme_id_, previous_using_native_theme_,
- extension, profile_);
+ ThemeInstalledInfoBarDelegate::Create(
+ extension, profile_, previous_theme_id_, previous_using_native_theme_);
return;
}
@@ -166,10 +179,8 @@ void ExtensionInstallUIDefault::OnInstallFailure(
WebContents* web_contents = chrome::GetActiveWebContents(browser);
if (!web_contents)
return;
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(web_contents);
- infobar_service->AddInfoBar(
- new ErrorInfobarDelegate(infobar_service, browser, error));
+ ErrorInfobarDelegate::Create(InfoBarService::FromWebContents(web_contents),
+ browser, error);
}
void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) {
@@ -181,69 +192,6 @@ void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) {
}
// static
-void ExtensionInstallUIDefault::ShowThemeInfoBar(
- const std::string& previous_theme_id, bool previous_using_native_theme,
- const Extension* new_theme, Profile* profile) {
- if (!new_theme->is_theme())
- return;
-
- // Get last active tabbed browser of profile.
- Browser* browser = browser::FindTabbedBrowser(profile,
- true,
- chrome::GetActiveDesktop());
- if (!browser)
- return;
-
- WebContents* web_contents = chrome::GetActiveWebContents(browser);
- if (!web_contents)
- return;
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(web_contents);
-
- // First find any previous theme preview infobars.
- InfoBarDelegate* old_delegate = NULL;
- for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) {
- InfoBarDelegate* delegate = infobar_service->GetInfoBarDelegateAt(i);
- ThemeInstalledInfoBarDelegate* theme_infobar =
- delegate->AsThemePreviewInfobarDelegate();
- if (theme_infobar) {
- // If the user installed the same theme twice, ignore the second install
- // and keep the first install info bar, so that they can easily undo to
- // get back the previous theme.
- if (theme_infobar->MatchesTheme(new_theme))
- return;
- old_delegate = delegate;
- break;
- }
- }
-
- // Then either replace that old one or add a new one.
- InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate(
- web_contents, new_theme, previous_theme_id, previous_using_native_theme);
-
- if (old_delegate)
- infobar_service->ReplaceInfoBar(old_delegate, new_delegate);
- else
- infobar_service->AddInfoBar(new_delegate);
-}
-
-InfoBarDelegate* ExtensionInstallUIDefault::GetNewThemeInstalledInfoBarDelegate(
- WebContents* web_contents,
- const Extension* new_theme,
- const std::string& previous_theme_id,
- bool previous_using_native_theme) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- return new ThemeInstalledInfoBarDelegate(
- InfoBarService::FromWebContents(web_contents),
- profile->GetExtensionService(),
- ThemeServiceFactory::GetForProfile(profile),
- new_theme,
- previous_theme_id,
- previous_using_native_theme);
-}
-
-// static
ExtensionInstallUI* ExtensionInstallUI::Create(Profile* profile) {
return new ExtensionInstallUIDefault(profile);
}
View
15 extensions/extension_install_ui_default.h
@@ -28,21 +28,6 @@ class ExtensionInstallUIDefault : public ExtensionInstallUI {
virtual void SetUseAppInstalledBubble(bool use_bubble) OVERRIDE;
private:
- // Shows an infobar for a newly-installed theme. previous_theme_id should be
- // empty if the previous theme was the system/default theme.
- static void ShowThemeInfoBar(const std::string& previous_theme_id,
- bool previous_using_native_theme,
- const extensions::Extension* new_theme,
- Profile* profile);
-
- // Returns the delegate to control the browser's info bar. This is
- // within its own function due to its platform-specific nature.
- static InfoBarDelegate* GetNewThemeInstalledInfoBarDelegate(
- content::WebContents* web_contents,
- const extensions::Extension* new_theme,
- const std::string& previous_theme_id,
- bool previous_using_native_theme);
-
// Whether or not to show the default UI after completing the installation.
bool skip_post_install_ui_;
View
97 extensions/theme_installed_infobar_delegate.cc
@@ -12,6 +12,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/notification_source.h"
@@ -20,6 +22,79 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+
+// static
+void ThemeInstalledInfoBarDelegate::Create(
+ const extensions::Extension* new_theme,
+ Profile* profile,
+ const std::string& previous_theme_id,
+ bool previous_using_native_theme) {
+ if (!new_theme->is_theme())
+ return;
+
+ // Get last active tabbed browser of profile.
+ Browser* browser = browser::FindTabbedBrowser(profile,
+ true,
+ chrome::GetActiveDesktop());
+ if (!browser)
+ return;
+
+ content::WebContents* web_contents = chrome::GetActiveWebContents(browser);
+ if (!web_contents)
+ return;
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(web_contents);
+
+ // First find any previous theme preview infobars.
+ InfoBarDelegate* old_delegate = NULL;
+ for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) {
+ InfoBarDelegate* delegate = infobar_service->GetInfoBarDelegateAt(i);
+ ThemeInstalledInfoBarDelegate* theme_infobar =
+ delegate->AsThemePreviewInfobarDelegate();
+ if (theme_infobar) {
+ // If the user installed the same theme twice, ignore the second install
+ // and keep the first install info bar, so that they can easily undo to
+ // get back the previous theme.
+ if (theme_infobar->theme_id_ == new_theme->id())
+ return;
+ old_delegate = delegate;
+ break;
+ }
+ }
+
+ // Then either replace that old one or add a new one.
+ scoped_ptr<InfoBarDelegate> new_delegate(
+ new ThemeInstalledInfoBarDelegate(
+ infobar_service,
+ profile->GetExtensionService(),
+ ThemeServiceFactory::GetForProfile(profile),
+ new_theme,
+ previous_theme_id,
+ previous_using_native_theme));
+
+ if (old_delegate)
+ infobar_service->ReplaceInfoBar(old_delegate, new_delegate.Pass());
+ else
+ infobar_service->AddInfoBar(new_delegate.Pass());
+}
+
+bool ThemeInstalledInfoBarDelegate::Cancel() {
+ if (!previous_theme_id_.empty()) {
+ const extensions::Extension* previous_theme =
+ extension_service_->GetExtensionById(previous_theme_id_, true);
+ if (previous_theme) {
+ theme_service_->SetTheme(previous_theme);
+ return false; // The theme change will close us.
+ }
+ }
+
+ if (previous_using_native_theme_)
+ theme_service_->SetNativeTheme();
+ else
+ theme_service_->UseDefaultTheme();
+ return false; // The theme change will close us.
+}
+
ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
InfoBarService* infobar_service,
ExtensionService* extension_service,
@@ -39,11 +114,6 @@ ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
content::Source<ThemeService>(theme_service_));
}
-bool ThemeInstalledInfoBarDelegate::MatchesTheme(
- const extensions::Extension* theme) const {
- return theme && (theme->id() == theme_id_);
-}
-
ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() {
// We don't want any notifications while we're running our destructor.
registrar_.RemoveAll();
@@ -51,23 +121,6 @@ ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() {
theme_service_->OnInfobarDestroyed();
}
-bool ThemeInstalledInfoBarDelegate::Cancel() {
- if (!previous_theme_id_.empty()) {
- const extensions::Extension* previous_theme =
- extension_service_->GetExtensionById(previous_theme_id_, true);
- if (previous_theme) {
- theme_service_->SetTheme(previous_theme);
- return false; // The theme change will close us.
- }
- }
-
- if (previous_using_native_theme_)
- theme_service_->SetNativeTheme();
- else
- theme_service_->UseDefaultTheme();
- return false; // The theme change will close us.
-}
-
gfx::Image* ThemeInstalledInfoBarDelegate::GetIcon() const {
// TODO(aa): Reply with the theme's icon, but this requires reading it
// asynchronously from disk.
View
27 extensions/theme_installed_infobar_delegate.h
@@ -14,6 +14,7 @@
class ExtensionService;
class InfoBarService;
+class Profile;
class ThemeService;
namespace extensions {
@@ -25,26 +26,28 @@ class Extension;
class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
public content::NotificationObserver {
public:
- ThemeInstalledInfoBarDelegate(InfoBarService* infobar_service,
- ExtensionService* extension_service,
- ThemeService* theme_service,
- const extensions::Extension* new_theme,
- const std::string& previous_theme_id,
- bool previous_using_native_theme);
-
- // Returns true if the given theme is the same as the one associated with this
- // info bar.
- bool MatchesTheme(const extensions::Extension* theme) const;
+ // Creates a theme installed delegate and adds it to the last active tab on
+ // |profile|.
+ static void Create(const extensions::Extension* new_theme,
+ Profile* profile,
+ const std::string& previous_theme_id,
+ bool previous_using_native_theme);
protected:
- virtual ~ThemeInstalledInfoBarDelegate();
-
ThemeService* theme_service() { return theme_service_; }
// ConfirmInfoBarDelegate:
virtual bool Cancel() OVERRIDE;
private:
+ ThemeInstalledInfoBarDelegate(InfoBarService* infobar_service,
+ ExtensionService* extension_service,
+ ThemeService* theme_service,
+ const extensions::Extension* new_theme,
+ const std::string& previous_theme_id,
+ bool previous_using_native_theme);
+ virtual ~ThemeInstalledInfoBarDelegate();
+
// ConfirmInfoBarDelegate:
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
View
26 geolocation/chrome_geolocation_permission_context_unittest.cc
@@ -294,7 +294,7 @@ TEST_F(GeolocationPermissionContextTests, SinglePermission) {
infobar_service()->RemoveInfoBar(infobar_0);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- infobar_0->InfoBarClosed();
+ delete infobar_0;
}
#if defined(OS_ANDROID)
@@ -399,7 +399,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
closed_delegate_tracker_.Clear();
- infobar_0->InfoBarClosed();
+ delete infobar_0;
// Now we should have a new infobar for the second frame.
ASSERT_EQ(1U, infobar_service()->GetInfoBarCount());
@@ -416,7 +416,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
infobar_service()->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
+ delete infobar_1;
EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
@@ -470,7 +470,7 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
closed_delegate_tracker_.Clear();
- infobar_0->InfoBarClosed();
+ delete infobar_0;
ASSERT_EQ(1U, infobar_service()->GetInfoBarCount());
ConfirmInfoBarDelegate* infobar_1 =
@@ -486,7 +486,7 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
infobar_service()->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
+ delete infobar_1;
EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -543,14 +543,14 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
infobar_service()->RemoveInfoBar(infobar_0);
EXPECT_EQ(2U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- infobar_0->InfoBarClosed();
+ delete infobar_0;
// Now the infobar for the tab with the same origin should have gone.
EXPECT_EQ(0U, infobar_service_for_tab(1)->GetInfoBarCount());
CheckPermissionMessageSentForTab(1, 0, true);
EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
closed_delegate_tracker_.Clear();
// Destroy the infobar that has just been removed.
- removed_infobar->InfoBarClosed();
+ delete removed_infobar;
// But the other tab should still have the info bar...
ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount());
@@ -560,7 +560,7 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
+ delete infobar_1;
}
TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
@@ -591,14 +591,14 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
infobar_service_for_tab(0)->RemoveInfoBar(infobar_0);
EXPECT_EQ(2U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- infobar_0->InfoBarClosed();
+ delete infobar_0;
// Now the infobar for the tab with the same origin should have gone.
EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
CheckPermissionMessageSent(0, true);
EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
closed_delegate_tracker_.Clear();
// Destroy the infobar that has just been removed.
- removed_infobar->InfoBarClosed();
+ delete removed_infobar;
// And we should have the queued infobar displayed now.
ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount());
@@ -612,7 +612,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
+ delete infobar_1;
}
TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
@@ -647,7 +647,7 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
// Delete the tab contents.
DeleteContents();
- infobar_0->InfoBarClosed();
+ delete infobar_0;
// During contents destruction, the infobar will have been closed, and the
// pending request should have been cleared without an infobar being created.
@@ -680,5 +680,5 @@ TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
// Delete the tab contents.
DeleteContents();
- infobar_0->InfoBarClosed();
+ delete infobar_0;
}
View
19 geolocation/geolocation_confirm_infobar_delegate.cc
@@ -17,6 +17,25 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#if defined(OS_ANDROID)
+#include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_android.h"
+typedef GeolocationConfirmInfoBarDelegateAndroid DelegateType;
+#else
+typedef GeolocationConfirmInfoBarDelegate DelegateType;
+#endif
+
+
+// static
+InfoBarDelegate* GeolocationConfirmInfoBarDelegate::Create(
+ InfoBarService* infobar_service,
+ GeolocationInfoBarQueueController* controller,
+ const GeolocationPermissionRequestID& id,
+ const GURL& requesting_frame,
+ const std::string& display_languages) {
+ return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new DelegateType(infobar_service, controller, id, requesting_frame,
+ display_languages)));
+}
GeolocationConfirmInfoBarDelegate::GeolocationConfirmInfoBarDelegate(
InfoBarService* infobar_service,
View
10 geolocation/geolocation_confirm_infobar_delegate.h
@@ -19,6 +19,15 @@ class InfoBarService;
// and handling of geolocation permission infobars to the user.
class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
+ // Creates a geolocation delegate and adds it to |infobar_service|. Returns
+ // the delegate if it was successfully added.
+ static InfoBarDelegate* Create(InfoBarService* infobar_service,
+ GeolocationInfoBarQueueController* controller,
+ const GeolocationPermissionRequestID& id,
+ const GURL& requesting_frame,
+ const std::string& display_languages);
+
+ protected:
GeolocationConfirmInfoBarDelegate(
InfoBarService* infobar_service,
GeolocationInfoBarQueueController* controller,
@@ -28,7 +37,6 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
const GeolocationPermissionRequestID& id() const { return id_; }
- protected:
// ConfirmInfoBarDelegate:
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
View
26 geolocation/geolocation_confirm_infobar_delegate_factory.cc
@@ -1,26 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_factory.h"
-
-#if defined(OS_ANDROID)
-#include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_android.h"
-#else
-#include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate.h"
-#endif
-
-GeolocationConfirmInfoBarDelegate*
- GeolocationConfirmInfoBarDelegateFactory::Create(
- InfoBarService* infobar_service,
- GeolocationInfoBarQueueController* controller,
- const GeolocationPermissionRequestID& id,
- const GURL& requesting_frame_url,
- const std::string& display_languages) {
-#if defined(OS_ANDROID)
- return new GeolocationConfirmInfoBarDelegateAndroid(
-#else
- return new GeolocationConfirmInfoBarDelegate(
-#endif
- infobar_service, controller, id, requesting_frame_url, display_languages);
-}
View
32 geolocation/geolocation_confirm_infobar_delegate_factory.h
@@ -1,32 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONFIRM_INFOBAR_DELEGATE_FACTORY_H_
-#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONFIRM_INFOBAR_DELEGATE_FACTORY_H_
-
-#include "base/values.h"
-
-class GeolocationConfirmInfoBarDelegate;
-class GeolocationInfoBarQueueController;
-class GeolocationPermissionRequestID;
-class GURL;
-class InfoBarService;
-
-class GeolocationConfirmInfoBarDelegateFactory {
- public:
- GeolocationConfirmInfoBarDelegateFactory() {}
- ~GeolocationConfirmInfoBarDelegateFactory() {}
- static GeolocationConfirmInfoBarDelegate* Create(
- InfoBarService* infobar_service,
- GeolocationInfoBarQueueController* controller,
- const GeolocationPermissionRequestID& id,
- const GURL& requesting_frame_url,
- const std::string& display_languages);
-
- private:
-
- DISALLOW_COPY_AND_ASSIGN(GeolocationConfirmInfoBarDelegateFactory);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONFIRM_INFOBAR_DELEGATE_FACTORY_H_
View
12 geolocation/geolocation_infobar_queue_controller.cc
@@ -7,7 +7,6 @@
#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate.h"
-#include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_factory.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -51,9 +50,7 @@ class GeolocationInfoBarQueueController::PendingInfoBarRequest {
const GeolocationPermissionRequestID& id() const { return id_; }
const GURL& requesting_frame() const { return requesting_frame_; }
bool has_infobar_delegate() const { return !!infobar_delegate_; }
- GeolocationConfirmInfoBarDelegate* infobar_delegate() {
- return infobar_delegate_;
- }
+ InfoBarDelegate* infobar_delegate() { return infobar_delegate_; }
void RunCallback(bool allowed);
void CreateInfoBarDelegate(GeolocationInfoBarQueueController* controller,
@@ -64,7 +61,7 @@ class GeolocationInfoBarQueueController::PendingInfoBarRequest {
GURL requesting_frame_;
GURL embedder_;
PermissionDecidedCallback callback_;
- GeolocationConfirmInfoBarDelegate* infobar_delegate_;
+ InfoBarDelegate* infobar_delegate_;
// Purposefully do not disable copying, as this is stored in STL containers.
};
@@ -99,7 +96,7 @@ void GeolocationInfoBarQueueController::PendingInfoBarRequest::RunCallback(
void GeolocationInfoBarQueueController::PendingInfoBarRequest::
CreateInfoBarDelegate(GeolocationInfoBarQueueController* controller,
const std::string& display_languages) {
- infobar_delegate_ = GeolocationConfirmInfoBarDelegateFactory::Create(
+ infobar_delegate_ = GeolocationConfirmInfoBarDelegate::Create(
GetInfoBarService(id_), controller, id_, requesting_frame_,
display_languages);
@@ -227,7 +224,7 @@ void GeolocationInfoBarQueueController::Observe(
content::Details<InfoBarRemovedDetails>(details)->first;
for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
i != pending_infobar_requests_.end(); ++i) {
- GeolocationConfirmInfoBarDelegate* confirm_delegate = i->infobar_delegate();
+ InfoBarDelegate* confirm_delegate = i->infobar_delegate();
if (confirm_delegate == delegate) {
GeolocationPermissionRequestID id(i->id());
pending_infobar_requests_.erase(i);
@@ -270,7 +267,6 @@ void GeolocationInfoBarQueueController::ShowQueuedInfoBarForTab(
RegisterForInfoBarNotifications(infobar_service);
i->CreateInfoBarDelegate(
this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
- infobar_service->AddInfoBar(i->infobar_delegate());
return;
}
}
View
20 google/google_url_tracker.cc
@@ -26,24 +26,6 @@
#include "net/url_request/url_request_status.h"
-namespace {
-
-GoogleURLTrackerInfoBarDelegate* CreateInfoBar(
- InfoBarService* infobar_service,
- GoogleURLTracker* google_url_tracker,
- const GURL& search_url) {
- GoogleURLTrackerInfoBarDelegate* infobar =
- new GoogleURLTrackerInfoBarDelegate(infobar_service, google_url_tracker,
- search_url);
- // AddInfoBar() takes ownership; it will delete |infobar| if it fails.
- return infobar_service->AddInfoBar(infobar) ? infobar : NULL;
-}
-
-} // namespace
-
-
-// GoogleURLTracker -----------------------------------------------------------
-
const char GoogleURLTracker::kDefaultGoogleHomepage[] =
"http://www.google.com/";
const char GoogleURLTracker::kSearchDomainCheckURL[] =
@@ -51,7 +33,7 @@ const char GoogleURLTracker::kSearchDomainCheckURL[] =
GoogleURLTracker::GoogleURLTracker(Profile* profile, Mode mode)
: profile_(profile),
- infobar_creator_(base::Bind(&CreateInfoBar)),
+ infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)),
google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage :
profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
View
23 google/google_url_tracker_infobar_delegate.cc
@@ -16,14 +16,15 @@
#include "ui/base/l10n/l10n_util.h"
-GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
+// static
+GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerInfoBarDelegate::Create(
InfoBarService* infobar_service,
GoogleURLTracker* google_url_tracker,
- const GURL& search_url)
- : ConfirmInfoBarDelegate(infobar_service),
- google_url_tracker_(google_url_tracker),
- search_url_(search_url),
- pending_id_(0) {
+ const GURL& search_url) {
+ return static_cast<GoogleURLTrackerInfoBarDelegate*>(
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new GoogleURLTrackerInfoBarDelegate(
+ infobar_service, google_url_tracker, search_url))));
}
bool GoogleURLTrackerInfoBarDelegate::Accept() {
@@ -81,6 +82,16 @@ void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
owner()->RemoveInfoBar(this);
}
+GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
+ InfoBarService* infobar_service,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& search_url)
+ : ConfirmInfoBarDelegate(infobar_service),
+ google_url_tracker_(google_url_tracker),
+ search_url_(search_url),
+ pending_id_(0) {
+}
+
GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
}
View
12 google/google_url_tracker_infobar_delegate.h
@@ -14,9 +14,12 @@ class GoogleURLTracker;
// changed.
class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- GoogleURLTrackerInfoBarDelegate(InfoBarService* infobar_service,
- GoogleURLTracker* google_url_tracker,
- const GURL& search_url);
+ // Creates a Google URL tracker delegate and adds it to |infobar_service|.
+ // Returns the delegate if it was successfully added.
+ static GoogleURLTrackerInfoBarDelegate* Create(
+ InfoBarService* infobar_service,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& search_url);
// ConfirmInfoBarDelegate:
virtual bool Accept() OVERRIDE;
@@ -37,6 +40,9 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual void Close(bool redo_search);
protected:
+ GoogleURLTrackerInfoBarDelegate(InfoBarService* infobar_service,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& search_url);
virtual ~GoogleURLTrackerInfoBarDelegate();
private:
View
37 google/google_url_tracker_unittest.cc
@@ -31,13 +31,25 @@ namespace {
class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate {
public:
+ // Creates a test delegate and returns it. Unlike the parent class, this does
+ // not create add the infobar to |infobar_service|, since that "pointer" is
+ // really just a magic number. Thus there is no InfoBarService ownership of
+ // the returned object; and since the caller doesn't own the returned object,
+ // we rely on |test_harness| cleaning this up eventually in
+ // GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks.
+ static GoogleURLTrackerInfoBarDelegate* Create(
+ GoogleURLTrackerTest* test_harness,
+ InfoBarService* infobar_service,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& search_url);
+
+ private:
TestInfoBarDelegate(GoogleURLTrackerTest* test_harness,
InfoBarService* infobar_service,
GoogleURLTracker* google_url_tracker,
const GURL& search_url);
virtual ~TestInfoBarDelegate();
- private:
// GoogleURLTrackerInfoBarDelegate:
virtual void Update(const GURL& search_url) OVERRIDE;
virtual void Close(bool redo_search) OVERRIDE;
@@ -106,7 +118,7 @@ void TestNotificationObserver::Observe(
class GoogleURLTrackerTest : public testing::Test {
public:
// Called by TestInfoBarDelegate::Close().
- void OnInfoBarClosed(GoogleURLTrackerInfoBarDelegate* infobar,
+ void OnInfoBarClosed(InfoBarDelegate* infobar,
InfoBarService* infobar_service);
protected:
@@ -170,9 +182,8 @@ class GoogleURLTrackerTest : public testing::Test {
std::set<int> unique_ids_seen_;
};
-void GoogleURLTrackerTest::OnInfoBarClosed(
- GoogleURLTrackerInfoBarDelegate* infobar,
- InfoBarService* infobar_service) {
+void GoogleURLTrackerTest::OnInfoBarClosed(InfoBarDelegate* infobar,
+ InfoBarService* infobar_service) {
// First, simulate the InfoBarService firing INFOBAR_REMOVED.
InfoBarRemovedDetails removed_details(infobar, false);
GoogleURLTracker::EntryMap::const_iterator i =
@@ -185,7 +196,7 @@ void GoogleURLTrackerTest::OnInfoBarClosed(
content::Details<InfoBarRemovedDetails>(&removed_details));
// Second, simulate the infobar container closing the infobar in response.
- infobar->InfoBarClosed();
+ delete infobar;
}
GoogleURLTrackerTest::GoogleURLTrackerTest()
@@ -386,8 +397,8 @@ GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar(
InfoBarService* infobar_service,
GoogleURLTracker* google_url_tracker,
const GURL& search_url) {
- return new TestInfoBarDelegate(this, infobar_service, google_url_tracker,
- search_url);
+ return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker,
+ search_url);
}
@@ -395,6 +406,16 @@ GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar(
namespace {
+// static
+GoogleURLTrackerInfoBarDelegate* TestInfoBarDelegate::Create(
+ GoogleURLTrackerTest* test_harness,
+ InfoBarService* infobar_service,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& search_url) {
+ return new TestInfoBarDelegate(test_harness, infobar_service,
+ google_url_tracker, search_url);
+}
+
TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness,
InfoBarService* infobar_service,
GoogleURLTracker* google_url_tracker,
View
7 infobars/alternate_nav_infobar_delegate.cc
@@ -12,6 +12,13 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+// static
+void AlternateNavInfoBarDelegate::Create(InfoBarService* infobar_service,
+ const GURL& alternate_nav_url) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new AlternateNavInfoBarDelegate(infobar_service, alternate_nav_url)));
+}
+
AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate(
InfoBarService* owner,
const GURL& alternate_nav_url)
View
10 infobars/alternate_nav_infobar_delegate.h
@@ -12,15 +12,19 @@
class AlternateNavInfoBarDelegate : public InfoBarDelegate {
public:
- AlternateNavInfoBarDelegate(InfoBarService* owner,
- const GURL& alternate_nav_url);
- virtual ~AlternateNavInfoBarDelegate();
+ // Creates an alternate nav delegate and adds it to |infobar_service|.
+ static void Create(InfoBarService* infobar_service,
+ const GURL& alternate_nav_url);
string16 GetMessageTextWithOffset(size_t* link_offset) const;
string16 GetLinkText() const;
bool LinkClicked(WindowOpenDisposition disposition);
private:
+ AlternateNavInfoBarDelegate(InfoBarService* owner,
+ const GURL& alternate_nav_url);
+ virtual ~AlternateNavInfoBarDelegate();
+
// InfoBarDelegate:
virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
View
2  infobars/infobar.cc
@@ -183,7 +183,7 @@ void InfoBar::MaybeDelete() {
if (!owner_ && delegate_ && (animation_.GetCurrentValue() == 0.0)) {
if (container_)
container_->RemoveInfoBar(this);
- delegate_->InfoBarClosed();
+ delete delegate_;
delegate_ = NULL;
}
}
View
8 infobars/infobar_extension_api.cc
@@ -64,11 +64,9 @@ bool ShowInfoBarFunction::RunImpl() {
return false;
}
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(web_contents);
- infobar_service->AddInfoBar(
- new ExtensionInfoBarDelegate(browser, infobar_service,
- GetExtension(), url, height));
+ ExtensionInfoBarDelegate::Create(
+ InfoBarService::FromWebContents(web_contents), browser, GetExtension(),
+ url, height);
// TODO(finnur): Return the actual DOMWindow object. Bug 26463.
DCHECK(browser->extension_window_controller());
View
64 infobars/infobar_tab_helper.cc
@@ -60,24 +60,23 @@ void InfoBarTabHelper::SetInfoBarsEnabled(bool enabled) {
infobars_enabled_ = enabled;
}
-bool InfoBarTabHelper::AddInfoBar(InfoBarDelegate* delegate) {
- if (!infobars_enabled_) {
- delegate->InfoBarClosed();
- return false;
- }
+InfoBarDelegate* InfoBarTabHelper::AddInfoBar(
+ scoped_ptr<InfoBarDelegate> delegate) {
+ if (!infobars_enabled_)
+ return NULL;
for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end();
++i) {
- if ((*i)->EqualsDelegate(delegate)) {
- DCHECK_NE(*i, delegate);
- delegate->InfoBarClosed();
- return false;
+ if ((*i)->EqualsDelegate(delegate.get())) {
+ DCHECK_NE(*i, delegate.get());
+ return NULL;
}
}
// TODO(pkasting): Consider removing InfoBarTabHelper arg from delegate
// constructors and instead using a setter from here.
- infobars_.push_back(delegate);
+ InfoBarDelegate* delegate_ptr = delegate.release();
+ infobars_.push_back(delegate_ptr);
// Add ourselves as an observer for navigations the first time a delegate is
// added. We use this notification to expire InfoBars that need to expire on
// page transitions.
@@ -91,35 +90,37 @@ bool InfoBarTabHelper::AddInfoBar(InfoBarDelegate* delegate) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
content::Source<InfoBarService>(this),
- content::Details<InfoBarAddedDetails>(delegate));
- return true;
+ content::Details<InfoBarAddedDetails>(delegate_ptr));
+ return delegate_ptr;
}
void InfoBarTabHelper::RemoveInfoBar(InfoBarDelegate* delegate) {
RemoveInfoBarInternal(delegate, true);
}
-bool InfoBarTabHelper::ReplaceInfoBar(InfoBarDelegate* old_delegate,
- InfoBarDelegate* new_delegate) {
+InfoBarDelegate* InfoBarTabHelper::ReplaceInfoBar(
+ InfoBarDelegate* old_delegate,
+ scoped_ptr<InfoBarDelegate> new_delegate) {
if (!infobars_enabled_)
- return AddInfoBar(new_delegate); // Deletes the delegate.
+ return AddInfoBar(new_delegate.Pass()); // Deletes the delegate.
InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(),
old_delegate));
DCHECK(i != infobars_.end());
- i = infobars_.insert(i, new_delegate) + 1;
+ InfoBarDelegate* new_delegate_ptr = new_delegate.release();
+ i = infobars_.insert(i, new_delegate_ptr);
+ InfoBarReplacedDetails replaced_details(old_delegate, new_delegate_ptr);
// Remove the old delegate before notifying, so that if any observers call
// back to AddInfoBar() or similar, we don't dupe-check against this delegate.
- infobars_.erase(i);
+ infobars_.erase(++i);
old_delegate->clear_owner();
- InfoBarReplacedDetails replaced_details(old_delegate, new_delegate);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
content::Source<InfoBarService>(this),
content::Details<InfoBarReplacedDetails>(&replaced_details));
- return true;