| Index: chrome/browser/extensions/api/tabs/tabs_event_router.cc | 
| diff --git a/chrome/browser/extensions/api/tabs/tabs_event_router.cc b/chrome/browser/extensions/api/tabs/tabs_event_router.cc | 
| index baab0e12ffeef2f666fae69c5454aeff8b6e8550..804d9a32df80f572edc6e34b5529f32e6070b809 100644 | 
| --- a/chrome/browser/extensions/api/tabs/tabs_event_router.cc | 
| +++ b/chrome/browser/extensions/api/tabs/tabs_event_router.cc | 
| @@ -16,6 +16,7 @@ | 
| #include "chrome/browser/ui/browser_iterator.h" | 
| #include "chrome/browser/ui/browser_list.h" | 
| #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
| +#include "chrome/browser/ui/tabs/tab_utils.h" | 
| #include "chrome/common/extensions/extension_constants.h" | 
| #include "content/public/browser/favicon_status.h" | 
| #include "content/public/browser/navigation_controller.h" | 
| @@ -58,40 +59,65 @@ bool WillDispatchTabUpdatedEvent( | 
|  | 
| }  // namespace | 
|  | 
| -TabsEventRouter::TabEntry::TabEntry() : complete_waiting_on_load_(false), | 
| -                                        url_() { | 
| +TabsEventRouter::TabEntry::TabEntry() | 
| +    : contents_(NULL), | 
| +      complete_waiting_on_load_(false), | 
| +      was_audible_(false), | 
| +      was_muted_(false) { | 
| } | 
|  | 
| -base::DictionaryValue* TabsEventRouter::TabEntry::UpdateLoadState( | 
| -    const WebContents* contents) { | 
| +TabsEventRouter::TabEntry::TabEntry(content::WebContents* contents) | 
| +    : contents_(contents), | 
| +      complete_waiting_on_load_(false), | 
| +      was_audible_(contents->WasRecentlyAudible()), | 
| +      was_muted_(contents->IsAudioMuted()) { | 
| +} | 
| + | 
| +scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::UpdateLoadState() { | 
| // The tab may go in & out of loading (for instance if iframes navigate). | 
| // We only want to respond to the first change from loading to !loading after | 
| // the NAV_ENTRY_COMMITTED was fired. | 
| -  if (!complete_waiting_on_load_ || contents->IsLoading()) | 
| -    return NULL; | 
| +  scoped_ptr<base::DictionaryValue> changed_properties( | 
| +      new base::DictionaryValue()); | 
| +  if (!complete_waiting_on_load_ || contents_->IsLoading()) { | 
| +    return changed_properties.Pass(); | 
| +  } | 
|  | 
| // Send "complete" state change. | 
| complete_waiting_on_load_ = false; | 
| -  base::DictionaryValue* changed_properties = new base::DictionaryValue(); | 
| changed_properties->SetString(tabs_constants::kStatusKey, | 
| tabs_constants::kStatusValueComplete); | 
| -  return changed_properties; | 
| +  return changed_properties.Pass(); | 
| } | 
|  | 
| -base::DictionaryValue* TabsEventRouter::TabEntry::DidNavigate( | 
| -    const WebContents* contents) { | 
| +scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::DidNavigate() { | 
| // Send "loading" state change. | 
| complete_waiting_on_load_ = true; | 
| -  base::DictionaryValue* changed_properties = new base::DictionaryValue(); | 
| +  scoped_ptr<base::DictionaryValue> changed_properties( | 
| +      new base::DictionaryValue()); | 
| changed_properties->SetString(tabs_constants::kStatusKey, | 
| tabs_constants::kStatusValueLoading); | 
|  | 
| -  if (contents->GetURL() != url_) { | 
| -    url_ = contents->GetURL(); | 
| +  if (contents_->GetURL() != url_) { | 
| +    url_ = contents_->GetURL(); | 
| changed_properties->SetString(tabs_constants::kUrlKey, url_.spec()); | 
| } | 
|  | 
| -  return changed_properties; | 
| +  return changed_properties.Pass(); | 
| +} | 
| + | 
| +bool TabsEventRouter::TabEntry::SetAudible(bool new_val) { | 
| +  if (was_audible_ == new_val) | 
| +    return false; | 
| +  was_audible_ = new_val; | 
| +  return true; | 
| +} | 
| + | 
| +bool TabsEventRouter::TabEntry::SetMuted(bool new_val) { | 
| +  if (was_muted_ == new_val) | 
| +    return false; | 
| +  was_muted_ = new_val; | 
| +  return true; | 
| } | 
|  | 
| TabsEventRouter::TabsEventRouter(Profile* profile) : profile_(profile) { | 
| @@ -110,7 +136,7 @@ TabsEventRouter::TabsEventRouter(Profile* profile) : profile_(profile) { | 
| for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { | 
| WebContents* contents = browser->tab_strip_model()->GetWebContentsAt(i); | 
| int tab_id = ExtensionTabUtil::GetTabId(contents); | 
| -        tab_entries_[tab_id] = TabEntry(); | 
| +        tab_entries_[tab_id] = TabEntry(contents); | 
| } | 
| } | 
| } | 
| @@ -215,7 +241,7 @@ void TabsEventRouter::TabInsertedAt(WebContents* contents, | 
| // If tab is new, send created event. | 
| int tab_id = ExtensionTabUtil::GetTabId(contents); | 
| if (!GetTabEntry(contents)) { | 
| -    tab_entries_[tab_id] = TabEntry(); | 
| +    tab_entries_[tab_id] = TabEntry(contents); | 
|  | 
| TabCreatedAt(contents, index, active); | 
| return; | 
| @@ -390,19 +416,27 @@ void TabsEventRouter::TabMoved(WebContents* contents, | 
| EventRouter::USER_GESTURE_UNKNOWN); | 
| } | 
|  | 
| -void TabsEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { | 
| -  TabEntry* entry = GetTabEntry(contents); | 
| -  scoped_ptr<base::DictionaryValue> changed_properties; | 
| +void TabsEventRouter::TabUpdated( | 
| +    TabsEventRouter::TabEntry* entry, | 
| +    scoped_ptr<base::DictionaryValue> changed_properties) { | 
| +  CHECK(entry->web_contents()); | 
|  | 
| -  CHECK(entry); | 
| +  bool audible = entry->web_contents()->WasRecentlyAudible(); | 
| +  if (entry->SetAudible(audible)) { | 
| +    changed_properties->SetBoolean(tabs_constants::kAudibleKey, audible); | 
| +  } | 
|  | 
| -  if (did_navigate) | 
| -    changed_properties.reset(entry->DidNavigate(contents)); | 
| -  else | 
| -    changed_properties.reset(entry->UpdateLoadState(contents)); | 
| +  bool muted = entry->web_contents()->IsAudioMuted(); | 
| +  if (entry->SetMuted(muted)) { | 
| +    changed_properties->SetBoolean(tabs_constants::kMutedKey, muted); | 
| +    changed_properties->SetString( | 
| +        tabs_constants::kMutedCauseKey, | 
| +        chrome::GetTabAudioMutedCause(entry->web_contents())); | 
| +  } | 
|  | 
| -  if (changed_properties) | 
| -    DispatchTabUpdatedEvent(contents, changed_properties.Pass()); | 
| +  if (!changed_properties->empty()) { | 
| +    DispatchTabUpdatedEvent(entry->web_contents(), changed_properties.Pass()); | 
| +  } | 
| } | 
|  | 
| void TabsEventRouter::FaviconUrlUpdated(WebContents* contents) { | 
| @@ -493,7 +527,9 @@ void TabsEventRouter::Observe(int type, | 
| if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 
| NavigationController* source_controller = | 
| content::Source<NavigationController>(source).ptr(); | 
| -    TabUpdated(source_controller->GetWebContents(), true); | 
| +    TabEntry* entry = GetTabEntry(source_controller->GetWebContents()); | 
| +    CHECK(entry); | 
| +    TabUpdated(entry, entry->DidNavigate()); | 
| } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 
| // Tab was destroyed after being detached (without being re-attached). | 
| WebContents* contents = content::Source<WebContents>(source).ptr(); | 
| @@ -515,7 +551,9 @@ void TabsEventRouter::Observe(int type, | 
| void TabsEventRouter::TabChangedAt(WebContents* contents, | 
| int index, | 
| TabChangeType change_type) { | 
| -  TabUpdated(contents, false); | 
| +  TabEntry* entry = GetTabEntry(contents); | 
| +  CHECK(entry); | 
| +  TabUpdated(entry, entry->UpdateLoadState()); | 
| } | 
|  | 
| void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, | 
| @@ -541,7 +579,7 @@ void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, | 
| UnregisterForTabNotifications(old_contents); | 
|  | 
| if (!GetTabEntry(new_contents)) { | 
| -    tab_entries_[new_tab_id] = TabEntry(); | 
| +    tab_entries_[new_tab_id] = TabEntry(new_contents); | 
| RegisterForTabNotifications(new_contents); | 
| } | 
| } | 
|  |