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

Side by Side Diff: chrome/browser/extensions/browser_event_router.cc

Issue 12591008: Trigger a tab updated event if the favicon URL changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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"
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/event_names.h" 13 #include "chrome/browser/extensions/event_names.h"
14 #include "chrome/browser/extensions/extension_action.h" 14 #include "chrome/browser/extensions/extension_action.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_system.h" 16 #include "chrome/browser/extensions/extension_system.h"
17 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
18 #include "chrome/browser/extensions/window_controller.h" 18 #include "chrome/browser/extensions/window_controller.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_iterator.h" 21 #include "chrome/browser/ui/browser_iterator.h"
22 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/extensions/api/extension_action/action_info.h" 25 #include "chrome/common/extensions/api/extension_action/action_info.h"
25 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
27 #include "content/public/browser/favicon_status.h"
26 #include "content/public/browser/navigation_controller.h" 28 #include "content/public/browser/navigation_controller.h"
29 #include "content/public/browser/navigation_entry.h"
27 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
30 33
31 namespace events = extensions::event_names; 34 namespace events = extensions::event_names;
32 namespace tab_keys = extensions::tabs_constants; 35 namespace tab_keys = extensions::tabs_constants;
33 namespace page_actions_keys = extension_page_actions_api_constants; 36 namespace page_actions_keys = extension_page_actions_api_constants;
34 37
35 using content::NavigationController; 38 using content::NavigationController;
36 using content::WebContents; 39 using content::WebContents;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 registrar_.Add( 124 registrar_.Add(
122 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 125 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
123 content::Source<NavigationController>(&contents->GetController())); 126 content::Source<NavigationController>(&contents->GetController()));
124 127
125 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's 128 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's
126 // possible for tabs to be created, detached and then destroyed without 129 // possible for tabs to be created, detached and then destroyed without
127 // ever having been re-attached and closed. This happens in the case of 130 // ever having been re-attached and closed. This happens in the case of
128 // a devtools WebContents that is opened in window, docked, then closed. 131 // a devtools WebContents that is opened in window, docked, then closed.
129 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 132 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
130 content::Source<WebContents>(contents)); 133 content::Source<WebContents>(contents));
134
135 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_UPDATED,
136 content::Source<WebContents>(contents));
131 } 137 }
132 138
133 void BrowserEventRouter::UnregisterForTabNotifications(WebContents* contents) { 139 void BrowserEventRouter::UnregisterForTabNotifications(WebContents* contents) {
134 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 140 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
135 content::Source<NavigationController>(&contents->GetController())); 141 content::Source<NavigationController>(&contents->GetController()));
136 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 142 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
137 content::Source<WebContents>(contents)); 143 content::Source<WebContents>(contents));
144 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED,
145 content::Source<WebContents>(contents));
138 } 146 }
139 147
140 void BrowserEventRouter::OnBrowserRemoved(Browser* browser) { 148 void BrowserEventRouter::OnBrowserRemoved(Browser* browser) {
141 if (!profile_->IsSameProfile(browser->profile())) 149 if (!profile_->IsSameProfile(browser->profile()))
142 return; 150 return;
143 151
144 // Stop listening to TabStripModel events for this browser. 152 // Stop listening to TabStripModel events for this browser.
145 browser->tab_strip_model()->RemoveObserver(this); 153 browser->tab_strip_model()->RemoveObserver(this);
146 } 154 }
147 155
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 353
346 if (did_navigate) 354 if (did_navigate)
347 changed_properties.reset(entry->DidNavigate(contents)); 355 changed_properties.reset(entry->DidNavigate(contents));
348 else 356 else
349 changed_properties.reset(entry->UpdateLoadState(contents)); 357 changed_properties.reset(entry->UpdateLoadState(contents));
350 358
351 if (changed_properties) 359 if (changed_properties)
352 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); 360 DispatchTabUpdatedEvent(contents, changed_properties.Pass());
353 } 361 }
354 362
363 void BrowserEventRouter::FaviconUrlUpdated(
364 WebContents* contents,
365 bool* icon_url_changed) {
366 if (!icon_url_changed || !*icon_url_changed)
pkotwicz 2013/03/13 17:44:49 Nit: 2 spaces of indent for the function body
Timo Reimann 2013/03/13 19:42:13 Done.
367 return;
368 scoped_ptr<DictionaryValue> changed_properties(new DictionaryValue());
pkotwicz 2013/03/13 17:44:49 Nit: Move the creation of |changed_properties| aft
Timo Reimann 2013/03/13 19:42:13 Done.
369 content::NavigationEntry* entry =
370 contents->GetController().GetActiveEntry();
pkotwicz 2013/03/13 17:44:49 Nit: 4 spaces of indent for the wrapped line
Timo Reimann 2013/03/13 19:42:13 Done.
371 if (!entry || !entry->GetFavicon().valid)
372 return;
373 changed_properties->SetString(tab_keys::kFaviconUrlKey,
374 entry->GetFavicon().url.spec());
375 DispatchTabUpdatedEvent(contents, changed_properties.Pass());
376 }
377
355 void BrowserEventRouter::DispatchEvent( 378 void BrowserEventRouter::DispatchEvent(
356 Profile* profile, 379 Profile* profile,
357 const char* event_name, 380 const char* event_name,
358 scoped_ptr<ListValue> args, 381 scoped_ptr<ListValue> args,
359 EventRouter::UserGestureState user_gesture) { 382 EventRouter::UserGestureState user_gesture) {
360 if (!profile_->IsSameProfile(profile) || 383 if (!profile_->IsSameProfile(profile) ||
361 !extensions::ExtensionSystem::Get(profile)->event_router()) 384 !extensions::ExtensionSystem::Get(profile)->event_router())
362 return; 385 return;
363 386
364 scoped_ptr<Event> event(new Event(event_name, args.Pass())); 387 scoped_ptr<Event> event(new Event(event_name, args.Pass()));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 return &i->second; 476 return &i->second;
454 } 477 }
455 478
456 void BrowserEventRouter::Observe(int type, 479 void BrowserEventRouter::Observe(int type,
457 const content::NotificationSource& source, 480 const content::NotificationSource& source,
458 const content::NotificationDetails& details) { 481 const content::NotificationDetails& details) {
459 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 482 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
460 NavigationController* source_controller = 483 NavigationController* source_controller =
461 content::Source<NavigationController>(source).ptr(); 484 content::Source<NavigationController>(source).ptr();
462 TabUpdated(source_controller->GetWebContents(), true); 485 TabUpdated(source_controller->GetWebContents(), true);
486 } else if (type == chrome::NOTIFICATION_FAVICON_UPDATED) {
487 WebContents* contents = content::Source<WebContents>(source).ptr();
488 bool* icon_url_changed = content::Details<bool>(details).ptr();
489 FaviconUrlUpdated(contents, icon_url_changed);
463 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 490 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
464 // Tab was destroyed after being detached (without being re-attached). 491 // Tab was destroyed after being detached (without being re-attached).
465 WebContents* contents = content::Source<WebContents>(source).ptr(); 492 WebContents* contents = content::Source<WebContents>(source).ptr();
466 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 493 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
467 content::Source<NavigationController>(&contents->GetController())); 494 content::Source<NavigationController>(&contents->GetController()));
468 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 495 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
469 content::Source<WebContents>(contents)); 496 content::Source<WebContents>(contents));
497 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED,
498 content::Source<WebContents>(contents));
pkotwicz 2013/03/13 17:44:49 Style Nit: Check type == chrome::NOTIFICATION_FAVI
Timo Reimann 2013/03/13 19:42:13 Done.
470 } else { 499 } else {
471 NOTREACHED(); 500 NOTREACHED();
472 } 501 }
473 } 502 }
474 503
475 void BrowserEventRouter::TabChangedAt(WebContents* contents, 504 void BrowserEventRouter::TabChangedAt(WebContents* contents,
476 int index, 505 int index,
477 TabChangeType change_type) { 506 TabChangeType change_type) {
478 TabUpdated(contents, false); 507 TabUpdated(contents, false);
479 } 508 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 637
609 DispatchEventToExtension(profile, 638 DispatchEventToExtension(profile,
610 extension_action.extension_id(), 639 extension_action.extension_id(),
611 event_name, 640 event_name,
612 args.Pass(), 641 args.Pass(),
613 EventRouter::USER_GESTURE_ENABLED); 642 EventRouter::USER_GESTURE_ENABLED);
614 } 643 }
615 } 644 }
616 645
617 } // namespace extensions 646 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698