From 37480ee69aed5e8a3f0ae1ff8efb518dfb2417f3 Mon Sep 17 00:00:00 2001 From: "rafaelw@chromium.org" Date: Fri, 21 May 2010 23:11:44 +0000 Subject: Prevent extensions api windows.onFocusChange from firing more than once with same windowId. For some reason (on windows, at least) BrowserList::SetLastActive seems to get called for every click in the content area of a window. This ensures that ExtensionBrowserEventRouter only fires once when the focus changes. BUG=39882 TEST=none Review URL: http://codereview.chromium.org/2076013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47970 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/extensions/extension_browser_event_router.cc | 12 ++++++++++-- chrome/browser/extensions/extension_browser_event_router.h | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index 1932552..88993b6 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -15,6 +15,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/notification_service.h" namespace events = extension_event_names; @@ -120,7 +121,8 @@ void ExtensionBrowserEventRouter::Init() { } ExtensionBrowserEventRouter::ExtensionBrowserEventRouter() - : initialized_(false) { } + : initialized_(false), + focused_window_id_(extension_misc::kUnknownWindowId) { } void ExtensionBrowserEventRouter::OnBrowserAdded(const Browser* browser) { RegisterForBrowserNotifications(browser); @@ -184,8 +186,14 @@ void ExtensionBrowserEventRouter::OnBrowserRemoving(const Browser* browser) { void ExtensionBrowserEventRouter::OnBrowserSetLastActive( const Browser* browser) { + + int window_id = ExtensionTabUtil::GetWindowId(browser); + if (focused_window_id_ == window_id) + return; + + focused_window_id_ = window_id; DispatchSimpleBrowserEvent(browser->profile(), - ExtensionTabUtil::GetWindowId(browser), + focused_window_id_, events::kOnWindowFocusedChanged); } diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h index f9b2367..089744d 100644 --- a/chrome/browser/extensions/extension_browser_event_router.h +++ b/chrome/browser/extensions/extension_browser_event_router.h @@ -140,6 +140,10 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver, std::map tab_entries_; + // The currently focused window. We keep this so as to avoid sending multiple + // windows.onFocusChanged events with the same windowId. + int focused_window_id_; + DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); }; -- cgit v1.1