Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_event_router.cc

Issue 2142413003: Adding Discarded property support for onUpdate function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@API_Discarded
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
139 DCHECK(!profile->IsOffTheRecord()); 141 DCHECK(!profile->IsOffTheRecord());
140 142
141 browser_tab_strip_tracker_.Init( 143 browser_tab_strip_tracker_.Init(
142 BrowserTabStripTracker::InitWith::ALL_BROWERS); 144 BrowserTabStripTracker::InitWith::ALL_BROWERS);
145
146 if (g_browser_process->GetTabManager())
147 g_browser_process->GetTabManager()->AddObserver(this);
143 } 148 }
144 149
145 TabsEventRouter::~TabsEventRouter() { 150 TabsEventRouter::~TabsEventRouter() {
151 if (g_browser_process->GetTabManager())
152 g_browser_process->GetTabManager()->RemoveObserver(this);
146 } 153 }
147 154
148 bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) { 155 bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) {
149 return profile_->IsSameProfile(browser->profile()) && 156 return profile_->IsSameProfile(browser->profile()) &&
150 ExtensionTabUtil::BrowserSupportsTabs(browser); 157 ExtensionTabUtil::BrowserSupportsTabs(browser);
151 } 158 }
152 159
153 void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) { 160 void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) {
154 favicon_scoped_observer_.Add( 161 favicon_scoped_observer_.Add(
155 favicon::ContentFaviconDriver::FromWebContents(contents)); 162 favicon::ContentFaviconDriver::FromWebContents(contents));
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 const GURL& icon_url, 552 const GURL& icon_url,
546 bool icon_url_changed, 553 bool icon_url_changed,
547 const gfx::Image& image) { 554 const gfx::Image& image) {
548 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { 555 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) {
549 favicon::ContentFaviconDriver* content_favicon_driver = 556 favicon::ContentFaviconDriver* content_favicon_driver =
550 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); 557 static_cast<favicon::ContentFaviconDriver*>(favicon_driver);
551 FaviconUrlUpdated(content_favicon_driver->web_contents()); 558 FaviconUrlUpdated(content_favicon_driver->web_contents());
552 } 559 }
553 } 560 }
554 561
562 void TabsEventRouter::OnDiscardedStateChange(WebContents* contents,
563 bool is_discarded) {
564 TabStripModel* tab_strip = NULL;
Georges Khalil 2016/07/13 15:52:10 nit: nullptr
Anderson Silva 2016/07/14 15:13:13 Done.
565 int tab_index;
Georges Khalil 2016/07/13 15:52:10 nit: initialize.
Anderson Silva 2016/07/14 15:13:13 Done.
566
567 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) {
568 std::set<std::string> changed_property_names;
569 changed_property_names.insert(tabs_constants::kDiscardedKey);
570 DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
571 }
572 }
573
555 } // namespace extensions 574 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698