From 0ba2a4cb378121906b5f3aad3ed25ff645b9e360 Mon Sep 17 00:00:00 2001 From: "rdevlin.cronin" Date: Thu, 6 Aug 2015 11:40:19 -0700 Subject: [PATCH] [Extensions UI] Have the ExtensionMessageBubble linked to a browser Right now, the ExtensionMessageBubbleController will try and find the most recently used browser if it needs to open a link. Instead, it should be linked to a particular browser, since it is shown in a single browser. This also fixes a crash where it was improperly using a developer tools window browser and trying to navigate it. BUG=515853 Review URL: https://codereview.chromium.org/1265093007 Cr-Commit-Position: refs/heads/master@{#342156} --- .../extensions/dev_mode_bubble_controller.cc | 21 ++---- .../extensions/dev_mode_bubble_controller.h | 2 +- .../extension_message_bubble_controller.cc | 41 +++++++---- .../extension_message_bubble_controller.h | 25 +++++-- ...extension_message_bubble_controller_unittest.cc | 86 ++++++++++------------ .../extensions/ntp_overridden_bubble_controller.cc | 28 +++---- .../extensions/ntp_overridden_bubble_controller.h | 5 +- .../proxy_overridden_bubble_controller.cc | 27 +++---- .../proxy_overridden_bubble_controller.h | 7 +- .../extensions/settings_api_bubble_controller.cc | 39 +++------- .../extensions/settings_api_bubble_controller.h | 5 +- .../suspicious_extension_bubble_controller.cc | 12 +-- .../suspicious_extension_bubble_controller.h | 9 +-- .../extensions/extension_message_bubble_factory.cc | 17 +++-- .../extensions/extension_message_bubble_factory.h | 6 +- chrome/browser/ui/toolbar/toolbar_actions_bar.cc | 2 +- .../ui/views/settings_api_bubble_helper_views.cc | 14 ++-- 17 files changed, 156 insertions(+), 190 deletions(-) diff --git a/chrome/browser/extensions/dev_mode_bubble_controller.cc b/chrome/browser/extensions/dev_mode_bubble_controller.cc index 7f4a3e79fe95..cbce3dbee9ea 100644 --- a/chrome/browser/extensions/dev_mode_bubble_controller.cc +++ b/chrome/browser/extensions/dev_mode_bubble_controller.cc @@ -55,15 +55,11 @@ class DevModeBubbleDelegate ExtensionMessageBubbleController::BubbleAction action) override; private: - // Our extension service. Weak, not owned by us. - ExtensionService* service_; - DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate); }; DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile) - : ExtensionMessageBubbleController::Delegate(profile), - service_(ExtensionSystem::Get(profile)->extension_service()) { + : ExtensionMessageBubbleController::Delegate(profile) { } DevModeBubbleDelegate::~DevModeBubbleDelegate() { @@ -71,7 +67,7 @@ DevModeBubbleDelegate::~DevModeBubbleDelegate() { bool DevModeBubbleDelegate::ShouldIncludeExtension( const std::string& extension_id) { - const Extension* extension = service_->GetExtensionById(extension_id, false); + const Extension* extension = service()->GetExtensionById(extension_id, false); if (!extension) return false; return (extension->location() == Manifest::UNPACKED || @@ -85,7 +81,7 @@ void DevModeBubbleDelegate::AcknowledgeExtension( void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) { for (size_t i = 0; i < list.size(); ++i) - service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); + service()->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); } base::string16 DevModeBubbleDelegate::GetTitle() const { @@ -147,21 +143,20 @@ void DevModeBubbleController::ClearProfileListForTesting() { g_shown_for_profiles.Get().clear(); } -DevModeBubbleController::DevModeBubbleController(Profile* profile) - : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), - profile), - profile_(profile) {} +DevModeBubbleController::DevModeBubbleController(Browser* browser) + : ExtensionMessageBubbleController( + new DevModeBubbleDelegate(browser->profile()), browser) {} DevModeBubbleController::~DevModeBubbleController() { } bool DevModeBubbleController::ShouldShow() { - return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && + return !g_shown_for_profiles.Get().count(profile()->GetOriginalProfile()) && !GetExtensionList().empty(); } void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { - g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); + g_shown_for_profiles.Get().insert(profile()->GetOriginalProfile()); ExtensionMessageBubbleController::Show(bubble); } diff --git a/chrome/browser/extensions/dev_mode_bubble_controller.h b/chrome/browser/extensions/dev_mode_bubble_controller.h index bda79854db1a..48246d248b6f 100644 --- a/chrome/browser/extensions/dev_mode_bubble_controller.h +++ b/chrome/browser/extensions/dev_mode_bubble_controller.h @@ -19,7 +19,7 @@ class DevModeBubbleController : public ExtensionMessageBubbleController { // used during testing. static void ClearProfileListForTesting(); - explicit DevModeBubbleController(Profile* profile); + explicit DevModeBubbleController(Browser* browser); ~DevModeBubbleController() override; // Whether the controller knows of extensions to list in the bubble. Returns diff --git a/chrome/browser/extensions/extension_message_bubble_controller.cc b/chrome/browser/extensions/extension_message_bubble_controller.cc index 278ad8ddaa28..9c2430a27153 100644 --- a/chrome/browser/extensions/extension_message_bubble_controller.cc +++ b/chrome/browser/extensions/extension_message_bubble_controller.cc @@ -18,6 +18,7 @@ #include "content/public/browser/user_metrics.h" #include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_registry.h" +#include "extensions/browser/extension_system.h" #include "grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" @@ -26,13 +27,18 @@ namespace extensions { namespace { // How many extensions to show in the bubble (max). const int kMaxExtensionsToShow = 7; + +// Whether or not to ignore the learn more link navigation for testing. +bool g_should_ignore_learn_more_for_testing = false; } //////////////////////////////////////////////////////////////////////////////// // ExtensionMessageBubbleController::Delegate ExtensionMessageBubbleController::Delegate::Delegate(Profile* profile) - : profile_(profile) { + : profile_(profile), + service_(ExtensionSystem::Get(profile)->extension_service()), + registry_(ExtensionRegistry::Get(profile)) { } ExtensionMessageBubbleController::Delegate::~Delegate() { @@ -71,10 +77,6 @@ void ExtensionMessageBubbleController::Delegate::SetBubbleInfoBeenAcknowledged( value ? new base::FundamentalValue(value) : NULL); } -Profile* ExtensionMessageBubbleController::Delegate::profile() const { - return profile_; -} - std::string ExtensionMessageBubbleController::Delegate::get_acknowledged_flag_pref_name() const { @@ -91,8 +93,9 @@ ExtensionMessageBubbleController::Delegate::set_acknowledged_flag_pref_name( // ExtensionMessageBubbleController ExtensionMessageBubbleController::ExtensionMessageBubbleController( - Delegate* delegate, Profile* profile) - : profile_(profile), + Delegate* delegate, + Browser* browser) + : browser_(browser), user_action_(ACTION_BOUNDARY), delegate_(delegate), initialized_(false), @@ -102,13 +105,17 @@ ExtensionMessageBubbleController::ExtensionMessageBubbleController( ExtensionMessageBubbleController::~ExtensionMessageBubbleController() { } +Profile* ExtensionMessageBubbleController::profile() { + return browser_->profile(); +} + std::vector ExtensionMessageBubbleController::GetExtensionList() { ExtensionIdList* list = GetOrCreateExtensionList(); if (list->empty()) return std::vector(); - ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); + ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); std::vector return_value; for (ExtensionIdList::const_iterator it = list->begin(); it != list->end(); ++it) { @@ -155,7 +162,7 @@ void ExtensionMessageBubbleController::HighlightExtensionsIfNecessary() { did_highlight_ = true; const ExtensionIdList& extension_ids = GetExtensionIdList(); DCHECK(!extension_ids.empty()); - ExtensionToolbarModel::Get(profile_)->HighlightExtensions( + ExtensionToolbarModel::Get(profile())->HighlightExtensions( extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); } } @@ -195,10 +202,8 @@ void ExtensionMessageBubbleController::OnLinkClicked() { user_action_ = ACTION_LEARN_MORE; delegate_->LogAction(ACTION_LEARN_MORE); - Browser* browser = - chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); - if (browser) { - browser->OpenURL( + if (!g_should_ignore_learn_more_for_testing) { + browser_->OpenURL( content::OpenURLParams(delegate_->GetLearnMoreUrl(), content::Referrer(), NEW_FOREGROUND_TAB, @@ -208,6 +213,12 @@ void ExtensionMessageBubbleController::OnLinkClicked() { OnClose(); } +// static +void ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( + bool should_ignore) { + g_should_ignore_learn_more_for_testing = should_ignore; +} + void ExtensionMessageBubbleController::AcknowledgeExtensions() { ExtensionIdList* list = GetOrCreateExtensionList(); for (ExtensionIdList::const_iterator it = list->begin(); @@ -218,7 +229,7 @@ void ExtensionMessageBubbleController::AcknowledgeExtensions() { ExtensionIdList* ExtensionMessageBubbleController::GetOrCreateExtensionList() { if (!initialized_) { scoped_ptr extension_set( - ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet()); + ExtensionRegistry::Get(profile())->GenerateInstalledExtensionsSet()); for (ExtensionSet::const_iterator it = extension_set->begin(); it != extension_set->end(); ++it) { std::string id = (*it)->id(); @@ -237,7 +248,7 @@ ExtensionIdList* ExtensionMessageBubbleController::GetOrCreateExtensionList() { void ExtensionMessageBubbleController::OnClose() { AcknowledgeExtensions(); if (did_highlight_) - ExtensionToolbarModel::Get(profile_)->StopHighlighting(); + ExtensionToolbarModel::Get(profile())->StopHighlighting(); } } // namespace extensions diff --git a/chrome/browser/extensions/extension_message_bubble_controller.h b/chrome/browser/extensions/extension_message_bubble_controller.h index 6d6e803f31e6..a2024a29b665 100644 --- a/chrome/browser/extensions/extension_message_bubble_controller.h +++ b/chrome/browser/extensions/extension_message_bubble_controller.h @@ -11,12 +11,13 @@ #include "extensions/common/extension.h" class Browser; +class ExtensionService; class Profile; namespace extensions { class ExtensionPrefs; -class SuspiciousExtensionBubble; +class ExtensionRegistry; class ExtensionMessageBubbleController { public: @@ -78,7 +79,9 @@ class ExtensionMessageBubbleController { bool value); protected: - Profile* profile() const; + Profile* profile() { return profile_; } + ExtensionService* service() { return service_; } + const ExtensionRegistry* registry() const { return registry_; } std::string get_acknowledged_flag_pref_name() const; void set_acknowledged_flag_pref_name(std::string pref_name); @@ -87,15 +90,24 @@ class ExtensionMessageBubbleController { // A weak pointer to the profile we are associated with. Not owned by us. Profile* profile_; + // The extension service associated with the profile. + ExtensionService* service_; + + // The extension registry associated with the profile. + ExtensionRegistry* registry_; + // Name for corresponding pref that keeps if the info the bubble contains // was acknowledged by user. std::string acknowledged_pref_name_; + + DISALLOW_COPY_AND_ASSIGN(Delegate); }; - ExtensionMessageBubbleController(Delegate* delegate, Profile* profile); + ExtensionMessageBubbleController(Delegate* delegate, Browser* browser); virtual ~ExtensionMessageBubbleController(); Delegate* delegate() const { return delegate_.get(); } + Profile* profile(); // Obtains a list of all extensions (by name) the controller knows about. std::vector GetExtensionList(); @@ -123,6 +135,9 @@ class ExtensionMessageBubbleController { virtual void OnBubbleDismiss(); virtual void OnLinkClicked(); + static void set_should_ignore_learn_more_for_testing( + bool should_ignore_learn_more); + private: // Iterate over the known extensions and acknowledge each one. void AcknowledgeExtensions(); @@ -133,8 +148,8 @@ class ExtensionMessageBubbleController { // Performs cleanup after the bubble closes. void OnClose(); - // A weak pointer to the profile we are associated with. Not owned by us. - Profile* profile_; + // A weak pointer to the Browser we are associated with. Not owned by us. + Browser* browser_; // The list of extensions found. ExtensionIdList extension_list_; diff --git a/chrome/browser/extensions/extension_message_bubble_controller_unittest.cc b/chrome/browser/extensions/extension_message_bubble_controller_unittest.cc index 2bf48259296f..b35baaead3ee 100644 --- a/chrome/browser/extensions/extension_message_bubble_controller_unittest.cc +++ b/chrome/browser/extensions/extension_message_bubble_controller_unittest.cc @@ -17,6 +17,7 @@ #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" #include "chrome/browser/extensions/test_extension_system.h" #include "chrome/common/pref_names.h" +#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/testing_profile.h" #include "content/public/test/test_browser_thread_bundle.h" #include "extensions/browser/api_test_utils.h" @@ -32,12 +33,6 @@ #include "extensions/common/value_builder.h" #include "testing/gtest/include/gtest/gtest.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#endif - namespace { const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; @@ -82,8 +77,8 @@ class TestSuspiciousExtensionBubbleController : public SuspiciousExtensionBubbleController, public TestDelegate { public: - explicit TestSuspiciousExtensionBubbleController(Profile* profile) - : SuspiciousExtensionBubbleController(profile) { + explicit TestSuspiciousExtensionBubbleController(Browser* browser) + : SuspiciousExtensionBubbleController(browser) { } void OnBubbleAction() override { @@ -107,8 +102,8 @@ class TestDevModeBubbleController : public DevModeBubbleController, public TestDelegate { public: - explicit TestDevModeBubbleController(Profile* profile) - : DevModeBubbleController(profile) { + explicit TestDevModeBubbleController(Browser* browser) + : DevModeBubbleController(browser) { } void OnBubbleAction() override { @@ -131,9 +126,9 @@ class TestDevModeBubbleController class TestSettingsApiBubbleController : public SettingsApiBubbleController, public TestDelegate { public: - TestSettingsApiBubbleController(Profile* profile, + TestSettingsApiBubbleController(Browser* browser, SettingsApiOverrideType type) - : SettingsApiBubbleController(profile, type) {} + : SettingsApiBubbleController(browser, type) {} void OnBubbleAction() override { ++action_button_callback_count_; @@ -156,8 +151,8 @@ class TestNtpOverriddenBubbleController : public NtpOverriddenBubbleController, public TestDelegate { public: - explicit TestNtpOverriddenBubbleController(Profile* profile) - : NtpOverriddenBubbleController(profile) { + explicit TestNtpOverriddenBubbleController(Browser* browser) + : NtpOverriddenBubbleController(browser) { } void OnBubbleAction() override { @@ -181,8 +176,8 @@ class TestProxyOverriddenBubbleController : public ProxyOverriddenBubbleController, public TestDelegate { public: - explicit TestProxyOverriddenBubbleController(Profile* profile) - : ProxyOverriddenBubbleController(profile) { + explicit TestProxyOverriddenBubbleController(Browser* browser) + : ProxyOverriddenBubbleController(browser) { } void OnBubbleAction() override { @@ -237,7 +232,7 @@ class FakeExtensionMessageBubble : public ExtensionMessageBubble { DISALLOW_COPY_AND_ASSIGN(FakeExtensionMessageBubble); }; -class ExtensionMessageBubbleTest : public testing::Test { +class ExtensionMessageBubbleTest : public BrowserWithTestWindowTest { public: ExtensionMessageBubbleTest() {} @@ -385,7 +380,6 @@ class ExtensionMessageBubbleTest : public testing::Test { void Init() { // The two lines of magical incantation required to get the extension // service to work inside a unit test and access the extension prefs. - profile_.reset(new TestingProfile); static_cast(ExtensionSystem::Get(profile())) ->CreateExtensionService(base::CommandLine::ForCurrentProcess(), base::FilePath(), false); @@ -393,18 +387,22 @@ class ExtensionMessageBubbleTest : public testing::Test { service_->Init(); } - ~ExtensionMessageBubbleTest() override { - // Make sure the profile is destroyed before the thread bundle. - profile_.reset(NULL); - } + ~ExtensionMessageBubbleTest() override {} void SetUp() override { + BrowserWithTestWindowTest::SetUp(); command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); + ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( + true); } - protected: - Profile* profile() { return profile_.get(); } + void TearDown() override { + ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( + false); + BrowserWithTestWindowTest::TearDown(); + } + protected: scoped_refptr CreateExtension( Manifest::Location location, const std::string& data, @@ -417,15 +415,7 @@ class ExtensionMessageBubbleTest : public testing::Test { ExtensionService* service_; private: - content::TestBrowserThreadBundle thread_bundle_; scoped_ptr command_line_; - scoped_ptr profile_; - -#if defined OS_CHROMEOS - chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; - chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; -#endif DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleTest); }; @@ -441,7 +431,7 @@ TEST_F(ExtensionMessageBubbleTest, WipeoutControllerTest) { ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); scoped_ptr controller( - new TestSuspiciousExtensionBubbleController(profile())); + new TestSuspiciousExtensionBubbleController(browser())); FakeExtensionMessageBubble bubble; bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); @@ -463,7 +453,7 @@ TEST_F(ExtensionMessageBubbleTest, WipeoutControllerTest) { EXPECT_FALSE(controller->delegate()->HasBubbleInfoBeenAcknowledged(kId1)); EXPECT_FALSE(controller->delegate()->HasBubbleInfoBeenAcknowledged(kId2)); controller.reset(new TestSuspiciousExtensionBubbleController( - profile())); + browser())); SuspiciousExtensionBubbleController::ClearProfileListForTesting(); EXPECT_TRUE(controller->ShouldShow()); suspicious_extensions = controller->GetExtensionList(); @@ -486,7 +476,7 @@ TEST_F(ExtensionMessageBubbleTest, WipeoutControllerTest) { bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); controller.reset(new TestSuspiciousExtensionBubbleController( - profile())); + browser())); SuspiciousExtensionBubbleController::ClearProfileListForTesting(); EXPECT_TRUE(controller->ShouldShow()); suspicious_extensions = controller->GetExtensionList(); @@ -514,7 +504,7 @@ TEST_F(ExtensionMessageBubbleTest, DevModeControllerTest) { ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); scoped_ptr controller( - new TestDevModeBubbleController(profile())); + new TestDevModeBubbleController(browser())); // The list will contain one enabled unpacked extension. EXPECT_TRUE(controller->ShouldShow()); @@ -544,7 +534,7 @@ TEST_F(ExtensionMessageBubbleTest, DevModeControllerTest) { bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); controller.reset(new TestDevModeBubbleController( - profile())); + browser())); DevModeBubbleController::ClearProfileListForTesting(); EXPECT_TRUE(controller->ShouldShow()); dev_mode_extensions = controller->GetExtensionList(); @@ -565,7 +555,7 @@ TEST_F(ExtensionMessageBubbleTest, DevModeControllerTest) { bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); controller.reset(new TestDevModeBubbleController( - profile())); + browser())); DevModeBubbleController::ClearProfileListForTesting(); EXPECT_TRUE(controller->ShouldShow()); dev_mode_extensions = controller->GetExtensionList(); @@ -583,7 +573,7 @@ TEST_F(ExtensionMessageBubbleTest, DevModeControllerTest) { service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); controller.reset(new TestDevModeBubbleController( - profile())); + browser())); DevModeBubbleController::ClearProfileListForTesting(); EXPECT_FALSE(controller->ShouldShow()); dev_mode_extensions = controller->GetExtensionList(); @@ -635,7 +625,7 @@ TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { scoped_ptr controller( new TestSettingsApiBubbleController( - profile(), static_cast(i))); + browser(), static_cast(i))); // The list will contain one enabled unpacked extension (ext 2). EXPECT_TRUE(controller->ShouldShow()); @@ -673,7 +663,7 @@ TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); controller.reset(new TestSettingsApiBubbleController( - profile(), static_cast(i))); + browser(), static_cast(i))); bubble.set_controller(controller.get()); controller->Show(&bubble); EXPECT_EQ(1U, controller->link_click_count()); @@ -694,7 +684,7 @@ TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); controller.reset(new TestSettingsApiBubbleController( - profile(), static_cast(i))); + browser(), static_cast(i))); EXPECT_TRUE(controller->ShouldShow()); override_extensions = controller->GetExtensionList(); EXPECT_EQ(1U, override_extensions.size()); @@ -740,7 +730,7 @@ TEST_F(ExtensionMessageBubbleTest, NtpOverriddenControllerTest) { ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); scoped_ptr controller( - new TestNtpOverriddenBubbleController(profile())); + new TestNtpOverriddenBubbleController(browser())); // The list will contain one enabled unpacked extension (ext 2). EXPECT_TRUE(controller->ShouldShow(kId2)); @@ -778,7 +768,7 @@ TEST_F(ExtensionMessageBubbleTest, NtpOverriddenControllerTest) { // Simulate clicking the learn more link to dismiss it. bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); - controller.reset(new TestNtpOverriddenBubbleController(profile())); + controller.reset(new TestNtpOverriddenBubbleController(browser())); EXPECT_TRUE(controller->ShouldShow(kId2)); bubble.set_controller(controller.get()); controller->Show(&bubble); @@ -799,7 +789,7 @@ TEST_F(ExtensionMessageBubbleTest, NtpOverriddenControllerTest) { // Do it again, but now opt to disable the extension. bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); - controller.reset(new TestNtpOverriddenBubbleController(profile())); + controller.reset(new TestNtpOverriddenBubbleController(browser())); EXPECT_TRUE(controller->ShouldShow(kId2)); override_extensions = controller->GetExtensionList(); EXPECT_EQ(1U, override_extensions.size()); @@ -868,7 +858,7 @@ TEST_F(ExtensionMessageBubbleTest, MAYBE_ProxyOverriddenControllerTest) { SetInstallTime(kId3, old_enough, prefs); scoped_ptr controller( - new TestProxyOverriddenBubbleController(profile())); + new TestProxyOverriddenBubbleController(browser())); // The second extension is too new to warn about. EXPECT_FALSE(controller->ShouldShow(kId1)); @@ -911,7 +901,7 @@ TEST_F(ExtensionMessageBubbleTest, MAYBE_ProxyOverriddenControllerTest) { // Simulate clicking the learn more link to dismiss it. bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); - controller.reset(new TestProxyOverriddenBubbleController(profile())); + controller.reset(new TestProxyOverriddenBubbleController(browser())); EXPECT_TRUE(controller->ShouldShow(kId2)); bubble.set_controller(controller.get()); controller->Show(&bubble); @@ -932,7 +922,7 @@ TEST_F(ExtensionMessageBubbleTest, MAYBE_ProxyOverriddenControllerTest) { // Do it again, but now opt to disable the extension. bubble.set_action_on_show( FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); - controller.reset(new TestProxyOverriddenBubbleController(profile())); + controller.reset(new TestProxyOverriddenBubbleController(browser())); EXPECT_TRUE(controller->ShouldShow(kId2)); override_extensions = controller->GetExtensionList(); EXPECT_EQ(1U, override_extensions.size()); diff --git a/chrome/browser/extensions/ntp_overridden_bubble_controller.cc b/chrome/browser/extensions/ntp_overridden_bubble_controller.cc index 86e437d2e1db..f982408c4d9b 100644 --- a/chrome/browser/extensions/ntp_overridden_bubble_controller.cc +++ b/chrome/browser/extensions/ntp_overridden_bubble_controller.cc @@ -7,6 +7,7 @@ #include "base/metrics/histogram.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" #include "chrome/common/url_constants.h" #include "chrome/grit/generated_resources.h" #include "extensions/browser/extension_registry.h" @@ -29,7 +30,7 @@ const char kNtpBubbleAcknowledged[] = "ack_ntp_bubble"; class NtpOverriddenBubbleDelegate : public extensions::ExtensionMessageBubbleController::Delegate { public: - NtpOverriddenBubbleDelegate(ExtensionService* service, Profile* profile); + explicit NtpOverriddenBubbleDelegate(Profile* profile); ~NtpOverriddenBubbleDelegate() override; // ExtensionMessageBubbleController::Delegate methods. @@ -55,9 +56,6 @@ class NtpOverriddenBubbleDelegate action) override; private: - // Our extension service. Weak, not owned by us. - ExtensionService* service_; - // The ID of the extension we are showing the bubble for. std::string extension_id_; @@ -65,10 +63,8 @@ class NtpOverriddenBubbleDelegate }; NtpOverriddenBubbleDelegate::NtpOverriddenBubbleDelegate( - ExtensionService* service, Profile* profile) - : extensions::ExtensionMessageBubbleController::Delegate(profile), - service_(service) { + : extensions::ExtensionMessageBubbleController::Delegate(profile) { set_acknowledged_flag_pref_name(kNtpBubbleAcknowledged); } @@ -79,10 +75,9 @@ bool NtpOverriddenBubbleDelegate::ShouldIncludeExtension( if (!extension_id_.empty() && extension_id_ != extension_id) return false; - using extensions::ExtensionRegistry; - ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); const extensions::Extension* extension = - registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); + registry()->GetExtensionById(extension_id, + extensions::ExtensionRegistry::ENABLED); if (!extension) return false; // The extension provided is no longer enabled. @@ -102,8 +97,8 @@ void NtpOverriddenBubbleDelegate::AcknowledgeExtension( void NtpOverriddenBubbleDelegate::PerformAction( const extensions::ExtensionIdList& list) { for (size_t i = 0; i < list.size(); ++i) { - service_->DisableExtension(list[i], - extensions::Extension::DISABLE_USER_ACTION); + service()->DisableExtension(list[i], + extensions::Extension::DISABLE_USER_ACTION); } } @@ -172,13 +167,10 @@ namespace extensions { //////////////////////////////////////////////////////////////////////////////// // NtpOverriddenBubbleController -NtpOverriddenBubbleController::NtpOverriddenBubbleController(Profile* profile) +NtpOverriddenBubbleController::NtpOverriddenBubbleController(Browser* browser) : ExtensionMessageBubbleController( - new NtpOverriddenBubbleDelegate( - ExtensionSystem::Get(profile)->extension_service(), - profile), - profile), - profile_(profile) {} + new NtpOverriddenBubbleDelegate(browser->profile()), + browser) {} NtpOverriddenBubbleController::~NtpOverriddenBubbleController() {} diff --git a/chrome/browser/extensions/ntp_overridden_bubble_controller.h b/chrome/browser/extensions/ntp_overridden_bubble_controller.h index 822401329d9f..4e43b856acfe 100644 --- a/chrome/browser/extensions/ntp_overridden_bubble_controller.h +++ b/chrome/browser/extensions/ntp_overridden_bubble_controller.h @@ -12,7 +12,7 @@ namespace extensions { class NtpOverriddenBubbleController : public ExtensionMessageBubbleController { public: - explicit NtpOverriddenBubbleController(Profile* profile); + explicit NtpOverriddenBubbleController(Browser* browser); ~NtpOverriddenBubbleController() override; // Whether the controller knows that we should show the bubble for extension @@ -23,9 +23,6 @@ class NtpOverriddenBubbleController : public ExtensionMessageBubbleController { bool CloseOnDeactivate() override; private: - // A weak pointer to the profile we are associated with. Not owned by us. - Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(NtpOverriddenBubbleController); }; diff --git a/chrome/browser/extensions/proxy_overridden_bubble_controller.cc b/chrome/browser/extensions/proxy_overridden_bubble_controller.cc index 0a401413c0cf..0c47a281ffd9 100644 --- a/chrome/browser/extensions/proxy_overridden_bubble_controller.cc +++ b/chrome/browser/extensions/proxy_overridden_bubble_controller.cc @@ -9,6 +9,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/settings_api_helpers.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" #include "chrome/common/url_constants.h" #include "chrome/grit/generated_resources.h" #include "extensions/browser/extension_prefs.h" @@ -34,7 +35,7 @@ const char kProxyBubbleAcknowledged[] = "ack_proxy_bubble"; class ProxyOverriddenBubbleDelegate : public ExtensionMessageBubbleController::Delegate { public: - ProxyOverriddenBubbleDelegate(ExtensionService* service, Profile* profile); + explicit ProxyOverriddenBubbleDelegate(Profile* profile); ~ProxyOverriddenBubbleDelegate() override; // ExtensionMessageBubbleController::Delegate methods. @@ -59,9 +60,6 @@ class ProxyOverriddenBubbleDelegate ExtensionMessageBubbleController::BubbleAction action) override; private: - // Our extension service. Weak, not owned by us. - ExtensionService* service_; - // The ID of the extension we are showing the bubble for. std::string extension_id_; @@ -69,10 +67,8 @@ class ProxyOverriddenBubbleDelegate }; ProxyOverriddenBubbleDelegate::ProxyOverriddenBubbleDelegate( - ExtensionService* service, Profile* profile) - : ExtensionMessageBubbleController::Delegate(profile), - service_(service) { + : ExtensionMessageBubbleController::Delegate(profile) { set_acknowledged_flag_pref_name(kProxyBubbleAcknowledged); } @@ -84,8 +80,7 @@ bool ProxyOverriddenBubbleDelegate::ShouldIncludeExtension( return false; const Extension* extension = - ExtensionRegistry::Get(profile())->enabled_extensions().GetByID( - extension_id); + registry()->enabled_extensions().GetByID(extension_id); if (!extension) return false; // The extension provided is no longer enabled. @@ -114,7 +109,7 @@ void ProxyOverriddenBubbleDelegate::AcknowledgeExtension( void ProxyOverriddenBubbleDelegate::PerformAction(const ExtensionIdList& list) { for (size_t i = 0; i < list.size(); ++i) - service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); + service()->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); } base::string16 ProxyOverriddenBubbleDelegate::GetTitle() const { @@ -129,8 +124,7 @@ base::string16 ProxyOverriddenBubbleDelegate::GetMessageBody( return l10n_util::GetStringUTF16( IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE_EXTENSION_SPECIFIC); } else { - const Extension* extension = - ExtensionRegistry::Get(profile())->GetExtensionById( + const Extension* extension = registry()->GetExtensionById( extension_id_, ExtensionRegistry::EVERYTHING); // If the bubble is about to show, the extension should certainly exist. CHECK(extension); @@ -189,13 +183,10 @@ void ProxyOverriddenBubbleDelegate::LogAction( // ProxyOverriddenBubbleController ProxyOverriddenBubbleController::ProxyOverriddenBubbleController( - Profile* profile) + Browser* browser) : ExtensionMessageBubbleController( - new ProxyOverriddenBubbleDelegate( - ExtensionSystem::Get(profile)->extension_service(), - profile), - profile), - profile_(profile) {} + new ProxyOverriddenBubbleDelegate(browser->profile()), + browser) {} ProxyOverriddenBubbleController::~ProxyOverriddenBubbleController() {} diff --git a/chrome/browser/extensions/proxy_overridden_bubble_controller.h b/chrome/browser/extensions/proxy_overridden_bubble_controller.h index 7ff8e002f7b9..8e9a90dee803 100644 --- a/chrome/browser/extensions/proxy_overridden_bubble_controller.h +++ b/chrome/browser/extensions/proxy_overridden_bubble_controller.h @@ -10,14 +10,14 @@ #include "base/macros.h" #include "chrome/browser/extensions/extension_message_bubble_controller.h" -class Profile; +class Browser; namespace extensions { class ProxyOverriddenBubbleController : public ExtensionMessageBubbleController { public: - explicit ProxyOverriddenBubbleController(Profile* profile); + explicit ProxyOverriddenBubbleController(Browser* browser); ~ProxyOverriddenBubbleController() override; // Whether the controller knows that we should show the bubble for extension @@ -28,9 +28,6 @@ class ProxyOverriddenBubbleController bool CloseOnDeactivate() override; private: - // A weak pointer to the profile we are associated with. Not owned by us. - Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(ProxyOverriddenBubbleController); }; diff --git a/chrome/browser/extensions/settings_api_bubble_controller.cc b/chrome/browser/extensions/settings_api_bubble_controller.cc index 7a4f65de773e..d5500195165c 100644 --- a/chrome/browser/extensions/settings_api_bubble_controller.cc +++ b/chrome/browser/extensions/settings_api_bubble_controller.cc @@ -9,6 +9,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/settings_api_helpers.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/startup/startup_browser_creator.h" #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h" #include "chrome/common/url_constants.h" @@ -34,9 +35,7 @@ const char kSettingsBubbleAcknowledged[] = "ack_settings_bubble"; class SettingsApiBubbleDelegate : public ExtensionMessageBubbleController::Delegate { public: - explicit SettingsApiBubbleDelegate(ExtensionService* service, - Profile* profile, - SettingsApiOverrideType type); + SettingsApiBubbleDelegate(Profile* profile, SettingsApiOverrideType type); ~SettingsApiBubbleDelegate() override; // ExtensionMessageBubbleController::Delegate methods. @@ -60,12 +59,6 @@ class SettingsApiBubbleDelegate ExtensionMessageBubbleController::BubbleAction action) override; private: - // Our extension service. Weak, not owned by us. - ExtensionService* service_; - - // A weak pointer to the profile we are associated with. Not owned by us. - Profile* profile_; - // The type of settings override this bubble will report on. This can be, for // example, a bubble to notify the user that the search engine has been // changed by an extension (or homepage/startup pages/etc). @@ -78,11 +71,9 @@ class SettingsApiBubbleDelegate }; SettingsApiBubbleDelegate::SettingsApiBubbleDelegate( - ExtensionService* service, Profile* profile, SettingsApiOverrideType type) : ExtensionMessageBubbleController::Delegate(profile), - service_(service), type_(type) { set_acknowledged_flag_pref_name(kSettingsBubbleAcknowledged); } @@ -91,9 +82,8 @@ SettingsApiBubbleDelegate::~SettingsApiBubbleDelegate() {} bool SettingsApiBubbleDelegate::ShouldIncludeExtension( const std::string& extension_id) { - ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); const Extension* extension = - registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); + registry()->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); if (!extension) return false; // The extension provided is no longer enabled. @@ -129,7 +119,7 @@ void SettingsApiBubbleDelegate::AcknowledgeExtension( void SettingsApiBubbleDelegate::PerformAction(const ExtensionIdList& list) { for (size_t i = 0; i < list.size(); ++i) { - service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); + service()->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); } } @@ -152,9 +142,8 @@ base::string16 SettingsApiBubbleDelegate::GetTitle() const { base::string16 SettingsApiBubbleDelegate::GetMessageBody( bool anchored_to_browser_action, int extension_count) const { - ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); const Extension* extension = - registry->GetExtensionById(extension_id_, ExtensionRegistry::ENABLED); + registry()->GetExtensionById(extension_id_, ExtensionRegistry::ENABLED); const SettingsOverrides* settings = extension ? SettingsOverrides::Get(extension) : NULL; if (!extension || !settings) { @@ -283,15 +272,11 @@ void SettingsApiBubbleDelegate::LogAction( // SettingsApiBubbleController SettingsApiBubbleController::SettingsApiBubbleController( - Profile* profile, + Browser* browser, SettingsApiOverrideType type) : ExtensionMessageBubbleController( - new SettingsApiBubbleDelegate( - ExtensionSystem::Get(profile)->extension_service(), - profile, - type), - profile), - profile_(profile), + new SettingsApiBubbleDelegate(browser->profile(), type), + browser), type_(type) {} SettingsApiBubbleController::~SettingsApiBubbleController() {} @@ -300,13 +285,13 @@ bool SettingsApiBubbleController::ShouldShow() { const Extension* extension = nullptr; switch (type_) { case BUBBLE_TYPE_HOME_PAGE: - extension = GetExtensionOverridingHomepage(profile_); + extension = GetExtensionOverridingHomepage(profile()); break; case BUBBLE_TYPE_SEARCH_ENGINE: - extension = GetExtensionOverridingSearchEngine(profile_); + extension = GetExtensionOverridingSearchEngine(profile()); break; case BUBBLE_TYPE_STARTUP_PAGES: - extension = GetExtensionOverridingStartupPages(profile_); + extension = GetExtensionOverridingStartupPages(profile()); break; } @@ -322,7 +307,7 @@ bool SettingsApiBubbleController::ShouldShow() { // If the browser is showing the 'Chrome crashed' infobar, it won't be showing // the startup pages, so there's no point in showing the bubble now. if (type_ == BUBBLE_TYPE_STARTUP_PAGES) - return profile_->GetLastSessionExitType() != Profile::EXIT_CRASHED; + return profile()->GetLastSessionExitType() != Profile::EXIT_CRASHED; return true; } diff --git a/chrome/browser/extensions/settings_api_bubble_controller.h b/chrome/browser/extensions/settings_api_bubble_controller.h index 42095330dc4e..6daf755b4f3a 100644 --- a/chrome/browser/extensions/settings_api_bubble_controller.h +++ b/chrome/browser/extensions/settings_api_bubble_controller.h @@ -16,7 +16,7 @@ class SettingsApiBubble; class SettingsApiBubbleController : public ExtensionMessageBubbleController { public: - SettingsApiBubbleController(Profile* profile, SettingsApiOverrideType type); + SettingsApiBubbleController(Browser* browser, SettingsApiOverrideType type); ~SettingsApiBubbleController() override; // Returns true if we should show the bubble for the extension actively @@ -27,9 +27,6 @@ class SettingsApiBubbleController : public ExtensionMessageBubbleController { bool CloseOnDeactivate() override; private: - // A weak pointer to the profile we are associated with. Not owned by us. - Profile* profile_; - // The type of settings override this bubble will report on. SettingsApiOverrideType type_; diff --git a/chrome/browser/extensions/suspicious_extension_bubble_controller.cc b/chrome/browser/extensions/suspicious_extension_bubble_controller.cc index 3f045e3dec4c..be2d2e7c36dd 100644 --- a/chrome/browser/extensions/suspicious_extension_bubble_controller.cc +++ b/chrome/browser/extensions/suspicious_extension_bubble_controller.cc @@ -59,6 +59,7 @@ class SuspiciousExtensionBubbleDelegate void LogAction( ExtensionMessageBubbleController::BubbleAction action) override; + private: DISALLOW_COPY_AND_ASSIGN(SuspiciousExtensionBubbleDelegate); }; @@ -166,22 +167,21 @@ void SuspiciousExtensionBubbleController::ClearProfileListForTesting() { } SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( - Profile* profile) + Browser* browser) : ExtensionMessageBubbleController( - new SuspiciousExtensionBubbleDelegate(profile), - profile), - profile_(profile) {} + new SuspiciousExtensionBubbleDelegate(browser->profile()), + browser) {} SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { } bool SuspiciousExtensionBubbleController::ShouldShow() { - return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && + return !g_shown_for_profiles.Get().count(profile()->GetOriginalProfile()) && !GetExtensionList().empty(); } void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) { - g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); + g_shown_for_profiles.Get().insert(profile()->GetOriginalProfile()); ExtensionMessageBubbleController::Show(bubble); } diff --git a/chrome/browser/extensions/suspicious_extension_bubble_controller.h b/chrome/browser/extensions/suspicious_extension_bubble_controller.h index 11464989a2e7..d44d2eb8d491 100644 --- a/chrome/browser/extensions/suspicious_extension_bubble_controller.h +++ b/chrome/browser/extensions/suspicious_extension_bubble_controller.h @@ -7,12 +7,10 @@ #include "chrome/browser/extensions/extension_message_bubble_controller.h" -class Profile; +class Browser; namespace extensions { -class SuspiciousExtensionBubble; - class SuspiciousExtensionBubbleController : public extensions::ExtensionMessageBubbleController { public: @@ -20,7 +18,7 @@ class SuspiciousExtensionBubbleController // used during testing. static void ClearProfileListForTesting(); - explicit SuspiciousExtensionBubbleController(Profile* profile); + explicit SuspiciousExtensionBubbleController(Browser* browser); ~SuspiciousExtensionBubbleController() override; // Whether the controller knows of extensions to list in the bubble. Returns @@ -31,9 +29,6 @@ class SuspiciousExtensionBubbleController void Show(ExtensionMessageBubble* bubble) override; private: - // A weak pointer to the profile we are associated with. Not owned by us. - Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(SuspiciousExtensionBubbleController); }; diff --git a/chrome/browser/ui/extensions/extension_message_bubble_factory.cc b/chrome/browser/ui/extensions/extension_message_bubble_factory.cc index 8e3c1e01c65e..92bf0287e88b 100644 --- a/chrome/browser/ui/extensions/extension_message_bubble_factory.cc +++ b/chrome/browser/ui/extensions/extension_message_bubble_factory.cc @@ -15,6 +15,7 @@ #include "chrome/browser/extensions/settings_api_helpers.h" #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" #include "chrome/common/channel_info.h" #include "chrome/common/chrome_switches.h" #include "components/version_info/version_info.h" @@ -86,8 +87,8 @@ bool EnableDevModeBubble() { } // namespace -ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Profile* profile) - : profile_(profile) { +ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Browser* browser) + : browser_(browser) { } ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { @@ -95,7 +96,7 @@ ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { scoped_ptr ExtensionMessageBubbleFactory::GetController() { - Profile* original_profile = profile_->GetOriginalProfile(); + Profile* original_profile = browser_->profile()->GetOriginalProfile(); std::set& profiles_evaluated = g_profiles_evaluated.Get(); bool is_initial_check = profiles_evaluated.count(original_profile) == 0; profiles_evaluated.insert(original_profile); @@ -110,7 +111,7 @@ ExtensionMessageBubbleFactory::GetController() { // way, we're not too spammy with the bubbles. if (EnableSuspiciousExtensionsBubble()) { scoped_ptr controller( - new extensions::SuspiciousExtensionBubbleController(profile_)); + new extensions::SuspiciousExtensionBubbleController(browser_)); if (controller->ShouldShow()) return controller.Pass(); } @@ -120,7 +121,7 @@ ExtensionMessageBubbleFactory::GetController() { if (is_initial_check) { scoped_ptr controller( new extensions::SettingsApiBubbleController( - profile_, extensions::BUBBLE_TYPE_STARTUP_PAGES)); + browser_, extensions::BUBBLE_TYPE_STARTUP_PAGES)); if (controller->ShouldShow()) return controller.Pass(); } @@ -130,10 +131,10 @@ ExtensionMessageBubbleFactory::GetController() { // TODO(devlin): Move the "GetExtensionOverridingProxy" part into the // proxy bubble controller. const extensions::Extension* extension = - extensions::GetExtensionOverridingProxy(profile_); + extensions::GetExtensionOverridingProxy(browser_->profile()); if (extension) { scoped_ptr controller( - new extensions::ProxyOverriddenBubbleController(profile_)); + new extensions::ProxyOverriddenBubbleController(browser_)); if (controller->ShouldShow(extension->id())) return controller.Pass(); } @@ -141,7 +142,7 @@ ExtensionMessageBubbleFactory::GetController() { if (EnableDevModeBubble()) { scoped_ptr controller( - new extensions::DevModeBubbleController(profile_)); + new extensions::DevModeBubbleController(browser_)); if (controller->ShouldShow()) return controller.Pass(); } diff --git a/chrome/browser/ui/extensions/extension_message_bubble_factory.h b/chrome/browser/ui/extensions/extension_message_bubble_factory.h index e9b0fd6d6a0c..494f7218e121 100644 --- a/chrome/browser/ui/extensions/extension_message_bubble_factory.h +++ b/chrome/browser/ui/extensions/extension_message_bubble_factory.h @@ -8,7 +8,7 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" -class Profile; +class Browser; namespace extensions { class ExtensionMessageBubbleController; @@ -19,7 +19,7 @@ class ExtensionMessageBubbleController; // running in developer mode that we want to warn the user about. class ExtensionMessageBubbleFactory { public: - explicit ExtensionMessageBubbleFactory(Profile* profile); + explicit ExtensionMessageBubbleFactory(Browser* browser); ~ExtensionMessageBubbleFactory(); // Returns the controller for the bubble that should be shown, if any. @@ -29,7 +29,7 @@ class ExtensionMessageBubbleFactory { static void set_enabled_for_tests(bool enabled); private: - Profile* profile_; + Browser* browser_; DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleFactory); }; diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar.cc b/chrome/browser/ui/toolbar/toolbar_actions_bar.cc index 573611043346..7fd4c1ee4aeb 100644 --- a/chrome/browser/ui/toolbar/toolbar_actions_bar.cc +++ b/chrome/browser/ui/toolbar/toolbar_actions_bar.cc @@ -379,7 +379,7 @@ void ToolbarActionsBar::CreateActions() { // CreateActions() can be called as part of the browser window set up, which // we need to let finish before showing the actions. scoped_ptr controller = - ExtensionMessageBubbleFactory(browser_->profile()).GetController(); + ExtensionMessageBubbleFactory(browser_).GetController(); if (controller) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, diff --git a/chrome/browser/ui/views/settings_api_bubble_helper_views.cc b/chrome/browser/ui/views/settings_api_bubble_helper_views.cc index 06bb439ba617..bac9adb31f3d 100644 --- a/chrome/browser/ui/views/settings_api_bubble_helper_views.cc +++ b/chrome/browser/ui/views/settings_api_bubble_helper_views.cc @@ -25,11 +25,11 @@ namespace extensions { namespace { void ShowSettingsApiBubble(SettingsApiOverrideType type, - Profile* profile, + Browser* browser, views::View* anchor_view, views::BubbleBorder::Arrow arrow) { scoped_ptr settings_api_bubble( - new SettingsApiBubbleController(profile, type)); + new SettingsApiBubbleController(browser, type)); if (!settings_api_bubble->ShouldShow()) return; @@ -51,7 +51,7 @@ void MaybeShowExtensionControlledHomeNotification(Browser* browser) { views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser)-> toolbar()->home_button(); ShowSettingsApiBubble(BUBBLE_TYPE_HOME_PAGE, - browser->profile(), + browser, anchor_view, views::BubbleBorder::TOP_LEFT); } @@ -66,11 +66,11 @@ void MaybeShowExtensionControlledSearchNotification( if (AutocompleteMatch::IsSearchType(match.type) && match.type != AutocompleteMatchType::SEARCH_OTHER_ENGINE) { + Browser* browser = chrome::FindBrowserWithWebContents(web_contents); ToolbarView* toolbar = - BrowserView::GetBrowserViewForBrowser( - chrome::FindBrowserWithWebContents(web_contents))->toolbar(); + BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); ShowSettingsApiBubble(BUBBLE_TYPE_SEARCH_ENGINE, - profile, + browser, toolbar->app_menu(), views::BubbleBorder::TOP_RIGHT); } @@ -101,7 +101,7 @@ void MaybeShowExtensionControlledNewTabPage( return; // Not being overridden by an extension. scoped_ptr ntp_overridden_bubble( - new NtpOverriddenBubbleController(browser->profile())); + new NtpOverriddenBubbleController(browser)); if (!ntp_overridden_bubble->ShouldShow(ntp_url.host())) return; -- 2.11.4.GIT