| 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> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.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/tabs_windows_api.h" | 16 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" |
| 16 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" | 17 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" |
| 17 #include "chrome/browser/extensions/extension_tab_util.h" | 18 #include "chrome/browser/extensions/extension_tab_util.h" |
| 19 #include "chrome/browser/memory/tab_manager.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "components/favicon/content/content_favicon_driver.h" | 25 #include "components/favicon/content/content_favicon_driver.h" |
| 24 #include "content/public/browser/favicon_status.h" | 26 #include "content/public/browser/favicon_status.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 27 | 29 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // and then destroyed without ever having been re-attached and closed. This | 130 // and then destroyed without ever having been re-attached and closed. This |
| 129 // happens in the case of a devtools WebContents that is opened in window, | 131 // happens in the case of a devtools WebContents that is opened in window, |
| 130 // docked, then closed. | 132 // docked, then closed. |
| 131 // Warning: |this| will be deleted after this call. | 133 // Warning: |this| will be deleted after this call. |
| 132 router_->UnregisterForTabNotifications(web_contents()); | 134 router_->UnregisterForTabNotifications(web_contents()); |
| 133 } | 135 } |
| 134 | 136 |
| 135 TabsEventRouter::TabsEventRouter(Profile* profile) | 137 TabsEventRouter::TabsEventRouter(Profile* profile) |
| 136 : profile_(profile), | 138 : profile_(profile), |
| 137 favicon_scoped_observer_(this), | 139 favicon_scoped_observer_(this), |
| 138 browser_tab_strip_tracker_(this, this, this) { | 140 browser_tab_strip_tracker_(this, this, this), |
| 141 tab_manager_scoped_observer_(this) { |
| 139 DCHECK(!profile->IsOffTheRecord()); | 142 DCHECK(!profile->IsOffTheRecord()); |
| 140 | 143 |
| 141 browser_tab_strip_tracker_.Init( | 144 browser_tab_strip_tracker_.Init( |
| 142 BrowserTabStripTracker::InitWith::ALL_BROWERS); | 145 BrowserTabStripTracker::InitWith::ALL_BROWERS); |
| 146 |
| 147 tab_manager_scoped_observer_.Add(g_browser_process->GetTabManager()); |
| 143 } | 148 } |
| 144 | 149 |
| 145 TabsEventRouter::~TabsEventRouter() { | 150 TabsEventRouter::~TabsEventRouter() { |
| 146 } | 151 } |
| 147 | 152 |
| 148 bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) { | 153 bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) { |
| 149 return profile_->IsSameProfile(browser->profile()) && | 154 return profile_->IsSameProfile(browser->profile()) && |
| 150 ExtensionTabUtil::BrowserSupportsTabs(browser); | 155 ExtensionTabUtil::BrowserSupportsTabs(browser); |
| 151 } | 156 } |
| 152 | 157 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 const GURL& icon_url, | 550 const GURL& icon_url, |
| 546 bool icon_url_changed, | 551 bool icon_url_changed, |
| 547 const gfx::Image& image) { | 552 const gfx::Image& image) { |
| 548 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { | 553 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { |
| 549 favicon::ContentFaviconDriver* content_favicon_driver = | 554 favicon::ContentFaviconDriver* content_favicon_driver = |
| 550 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); | 555 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); |
| 551 FaviconUrlUpdated(content_favicon_driver->web_contents()); | 556 FaviconUrlUpdated(content_favicon_driver->web_contents()); |
| 552 } | 557 } |
| 553 } | 558 } |
| 554 | 559 |
| 560 void TabsEventRouter::OnDiscardedStateChange(WebContents* contents, |
| 561 bool is_discarded) { |
| 562 TabStripModel* tab_strip = nullptr; |
| 563 int tab_index = -1; |
| 564 |
| 565 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { |
| 566 std::set<std::string> changed_property_names; |
| 567 changed_property_names.insert(tabs_constants::kDiscardedKey); |
| 568 DispatchTabUpdatedEvent(contents, std::move(changed_property_names)); |
| 569 } |
| 570 } |
| 571 |
| 555 } // namespace extensions | 572 } // namespace extensions |
| OLD | NEW |