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/api/tabs/app_base_window.h" | 9 #include "chrome/browser/extensions/api/tabs/app_base_window.h" |
10 #include "chrome/browser/extensions/api/tabs/app_window_controller.h" | 10 #include "chrome/browser/extensions/api/tabs/app_window_controller.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 const content::NotificationDetails& details) { | 131 const content::NotificationDetails& details) { |
132 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
133 if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { | 133 if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { |
134 OnActiveWindowChanged(nullptr); | 134 OnActiveWindowChanged(nullptr); |
135 return; | 135 return; |
136 } | 136 } |
137 #endif | 137 #endif |
138 } | 138 } |
139 | 139 |
140 static bool WillDispatchWindowFocusedEvent( | 140 static bool WillDispatchWindowFocusedEvent( |
141 BrowserContext* new_active_context, | 141 WindowController* window_controller, |
142 int window_id, | |
143 BrowserContext* context, | 142 BrowserContext* context, |
144 const Extension* extension, | 143 const Extension* extension, |
145 base::ListValue* event_args, | 144 base::ListValue* event_args, |
146 const base::DictionaryValue* listener_filter) { | 145 const base::DictionaryValue* listener_filter) { |
| 146 int window_id = window_controller ? window_controller->GetWindowId() |
| 147 : extension_misc::kUnknownWindowId; |
| 148 Profile* new_active_context = |
| 149 window_controller ? window_controller->profile() : nullptr; |
| 150 |
147 // When switching between windows in the default and incognito profiles, | 151 // When switching between windows in the default and incognito profiles, |
148 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that | 152 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that |
149 // can't see the new focused window across the incognito boundary. | 153 // can't see the new focused window across the incognito boundary. |
150 // See crbug.com/46610. | 154 // See crbug.com/46610. |
151 if (new_active_context && new_active_context != context && | 155 if (new_active_context && new_active_context != context && |
152 !util::CanCrossIncognito(extension, context)) { | 156 !util::CanCrossIncognito(extension, context)) { |
153 event_args->Clear(); | 157 event_args->Clear(); |
154 event_args->Append(new base::FundamentalValue( | 158 event_args->Append(new base::FundamentalValue( |
155 extension_misc::kUnknownWindowId)); | 159 extension_misc::kUnknownWindowId)); |
156 } else { | 160 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
178 focused_profile_ = window_profile; | 182 focused_profile_ = window_profile; |
179 focused_window_id_ = window_id; | 183 focused_window_id_ = window_id; |
180 | 184 |
181 if (!HasEventListener(windows::OnFocusChanged::kEventName)) | 185 if (!HasEventListener(windows::OnFocusChanged::kEventName)) |
182 return; | 186 return; |
183 | 187 |
184 scoped_ptr<Event> event(new Event(events::WINDOWS_ON_FOCUS_CHANGED, | 188 scoped_ptr<Event> event(new Event(events::WINDOWS_ON_FOCUS_CHANGED, |
185 windows::OnFocusChanged::kEventName, | 189 windows::OnFocusChanged::kEventName, |
186 make_scoped_ptr(new base::ListValue()))); | 190 make_scoped_ptr(new base::ListValue()))); |
187 event->will_dispatch_callback = | 191 event->will_dispatch_callback = |
188 base::Bind(&WillDispatchWindowFocusedEvent, | 192 base::Bind(&WillDispatchWindowFocusedEvent, window_controller); |
189 static_cast<BrowserContext*>(window_profile), | 193 // Set the window type to 'normal' if we don't have a window |
190 window_id); | 194 // controller, so the event is not filtered. |
| 195 event->filter_info.SetWindowType(window_controller |
| 196 ? window_controller->GetWindowTypeText() |
| 197 : keys::kWindowTypeValueNormal); |
191 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 198 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
192 } | 199 } |
193 | 200 |
194 void WindowsEventRouter::DispatchEvent(events::HistogramValue histogram_value, | 201 void WindowsEventRouter::DispatchEvent(events::HistogramValue histogram_value, |
195 const std::string& event_name, | 202 const std::string& event_name, |
196 WindowController* window_controller, | 203 WindowController* window_controller, |
197 scoped_ptr<base::ListValue> args) { | 204 scoped_ptr<base::ListValue> args) { |
198 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); | 205 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); |
199 event->restrict_to_browser_context = window_controller->profile(); | 206 event->restrict_to_browser_context = window_controller->profile(); |
| 207 event->filter_info.SetWindowType(window_controller->GetWindowTypeText()); |
200 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 208 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
201 } | 209 } |
202 | 210 |
203 bool WindowsEventRouter::HasEventListener(const std::string& event_name) { | 211 bool WindowsEventRouter::HasEventListener(const std::string& event_name) { |
204 return EventRouter::Get(profile_)->HasEventListener(event_name); | 212 return EventRouter::Get(profile_)->HasEventListener(event_name); |
205 } | 213 } |
206 | 214 |
207 void WindowsEventRouter::AddAppWindow(extensions::AppWindow* app_window) { | 215 void WindowsEventRouter::AddAppWindow(extensions::AppWindow* app_window) { |
208 scoped_ptr<AppWindowController> controller(new AppWindowController( | 216 scoped_ptr<AppWindowController> controller(new AppWindowController( |
209 app_window, make_scoped_ptr(new AppBaseWindow(app_window)), profile_)); | 217 app_window, make_scoped_ptr(new AppBaseWindow(app_window)), profile_)); |
210 app_windows_.set(app_window->session_id().id(), controller.Pass()); | 218 app_windows_.set(app_window->session_id().id(), controller.Pass()); |
211 } | 219 } |
212 | 220 |
213 } // namespace extensions | 221 } // namespace extensions |
OLD | NEW |