| 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 <utility> |
| 8 |
| 7 #include "base/values.h" | 9 #include "base/values.h" |
| 8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/api/tabs/app_base_window.h" | 12 #include "chrome/browser/extensions/api/tabs/app_base_window.h" |
| 11 #include "chrome/browser/extensions/api/tabs/app_window_controller.h" | 13 #include "chrome/browser/extensions/api/tabs/app_window_controller.h" |
| 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 14 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 13 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 15 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
| 16 #include "chrome/browser/extensions/window_controller.h" | 18 #include "chrome/browser/extensions/window_controller.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 if (!HasEventListener(windows::OnCreated::kEventName)) | 192 if (!HasEventListener(windows::OnCreated::kEventName)) |
| 191 return; | 193 return; |
| 192 if (!profile_->IsSameProfile(window_controller->profile())) | 194 if (!profile_->IsSameProfile(window_controller->profile())) |
| 193 return; | 195 return; |
| 194 | 196 |
| 195 scoped_ptr<base::ListValue> args(new base::ListValue()); | 197 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 196 base::DictionaryValue* window_dictionary = | 198 base::DictionaryValue* window_dictionary = |
| 197 window_controller->CreateWindowValue(); | 199 window_controller->CreateWindowValue(); |
| 198 args->Append(window_dictionary); | 200 args->Append(window_dictionary); |
| 199 DispatchEvent(events::WINDOWS_ON_CREATED, windows::OnCreated::kEventName, | 201 DispatchEvent(events::WINDOWS_ON_CREATED, windows::OnCreated::kEventName, |
| 200 window_controller, args.Pass()); | 202 window_controller, std::move(args)); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void WindowsEventRouter::OnWindowControllerRemoved( | 205 void WindowsEventRouter::OnWindowControllerRemoved( |
| 204 WindowController* window_controller) { | 206 WindowController* window_controller) { |
| 205 if (!HasEventListener(windows::OnRemoved::kEventName)) | 207 if (!HasEventListener(windows::OnRemoved::kEventName)) |
| 206 return; | 208 return; |
| 207 if (!profile_->IsSameProfile(window_controller->profile())) | 209 if (!profile_->IsSameProfile(window_controller->profile())) |
| 208 return; | 210 return; |
| 209 | 211 |
| 210 int window_id = window_controller->GetWindowId(); | 212 int window_id = window_controller->GetWindowId(); |
| 211 scoped_ptr<base::ListValue> args(new base::ListValue()); | 213 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 212 args->Append(new base::FundamentalValue(window_id)); | 214 args->Append(new base::FundamentalValue(window_id)); |
| 213 DispatchEvent(events::WINDOWS_ON_REMOVED, windows::OnRemoved::kEventName, | 215 DispatchEvent(events::WINDOWS_ON_REMOVED, windows::OnRemoved::kEventName, |
| 214 window_controller, args.Pass()); | 216 window_controller, std::move(args)); |
| 215 } | 217 } |
| 216 | 218 |
| 217 #if !defined(OS_MACOSX) | 219 #if !defined(OS_MACOSX) |
| 218 void WindowsEventRouter::OnNativeFocusChanged(gfx::NativeView focused_now) { | 220 void WindowsEventRouter::OnNativeFocusChanged(gfx::NativeView focused_now) { |
| 219 if (!focused_now) | 221 if (!focused_now) |
| 220 OnActiveWindowChanged(nullptr); | 222 OnActiveWindowChanged(nullptr); |
| 221 } | 223 } |
| 222 #endif | 224 #endif |
| 223 | 225 |
| 224 void WindowsEventRouter::Observe( | 226 void WindowsEventRouter::Observe( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 252 focused_window_id_ = window_id; | 254 focused_window_id_ = window_id; |
| 253 | 255 |
| 254 if (!HasEventListener(windows::OnFocusChanged::kEventName)) | 256 if (!HasEventListener(windows::OnFocusChanged::kEventName)) |
| 255 return; | 257 return; |
| 256 | 258 |
| 257 scoped_ptr<Event> event(new Event(events::WINDOWS_ON_FOCUS_CHANGED, | 259 scoped_ptr<Event> event(new Event(events::WINDOWS_ON_FOCUS_CHANGED, |
| 258 windows::OnFocusChanged::kEventName, | 260 windows::OnFocusChanged::kEventName, |
| 259 make_scoped_ptr(new base::ListValue()))); | 261 make_scoped_ptr(new base::ListValue()))); |
| 260 event->will_dispatch_callback = | 262 event->will_dispatch_callback = |
| 261 base::Bind(&WillDispatchWindowFocusedEvent, window_controller); | 263 base::Bind(&WillDispatchWindowFocusedEvent, window_controller); |
| 262 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 264 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); |
| 263 } | 265 } |
| 264 | 266 |
| 265 void WindowsEventRouter::DispatchEvent(events::HistogramValue histogram_value, | 267 void WindowsEventRouter::DispatchEvent(events::HistogramValue histogram_value, |
| 266 const std::string& event_name, | 268 const std::string& event_name, |
| 267 WindowController* window_controller, | 269 WindowController* window_controller, |
| 268 scoped_ptr<base::ListValue> args) { | 270 scoped_ptr<base::ListValue> args) { |
| 269 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); | 271 scoped_ptr<Event> event( |
| 272 new Event(histogram_value, event_name, std::move(args))); |
| 270 event->restrict_to_browser_context = window_controller->profile(); | 273 event->restrict_to_browser_context = window_controller->profile(); |
| 271 event->will_dispatch_callback = | 274 event->will_dispatch_callback = |
| 272 base::Bind(&WillDispatchWindowEvent, window_controller); | 275 base::Bind(&WillDispatchWindowEvent, window_controller); |
| 273 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 276 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); |
| 274 } | 277 } |
| 275 | 278 |
| 276 bool WindowsEventRouter::HasEventListener(const std::string& event_name) { | 279 bool WindowsEventRouter::HasEventListener(const std::string& event_name) { |
| 277 return EventRouter::Get(profile_)->HasEventListener(event_name); | 280 return EventRouter::Get(profile_)->HasEventListener(event_name); |
| 278 } | 281 } |
| 279 | 282 |
| 280 void WindowsEventRouter::AddAppWindow(extensions::AppWindow* app_window) { | 283 void WindowsEventRouter::AddAppWindow(extensions::AppWindow* app_window) { |
| 281 scoped_ptr<AppWindowController> controller(new AppWindowController( | 284 scoped_ptr<AppWindowController> controller(new AppWindowController( |
| 282 app_window, make_scoped_ptr(new AppBaseWindow(app_window)), profile_)); | 285 app_window, make_scoped_ptr(new AppBaseWindow(app_window)), profile_)); |
| 283 app_windows_[app_window->session_id().id()] = controller.Pass(); | 286 app_windows_[app_window->session_id().id()] = std::move(controller); |
| 284 } | 287 } |
| 285 | 288 |
| 286 } // namespace extensions | 289 } // namespace extensions |
| OLD | NEW |