summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 23:11:44 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 23:11:44 +0000
commit37480ee69aed5e8a3f0ae1ff8efb518dfb2417f3 (patch)
tree5585dd6d6ca68fdee84a91644bee02a7df8bfc5a /chrome
parent9807f1fe18b7680c91bcd8c56a0135ed3a7cc83f (diff)
downloadchromium_src-37480ee69aed5e8a3f0ae1ff8efb518dfb2417f3.zip
chromium_src-37480ee69aed5e8a3f0ae1ff8efb518dfb2417f3.tar.gz
chromium_src-37480ee69aed5e8a3f0ae1ff8efb518dfb2417f3.tar.bz2
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
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc12
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h4
2 files changed, 14 insertions, 2 deletions
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<int, TabEntry> 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);
};