Fix: Omnibox is not updated properly when the main frame results in a file download

This is the second attempt, to address the cases where downloadable
URLs are input multiple times.

It seems that depending on the thread execution order, 
TabContents::DidFailProvisionalLoadWithError is sometimes called after
TabContents::OnStartDownload. In such cases, URL display invalidation
happens before the navigation entry removal. The result is
that the downlodable URL remains in the omnibox.

This change ensures that the URL invalidation happens right after
the navigation entry removal.

BUG=1904

TESTED=manually, gcl try

TEST=Type any URLs that causes download, e.g.,
ftp://ftp.vim.org/pub/vim/pc/gvim72.zip into the omnibox.
Observe that the URL is changed back to the original once the download starts.
Repeat this multiple times, with other URLs, to confirm it always works.



Review URL: http://codereview.chromium.org/147006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19094 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index bde80b185..e9190cd8 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -899,13 +899,6 @@
 
   if (tab_contents && tab_contents->delegate())
     tab_contents->delegate()->OnStartDownload(download);
-
-  // Update the URL display.
-  // If the download is caused by typing in a downloadable URL, e.g.,
-  // http://example.com/somefile.zip, into the omnibox, the previous URL
-  // will reappear.
-  if (delegate())
-    delegate()->NavigationStateChanged(this, TabContents::INVALIDATE_URL);
 }
 
 void TabContents::WillClose(ConstrainedWindow* window) {
@@ -1785,8 +1778,11 @@
     // pending entry if the URLs match, otherwise the user initiated a navigate
     // before the page loaded so that the discard would discard the wrong entry.
     NavigationEntry* pending_entry = controller_.pending_entry();
-    if (pending_entry && pending_entry->url() == url)
+    if (pending_entry && pending_entry->url() == url) {
       controller_.DiscardNonCommittedEntries();
+      // Update the URL display.
+      NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
+    }
 
     render_manager_.RendererAbortedProvisionalLoad(render_view_host);
   }