OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tabs_event_router.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
11 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" | 12 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" |
12 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" | 13 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" |
13 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_iterator.h" | 17 #include "chrome/browser/ui/browser_iterator.h" |
17 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 was_muted_(contents->IsAudioMuted()), | 66 was_muted_(contents->IsAudioMuted()), |
66 router_(router) {} | 67 router_(router) {} |
67 | 68 |
68 scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::UpdateLoadState() { | 69 scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::UpdateLoadState() { |
69 // The tab may go in & out of loading (for instance if iframes navigate). | 70 // The tab may go in & out of loading (for instance if iframes navigate). |
70 // We only want to respond to the first change from loading to !loading after | 71 // We only want to respond to the first change from loading to !loading after |
71 // the NavigationEntryCommitted() was fired. | 72 // the NavigationEntryCommitted() was fired. |
72 scoped_ptr<base::DictionaryValue> changed_properties( | 73 scoped_ptr<base::DictionaryValue> changed_properties( |
73 new base::DictionaryValue()); | 74 new base::DictionaryValue()); |
74 if (!complete_waiting_on_load_ || web_contents()->IsLoading()) { | 75 if (!complete_waiting_on_load_ || web_contents()->IsLoading()) { |
75 return changed_properties.Pass(); | 76 return changed_properties; |
76 } | 77 } |
77 | 78 |
78 // Send "complete" state change. | 79 // Send "complete" state change. |
79 complete_waiting_on_load_ = false; | 80 complete_waiting_on_load_ = false; |
80 changed_properties->SetString(tabs_constants::kStatusKey, | 81 changed_properties->SetString(tabs_constants::kStatusKey, |
81 tabs_constants::kStatusValueComplete); | 82 tabs_constants::kStatusValueComplete); |
82 return changed_properties.Pass(); | 83 return changed_properties; |
83 } | 84 } |
84 | 85 |
85 scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::DidNavigate() { | 86 scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::DidNavigate() { |
86 // Send "loading" state change. | 87 // Send "loading" state change. |
87 complete_waiting_on_load_ = true; | 88 complete_waiting_on_load_ = true; |
88 scoped_ptr<base::DictionaryValue> changed_properties( | 89 scoped_ptr<base::DictionaryValue> changed_properties( |
89 new base::DictionaryValue()); | 90 new base::DictionaryValue()); |
90 changed_properties->SetString(tabs_constants::kStatusKey, | 91 changed_properties->SetString(tabs_constants::kStatusKey, |
91 tabs_constants::kStatusValueLoading); | 92 tabs_constants::kStatusValueLoading); |
92 | 93 |
93 if (web_contents()->GetURL() != url_) { | 94 if (web_contents()->GetURL() != url_) { |
94 url_ = web_contents()->GetURL(); | 95 url_ = web_contents()->GetURL(); |
95 changed_properties->SetString(tabs_constants::kUrlKey, url_.spec()); | 96 changed_properties->SetString(tabs_constants::kUrlKey, url_.spec()); |
96 } | 97 } |
97 | 98 |
98 return changed_properties.Pass(); | 99 return changed_properties; |
99 } | 100 } |
100 | 101 |
101 scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::TitleChanged() { | 102 scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::TitleChanged() { |
102 scoped_ptr<base::DictionaryValue> changed_properties( | 103 scoped_ptr<base::DictionaryValue> changed_properties( |
103 new base::DictionaryValue()); | 104 new base::DictionaryValue()); |
104 changed_properties->SetString(tabs_constants::kTitleKey, | 105 changed_properties->SetString(tabs_constants::kTitleKey, |
105 web_contents()->GetTitle()); | 106 web_contents()->GetTitle()); |
106 return changed_properties.Pass(); | 107 return changed_properties; |
107 } | 108 } |
108 | 109 |
109 bool TabsEventRouter::TabEntry::SetAudible(bool new_val) { | 110 bool TabsEventRouter::TabEntry::SetAudible(bool new_val) { |
110 if (was_audible_ == new_val) | 111 if (was_audible_ == new_val) |
111 return false; | 112 return false; |
112 was_audible_ = new_val; | 113 was_audible_ = new_val; |
113 return true; | 114 return true; |
114 } | 115 } |
115 | 116 |
116 bool TabsEventRouter::TabEntry::SetMuted(bool new_val) { | 117 bool TabsEventRouter::TabEntry::SetMuted(bool new_val) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 event->event_args->Append(tab_value); | 201 event->event_args->Append(tab_value); |
201 tab_value->SetBoolean(tabs_constants::kSelectedKey, active); | 202 tab_value->SetBoolean(tabs_constants::kSelectedKey, active); |
202 return true; | 203 return true; |
203 } | 204 } |
204 | 205 |
205 void TabsEventRouter::TabCreatedAt(WebContents* contents, | 206 void TabsEventRouter::TabCreatedAt(WebContents* contents, |
206 int index, | 207 int index, |
207 bool active) { | 208 bool active) { |
208 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 209 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
209 scoped_ptr<base::ListValue> args(new base::ListValue); | 210 scoped_ptr<base::ListValue> args(new base::ListValue); |
210 scoped_ptr<Event> event(new Event(events::TABS_ON_CREATED, | 211 scoped_ptr<Event> event(new Event( |
211 tabs::OnCreated::kEventName, args.Pass())); | 212 events::TABS_ON_CREATED, tabs::OnCreated::kEventName, std::move(args))); |
212 event->restrict_to_browser_context = profile; | 213 event->restrict_to_browser_context = profile; |
213 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 214 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
214 event->will_dispatch_callback = | 215 event->will_dispatch_callback = |
215 base::Bind(&WillDispatchTabCreatedEvent, contents, active); | 216 base::Bind(&WillDispatchTabCreatedEvent, contents, active); |
216 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 217 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); |
217 | 218 |
218 RegisterForTabNotifications(contents); | 219 RegisterForTabNotifications(contents); |
219 } | 220 } |
220 | 221 |
221 void TabsEventRouter::TabInsertedAt(WebContents* contents, | 222 void TabsEventRouter::TabInsertedAt(WebContents* contents, |
222 int index, | 223 int index, |
223 bool active) { | 224 bool active) { |
224 if (!GetTabEntry(contents)) { | 225 if (!GetTabEntry(contents)) { |
225 // We've never seen this tab, send create event as long as we're not in the | 226 // We've never seen this tab, send create event as long as we're not in the |
226 // constructor. | 227 // constructor. |
(...skipping 11 matching lines...) Expand all Loading... |
238 base::DictionaryValue* object_args = new base::DictionaryValue(); | 239 base::DictionaryValue* object_args = new base::DictionaryValue(); |
239 object_args->Set(tabs_constants::kNewWindowIdKey, | 240 object_args->Set(tabs_constants::kNewWindowIdKey, |
240 new FundamentalValue( | 241 new FundamentalValue( |
241 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 242 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
242 object_args->Set(tabs_constants::kNewPositionKey, | 243 object_args->Set(tabs_constants::kNewPositionKey, |
243 new FundamentalValue(index)); | 244 new FundamentalValue(index)); |
244 args->Append(object_args); | 245 args->Append(object_args); |
245 | 246 |
246 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 247 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
247 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, | 248 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, |
248 args.Pass(), EventRouter::USER_GESTURE_UNKNOWN); | 249 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
249 } | 250 } |
250 | 251 |
251 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { | 252 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { |
252 if (!GetTabEntry(contents)) { | 253 if (!GetTabEntry(contents)) { |
253 // The tab was removed. Don't send detach event. | 254 // The tab was removed. Don't send detach event. |
254 return; | 255 return; |
255 } | 256 } |
256 | 257 |
257 scoped_ptr<base::ListValue> args(new base::ListValue); | 258 scoped_ptr<base::ListValue> args(new base::ListValue); |
258 args->Append( | 259 args->Append( |
259 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); | 260 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); |
260 | 261 |
261 base::DictionaryValue* object_args = new base::DictionaryValue(); | 262 base::DictionaryValue* object_args = new base::DictionaryValue(); |
262 object_args->Set(tabs_constants::kOldWindowIdKey, | 263 object_args->Set(tabs_constants::kOldWindowIdKey, |
263 new FundamentalValue( | 264 new FundamentalValue( |
264 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 265 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
265 object_args->Set(tabs_constants::kOldPositionKey, | 266 object_args->Set(tabs_constants::kOldPositionKey, |
266 new FundamentalValue(index)); | 267 new FundamentalValue(index)); |
267 args->Append(object_args); | 268 args->Append(object_args); |
268 | 269 |
269 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 270 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
270 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, | 271 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, |
271 args.Pass(), EventRouter::USER_GESTURE_UNKNOWN); | 272 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
272 } | 273 } |
273 | 274 |
274 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, | 275 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
275 WebContents* contents, | 276 WebContents* contents, |
276 int index) { | 277 int index) { |
277 int tab_id = ExtensionTabUtil::GetTabId(contents); | 278 int tab_id = ExtensionTabUtil::GetTabId(contents); |
278 | 279 |
279 scoped_ptr<base::ListValue> args(new base::ListValue); | 280 scoped_ptr<base::ListValue> args(new base::ListValue); |
280 args->Append(new FundamentalValue(tab_id)); | 281 args->Append(new FundamentalValue(tab_id)); |
281 | 282 |
282 base::DictionaryValue* object_args = new base::DictionaryValue(); | 283 base::DictionaryValue* object_args = new base::DictionaryValue(); |
283 object_args->SetInteger(tabs_constants::kWindowIdKey, | 284 object_args->SetInteger(tabs_constants::kWindowIdKey, |
284 ExtensionTabUtil::GetWindowIdOfTab(contents)); | 285 ExtensionTabUtil::GetWindowIdOfTab(contents)); |
285 object_args->SetBoolean(tabs_constants::kWindowClosing, | 286 object_args->SetBoolean(tabs_constants::kWindowClosing, |
286 tab_strip_model->closing_all()); | 287 tab_strip_model->closing_all()); |
287 args->Append(object_args); | 288 args->Append(object_args); |
288 | 289 |
289 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 290 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
290 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName, | 291 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName, |
291 args.Pass(), EventRouter::USER_GESTURE_UNKNOWN); | 292 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
292 | 293 |
293 UnregisterForTabNotifications(contents); | 294 UnregisterForTabNotifications(contents); |
294 } | 295 } |
295 | 296 |
296 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, | 297 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, |
297 WebContents* new_contents, | 298 WebContents* new_contents, |
298 int index, | 299 int index, |
299 int reason) { | 300 int reason) { |
300 scoped_ptr<base::ListValue> args(new base::ListValue); | 301 scoped_ptr<base::ListValue> args(new base::ListValue); |
301 int tab_id = ExtensionTabUtil::GetTabId(new_contents); | 302 int tab_id = ExtensionTabUtil::GetTabId(new_contents); |
(...skipping 18 matching lines...) Expand all Loading... |
320 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); | 321 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); |
321 DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED, | 322 DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED, |
322 tabs::OnActiveChanged::kEventName, | 323 tabs::OnActiveChanged::kEventName, |
323 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); | 324 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); |
324 | 325 |
325 // The onActivated event takes one argument: {windowId, tabId}. | 326 // The onActivated event takes one argument: {windowId, tabId}. |
326 args->Remove(0, NULL); | 327 args->Remove(0, NULL); |
327 object_args->Set(tabs_constants::kTabIdKey, | 328 object_args->Set(tabs_constants::kTabIdKey, |
328 new FundamentalValue(tab_id)); | 329 new FundamentalValue(tab_id)); |
329 DispatchEvent(profile, events::TABS_ON_ACTIVATED, | 330 DispatchEvent(profile, events::TABS_ON_ACTIVATED, |
330 tabs::OnActivated::kEventName, args.Pass(), gesture); | 331 tabs::OnActivated::kEventName, std::move(args), gesture); |
331 } | 332 } |
332 | 333 |
333 void TabsEventRouter::TabSelectionChanged( | 334 void TabsEventRouter::TabSelectionChanged( |
334 TabStripModel* tab_strip_model, | 335 TabStripModel* tab_strip_model, |
335 const ui::ListSelectionModel& old_model) { | 336 const ui::ListSelectionModel& old_model) { |
336 ui::ListSelectionModel::SelectedIndices new_selection = | 337 ui::ListSelectionModel::SelectedIndices new_selection = |
337 tab_strip_model->selection_model().selected_indices(); | 338 tab_strip_model->selection_model().selected_indices(); |
338 scoped_ptr<base::ListValue> all_tabs(new base::ListValue); | 339 scoped_ptr<base::ListValue> all_tabs(new base::ListValue); |
339 | 340 |
340 for (size_t i = 0; i < new_selection.size(); ++i) { | 341 for (size_t i = 0; i < new_selection.size(); ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
357 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); | 358 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); |
358 args->Append(select_info.release()); | 359 args->Append(select_info.release()); |
359 | 360 |
360 // The onHighlighted event replaced onHighlightChanged. | 361 // The onHighlighted event replaced onHighlightChanged. |
361 Profile* profile = tab_strip_model->profile(); | 362 Profile* profile = tab_strip_model->profile(); |
362 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, | 363 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, |
363 tabs::OnHighlightChanged::kEventName, | 364 tabs::OnHighlightChanged::kEventName, |
364 scoped_ptr<base::ListValue>(args->DeepCopy()), | 365 scoped_ptr<base::ListValue>(args->DeepCopy()), |
365 EventRouter::USER_GESTURE_UNKNOWN); | 366 EventRouter::USER_GESTURE_UNKNOWN); |
366 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, | 367 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, |
367 tabs::OnHighlighted::kEventName, args.Pass(), | 368 tabs::OnHighlighted::kEventName, std::move(args), |
368 EventRouter::USER_GESTURE_UNKNOWN); | 369 EventRouter::USER_GESTURE_UNKNOWN); |
369 } | 370 } |
370 | 371 |
371 void TabsEventRouter::TabMoved(WebContents* contents, | 372 void TabsEventRouter::TabMoved(WebContents* contents, |
372 int from_index, | 373 int from_index, |
373 int to_index) { | 374 int to_index) { |
374 scoped_ptr<base::ListValue> args(new base::ListValue); | 375 scoped_ptr<base::ListValue> args(new base::ListValue); |
375 args->Append( | 376 args->Append( |
376 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); | 377 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); |
377 | 378 |
378 base::DictionaryValue* object_args = new base::DictionaryValue(); | 379 base::DictionaryValue* object_args = new base::DictionaryValue(); |
379 object_args->Set(tabs_constants::kWindowIdKey, | 380 object_args->Set(tabs_constants::kWindowIdKey, |
380 new FundamentalValue( | 381 new FundamentalValue( |
381 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 382 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
382 object_args->Set(tabs_constants::kFromIndexKey, | 383 object_args->Set(tabs_constants::kFromIndexKey, |
383 new FundamentalValue(from_index)); | 384 new FundamentalValue(from_index)); |
384 object_args->Set(tabs_constants::kToIndexKey, | 385 object_args->Set(tabs_constants::kToIndexKey, |
385 new FundamentalValue(to_index)); | 386 new FundamentalValue(to_index)); |
386 args->Append(object_args); | 387 args->Append(object_args); |
387 | 388 |
388 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 389 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
389 DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName, | 390 DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName, |
390 args.Pass(), EventRouter::USER_GESTURE_UNKNOWN); | 391 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
391 } | 392 } |
392 | 393 |
393 void TabsEventRouter::TabUpdated( | 394 void TabsEventRouter::TabUpdated( |
394 TabEntry* entry, | 395 TabEntry* entry, |
395 scoped_ptr<base::DictionaryValue> changed_properties) { | 396 scoped_ptr<base::DictionaryValue> changed_properties) { |
396 CHECK(entry->web_contents()); | 397 CHECK(entry->web_contents()); |
397 | 398 |
398 bool audible = entry->web_contents()->WasRecentlyAudible(); | 399 bool audible = entry->web_contents()->WasRecentlyAudible(); |
399 if (entry->SetAudible(audible)) { | 400 if (entry->SetAudible(audible)) { |
400 changed_properties->SetBoolean(tabs_constants::kAudibleKey, audible); | 401 changed_properties->SetBoolean(tabs_constants::kAudibleKey, audible); |
401 } | 402 } |
402 | 403 |
403 bool muted = entry->web_contents()->IsAudioMuted(); | 404 bool muted = entry->web_contents()->IsAudioMuted(); |
404 if (entry->SetMuted(muted)) { | 405 if (entry->SetMuted(muted)) { |
405 changed_properties->Set( | 406 changed_properties->Set( |
406 tabs_constants::kMutedInfoKey, | 407 tabs_constants::kMutedInfoKey, |
407 ExtensionTabUtil::CreateMutedInfo(entry->web_contents()).Pass()); | 408 ExtensionTabUtil::CreateMutedInfo(entry->web_contents())); |
408 } | 409 } |
409 | 410 |
410 if (!changed_properties->empty()) { | 411 if (!changed_properties->empty()) { |
411 DispatchTabUpdatedEvent(entry->web_contents(), changed_properties.Pass()); | 412 DispatchTabUpdatedEvent(entry->web_contents(), |
| 413 std::move(changed_properties)); |
412 } | 414 } |
413 } | 415 } |
414 | 416 |
415 void TabsEventRouter::FaviconUrlUpdated(WebContents* contents) { | 417 void TabsEventRouter::FaviconUrlUpdated(WebContents* contents) { |
416 content::NavigationEntry* entry = | 418 content::NavigationEntry* entry = |
417 contents->GetController().GetVisibleEntry(); | 419 contents->GetController().GetVisibleEntry(); |
418 if (!entry || !entry->GetFavicon().valid) | 420 if (!entry || !entry->GetFavicon().valid) |
419 return; | 421 return; |
420 scoped_ptr<base::DictionaryValue> changed_properties( | 422 scoped_ptr<base::DictionaryValue> changed_properties( |
421 new base::DictionaryValue); | 423 new base::DictionaryValue); |
422 changed_properties->SetString( | 424 changed_properties->SetString( |
423 tabs_constants::kFaviconUrlKey, | 425 tabs_constants::kFaviconUrlKey, |
424 entry->GetFavicon().url.possibly_invalid_spec()); | 426 entry->GetFavicon().url.possibly_invalid_spec()); |
425 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); | 427 DispatchTabUpdatedEvent(contents, std::move(changed_properties)); |
426 } | 428 } |
427 | 429 |
428 void TabsEventRouter::DispatchEvent( | 430 void TabsEventRouter::DispatchEvent( |
429 Profile* profile, | 431 Profile* profile, |
430 events::HistogramValue histogram_value, | 432 events::HistogramValue histogram_value, |
431 const std::string& event_name, | 433 const std::string& event_name, |
432 scoped_ptr<base::ListValue> args, | 434 scoped_ptr<base::ListValue> args, |
433 EventRouter::UserGestureState user_gesture) { | 435 EventRouter::UserGestureState user_gesture) { |
434 EventRouter* event_router = EventRouter::Get(profile); | 436 EventRouter* event_router = EventRouter::Get(profile); |
435 if (!profile_->IsSameProfile(profile) || !event_router) | 437 if (!profile_->IsSameProfile(profile) || !event_router) |
436 return; | 438 return; |
437 | 439 |
438 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); | 440 scoped_ptr<Event> event( |
| 441 new Event(histogram_value, event_name, std::move(args))); |
439 event->restrict_to_browser_context = profile; | 442 event->restrict_to_browser_context = profile; |
440 event->user_gesture = user_gesture; | 443 event->user_gesture = user_gesture; |
441 event_router->BroadcastEvent(event.Pass()); | 444 event_router->BroadcastEvent(std::move(event)); |
442 } | 445 } |
443 | 446 |
444 void TabsEventRouter::DispatchTabUpdatedEvent( | 447 void TabsEventRouter::DispatchTabUpdatedEvent( |
445 WebContents* contents, | 448 WebContents* contents, |
446 scoped_ptr<base::DictionaryValue> changed_properties) { | 449 scoped_ptr<base::DictionaryValue> changed_properties) { |
447 DCHECK(changed_properties); | 450 DCHECK(changed_properties); |
448 DCHECK(contents); | 451 DCHECK(contents); |
449 | 452 |
450 // The state of the tab (as seen from the extension point of view) has | 453 // The state of the tab (as seen from the extension point of view) has |
451 // changed. Send a notification to the extension. | 454 // changed. Send a notification to the extension. |
452 scoped_ptr<base::ListValue> args_base(new base::ListValue); | 455 scoped_ptr<base::ListValue> args_base(new base::ListValue); |
453 | 456 |
454 // First arg: The id of the tab that changed. | 457 // First arg: The id of the tab that changed. |
455 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 458 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
456 | 459 |
457 // Second arg: An object containing the changes to the tab state. Filled in | 460 // Second arg: An object containing the changes to the tab state. Filled in |
458 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the | 461 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the |
459 // extension has the tabs permission. | 462 // extension has the tabs permission. |
460 | 463 |
461 // Third arg: An object containing the state of the tab. Filled in by | 464 // Third arg: An object containing the state of the tab. Filled in by |
462 // WillDispatchTabUpdatedEvent. | 465 // WillDispatchTabUpdatedEvent. |
463 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 466 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
464 | 467 |
465 scoped_ptr<Event> event(new Event( | 468 scoped_ptr<Event> event(new Event(events::TABS_ON_UPDATED, |
466 events::TABS_ON_UPDATED, tabs::OnUpdated::kEventName, args_base.Pass())); | 469 tabs::OnUpdated::kEventName, |
| 470 std::move(args_base))); |
467 event->restrict_to_browser_context = profile; | 471 event->restrict_to_browser_context = profile; |
468 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 472 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
469 event->will_dispatch_callback = | 473 event->will_dispatch_callback = |
470 base::Bind(&WillDispatchTabUpdatedEvent, | 474 base::Bind(&WillDispatchTabUpdatedEvent, |
471 contents, | 475 contents, |
472 changed_properties.get()); | 476 changed_properties.get()); |
473 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 477 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); |
474 } | 478 } |
475 | 479 |
476 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { | 480 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { |
477 const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents)); | 481 const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents)); |
478 | 482 |
479 return it == tab_entries_.end() ? nullptr : it->second.get(); | 483 return it == tab_entries_.end() ? nullptr : it->second.get(); |
480 } | 484 } |
481 | 485 |
482 void TabsEventRouter::TabChangedAt(WebContents* contents, | 486 void TabsEventRouter::TabChangedAt(WebContents* contents, |
483 int index, | 487 int index, |
(...skipping 10 matching lines...) Expand all Loading... |
494 // Notify listeners that the next tabs closing or being added are due to | 498 // Notify listeners that the next tabs closing or being added are due to |
495 // WebContents being swapped. | 499 // WebContents being swapped. |
496 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); | 500 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); |
497 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); | 501 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); |
498 scoped_ptr<base::ListValue> args(new base::ListValue); | 502 scoped_ptr<base::ListValue> args(new base::ListValue); |
499 args->Append(new FundamentalValue(new_tab_id)); | 503 args->Append(new FundamentalValue(new_tab_id)); |
500 args->Append(new FundamentalValue(old_tab_id)); | 504 args->Append(new FundamentalValue(old_tab_id)); |
501 | 505 |
502 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 506 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
503 events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName, | 507 events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName, |
504 args.Pass(), EventRouter::USER_GESTURE_UNKNOWN); | 508 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
505 | 509 |
506 UnregisterForTabNotifications(old_contents); | 510 UnregisterForTabNotifications(old_contents); |
507 | 511 |
508 if (!GetTabEntry(new_contents)) | 512 if (!GetTabEntry(new_contents)) |
509 RegisterForTabNotifications(new_contents); | 513 RegisterForTabNotifications(new_contents); |
510 } | 514 } |
511 | 515 |
512 void TabsEventRouter::TabPinnedStateChanged(WebContents* contents, int index) { | 516 void TabsEventRouter::TabPinnedStateChanged(WebContents* contents, int index) { |
513 TabStripModel* tab_strip = NULL; | 517 TabStripModel* tab_strip = NULL; |
514 int tab_index; | 518 int tab_index; |
515 | 519 |
516 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { | 520 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { |
517 scoped_ptr<base::DictionaryValue> changed_properties( | 521 scoped_ptr<base::DictionaryValue> changed_properties( |
518 new base::DictionaryValue()); | 522 new base::DictionaryValue()); |
519 changed_properties->SetBoolean(tabs_constants::kPinnedKey, | 523 changed_properties->SetBoolean(tabs_constants::kPinnedKey, |
520 tab_strip->IsTabPinned(tab_index)); | 524 tab_strip->IsTabPinned(tab_index)); |
521 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); | 525 DispatchTabUpdatedEvent(contents, std::move(changed_properties)); |
522 } | 526 } |
523 } | 527 } |
524 | 528 |
525 void TabsEventRouter::OnZoomChanged( | 529 void TabsEventRouter::OnZoomChanged( |
526 const ZoomController::ZoomChangedEventData& data) { | 530 const ZoomController::ZoomChangedEventData& data) { |
527 DCHECK(data.web_contents); | 531 DCHECK(data.web_contents); |
528 int tab_id = ExtensionTabUtil::GetTabId(data.web_contents); | 532 int tab_id = ExtensionTabUtil::GetTabId(data.web_contents); |
529 if (tab_id < 0) | 533 if (tab_id < 0) |
530 return; | 534 return; |
531 | 535 |
(...skipping 23 matching lines...) Expand all Loading... |
555 bool icon_url_changed, | 559 bool icon_url_changed, |
556 const gfx::Image& image) { | 560 const gfx::Image& image) { |
557 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { | 561 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { |
558 favicon::ContentFaviconDriver* content_favicon_driver = | 562 favicon::ContentFaviconDriver* content_favicon_driver = |
559 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); | 563 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); |
560 FaviconUrlUpdated(content_favicon_driver->web_contents()); | 564 FaviconUrlUpdated(content_favicon_driver->web_contents()); |
561 } | 565 } |
562 } | 566 } |
563 | 567 |
564 } // namespace extensions | 568 } // namespace extensions |
OLD | NEW |