Commit aeffd18e authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

Remove NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED

We're trying to kill off notifications, and this one's no
different.
Also, move the logic for notifying the location bar of
page actions being updated to ExtensionActionAPI.

BUG=406590

Review URL: https://codereview.chromium.org/496403003

Cr-Commit-Position: refs/heads/master@{#291920}
parent f830881a
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chrome/browser/extensions/active_tab_permission_granter.h" #include "chrome/browser/extensions/active_tab_permission_granter.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/extensions/extension_util.h"
...@@ -218,8 +219,10 @@ void ActiveScriptController::RequestScriptInjection( ...@@ -218,8 +219,10 @@ void ActiveScriptController::RequestScriptInjection(
// If this was the first entry, notify the location bar that there's a new // If this was the first entry, notify the location bar that there's a new
// icon. // icon.
if (list.size() == 1u) if (list.size() == 1u) {
LocationBarController::NotifyChange(web_contents()); ExtensionActionAPI::Get(web_contents()->GetBrowserContext())->
NotifyPageActionsChanged(web_contents());
}
} }
void ActiveScriptController::RunPendingForExtension( void ActiveScriptController::RunPendingForExtension(
...@@ -261,7 +264,8 @@ void ActiveScriptController::RunPendingForExtension( ...@@ -261,7 +264,8 @@ void ActiveScriptController::RunPendingForExtension(
} }
// Inform the location bar that the action is now gone. // Inform the location bar that the action is now gone.
LocationBarController::NotifyChange(web_contents()); ExtensionActionAPI::Get(web_contents()->GetBrowserContext())->
NotifyPageActionsChanged(web_contents());
} }
void ActiveScriptController::OnRequestScriptInjectionPermission( void ActiveScriptController::OnRequestScriptInjectionPermission(
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h" #include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/api/extension_action/action_info.h" #include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
...@@ -231,6 +234,26 @@ scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { ...@@ -231,6 +234,26 @@ scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) {
} // namespace } // namespace
//
// ExtensionActionAPI::Observer
//
void ExtensionActionAPI::Observer::OnExtensionActionUpdated(
ExtensionAction* extension_action,
content::WebContents* web_contents,
content::BrowserContext* browser_context) {
}
void ExtensionActionAPI::Observer::OnPageActionsUpdated(
content::WebContents* web_contents) {
}
void ExtensionActionAPI::Observer::OnExtensionActionAPIShuttingDown() {
}
ExtensionActionAPI::Observer::~Observer() {
}
// //
// ExtensionActionAPI // ExtensionActionAPI
// //
...@@ -371,6 +394,9 @@ void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, ...@@ -371,6 +394,9 @@ void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action,
Observer, Observer,
observers_, observers_,
OnExtensionActionUpdated(extension_action, web_contents, context)); OnExtensionActionUpdated(extension_action, web_contents, context));
if (extension_action->action_type() == ActionInfo::TYPE_PAGE)
NotifyPageActionsChanged(web_contents);
} }
void ExtensionActionAPI::ClearAllValuesForTab( void ExtensionActionAPI::ClearAllValuesForTab(
...@@ -441,6 +467,20 @@ void ExtensionActionAPI::ExtensionActionExecuted( ...@@ -441,6 +467,20 @@ void ExtensionActionAPI::ExtensionActionExecuted(
} }
} }
void ExtensionActionAPI::NotifyPageActionsChanged(
content::WebContents* web_contents) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser)
return;
LocationBar* location_bar =
browser->window() ? browser->window()->GetLocationBar() : NULL;
if (!location_bar)
return;
location_bar->UpdatePageActions();
FOR_EACH_OBSERVER(Observer, observers_, OnPageActionsUpdated(web_contents));
}
void ExtensionActionAPI::Shutdown() { void ExtensionActionAPI::Shutdown() {
FOR_EACH_OBSERVER(Observer, observers_, OnExtensionActionAPIShuttingDown()); FOR_EACH_OBSERVER(Observer, observers_, OnExtensionActionAPIShuttingDown());
} }
......
...@@ -44,14 +44,18 @@ class ExtensionActionAPI : public BrowserContextKeyedAPI { ...@@ -44,14 +44,18 @@ class ExtensionActionAPI : public BrowserContextKeyedAPI {
virtual void OnExtensionActionUpdated( virtual void OnExtensionActionUpdated(
ExtensionAction* extension_action, ExtensionAction* extension_action,
content::WebContents* web_contents, content::WebContents* web_contents,
content::BrowserContext* browser_context) = 0; content::BrowserContext* browser_context);
// Called when the page actions have been refreshed do to a possible change
// in count or visibility.
virtual void OnPageActionsUpdated(content::WebContents* web_contents);
// Called when the ExtensionActionAPI is shutting down, giving observers a // Called when the ExtensionActionAPI is shutting down, giving observers a
// chance to unregister themselves if there is not a definitive lifecycle. // chance to unregister themselves if there is not a definitive lifecycle.
virtual void OnExtensionActionAPIShuttingDown() {} virtual void OnExtensionActionAPIShuttingDown();
protected: protected:
virtual ~Observer() {} virtual ~Observer();
}; };
explicit ExtensionActionAPI(content::BrowserContext* context); explicit ExtensionActionAPI(content::BrowserContext* context);
...@@ -83,14 +87,19 @@ class ExtensionActionAPI : public BrowserContextKeyedAPI { ...@@ -83,14 +87,19 @@ class ExtensionActionAPI : public BrowserContextKeyedAPI {
Browser* browser, Browser* browser,
bool grant_active_tab_permissions); bool grant_active_tab_permissions);
// Notifies that there has been a change in the given |extension_action|.
void NotifyChange(ExtensionAction* extension_action, void NotifyChange(ExtensionAction* extension_action,
content::WebContents* web_contents, content::WebContents* web_contents,
content::BrowserContext* browser_context); content::BrowserContext* browser_context);
// Clears the values for all ExtensionActions for the tab associated with the // Clears the values for all ExtensionActions for the tab associated with the
// given |web_contents|. // given |web_contents| (and signals that page actions changed).
void ClearAllValuesForTab(content::WebContents* web_contents); void ClearAllValuesForTab(content::WebContents* web_contents);
// Notifies that the current set of page actions for |web_contents| has
// changed, and signals the browser to update.
void NotifyPageActionsChanged(content::WebContents* web_contents);
private: private:
friend class BrowserContextKeyedAPIFactory<ExtensionActionAPI>; friend class BrowserContextKeyedAPIFactory<ExtensionActionAPI>;
......
...@@ -21,11 +21,12 @@ using extensions::Extension; ...@@ -21,11 +21,12 @@ using extensions::Extension;
namespace { namespace {
bool HasExtensionPageActionVisibilityReachedTarget( // A callback that returns true if the condition has been met and takes no
LocationBarTesting* location_bar, // arguments.
int target_visible_page_action_count) { typedef base::Callback<bool(void)> ConditionCallback;
VLOG(1) << "Number of visible page actions: "
<< location_bar->PageActionVisibleCount(); bool HasPageActionVisibilityReachedTarget(
LocationBarTesting* location_bar, int target_visible_page_action_count) {
return location_bar->PageActionVisibleCount() == return location_bar->PageActionVisibleCount() ==
target_visible_page_action_count; target_visible_page_action_count;
} }
...@@ -42,7 +43,13 @@ bool HaveAllExtensionRenderViewHostsFinishedLoading( ...@@ -42,7 +43,13 @@ bool HaveAllExtensionRenderViewHostsFinishedLoading(
return true; return true;
} }
class NotificationSet : public content::NotificationObserver { } // namespace
////////////////////////////////////////////////////////////////////////////////
// ExtensionTestNotificationObserver::NotificationSet
class ExtensionTestNotificationObserver::NotificationSet
: public content::NotificationObserver {
public: public:
void Add(int type, const content::NotificationSource& source); void Add(int type, const content::NotificationSource& source);
void Add(int type); void Add(int type);
...@@ -63,52 +70,25 @@ class NotificationSet : public content::NotificationObserver { ...@@ -63,52 +70,25 @@ class NotificationSet : public content::NotificationObserver {
base::CallbackList<void()> callback_list_; base::CallbackList<void()> callback_list_;
}; };
void NotificationSet::Add( void ExtensionTestNotificationObserver::NotificationSet::Add(
int type, int type,
const content::NotificationSource& source) { const content::NotificationSource& source) {
notification_registrar_.Add(this, type, source); notification_registrar_.Add(this, type, source);
} }
void NotificationSet::Add(int type) { void ExtensionTestNotificationObserver::NotificationSet::Add(int type) {
Add(type, content::NotificationService::AllSources()); Add(type, content::NotificationService::AllSources());
} }
void NotificationSet::Observe( void ExtensionTestNotificationObserver::NotificationSet::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
callback_list_.Notify(); callback_list_.Notify();
} }
void MaybeQuit(content::MessageLoopRunner* runner, ////////////////////////////////////////////////////////////////////////////////
const base::Callback<bool(void)>& condition) { // ExtensionTestNotificationObserver
if (condition.Run())
runner->Quit();
}
void WaitForCondition(
const base::Callback<bool(void)>& condition,
NotificationSet* notification_set) {
if (condition.Run())
return;
scoped_refptr<content::MessageLoopRunner> runner(
new content::MessageLoopRunner);
scoped_ptr<base::CallbackList<void()>::Subscription> subscription =
notification_set->callback_list().Add(
base::Bind(&MaybeQuit, base::Unretained(runner.get()), condition));
runner->Run();
}
void WaitForCondition(
const base::Callback<bool(void)>& condition,
int type) {
NotificationSet notification_set;
notification_set.Add(type);
WaitForCondition(condition, &notification_set);
}
} // namespace
ExtensionTestNotificationObserver::ExtensionTestNotificationObserver( ExtensionTestNotificationObserver::ExtensionTestNotificationObserver(
Browser* browser) Browser* browser)
...@@ -147,10 +127,12 @@ bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( ...@@ -147,10 +127,12 @@ bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo(
int count) { int count) {
LocationBarTesting* location_bar = LocationBarTesting* location_bar =
browser_->window()->GetLocationBar()->GetLocationBarForTesting(); browser_->window()->GetLocationBar()->GetLocationBarForTesting();
extensions::ExtensionActionAPI::Get(GetProfile())->AddObserver(this);
WaitForCondition( WaitForCondition(
base::Bind( base::Bind(&HasPageActionVisibilityReachedTarget, location_bar, count),
&HasExtensionPageActionVisibilityReachedTarget, location_bar, count), NULL);
extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED); extensions::ExtensionActionAPI::Get(GetProfile())->
RemoveObserver(this);
return true; return true;
} }
...@@ -271,3 +253,36 @@ void ExtensionTestNotificationObserver::Observe( ...@@ -271,3 +253,36 @@ void ExtensionTestNotificationObserver::Observe(
break; break;
} }
} }
void ExtensionTestNotificationObserver::OnPageActionsUpdated(
content::WebContents* web_contents) {
MaybeQuit();
}
void ExtensionTestNotificationObserver::WaitForCondition(
const ConditionCallback& condition,
NotificationSet* notification_set) {
if (condition.Run())
return;
condition_ = condition;
scoped_refptr<content::MessageLoopRunner> runner(
new content::MessageLoopRunner);
quit_closure_ = runner->QuitClosure();
scoped_ptr<base::CallbackList<void()>::Subscription> subscription;
if (notification_set) {
subscription = notification_set->callback_list().Add(
base::Bind(&ExtensionTestNotificationObserver::MaybeQuit,
base::Unretained(this)));
}
runner->Run();
condition_.Reset();
quit_closure_.Reset();
}
void ExtensionTestNotificationObserver::MaybeQuit() {
if (condition_.Run())
quit_closure_.Run();
}
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include <string> #include <string>
#include "base/callback.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/location_bar/location_bar.h" #include "chrome/browser/ui/location_bar/location_bar.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
...@@ -20,14 +22,13 @@ class WindowedNotificationObserver; ...@@ -20,14 +22,13 @@ class WindowedNotificationObserver;
} }
// Test helper class for observing extension-related events. // Test helper class for observing extension-related events.
class ExtensionTestNotificationObserver : public content::NotificationObserver { class ExtensionTestNotificationObserver
: public content::NotificationObserver,
public extensions::ExtensionActionAPI::Observer {
public: public:
explicit ExtensionTestNotificationObserver(Browser* browser); explicit ExtensionTestNotificationObserver(Browser* browser);
virtual ~ExtensionTestNotificationObserver(); virtual ~ExtensionTestNotificationObserver();
// Wait for the total number of page actions to change to |count|.
bool WaitForPageActionCountChangeTo(int count);
// Wait for the number of visible page actions to change to |count|. // Wait for the number of visible page actions to change to |count|.
bool WaitForPageActionVisibilityChangeTo(int count); bool WaitForPageActionVisibilityChangeTo(int count);
...@@ -82,10 +83,25 @@ class ExtensionTestNotificationObserver : public content::NotificationObserver { ...@@ -82,10 +83,25 @@ class ExtensionTestNotificationObserver : public content::NotificationObserver {
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
private: private:
class NotificationSet;
Profile* GetProfile(); Profile* GetProfile();
void WaitForNotification(int notification_type); void WaitForNotification(int notification_type);
// Wait for |condition_| to be met. |notification_set| is the set of
// notifications to wait for and to check |condition| when observing. This
// can be NULL if we are instead waiting for a different observer method, like
// OnPageActionsUpdated().
void WaitForCondition(const base::Callback<bool(void)>& condition,
NotificationSet* notification_set);
// Quits the message loop if |condition_| is met.
void MaybeQuit();
// extensions::ExtensionActionAPI::Observer:
virtual void OnPageActionsUpdated(content::WebContents* contents) OVERRIDE;
Browser* browser_; Browser* browser_;
Profile* profile_; Profile* profile_;
...@@ -96,6 +112,13 @@ class ExtensionTestNotificationObserver : public content::NotificationObserver { ...@@ -96,6 +112,13 @@ class ExtensionTestNotificationObserver : public content::NotificationObserver {
int extension_installs_observed_; int extension_installs_observed_;
int extension_load_errors_observed_; int extension_load_errors_observed_;
int crx_installers_done_observed_; int crx_installers_done_observed_;
// The condition for which we are waiting. This should be checked in any
// observing methods that could trigger it.
base::Callback<bool(void)> condition_;
// The closure to quit the currently-running message loop.
base::Closure quit_closure_;
}; };
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/browser_action_test_util.h" #include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
...@@ -24,7 +23,6 @@ ...@@ -24,7 +23,6 @@
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h" #include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/test/bookmark_test_helpers.h" #include "components/bookmarks/test/bookmark_test_helpers.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
...@@ -172,9 +170,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { ...@@ -172,9 +170,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) {
// Open a tab to a URL that will trigger the page action to show. // Open a tab to a URL that will trigger the page action to show.
LazyBackgroundObserver page_complete; LazyBackgroundObserver page_complete;
content::WindowedNotificationObserver page_action_changed(
extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED,
content::NotificationService::AllSources());
ui_test_utils::NavigateToURL( ui_test_utils::NavigateToURL(
browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
page_complete.Wait(); page_complete.Wait();
...@@ -182,7 +177,7 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { ...@@ -182,7 +177,7 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) {
EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
// Page action is shown. // Page action is shown.
page_action_changed.Wait(); WaitForPageActionVisibilityChangeTo(num_page_actions + 1);
EXPECT_EQ(num_page_actions + 1, EXPECT_EQ(num_page_actions + 1,
browser()->window()->GetLocationBar()-> browser()->window()->GetLocationBar()->
GetLocationBarForTesting()->PageActionVisibleCount()); GetLocationBarForTesting()->PageActionVisibleCount());
......
...@@ -6,18 +6,12 @@ ...@@ -6,18 +6,12 @@
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/extensions/active_script_controller.h" #include "chrome/browser/extensions/active_script_controller.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/page_action_controller.h" #include "chrome/browser/extensions/page_action_controller.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/common/extensions/api/extension_action/action_info.h" #include "chrome/common/extensions/api/extension_action/action_info.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/notification_types.h"
namespace extensions { namespace extensions {
...@@ -57,23 +51,6 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { ...@@ -57,23 +51,6 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
return current_actions; return current_actions;
} }
// static
void LocationBarController::NotifyChange(content::WebContents* web_contents) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser)
return;
LocationBar* location_bar =
browser->window() ? browser->window()->GetLocationBar() : NULL;
if (!location_bar)
return;
location_bar->UpdatePageActions();
content::NotificationService::current()->Notify(
NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED,
content::Source<content::WebContents>(web_contents),
content::NotificationService::NoDetails());
}
void LocationBarController::DidNavigateMainFrame( void LocationBarController::DidNavigateMainFrame(
const content::LoadCommittedDetails& details, const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) { const content::FrameNavigateParams& params) {
...@@ -98,8 +75,10 @@ void LocationBarController::OnExtensionUnloaded( ...@@ -98,8 +75,10 @@ void LocationBarController::OnExtensionUnloaded(
should_update = true; should_update = true;
} }
if (should_update) if (should_update) {
NotifyChange(web_contents()); ExtensionActionAPI::Get(browser_context)->
NotifyPageActionsChanged(web_contents());
}
} }
} // namespace extensions } // namespace extensions
...@@ -44,8 +44,8 @@ class LocationBarController : public content::WebContentsObserver, ...@@ -44,8 +44,8 @@ class LocationBarController : public content::WebContentsObserver,
// A notification that the given |extension| has been unloaded, and any // A notification that the given |extension| has been unloaded, and any
// actions associated with it should be removed. // actions associated with it should be removed.
// The location bar controller will update itself after this if needed, so // The LocationBarController will handle notifying of page action changes,
// Providers should not call NotifyChange(). // if any.
virtual void OnExtensionUnloaded(const Extension* extension) {} virtual void OnExtensionUnloaded(const Extension* extension) {}
}; };
...@@ -55,9 +55,6 @@ class LocationBarController : public content::WebContentsObserver, ...@@ -55,9 +55,6 @@ class LocationBarController : public content::WebContentsObserver,
// Returns the actions which should be displayed in the location bar. // Returns the actions which should be displayed in the location bar.
std::vector<ExtensionAction*> GetCurrentActions(); std::vector<ExtensionAction*> GetCurrentActions();
// Notifies the window that the actions have changed.
static void NotifyChange(content::WebContents* web_contents);
ActiveScriptController* active_script_controller() { ActiveScriptController* active_script_controller() {
return active_script_controller_.get(); return active_script_controller_.get();
} }
......
...@@ -4,32 +4,14 @@ ...@@ -4,32 +4,14 @@
#include "chrome/browser/extensions/page_action_controller.h" #include "chrome/browser/extensions/page_action_controller.h"
#include <set>
#include "base/lazy_instance.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_set.h"
namespace extensions { namespace extensions {
// Keeps track of the profiles for which we've sent UMA statistics.
base::LazyInstance<std::set<Profile*> > g_reported_for_profiles =
LAZY_INSTANCE_INITIALIZER;
PageActionController::PageActionController(content::WebContents* web_contents) PageActionController::PageActionController(content::WebContents* web_contents)
: web_contents_(web_contents), : web_contents_(web_contents),
extension_action_observer_(this) { browser_context_(web_contents_->GetBrowserContext()) {
extension_action_observer_.Add(
ExtensionActionAPI::Get(web_contents_->GetBrowserContext()));
} }
PageActionController::~PageActionController() { PageActionController::~PageActionController() {
...@@ -37,7 +19,8 @@ PageActionController::~PageActionController() { ...@@ -37,7 +19,8 @@ PageActionController::~PageActionController() {
ExtensionAction* PageActionController::GetActionForExtension( ExtensionAction* PageActionController::GetActionForExtension(
const Extension* extension) { const Extension* extension) {
return ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); return ExtensionActionManager::Get(browser_context_)->GetPageAction(
*extension);
} }
void PageActionController::OnNavigated() { void PageActionController::OnNavigated() {
...@@ -45,17 +28,4 @@ void PageActionController::OnNavigated() { ...@@ -45,17 +28,4 @@ void PageActionController::OnNavigated() {
// do here. // do here.
} }
void PageActionController::OnExtensionActionUpdated(
ExtensionAction* extension_action,
content::WebContents* web_contents,
content::BrowserContext* browser_context) {
if (web_contents == web_contents_ &&
extension_action->action_type() == ActionInfo::TYPE_PAGE)
LocationBarController::NotifyChange(web_contents_);
}
Profile* PageActionController::GetProfile() {
return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
}
} // namespace extensions } // namespace extensions
...@@ -5,21 +5,21 @@ ...@@ -5,21 +5,21 @@
#ifndef CHROME_BROWSER_EXTENSIONS_PAGE_ACTION_CONTROLLER_H_ #ifndef CHROME_BROWSER_EXTENSIONS_PAGE_ACTION_CONTROLLER_H_
#define CHROME_BROWSER_EXTENSIONS_PAGE_ACTION_CONTROLLER_H_ #define CHROME_BROWSER_EXTENSIONS_PAGE_ACTION_CONTROLLER_H_
#include <string> #include "base/macros.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/location_bar_controller.h" #include "chrome/browser/extensions/location_bar_controller.h"
class Profile; namespace content {
class BrowserContext;
class WebContents;
}
namespace extensions { namespace extensions {
class ExtensionRegistry; class Extension;
// A LocationBarControllerProvider which populates the location bar with icons // A LocationBarControllerProvider which populates the location bar with icons
// based on the page_action extension API. // based on the page_action extension API.
// TODO(rdevlin.cronin): This isn't really a controller. // TODO(rdevlin.cronin): This isn't really a controller.
class PageActionController : public LocationBarController::ActionProvider, class PageActionController : public LocationBarController::ActionProvider {
public ExtensionActionAPI::Observer {
public: public:
explicit PageActionController(content::WebContents* web_contents); explicit PageActionController(content::WebContents* web_contents);
virtual ~PageActionController(); virtual ~PageActionController();
...@@ -30,20 +30,11 @@ class PageActionController : public LocationBarController::ActionProvider, ...@@ -30,20 +30,11 @@ class PageActionController : public LocationBarController::ActionProvider,
virtual void OnNavigated() OVERRIDE; virtual void OnNavigated() OVERRIDE;
private: private:
// ExtensionActionAPI::Observer implementation.
virtual void OnExtensionActionUpdated(
ExtensionAction* extension_action,
content::WebContents* web_contents,
content::BrowserContext* browser_context) OVERRIDE;
// Returns the associated Profile.
Profile* GetProfile();
// The associated WebContents. // The associated WebContents.
content::WebContents* web_contents_; content::WebContents* web_contents_;
ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer> // The associated browser context.
extension_action_observer_; content::BrowserContext* browser_context_;
DISALLOW_COPY_AND_ASSIGN(PageActionController); DISALLOW_COPY_AND_ASSIGN(PageActionController);
}; };
......
...@@ -143,10 +143,6 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, ...@@ -143,10 +143,6 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
new ContentSettingDecoration(type, this, profile)); new ContentSettingDecoration(type, this, profile));
} }
registrar_.Add(
this,
extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED,
content::NotificationService::AllSources());
content::Source<Profile> profile_source = content::Source<Profile>(profile); content::Source<Profile> profile_source = content::Source<Profile>(profile);
registrar_.Add(this, registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
...@@ -227,6 +223,9 @@ void LocationBarViewMac::UpdateManagePasswordsIconAndBubble() { ...@@ -227,6 +223,9 @@ void LocationBarViewMac::UpdateManagePasswordsIconAndBubble() {
void LocationBarViewMac::UpdatePageActions() { void LocationBarViewMac::UpdatePageActions() {
RefreshPageActionDecorations(); RefreshPageActionDecorations();
Layout(); Layout();
[field_ updateMouseTracking];
[field_ setNeedsDisplay:YES];
} }
void LocationBarViewMac::InvalidatePageActions() { void LocationBarViewMac::InvalidatePageActions() {
...@@ -624,25 +623,10 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { ...@@ -624,25 +623,10 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
void LocationBarViewMac::Observe(int type, void LocationBarViewMac::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { DCHECK(type == extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED ||
case extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED: { type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
if (content::Source<WebContents>(source).ptr() != GetWebContents())
return;
[field_ updateMouseTracking];
[field_ setNeedsDisplay:YES];
break;
}
case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
Update(NULL);
break;
default: Update(NULL);
NOTREACHED() << "Unexpected notification";
break;
}
} }
void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state, void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state,
......
...@@ -126,10 +126,6 @@ enum NotificationType { ...@@ -126,10 +126,6 @@ enum NotificationType {
// extension's ID. // extension's ID.
NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
// Sent when the page actions have been updated. The source is a WebContents*,
// and there are no details.
NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED,
// Sent when an extension command has been removed. The source is the // Sent when an extension command has been removed. The source is the
// BrowserContext* and the details is a std::pair of two std::string objects // BrowserContext* and the details is a std::pair of two std::string objects
// (an extension ID and the name of the command being removed). // (an extension ID and the name of the command being removed).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment