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" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 namespace windows = extensions::api::windows; | 24 namespace windows = extensions::api::windows; |
25 | 25 |
26 WindowsEventRouter::WindowsEventRouter(Profile* profile) | 26 WindowsEventRouter::WindowsEventRouter(Profile* profile) |
27 : profile_(profile), | 27 : profile_(profile), |
28 focused_profile_(NULL), | 28 focused_profile_(NULL), |
29 focused_window_id_(extension_misc::kUnknownWindowId) { | 29 focused_window_id_(extension_misc::kUnknownWindowId) { |
30 DCHECK(!profile->IsOffTheRecord()); | 30 DCHECK(!profile->IsOffTheRecord()); |
31 | 31 |
32 WindowControllerList::GetInstance()->AddObserver(this); | 32 WindowControllerList::GetInstance()->AddObserver(this); |
33 #if defined(TOOLKIT_VIEWS) | |
34 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); | |
35 #elif defined(OS_MACOSX) | |
36 // Needed for when no suitable window can be passed to an extension as the | 33 // Needed for when no suitable window can be passed to an extension as the |
37 // currently focused window. | 34 // currently focused window. On Mac (event in a toolkit-views build) always |
not at google - send to devlin
2014/12/12 16:37:22
event -> even?
tapted
2014/12/15 22:20:45
Whoops - Done.
| |
35 // rely on the notification sent by AppControllerMac after AppKit sends | |
36 // NSWindowDidBecomeKeyNotification and there is no [NSApp keyWindow]. This | |
37 // allows windows not created by toolkit-views to be tracked. | |
38 // TODO(tapted): Remove the ifdefs (and NOTIFICATION_NO_KEY_WINDOW) when | |
39 // Chrome on Mac only makes windows with toolkit-views. | |
40 #if defined(OS_MACOSX) | |
38 registrar_.Add(this, chrome::NOTIFICATION_NO_KEY_WINDOW, | 41 registrar_.Add(this, chrome::NOTIFICATION_NO_KEY_WINDOW, |
39 content::NotificationService::AllSources()); | 42 content::NotificationService::AllSources()); |
43 #elif defined(TOOLKIT_VIEWS) | |
44 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); | |
45 #else | |
46 #error Unsupported | |
40 #endif | 47 #endif |
41 } | 48 } |
42 | 49 |
43 WindowsEventRouter::~WindowsEventRouter() { | 50 WindowsEventRouter::~WindowsEventRouter() { |
44 WindowControllerList::GetInstance()->RemoveObserver(this); | 51 WindowControllerList::GetInstance()->RemoveObserver(this); |
45 #if defined(TOOLKIT_VIEWS) | 52 #if !defined(OS_MACOSX) |
46 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 53 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
47 #endif | 54 #endif |
48 } | 55 } |
49 | 56 |
50 void WindowsEventRouter::OnWindowControllerAdded( | 57 void WindowsEventRouter::OnWindowControllerAdded( |
51 WindowController* window_controller) { | 58 WindowController* window_controller) { |
52 if (!profile_->IsSameProfile(window_controller->profile())) | 59 if (!profile_->IsSameProfile(window_controller->profile())) |
53 return; | 60 return; |
54 | 61 |
55 scoped_ptr<base::ListValue> args(new base::ListValue()); | 62 scoped_ptr<base::ListValue> args(new base::ListValue()); |
(...skipping 10 matching lines...) Expand all Loading... | |
66 return; | 73 return; |
67 | 74 |
68 int window_id = window_controller->GetWindowId(); | 75 int window_id = window_controller->GetWindowId(); |
69 scoped_ptr<base::ListValue> args(new base::ListValue()); | 76 scoped_ptr<base::ListValue> args(new base::ListValue()); |
70 args->Append(new base::FundamentalValue(window_id)); | 77 args->Append(new base::FundamentalValue(window_id)); |
71 DispatchEvent(windows::OnRemoved::kEventName, | 78 DispatchEvent(windows::OnRemoved::kEventName, |
72 window_controller->profile(), | 79 window_controller->profile(), |
73 args.Pass()); | 80 args.Pass()); |
74 } | 81 } |
75 | 82 |
76 #if defined(TOOLKIT_VIEWS) | 83 #if !defined(OS_MACOSX) |
77 void WindowsEventRouter::OnNativeFocusChange( | 84 void WindowsEventRouter::OnNativeFocusChange( |
78 gfx::NativeView focused_before, | 85 gfx::NativeView focused_before, |
79 gfx::NativeView focused_now) { | 86 gfx::NativeView focused_now) { |
80 if (!focused_now) | 87 if (!focused_now) |
81 OnActiveWindowChanged(NULL); | 88 OnActiveWindowChanged(NULL); |
82 } | 89 } |
83 #endif | 90 #endif |
84 | 91 |
85 void WindowsEventRouter::Observe( | 92 void WindowsEventRouter::Observe( |
86 int type, | 93 int type, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 150 |
144 void WindowsEventRouter::DispatchEvent(const std::string& event_name, | 151 void WindowsEventRouter::DispatchEvent(const std::string& event_name, |
145 Profile* profile, | 152 Profile* profile, |
146 scoped_ptr<base::ListValue> args) { | 153 scoped_ptr<base::ListValue> args) { |
147 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 154 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
148 event->restrict_to_browser_context = profile; | 155 event->restrict_to_browser_context = profile; |
149 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 156 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); |
150 } | 157 } |
151 | 158 |
152 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |