| 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 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 25 #include "components/favicon/content/content_favicon_driver.h" | 25 #include "components/favicon/content/content_favicon_driver.h" |
| 26 #include "content/public/browser/favicon_status.h" | 26 #include "content/public/browser/favicon_status.h" |
| 27 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 | 29 |
| 30 using base::DictionaryValue; | 30 using base::DictionaryValue; |
| 31 using base::ListValue; | 31 using base::ListValue; |
| 32 using base::FundamentalValue; | 32 using base::Value; |
| 33 using content::WebContents; | 33 using content::WebContents; |
| 34 using zoom::ZoomController; | 34 using zoom::ZoomController; |
| 35 | 35 |
| 36 namespace extensions { | 36 namespace extensions { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 namespace tabs = api::tabs; | 40 namespace tabs = api::tabs; |
| 41 | 41 |
| 42 bool WillDispatchTabUpdatedEvent( | 42 bool WillDispatchTabUpdatedEvent( |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return; | 231 return; |
| 232 } | 232 } |
| 233 | 233 |
| 234 int tab_id = ExtensionTabUtil::GetTabId(contents); | 234 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 235 std::unique_ptr<base::ListValue> args(new base::ListValue); | 235 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 236 args->AppendInteger(tab_id); | 236 args->AppendInteger(tab_id); |
| 237 | 237 |
| 238 std::unique_ptr<base::DictionaryValue> object_args( | 238 std::unique_ptr<base::DictionaryValue> object_args( |
| 239 new base::DictionaryValue()); | 239 new base::DictionaryValue()); |
| 240 object_args->Set(tabs_constants::kNewWindowIdKey, | 240 object_args->Set(tabs_constants::kNewWindowIdKey, |
| 241 new FundamentalValue( | 241 new Value( |
| 242 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 242 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
| 243 object_args->Set(tabs_constants::kNewPositionKey, | 243 object_args->Set(tabs_constants::kNewPositionKey, |
| 244 new FundamentalValue(index)); | 244 new Value(index)); |
| 245 args->Append(std::move(object_args)); | 245 args->Append(std::move(object_args)); |
| 246 | 246 |
| 247 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 247 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 248 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, | 248 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, |
| 249 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 249 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { | 252 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { |
| 253 if (!GetTabEntry(contents)) { | 253 if (!GetTabEntry(contents)) { |
| 254 // The tab was removed. Don't send detach event. | 254 // The tab was removed. Don't send detach event. |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 | 257 |
| 258 std::unique_ptr<base::ListValue> args(new base::ListValue); | 258 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 259 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 259 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
| 260 | 260 |
| 261 std::unique_ptr<base::DictionaryValue> object_args( | 261 std::unique_ptr<base::DictionaryValue> object_args( |
| 262 new base::DictionaryValue()); | 262 new base::DictionaryValue()); |
| 263 object_args->Set(tabs_constants::kOldWindowIdKey, | 263 object_args->Set(tabs_constants::kOldWindowIdKey, |
| 264 new FundamentalValue( | 264 new Value( |
| 265 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 265 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
| 266 object_args->Set(tabs_constants::kOldPositionKey, | 266 object_args->Set(tabs_constants::kOldPositionKey, |
| 267 new FundamentalValue(index)); | 267 new Value(index)); |
| 268 args->Append(std::move(object_args)); | 268 args->Append(std::move(object_args)); |
| 269 | 269 |
| 270 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 270 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 271 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, | 271 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, |
| 272 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 272 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, | 275 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
| 276 WebContents* contents, | 276 WebContents* contents, |
| 277 int index) { | 277 int index) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 298 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, | 298 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, |
| 299 WebContents* new_contents, | 299 WebContents* new_contents, |
| 300 int index, | 300 int index, |
| 301 int reason) { | 301 int reason) { |
| 302 auto args = base::MakeUnique<base::ListValue>(); | 302 auto args = base::MakeUnique<base::ListValue>(); |
| 303 int tab_id = ExtensionTabUtil::GetTabId(new_contents); | 303 int tab_id = ExtensionTabUtil::GetTabId(new_contents); |
| 304 args->AppendInteger(tab_id); | 304 args->AppendInteger(tab_id); |
| 305 | 305 |
| 306 auto object_args = base::MakeUnique<base::DictionaryValue>(); | 306 auto object_args = base::MakeUnique<base::DictionaryValue>(); |
| 307 object_args->Set(tabs_constants::kWindowIdKey, | 307 object_args->Set(tabs_constants::kWindowIdKey, |
| 308 new FundamentalValue( | 308 new Value( |
| 309 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); | 309 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); |
| 310 args->Append(object_args->CreateDeepCopy()); | 310 args->Append(object_args->CreateDeepCopy()); |
| 311 | 311 |
| 312 // The onActivated event replaced onActiveChanged and onSelectionChanged. The | 312 // The onActivated event replaced onActiveChanged and onSelectionChanged. The |
| 313 // deprecated events take two arguments: tabId, {windowId}. | 313 // deprecated events take two arguments: tabId, {windowId}. |
| 314 Profile* profile = | 314 Profile* profile = |
| 315 Profile::FromBrowserContext(new_contents->GetBrowserContext()); | 315 Profile::FromBrowserContext(new_contents->GetBrowserContext()); |
| 316 EventRouter::UserGestureState gesture = | 316 EventRouter::UserGestureState gesture = |
| 317 reason & CHANGE_REASON_USER_GESTURE | 317 reason & CHANGE_REASON_USER_GESTURE |
| 318 ? EventRouter::USER_GESTURE_ENABLED | 318 ? EventRouter::USER_GESTURE_ENABLED |
| 319 : EventRouter::USER_GESTURE_NOT_ENABLED; | 319 : EventRouter::USER_GESTURE_NOT_ENABLED; |
| 320 DispatchEvent(profile, events::TABS_ON_SELECTION_CHANGED, | 320 DispatchEvent(profile, events::TABS_ON_SELECTION_CHANGED, |
| 321 tabs::OnSelectionChanged::kEventName, args->CreateDeepCopy(), | 321 tabs::OnSelectionChanged::kEventName, args->CreateDeepCopy(), |
| 322 gesture); | 322 gesture); |
| 323 DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED, | 323 DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED, |
| 324 tabs::OnActiveChanged::kEventName, std::move(args), gesture); | 324 tabs::OnActiveChanged::kEventName, std::move(args), gesture); |
| 325 | 325 |
| 326 // The onActivated event takes one argument: {windowId, tabId}. | 326 // The onActivated event takes one argument: {windowId, tabId}. |
| 327 auto on_activated_args = base::MakeUnique<base::ListValue>(); | 327 auto on_activated_args = base::MakeUnique<base::ListValue>(); |
| 328 object_args->Set(tabs_constants::kTabIdKey, | 328 object_args->Set(tabs_constants::kTabIdKey, |
| 329 new FundamentalValue(tab_id)); | 329 new Value(tab_id)); |
| 330 on_activated_args->Append(std::move(object_args)); | 330 on_activated_args->Append(std::move(object_args)); |
| 331 DispatchEvent(profile, events::TABS_ON_ACTIVATED, | 331 DispatchEvent(profile, events::TABS_ON_ACTIVATED, |
| 332 tabs::OnActivated::kEventName, std::move(on_activated_args), | 332 tabs::OnActivated::kEventName, std::move(on_activated_args), |
| 333 gesture); | 333 gesture); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void TabsEventRouter::TabSelectionChanged( | 336 void TabsEventRouter::TabSelectionChanged( |
| 337 TabStripModel* tab_strip_model, | 337 TabStripModel* tab_strip_model, |
| 338 const ui::ListSelectionModel& old_model) { | 338 const ui::ListSelectionModel& old_model) { |
| 339 ui::ListSelectionModel::SelectedIndices new_selection = | 339 ui::ListSelectionModel::SelectedIndices new_selection = |
| 340 tab_strip_model->selection_model().selected_indices(); | 340 tab_strip_model->selection_model().selected_indices(); |
| 341 std::unique_ptr<base::ListValue> all_tabs(new base::ListValue); | 341 std::unique_ptr<base::ListValue> all_tabs(new base::ListValue); |
| 342 | 342 |
| 343 for (size_t i = 0; i < new_selection.size(); ++i) { | 343 for (size_t i = 0; i < new_selection.size(); ++i) { |
| 344 int index = new_selection[i]; | 344 int index = new_selection[i]; |
| 345 WebContents* contents = tab_strip_model->GetWebContentsAt(index); | 345 WebContents* contents = tab_strip_model->GetWebContentsAt(index); |
| 346 if (!contents) | 346 if (!contents) |
| 347 break; | 347 break; |
| 348 int tab_id = ExtensionTabUtil::GetTabId(contents); | 348 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 349 all_tabs->AppendInteger(tab_id); | 349 all_tabs->AppendInteger(tab_id); |
| 350 } | 350 } |
| 351 | 351 |
| 352 std::unique_ptr<base::ListValue> args(new base::ListValue); | 352 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 353 std::unique_ptr<base::DictionaryValue> select_info(new base::DictionaryValue); | 353 std::unique_ptr<base::DictionaryValue> select_info(new base::DictionaryValue); |
| 354 | 354 |
| 355 select_info->Set( | 355 select_info->Set( |
| 356 tabs_constants::kWindowIdKey, | 356 tabs_constants::kWindowIdKey, |
| 357 new FundamentalValue( | 357 new Value( |
| 358 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); | 358 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); |
| 359 | 359 |
| 360 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); | 360 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); |
| 361 args->Append(std::move(select_info)); | 361 args->Append(std::move(select_info)); |
| 362 | 362 |
| 363 // The onHighlighted event replaced onHighlightChanged. | 363 // The onHighlighted event replaced onHighlightChanged. |
| 364 Profile* profile = tab_strip_model->profile(); | 364 Profile* profile = tab_strip_model->profile(); |
| 365 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, | 365 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, |
| 366 tabs::OnHighlightChanged::kEventName, | 366 tabs::OnHighlightChanged::kEventName, |
| 367 std::unique_ptr<base::ListValue>(args->DeepCopy()), | 367 std::unique_ptr<base::ListValue>(args->DeepCopy()), |
| 368 EventRouter::USER_GESTURE_UNKNOWN); | 368 EventRouter::USER_GESTURE_UNKNOWN); |
| 369 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, | 369 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, |
| 370 tabs::OnHighlighted::kEventName, std::move(args), | 370 tabs::OnHighlighted::kEventName, std::move(args), |
| 371 EventRouter::USER_GESTURE_UNKNOWN); | 371 EventRouter::USER_GESTURE_UNKNOWN); |
| 372 } | 372 } |
| 373 | 373 |
| 374 void TabsEventRouter::TabMoved(WebContents* contents, | 374 void TabsEventRouter::TabMoved(WebContents* contents, |
| 375 int from_index, | 375 int from_index, |
| 376 int to_index) { | 376 int to_index) { |
| 377 std::unique_ptr<base::ListValue> args(new base::ListValue); | 377 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 378 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 378 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
| 379 | 379 |
| 380 std::unique_ptr<base::DictionaryValue> object_args( | 380 std::unique_ptr<base::DictionaryValue> object_args( |
| 381 new base::DictionaryValue()); | 381 new base::DictionaryValue()); |
| 382 object_args->Set(tabs_constants::kWindowIdKey, | 382 object_args->Set(tabs_constants::kWindowIdKey, |
| 383 new FundamentalValue( | 383 new Value( |
| 384 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 384 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
| 385 object_args->Set(tabs_constants::kFromIndexKey, | 385 object_args->Set(tabs_constants::kFromIndexKey, |
| 386 new FundamentalValue(from_index)); | 386 new Value(from_index)); |
| 387 object_args->Set(tabs_constants::kToIndexKey, | 387 object_args->Set(tabs_constants::kToIndexKey, |
| 388 new FundamentalValue(to_index)); | 388 new Value(to_index)); |
| 389 args->Append(std::move(object_args)); | 389 args->Append(std::move(object_args)); |
| 390 | 390 |
| 391 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 391 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 392 DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName, | 392 DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName, |
| 393 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 393 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void TabsEventRouter::TabUpdated(TabEntry* entry, | 396 void TabsEventRouter::TabUpdated(TabEntry* entry, |
| 397 std::set<std::string> changed_property_names) { | 397 std::set<std::string> changed_property_names) { |
| 398 bool audible = entry->web_contents()->WasRecentlyAudible(); | 398 bool audible = entry->web_contents()->WasRecentlyAudible(); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 } | 562 } |
| 563 | 563 |
| 564 void TabsEventRouter::OnAutoDiscardableStateChange(WebContents* contents, | 564 void TabsEventRouter::OnAutoDiscardableStateChange(WebContents* contents, |
| 565 bool is_auto_discardable) { | 565 bool is_auto_discardable) { |
| 566 std::set<std::string> changed_property_names; | 566 std::set<std::string> changed_property_names; |
| 567 changed_property_names.insert(tabs_constants::kAutoDiscardableKey); | 567 changed_property_names.insert(tabs_constants::kAutoDiscardableKey); |
| 568 DispatchTabUpdatedEvent(contents, std::move(changed_property_names)); | 568 DispatchTabUpdatedEvent(contents, std::move(changed_property_names)); |
| 569 } | 569 } |
| 570 | 570 |
| 571 } // namespace extensions | 571 } // namespace extensions |
| OLD | NEW |