| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // constructor. | 221 // constructor. |
| 222 if (browser_tab_strip_tracker_.is_processing_initial_browsers()) | 222 if (browser_tab_strip_tracker_.is_processing_initial_browsers()) |
| 223 RegisterForTabNotifications(contents); | 223 RegisterForTabNotifications(contents); |
| 224 else | 224 else |
| 225 TabCreatedAt(contents, index, active); | 225 TabCreatedAt(contents, index, active); |
| 226 return; | 226 return; |
| 227 } | 227 } |
| 228 | 228 |
| 229 int tab_id = ExtensionTabUtil::GetTabId(contents); | 229 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 230 std::unique_ptr<base::ListValue> args(new base::ListValue); | 230 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 231 args->Append(new FundamentalValue(tab_id)); | 231 args->AppendInteger(tab_id); |
| 232 | 232 |
| 233 base::DictionaryValue* object_args = new base::DictionaryValue(); | 233 base::DictionaryValue* object_args = new base::DictionaryValue(); |
| 234 object_args->Set(tabs_constants::kNewWindowIdKey, | 234 object_args->Set(tabs_constants::kNewWindowIdKey, |
| 235 new FundamentalValue( | 235 new FundamentalValue( |
| 236 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 236 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
| 237 object_args->Set(tabs_constants::kNewPositionKey, | 237 object_args->Set(tabs_constants::kNewPositionKey, |
| 238 new FundamentalValue(index)); | 238 new FundamentalValue(index)); |
| 239 args->Append(object_args); | 239 args->Append(object_args); |
| 240 | 240 |
| 241 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 241 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 242 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, | 242 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, |
| 243 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 243 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { | 246 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { |
| 247 if (!GetTabEntry(contents)) { | 247 if (!GetTabEntry(contents)) { |
| 248 // The tab was removed. Don't send detach event. | 248 // The tab was removed. Don't send detach event. |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 | 251 |
| 252 std::unique_ptr<base::ListValue> args(new base::ListValue); | 252 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 253 args->Append( | 253 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
| 254 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); | |
| 255 | 254 |
| 256 base::DictionaryValue* object_args = new base::DictionaryValue(); | 255 base::DictionaryValue* object_args = new base::DictionaryValue(); |
| 257 object_args->Set(tabs_constants::kOldWindowIdKey, | 256 object_args->Set(tabs_constants::kOldWindowIdKey, |
| 258 new FundamentalValue( | 257 new FundamentalValue( |
| 259 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 258 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
| 260 object_args->Set(tabs_constants::kOldPositionKey, | 259 object_args->Set(tabs_constants::kOldPositionKey, |
| 261 new FundamentalValue(index)); | 260 new FundamentalValue(index)); |
| 262 args->Append(object_args); | 261 args->Append(object_args); |
| 263 | 262 |
| 264 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 263 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 265 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, | 264 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, |
| 266 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 265 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 267 } | 266 } |
| 268 | 267 |
| 269 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, | 268 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
| 270 WebContents* contents, | 269 WebContents* contents, |
| 271 int index) { | 270 int index) { |
| 272 int tab_id = ExtensionTabUtil::GetTabId(contents); | 271 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 273 | 272 |
| 274 std::unique_ptr<base::ListValue> args(new base::ListValue); | 273 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 275 args->Append(new FundamentalValue(tab_id)); | 274 args->AppendInteger(tab_id); |
| 276 | 275 |
| 277 base::DictionaryValue* object_args = new base::DictionaryValue(); | 276 base::DictionaryValue* object_args = new base::DictionaryValue(); |
| 278 object_args->SetInteger(tabs_constants::kWindowIdKey, | 277 object_args->SetInteger(tabs_constants::kWindowIdKey, |
| 279 ExtensionTabUtil::GetWindowIdOfTab(contents)); | 278 ExtensionTabUtil::GetWindowIdOfTab(contents)); |
| 280 object_args->SetBoolean(tabs_constants::kWindowClosing, | 279 object_args->SetBoolean(tabs_constants::kWindowClosing, |
| 281 tab_strip_model->closing_all()); | 280 tab_strip_model->closing_all()); |
| 282 args->Append(object_args); | 281 args->Append(object_args); |
| 283 | 282 |
| 284 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 283 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 285 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName, | 284 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName, |
| 286 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 285 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 287 | 286 |
| 288 UnregisterForTabNotifications(contents); | 287 UnregisterForTabNotifications(contents); |
| 289 } | 288 } |
| 290 | 289 |
| 291 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, | 290 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, |
| 292 WebContents* new_contents, | 291 WebContents* new_contents, |
| 293 int index, | 292 int index, |
| 294 int reason) { | 293 int reason) { |
| 295 std::unique_ptr<base::ListValue> args(new base::ListValue); | 294 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 296 int tab_id = ExtensionTabUtil::GetTabId(new_contents); | 295 int tab_id = ExtensionTabUtil::GetTabId(new_contents); |
| 297 args->Append(new FundamentalValue(tab_id)); | 296 args->AppendInteger(tab_id); |
| 298 | 297 |
| 299 base::DictionaryValue* object_args = new base::DictionaryValue(); | 298 base::DictionaryValue* object_args = new base::DictionaryValue(); |
| 300 object_args->Set(tabs_constants::kWindowIdKey, | 299 object_args->Set(tabs_constants::kWindowIdKey, |
| 301 new FundamentalValue( | 300 new FundamentalValue( |
| 302 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); | 301 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); |
| 303 args->Append(object_args); | 302 args->Append(object_args); |
| 304 | 303 |
| 305 // The onActivated event replaced onActiveChanged and onSelectionChanged. The | 304 // The onActivated event replaced onActiveChanged and onSelectionChanged. The |
| 306 // deprecated events take two arguments: tabId, {windowId}. | 305 // deprecated events take two arguments: tabId, {windowId}. |
| 307 Profile* profile = | 306 Profile* profile = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 331 ui::ListSelectionModel::SelectedIndices new_selection = | 330 ui::ListSelectionModel::SelectedIndices new_selection = |
| 332 tab_strip_model->selection_model().selected_indices(); | 331 tab_strip_model->selection_model().selected_indices(); |
| 333 std::unique_ptr<base::ListValue> all_tabs(new base::ListValue); | 332 std::unique_ptr<base::ListValue> all_tabs(new base::ListValue); |
| 334 | 333 |
| 335 for (size_t i = 0; i < new_selection.size(); ++i) { | 334 for (size_t i = 0; i < new_selection.size(); ++i) { |
| 336 int index = new_selection[i]; | 335 int index = new_selection[i]; |
| 337 WebContents* contents = tab_strip_model->GetWebContentsAt(index); | 336 WebContents* contents = tab_strip_model->GetWebContentsAt(index); |
| 338 if (!contents) | 337 if (!contents) |
| 339 break; | 338 break; |
| 340 int tab_id = ExtensionTabUtil::GetTabId(contents); | 339 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 341 all_tabs->Append(new FundamentalValue(tab_id)); | 340 all_tabs->AppendInteger(tab_id); |
| 342 } | 341 } |
| 343 | 342 |
| 344 std::unique_ptr<base::ListValue> args(new base::ListValue); | 343 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 345 std::unique_ptr<base::DictionaryValue> select_info(new base::DictionaryValue); | 344 std::unique_ptr<base::DictionaryValue> select_info(new base::DictionaryValue); |
| 346 | 345 |
| 347 select_info->Set( | 346 select_info->Set( |
| 348 tabs_constants::kWindowIdKey, | 347 tabs_constants::kWindowIdKey, |
| 349 new FundamentalValue( | 348 new FundamentalValue( |
| 350 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); | 349 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); |
| 351 | 350 |
| 352 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); | 351 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); |
| 353 args->Append(select_info.release()); | 352 args->Append(select_info.release()); |
| 354 | 353 |
| 355 // The onHighlighted event replaced onHighlightChanged. | 354 // The onHighlighted event replaced onHighlightChanged. |
| 356 Profile* profile = tab_strip_model->profile(); | 355 Profile* profile = tab_strip_model->profile(); |
| 357 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, | 356 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, |
| 358 tabs::OnHighlightChanged::kEventName, | 357 tabs::OnHighlightChanged::kEventName, |
| 359 std::unique_ptr<base::ListValue>(args->DeepCopy()), | 358 std::unique_ptr<base::ListValue>(args->DeepCopy()), |
| 360 EventRouter::USER_GESTURE_UNKNOWN); | 359 EventRouter::USER_GESTURE_UNKNOWN); |
| 361 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, | 360 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, |
| 362 tabs::OnHighlighted::kEventName, std::move(args), | 361 tabs::OnHighlighted::kEventName, std::move(args), |
| 363 EventRouter::USER_GESTURE_UNKNOWN); | 362 EventRouter::USER_GESTURE_UNKNOWN); |
| 364 } | 363 } |
| 365 | 364 |
| 366 void TabsEventRouter::TabMoved(WebContents* contents, | 365 void TabsEventRouter::TabMoved(WebContents* contents, |
| 367 int from_index, | 366 int from_index, |
| 368 int to_index) { | 367 int to_index) { |
| 369 std::unique_ptr<base::ListValue> args(new base::ListValue); | 368 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 370 args->Append( | 369 args->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
| 371 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); | |
| 372 | 370 |
| 373 base::DictionaryValue* object_args = new base::DictionaryValue(); | 371 base::DictionaryValue* object_args = new base::DictionaryValue(); |
| 374 object_args->Set(tabs_constants::kWindowIdKey, | 372 object_args->Set(tabs_constants::kWindowIdKey, |
| 375 new FundamentalValue( | 373 new FundamentalValue( |
| 376 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 374 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
| 377 object_args->Set(tabs_constants::kFromIndexKey, | 375 object_args->Set(tabs_constants::kFromIndexKey, |
| 378 new FundamentalValue(from_index)); | 376 new FundamentalValue(from_index)); |
| 379 object_args->Set(tabs_constants::kToIndexKey, | 377 object_args->Set(tabs_constants::kToIndexKey, |
| 380 new FundamentalValue(to_index)); | 378 new FundamentalValue(to_index)); |
| 381 args->Append(object_args); | 379 args->Append(object_args); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 477 |
| 480 void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, | 478 void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, |
| 481 WebContents* old_contents, | 479 WebContents* old_contents, |
| 482 WebContents* new_contents, | 480 WebContents* new_contents, |
| 483 int index) { | 481 int index) { |
| 484 // Notify listeners that the next tabs closing or being added are due to | 482 // Notify listeners that the next tabs closing or being added are due to |
| 485 // WebContents being swapped. | 483 // WebContents being swapped. |
| 486 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); | 484 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); |
| 487 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); | 485 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); |
| 488 std::unique_ptr<base::ListValue> args(new base::ListValue); | 486 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 489 args->Append(new FundamentalValue(new_tab_id)); | 487 args->AppendInteger(new_tab_id); |
| 490 args->Append(new FundamentalValue(old_tab_id)); | 488 args->AppendInteger(old_tab_id); |
| 491 | 489 |
| 492 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 490 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
| 493 events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName, | 491 events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName, |
| 494 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); | 492 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); |
| 495 | 493 |
| 496 UnregisterForTabNotifications(old_contents); | 494 UnregisterForTabNotifications(old_contents); |
| 497 | 495 |
| 498 if (!GetTabEntry(new_contents)) | 496 if (!GetTabEntry(new_contents)) |
| 499 RegisterForTabNotifications(new_contents); | 497 RegisterForTabNotifications(new_contents); |
| 500 } | 498 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 bool icon_url_changed, | 541 bool icon_url_changed, |
| 544 const gfx::Image& image) { | 542 const gfx::Image& image) { |
| 545 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { | 543 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { |
| 546 favicon::ContentFaviconDriver* content_favicon_driver = | 544 favicon::ContentFaviconDriver* content_favicon_driver = |
| 547 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); | 545 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); |
| 548 FaviconUrlUpdated(content_favicon_driver->web_contents()); | 546 FaviconUrlUpdated(content_favicon_driver->web_contents()); |
| 549 } | 547 } |
| 550 } | 548 } |
| 551 | 549 |
| 552 } // namespace extensions | 550 } // namespace extensions |
| OLD | NEW |