summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions')
-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);
};