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

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

Issue 1059743003: Remove NOTIFICATION_FAVICON_UPDATED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@get-active-title
Patch Set: Add DISALLOW_COPY_AND_ASSIGN(FaviconUpdateWatcher) Created 5 years, 8 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 "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/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
11 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" 11 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
12 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" 12 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 13 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/favicon/favicon_tab_helper.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_iterator.h" 17 #include "chrome/browser/ui/browser_iterator.h"
17 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
20 #include "content/public/browser/favicon_status.h" 21 #include "content/public/browser/favicon_status.h"
21 #include "content/public/browser/navigation_controller.h" 22 #include "content/public/browser/navigation_controller.h"
22 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
23 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 tabs_constants::kStatusValueLoading); 88 tabs_constants::kStatusValueLoading);
88 89
89 if (contents->GetURL() != url_) { 90 if (contents->GetURL() != url_) {
90 url_ = contents->GetURL(); 91 url_ = contents->GetURL();
91 changed_properties->SetString(tabs_constants::kUrlKey, url_.spec()); 92 changed_properties->SetString(tabs_constants::kUrlKey, url_.spec());
92 } 93 }
93 94
94 return changed_properties; 95 return changed_properties;
95 } 96 }
96 97
97 TabsEventRouter::TabsEventRouter(Profile* profile) : profile_(profile) { 98 TabsEventRouter::TabsEventRouter(Profile* profile)
99 : profile_(profile), favicon_scoped_observer_(this) {
98 DCHECK(!profile->IsOffTheRecord()); 100 DCHECK(!profile->IsOffTheRecord());
99 101
100 BrowserList::AddObserver(this); 102 BrowserList::AddObserver(this);
101 103
102 // Init() can happen after the browser is running, so catch up with any 104 // Init() can happen after the browser is running, so catch up with any
103 // windows that already exist. 105 // windows that already exist.
104 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 106 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
105 RegisterForBrowserNotifications(*it); 107 RegisterForBrowserNotifications(*it);
106 108
107 // Also catch up our internal bookkeeping of tab entries. 109 // Also catch up our internal bookkeeping of tab entries.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 143 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
142 content::Source<NavigationController>(&contents->GetController())); 144 content::Source<NavigationController>(&contents->GetController()));
143 145
144 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's 146 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's
145 // possible for tabs to be created, detached and then destroyed without 147 // possible for tabs to be created, detached and then destroyed without
146 // ever having been re-attached and closed. This happens in the case of 148 // ever having been re-attached and closed. This happens in the case of
147 // a devtools WebContents that is opened in window, docked, then closed. 149 // a devtools WebContents that is opened in window, docked, then closed.
148 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 150 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
149 content::Source<WebContents>(contents)); 151 content::Source<WebContents>(contents));
150 152
151 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_UPDATED, 153 favicon_scoped_observer_.Add(FaviconTabHelper::FromWebContents(contents));
152 content::Source<WebContents>(contents));
153 154
154 ZoomController::FromWebContents(contents)->AddObserver(this); 155 ZoomController::FromWebContents(contents)->AddObserver(this);
155 } 156 }
156 157
157 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) { 158 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) {
158 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 159 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
159 content::Source<NavigationController>(&contents->GetController())); 160 content::Source<NavigationController>(&contents->GetController()));
160 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 161 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
161 content::Source<WebContents>(contents)); 162 content::Source<WebContents>(contents));
162 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED, 163 favicon_scoped_observer_.Remove(FaviconTabHelper::FromWebContents(contents));
163 content::Source<WebContents>(contents));
164 164
165 ZoomController::FromWebContents(contents)->RemoveObserver(this); 165 ZoomController::FromWebContents(contents)->RemoveObserver(this);
166 } 166 }
167 167
168 void TabsEventRouter::OnBrowserRemoved(Browser* browser) { 168 void TabsEventRouter::OnBrowserRemoved(Browser* browser) {
169 if (!profile_->IsSameProfile(browser->profile())) 169 if (!profile_->IsSameProfile(browser->profile()))
170 return; 170 return;
171 171
172 // Stop listening to TabStripModel events for this browser. 172 // Stop listening to TabStripModel events for this browser.
173 browser->tab_strip_model()->RemoveObserver(this); 173 browser->tab_strip_model()->RemoveObserver(this);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 NavigationController* source_controller = 494 NavigationController* source_controller =
495 content::Source<NavigationController>(source).ptr(); 495 content::Source<NavigationController>(source).ptr();
496 TabUpdated(source_controller->GetWebContents(), true); 496 TabUpdated(source_controller->GetWebContents(), true);
497 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 497 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
498 // Tab was destroyed after being detached (without being re-attached). 498 // Tab was destroyed after being detached (without being re-attached).
499 WebContents* contents = content::Source<WebContents>(source).ptr(); 499 WebContents* contents = content::Source<WebContents>(source).ptr();
500 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 500 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
501 content::Source<NavigationController>(&contents->GetController())); 501 content::Source<NavigationController>(&contents->GetController()));
502 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 502 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
503 content::Source<WebContents>(contents)); 503 content::Source<WebContents>(contents));
504 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED, 504 favicon_scoped_observer_.Remove(
505 content::Source<WebContents>(contents)); 505 FaviconTabHelper::FromWebContents(contents));
506 } else if (type == chrome::NOTIFICATION_FAVICON_UPDATED) {
507 bool icon_url_changed = *content::Details<bool>(details).ptr();
508 if (icon_url_changed)
509 FaviconUrlUpdated(content::Source<WebContents>(source).ptr());
510 } else { 506 } else {
511 NOTREACHED(); 507 NOTREACHED();
512 } 508 }
513 } 509 }
514 510
515 void TabsEventRouter::TabChangedAt(WebContents* contents, 511 void TabsEventRouter::TabChangedAt(WebContents* contents,
516 int index, 512 int index,
517 TabChangeType change_type) { 513 TabChangeType change_type) {
518 TabUpdated(contents, false); 514 TabUpdated(contents, false);
519 } 515 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 574
579 // Dispatch the |onZoomChange| event. 575 // Dispatch the |onZoomChange| event.
580 Profile* profile = Profile::FromBrowserContext( 576 Profile* profile = Profile::FromBrowserContext(
581 data.web_contents->GetBrowserContext()); 577 data.web_contents->GetBrowserContext());
582 DispatchEvent(profile, 578 DispatchEvent(profile,
583 tabs::OnZoomChange::kEventName, 579 tabs::OnZoomChange::kEventName,
584 api::tabs::OnZoomChange::Create(zoom_change_info), 580 api::tabs::OnZoomChange::Create(zoom_change_info),
585 EventRouter::USER_GESTURE_UNKNOWN); 581 EventRouter::USER_GESTURE_UNKNOWN);
586 } 582 }
587 583
584 void TabsEventRouter::OnFaviconAvailable(const gfx::Image& image) {
585 }
586
587 void TabsEventRouter::OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
588 bool icon_url_changed) {
589 if (icon_url_changed) {
590 FaviconTabHelper* favicon_tab_helper =
591 static_cast<FaviconTabHelper*>(favicon_driver);
592 FaviconUrlUpdated(favicon_tab_helper->web_contents());
593 }
594 }
595
588 } // namespace extensions 596 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_event_router.h ('k') | chrome/browser/favicon/favicon_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698