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/browser_event_router.h" | 5 #include "chrome/browser/extensions/browser_event_router.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" |
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 void BrowserEventRouter::TabChangedAt(WebContents* contents, | 464 void BrowserEventRouter::TabChangedAt(WebContents* contents, |
465 int index, | 465 int index, |
466 TabChangeType change_type) { | 466 TabChangeType change_type) { |
467 TabUpdated(contents, false); | 467 TabUpdated(contents, false); |
468 } | 468 } |
469 | 469 |
470 void BrowserEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, | 470 void BrowserEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, |
471 WebContents* old_contents, | 471 WebContents* old_contents, |
472 WebContents* new_contents, | 472 WebContents* new_contents, |
473 int index) { | 473 int index) { |
474 TabClosingAt(tab_strip_model, old_contents, index); | 474 // Notify listeners that the next tabs closing or being added are due to |
475 TabInsertedAt(new_contents, index, tab_strip_model->active_index() == index); | 475 // WebContents being swapped. |
| 476 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); |
| 477 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); |
| 478 scoped_ptr<ListValue> args(new ListValue()); |
| 479 args->Append(Value::CreateIntegerValue(new_tab_id)); |
| 480 args->Append(Value::CreateIntegerValue(old_tab_id)); |
| 481 |
| 482 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
| 483 events::kOnTabReplaced, |
| 484 args.Pass(), |
| 485 EventRouter::USER_GESTURE_UNKNOWN); |
| 486 |
| 487 // Update tab_entries_. |
| 488 const int removed_count = tab_entries_.erase(old_tab_id); |
| 489 DCHECK_GT(removed_count, 0); |
| 490 UnregisterForTabNotifications(old_contents); |
| 491 |
| 492 if (!GetTabEntry(new_contents)) { |
| 493 tab_entries_[new_tab_id] = TabEntry(); |
| 494 RegisterForTabNotifications(new_contents); |
| 495 } |
476 } | 496 } |
477 | 497 |
478 void BrowserEventRouter::TabPinnedStateChanged(WebContents* contents, | 498 void BrowserEventRouter::TabPinnedStateChanged(WebContents* contents, |
479 int index) { | 499 int index) { |
480 TabStripModel* tab_strip = NULL; | 500 TabStripModel* tab_strip = NULL; |
481 int tab_index; | 501 int tab_index; |
482 | 502 |
483 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { | 503 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { |
484 DictionaryValue* changed_properties = new DictionaryValue(); | 504 DictionaryValue* changed_properties = new DictionaryValue(); |
485 changed_properties->SetBoolean(tab_keys::kPinnedKey, | 505 changed_properties->SetBoolean(tab_keys::kPinnedKey, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 597 |
578 DispatchEventToExtension(profile, | 598 DispatchEventToExtension(profile, |
579 extension_action.extension_id(), | 599 extension_action.extension_id(), |
580 event_name, | 600 event_name, |
581 args.Pass(), | 601 args.Pass(), |
582 EventRouter::USER_GESTURE_ENABLED); | 602 EventRouter::USER_GESTURE_ENABLED); |
583 } | 603 } |
584 } | 604 } |
585 | 605 |
586 } // namespace extensions | 606 } // namespace extensions |
OLD | NEW |