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