diff options
author | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 20:26:25 +0000 |
---|---|---|
committer | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 20:26:25 +0000 |
commit | 5f362e0129c6f92953d1e772d72c07d9f0906ab2 (patch) | |
tree | c180150b6f2808cbd61cc2a7cdab918e4f54e01c /chrome/browser/extensions/extension_browser_event_router.cc | |
parent | a1a82d5215198f9ed128f6fc0b1f14cdf3034867 (diff) | |
download | chromium_src-5f362e0129c6f92953d1e772d72c07d9f0906ab2.zip chromium_src-5f362e0129c6f92953d1e772d72c07d9f0906ab2.tar.gz chromium_src-5f362e0129c6f92953d1e772d72c07d9f0906ab2.tar.bz2 |
fix chrome.tabs.onUpdated bugs, add browsertest.
This CL addresses a few issues related to the behavior of the onUpdated event.
Issue 1: The page re-entering the load state and the completing was causing multiple 'complete' status events to be fired. We now only report the first 'complete' after the didNavigate message is fired (iframe navigation, for example).
Issue 2: We were initializing the URL when the TabEntry was created, and this caused us to fail to send the url with the first navigation because we thought it wasn't changing.
BUG=27208,37149
Review URL: http://codereview.chromium.org/2111010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47717 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_browser_event_router.cc')
-rw-r--r-- | chrome/browser/extensions/extension_browser_event_router.cc | 56 |
1 files changed, 17 insertions, 39 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index 52d26da..1932552 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -22,61 +22,39 @@ namespace tab_keys = extension_tabs_module_constants; namespace page_action_keys = extension_page_actions_module_constants; ExtensionBrowserEventRouter::TabEntry::TabEntry() - : state_(ExtensionTabUtil::TAB_COMPLETE), - pending_navigate_(false), + : complete_waiting_on_load_(false), url_() { } -ExtensionBrowserEventRouter::TabEntry::TabEntry(const TabContents* contents) - : state_(ExtensionTabUtil::TAB_COMPLETE), - pending_navigate_(false), - url_(contents->GetURL()) { - UpdateLoadState(contents); -} - DictionaryValue* ExtensionBrowserEventRouter::TabEntry::UpdateLoadState( const TabContents* contents) { - ExtensionTabUtil::TabStatus old_state = state_; - state_ = ExtensionTabUtil::GetTabStatus(contents); - - if (old_state == state_) - return false; - - if (state_ == ExtensionTabUtil::TAB_LOADING) { - // Do not send "loading" state changed now. Wait for navigate so the new - // url is available. - pending_navigate_ = true; + // 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->is_loading()) return NULL; - } else if (state_ == ExtensionTabUtil::TAB_COMPLETE) { - // Send "complete" state change. - DictionaryValue* changed_properties = new DictionaryValue(); - changed_properties->SetString(tab_keys::kStatusKey, - tab_keys::kStatusValueComplete); - return changed_properties; - - } else { - NOTREACHED(); - return NULL; - } + // Send "complete" state change. + complete_waiting_on_load_ = false; + DictionaryValue* changed_properties = new DictionaryValue(); + changed_properties->SetString(tab_keys::kStatusKey, + tab_keys::kStatusValueComplete); + return changed_properties; } DictionaryValue* ExtensionBrowserEventRouter::TabEntry::DidNavigate( const TabContents* contents) { - if (!pending_navigate_) - return NULL; - + // Send "loading" state change. + complete_waiting_on_load_ = true; DictionaryValue* changed_properties = new DictionaryValue(); changed_properties->SetString(tab_keys::kStatusKey, tab_keys::kStatusValueLoading); - GURL new_url = contents->GetURL(); - if (new_url != url_) { - url_ = new_url; + if (contents->GetURL() != url_) { + url_ = contents->GetURL(); changed_properties->SetString(tab_keys::kUrlKey, url_.spec()); } - pending_navigate_ = false; return changed_properties; } @@ -133,7 +111,7 @@ void ExtensionBrowserEventRouter::Init() { for (int i = 0; i < browser->tabstrip_model()->count(); ++i) { TabContents* contents = browser->tabstrip_model()->GetTabContentsAt(i); int tab_id = ExtensionTabUtil::GetTabId(contents); - tab_entries_[tab_id] = TabEntry(contents); + tab_entries_[tab_id] = TabEntry(); } } } @@ -225,7 +203,7 @@ void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, // If tab is new, send created event. int tab_id = ExtensionTabUtil::GetTabId(contents); if (tab_entries_.find(tab_id) == tab_entries_.end()) { - tab_entries_[tab_id] = TabEntry(contents); + tab_entries_[tab_id] = TabEntry(); TabCreatedAt(contents, index, foreground); return; |