Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 const content::NotificationDetails& details) { | 135 const content::NotificationDetails& details) { |
| 136 #if defined(OS_MACOSX) | 136 #if defined(OS_MACOSX) |
| 137 if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { | 137 if (chrome::NOTIFICATION_NO_KEY_WINDOW == type) { |
| 138 OnActiveWindowChanged(NULL); | 138 OnActiveWindowChanged(NULL); |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 #endif | 141 #endif |
| 142 } | 142 } |
| 143 | 143 |
| 144 static bool WillDispatchWindowFocusedEvent( | 144 static bool WillDispatchWindowFocusedEvent( |
| 145 BrowserContext* new_active_context, | 145 WindowController* window_controller, |
| 146 int window_id, | |
| 147 BrowserContext* context, | 146 BrowserContext* context, |
| 148 const Extension* extension, | 147 const Extension* extension, |
| 149 base::ListValue* event_args, | 148 base::ListValue* event_args, |
| 150 const base::DictionaryValue* listener_filter) { | 149 const base::DictionaryValue* listener_filter) { |
| 150 int window_id = window_controller ? window_controller->GetWindowId() | |
| 151 : extension_misc::kUnknownWindowId; | |
| 152 Profile* new_active_context = | |
| 153 window_controller ? window_controller->profile() : nullptr; | |
| 154 | |
| 151 // When switching between windows in the default and incognito profiles, | 155 // When switching between windows in the default and incognito profiles, |
| 152 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that | 156 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that |
| 153 // can't see the new focused window across the incognito boundary. | 157 // can't see the new focused window across the incognito boundary. |
| 154 // See crbug.com/46610. | 158 // See crbug.com/46610. |
| 155 if (new_active_context && new_active_context != context && | 159 if (new_active_context && new_active_context != context && |
| 156 !util::CanCrossIncognito(extension, context)) { | 160 !util::CanCrossIncognito(extension, context)) { |
| 157 event_args->Clear(); | 161 event_args->Clear(); |
| 158 event_args->Append(new base::FundamentalValue( | 162 event_args->Append(new base::FundamentalValue( |
| 159 extension_misc::kUnknownWindowId)); | 163 extension_misc::kUnknownWindowId)); |
| 160 } else { | 164 } else { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 182 focused_profile_ = window_profile; | 186 focused_profile_ = window_profile; |
| 183 focused_window_id_ = window_id; | 187 focused_window_id_ = window_id; |
| 184 | 188 |
| 185 if (!HasEventListener(windows::OnFocusChanged::kEventName)) | 189 if (!HasEventListener(windows::OnFocusChanged::kEventName)) |
| 186 return; | 190 return; |
| 187 | 191 |
| 188 scoped_ptr<Event> event(new Event(events::WINDOWS_ON_FOCUS_CHANGED, | 192 scoped_ptr<Event> event(new Event(events::WINDOWS_ON_FOCUS_CHANGED, |
| 189 windows::OnFocusChanged::kEventName, | 193 windows::OnFocusChanged::kEventName, |
| 190 make_scoped_ptr(new base::ListValue()))); | 194 make_scoped_ptr(new base::ListValue()))); |
| 191 event->will_dispatch_callback = | 195 event->will_dispatch_callback = |
| 192 base::Bind(&WillDispatchWindowFocusedEvent, | 196 base::Bind(&WillDispatchWindowFocusedEvent, window_controller); |
| 193 static_cast<BrowserContext*>(window_profile), | 197 |
| 194 window_id); | 198 // Set the window type to 'normal' if we don't have a window |
| 199 // controller, so the event is not filtered. | |
| 200 EventFilteringInfo info; | |
| 201 info.SetWindowType(window_controller ? window_controller->GetWindowTypeText() | |
| 202 : keys::kWindowTypeValueNormal); | |
| 203 event->filter_info = info; | |
|
stevenjb
2015/07/30 19:00:37
nit: I think this can be just: event->filter_info.
llandwerlin-old
2015/07/31 13:58:32
Done.
| |
| 204 | |
| 195 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 205 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
| 196 } | 206 } |
| 197 | 207 |
| 198 void WindowsEventRouter::DispatchEvent(events::HistogramValue histogram_value, | 208 void WindowsEventRouter::DispatchEvent(events::HistogramValue histogram_value, |
| 199 const std::string& event_name, | 209 const std::string& event_name, |
| 200 WindowController* window_controller, | 210 WindowController* window_controller, |
| 201 scoped_ptr<base::ListValue> args) { | 211 scoped_ptr<base::ListValue> args) { |
| 202 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); | 212 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); |
| 203 event->restrict_to_browser_context = window_controller->profile(); | 213 event->restrict_to_browser_context = window_controller->profile(); |
| 214 | |
| 215 EventFilteringInfo info; | |
| 216 info.SetWindowType(window_controller->GetWindowTypeText()); | |
| 217 event->filter_info = info; | |
|
stevenjb
2015/07/30 19:00:37
Same here
llandwerlin-old
2015/07/31 13:58:32
Done.
| |
| 218 | |
| 204 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 219 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
| 205 } | 220 } |
| 206 | 221 |
| 207 bool WindowsEventRouter::HasEventListener(const std::string& event_name) { | 222 bool WindowsEventRouter::HasEventListener(const std::string& event_name) { |
| 208 return EventRouter::Get(profile_)->HasEventListener(event_name); | 223 return EventRouter::Get(profile_)->HasEventListener(event_name); |
| 209 } | 224 } |
| 210 | 225 |
| 211 } // namespace extensions | 226 } // namespace extensions |
| OLD | NEW |