Index: chrome/browser/extensions/api/tabs/windows_event_router.cc |
diff --git a/chrome/browser/extensions/api/tabs/windows_event_router.cc b/chrome/browser/extensions/api/tabs/windows_event_router.cc |
index 31a37655aa7774922c6cee476036aecaf5a3552d..605e444fe431e7cf0c1d9ceb7c0e8656fa62a2e6 100644 |
--- a/chrome/browser/extensions/api/tabs/windows_event_router.cc |
+++ b/chrome/browser/extensions/api/tabs/windows_event_router.cc |
@@ -6,6 +6,7 @@ |
#include "base/values.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/extensions/api/tabs/app_window_controller.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/extension_util.h" |
#include "chrome/browser/extensions/window_controller.h" |
@@ -14,6 +15,7 @@ |
#include "chrome/common/extensions/api/windows.h" |
#include "chrome/common/extensions/extension_constants.h" |
#include "content/public/browser/notification_service.h" |
+#include "extensions/browser/app_window/app_window.h" |
#include "extensions/browser/event_router.h" |
#include "extensions/common/constants.h" |
@@ -26,10 +28,12 @@ namespace windows = extensions::api::windows; |
WindowsEventRouter::WindowsEventRouter(Profile* profile) |
: profile_(profile), |
focused_profile_(NULL), |
- focused_window_id_(extension_misc::kUnknownWindowId) { |
+ focused_window_id_(extension_misc::kUnknownWindowId), |
+ dispatch_events_(false) { |
DCHECK(!profile->IsOffTheRecord()); |
WindowControllerList::GetInstance()->AddObserver(this); |
+ AppWindowRegistry::Get(profile_)->AddObserver(this); |
// Needed for when no suitable window can be passed to an extension as the |
// currently focused window. On Mac (even in a toolkit-views build) always |
// rely on the notification sent by AppControllerMac after AppKit sends |
@@ -45,17 +49,41 @@ WindowsEventRouter::WindowsEventRouter(Profile* profile) |
#else |
#error Unsupported |
#endif |
+ |
+ AppWindowRegistry* registry = AppWindowRegistry::Get(profile_); |
+ for (AppWindow* app_window : registry->app_windows()) { |
+ scoped_ptr<AppWindowController> controller(new AppWindowController( |
+ app_window, make_scoped_ptr(new AppBaseWindow(app_window)), profile_)); |
+ app_windows_.set(app_window->session_id().id(), controller.Pass()); |
+ } |
} |
WindowsEventRouter::~WindowsEventRouter() { |
+ AppWindowRegistry::Get(profile_)->RemoveObserver(this); |
WindowControllerList::GetInstance()->RemoveObserver(this); |
#if !defined(OS_MACOSX) |
views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
#endif |
} |
+void WindowsEventRouter::DispatchEvents() { |
+ dispatch_events_ = true; |
+} |
+ |
+void WindowsEventRouter::OnAppWindowAdded(extensions::AppWindow* app_window) { |
+ scoped_ptr<AppWindowController> controller(new AppWindowController( |
+ app_window, make_scoped_ptr(new AppBaseWindow(app_window)), profile_)); |
+ app_windows_.set(app_window->session_id().id(), controller.Pass()); |
+} |
+ |
+void WindowsEventRouter::OnAppWindowRemoved(extensions::AppWindow* app_window) { |
+ app_windows_.erase(app_window->session_id().id()); |
+} |
+ |
void WindowsEventRouter::OnWindowControllerAdded( |
WindowController* window_controller) { |
+ if (!dispatch_events_) |
+ return; |
if (!profile_->IsSameProfile(window_controller->profile())) |
return; |
@@ -69,6 +97,8 @@ void WindowsEventRouter::OnWindowControllerAdded( |
void WindowsEventRouter::OnWindowControllerRemoved( |
WindowController* window_controller) { |
+ if (!dispatch_events_) |
+ return; |
if (!profile_->IsSameProfile(window_controller->profile())) |
return; |
@@ -82,6 +112,8 @@ void WindowsEventRouter::OnWindowControllerRemoved( |
#if !defined(OS_MACOSX) |
void WindowsEventRouter::OnNativeFocusChanged(gfx::NativeView focused_now) { |
+ if (!dispatch_events_) |
+ return; |
if (!focused_now) |
OnActiveWindowChanged(NULL); |
} |
@@ -91,6 +123,8 @@ void WindowsEventRouter::Observe( |
int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
+ if (!dispatch_events_) |
+ return; |
#if defined(OS_MACOSX) |
if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { |
OnActiveWindowChanged(NULL); |
@@ -138,6 +172,9 @@ void WindowsEventRouter::OnActiveWindowChanged( |
focused_profile_ = window_profile; |
focused_window_id_ = window_id; |
+ if (!dispatch_events_) |
+ return; |
+ |
scoped_ptr<Event> event(new Event(events::UNKNOWN, |
windows::OnFocusChanged::kEventName, |
make_scoped_ptr(new base::ListValue()))); |