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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_event_router.cc

Issue 1156043002: chrome.tabs.onUpdated doesn't called with 'loading' twice. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DO NOT SUBMIT/ having only Update() Created 5 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 side-by-side diff with in-line comments
Download patch
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,

Powered by Google App Engine
This is Rietveld 408576698