| 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 c2bc47d3da0a3460b250b99021752a166a85fb5b..41fe9449c4927941feb4b2ee755627b5afe85567 100644
|
| --- a/chrome/browser/extensions/api/tabs/tabs_event_router.cc
|
| +++ b/chrome/browser/extensions/api/tabs/tabs_event_router.cc
|
| @@ -64,41 +64,28 @@ bool WillDispatchTabUpdatedEvent(
|
|
|
| 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.
|
| +scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::Update() {
|
| scoped_ptr<base::DictionaryValue> changed_properties(
|
| new base::DictionaryValue());
|
| - if (!complete_waiting_on_load_ || contents_->IsLoading()) {
|
| - return changed_properties.Pass();
|
| + if (status_ != "loading" && contents_->IsLoading() &&
|
| + contents_->GetLastCommittedURL() != url_) {
|
| + changed_properties->SetString(tabs_constants::kStatusKey,
|
| + tabs_constants::kStatusValueLoading);
|
| + status_ = "loading";
|
| + } else if (status_ == "loading" && !contents_->IsLoading()) {
|
| + changed_properties->SetString(tabs_constants::kStatusKey,
|
| + tabs_constants::kStatusValueComplete);
|
| + status_ = "complete";
|
| }
|
|
|
| - // Send "complete" state change.
|
| - complete_waiting_on_load_ = false;
|
| - changed_properties->SetString(tabs_constants::kStatusKey,
|
| - tabs_constants::kStatusValueComplete);
|
| - return changed_properties.Pass();
|
| -}
|
| -
|
| -scoped_ptr<base::DictionaryValue> TabsEventRouter::TabEntry::DidNavigate() {
|
| - // Send "loading" state change.
|
| - complete_waiting_on_load_ = true;
|
| - 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_->GetLastCommittedURL() != url_) {
|
| + url_ = contents_->GetLastCommittedURL();
|
| changed_properties->SetString(tabs_constants::kUrlKey, url_.spec());
|
| }
|
| -
|
| return changed_properties.Pass();
|
| }
|
|
|
| @@ -160,6 +147,8 @@ void TabsEventRouter::RegisterForBrowserNotifications(Browser* browser) {
|
| }
|
|
|
| void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) {
|
| + // TODO(limasdf): Attach WebContentsObservers to |contents| rather than
|
| + // registering for notifications.
|
| registrar_.Add(
|
| this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
|
| content::Source<NavigationController>(&contents->GetController()));
|
| @@ -506,14 +495,16 @@ linked_ptr<TabsEventRouter::TabEntry> TabsEventRouter::GetTabEntry(
|
| void TabsEventRouter::Observe(int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| - if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
|
| + switch (type) {
|
| + case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
|
| NavigationController* source_controller =
|
| content::Source<NavigationController>(source).ptr();
|
| linked_ptr<TabEntry> entry =
|
| GetTabEntry(source_controller->GetWebContents());
|
| CHECK(entry.get());
|
| - TabUpdated(entry, (entry.get())->DidNavigate());
|
| - } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
|
| + TabUpdated(entry, (entry.get())->Update());
|
| + }
|
| + case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
|
| // Tab was destroyed after being detached (without being re-attached).
|
| WebContents* contents = content::Source<WebContents>(source).ptr();
|
| registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
|
| @@ -522,8 +513,9 @@ void TabsEventRouter::Observe(int type,
|
| content::Source<WebContents>(contents));
|
| favicon_scoped_observer_.Remove(
|
| favicon::ContentFaviconDriver::FromWebContents(contents));
|
| - } else {
|
| - NOTREACHED();
|
| + }
|
| + default:
|
| + NOTREACHED();
|
| }
|
| }
|
|
|
| @@ -532,7 +524,7 @@ void TabsEventRouter::TabChangedAt(WebContents* contents,
|
| TabChangeType change_type) {
|
| linked_ptr<TabEntry> entry = GetTabEntry(contents);
|
| CHECK(entry.get());
|
| - TabUpdated(entry, (entry.get())->UpdateLoadState());
|
| + TabUpdated(entry, (entry.get())->Update());
|
| }
|
|
|
| void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
|
|
|