| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" | 5 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/extensions/window_controller.h" | 11 #include "chrome/browser/extensions/window_controller.h" |
| 12 #include "chrome/browser/extensions/window_controller_list.h" | 12 #include "chrome/browser/extensions/window_controller_list.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/extensions/api/windows.h" | 14 #include "chrome/common/extensions/api/windows.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
| 18 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 19 | 19 |
| 20 #if defined(TOOLKIT_GTK) | |
| 21 #include "ui/base/x/active_window_watcher_x.h" | |
| 22 #endif | |
| 23 | |
| 24 using content::BrowserContext; | 20 using content::BrowserContext; |
| 25 | 21 |
| 26 namespace extensions { | 22 namespace extensions { |
| 27 | 23 |
| 28 namespace windows = extensions::api::windows; | 24 namespace windows = extensions::api::windows; |
| 29 | 25 |
| 30 WindowsEventRouter::WindowsEventRouter(Profile* profile) | 26 WindowsEventRouter::WindowsEventRouter(Profile* profile) |
| 31 : profile_(profile), | 27 : profile_(profile), |
| 32 focused_profile_(NULL), | 28 focused_profile_(NULL), |
| 33 focused_window_id_(extension_misc::kUnknownWindowId) { | 29 focused_window_id_(extension_misc::kUnknownWindowId) { |
| 34 DCHECK(!profile->IsOffTheRecord()); | 30 DCHECK(!profile->IsOffTheRecord()); |
| 35 | 31 |
| 36 WindowControllerList::GetInstance()->AddObserver(this); | 32 WindowControllerList::GetInstance()->AddObserver(this); |
| 37 #if defined(TOOLKIT_VIEWS) | 33 #if defined(TOOLKIT_VIEWS) |
| 38 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); | 34 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); |
| 39 #elif defined(TOOLKIT_GTK) | |
| 40 ui::ActiveWindowWatcherX::AddObserver(this); | |
| 41 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
| 42 // Needed for when no suitable window can be passed to an extension as the | 36 // Needed for when no suitable window can be passed to an extension as the |
| 43 // currently focused window. | 37 // currently focused window. |
| 44 registrar_.Add(this, chrome::NOTIFICATION_NO_KEY_WINDOW, | 38 registrar_.Add(this, chrome::NOTIFICATION_NO_KEY_WINDOW, |
| 45 content::NotificationService::AllSources()); | 39 content::NotificationService::AllSources()); |
| 46 #endif | 40 #endif |
| 47 } | 41 } |
| 48 | 42 |
| 49 WindowsEventRouter::~WindowsEventRouter() { | 43 WindowsEventRouter::~WindowsEventRouter() { |
| 50 WindowControllerList::GetInstance()->RemoveObserver(this); | 44 WindowControllerList::GetInstance()->RemoveObserver(this); |
| 51 #if defined(TOOLKIT_VIEWS) | 45 #if defined(TOOLKIT_VIEWS) |
| 52 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 46 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
| 53 #elif defined(TOOLKIT_GTK) | |
| 54 ui::ActiveWindowWatcherX::RemoveObserver(this); | |
| 55 #endif | 47 #endif |
| 56 } | 48 } |
| 57 | 49 |
| 58 void WindowsEventRouter::OnWindowControllerAdded( | 50 void WindowsEventRouter::OnWindowControllerAdded( |
| 59 WindowController* window_controller) { | 51 WindowController* window_controller) { |
| 60 if (!profile_->IsSameProfile(window_controller->profile())) | 52 if (!profile_->IsSameProfile(window_controller->profile())) |
| 61 return; | 53 return; |
| 62 | 54 |
| 63 scoped_ptr<base::ListValue> args(new base::ListValue()); | 55 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 64 base::DictionaryValue* window_dictionary = | 56 base::DictionaryValue* window_dictionary = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 81 args.Pass()); | 73 args.Pass()); |
| 82 } | 74 } |
| 83 | 75 |
| 84 #if defined(TOOLKIT_VIEWS) | 76 #if defined(TOOLKIT_VIEWS) |
| 85 void WindowsEventRouter::OnNativeFocusChange( | 77 void WindowsEventRouter::OnNativeFocusChange( |
| 86 gfx::NativeView focused_before, | 78 gfx::NativeView focused_before, |
| 87 gfx::NativeView focused_now) { | 79 gfx::NativeView focused_now) { |
| 88 if (!focused_now) | 80 if (!focused_now) |
| 89 OnActiveWindowChanged(NULL); | 81 OnActiveWindowChanged(NULL); |
| 90 } | 82 } |
| 91 #elif defined(TOOLKIT_GTK) | |
| 92 void WindowsEventRouter::ActiveWindowChanged( | |
| 93 GdkWindow* active_window) { | |
| 94 if (!active_window) | |
| 95 OnActiveWindowChanged(NULL); | |
| 96 } | |
| 97 #endif | 83 #endif |
| 98 | 84 |
| 99 void WindowsEventRouter::Observe( | 85 void WindowsEventRouter::Observe( |
| 100 int type, | 86 int type, |
| 101 const content::NotificationSource& source, | 87 const content::NotificationSource& source, |
| 102 const content::NotificationDetails& details) { | 88 const content::NotificationDetails& details) { |
| 103 #if defined(OS_MACOSX) | 89 #if defined(OS_MACOSX) |
| 104 if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { | 90 if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { |
| 105 OnActiveWindowChanged(NULL); | 91 OnActiveWindowChanged(NULL); |
| 106 return; | 92 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 143 |
| 158 void WindowsEventRouter::DispatchEvent(const std::string& event_name, | 144 void WindowsEventRouter::DispatchEvent(const std::string& event_name, |
| 159 Profile* profile, | 145 Profile* profile, |
| 160 scoped_ptr<base::ListValue> args) { | 146 scoped_ptr<base::ListValue> args) { |
| 161 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 147 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
| 162 event->restrict_to_browser_context = profile; | 148 event->restrict_to_browser_context = profile; |
| 163 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 149 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
| 164 } | 150 } |
| 165 | 151 |
| 166 } // namespace extensions | 152 } // namespace extensions |
| OLD | NEW |