Show the filebrowse ui rather than the download shelf in chromeos.

This cl displays the filebrowse ui rather than download shelf for
downloads in chrom(e|ium) os. It conditionally replaces (with
preprocessor macros) the Browser::OnStartDownload method to do this.

The cl adds a static FileBrowseUI::OpenPopup(profile, hashArgument),
which opens the file browse ui and passes it the provided hash argument.
This is invoked directly from Browser::OnStartDownload. The
USBMountObserver code was changed to call this static method, rather
than open the popup by hand as it had been doing.

I'm not sure about ownership of the Browser* returned by OpenPopup, but
based on other code in the tree I assume chrome will deal with freeing
it when appropriate.

Before this change, USBMountObserver would add the window to registrar_
*before* showing it. Now that FileBrowseUI::OpenPopup returns a which
which is already visible, this is no longer the case. I assume this
won't be a problem.

Commit this for rginda.
Original review: http://codereview.chromium.org/555167

BUG=none
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38222 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 9a02f042..e284f69 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -59,6 +59,7 @@
 #include "chrome/common/platform_util.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/pref_service.h"
+#include "chrome/common/url_constants.h"
 #include "chrome/test/automation/automation_messages.h"
 #include "chrome/test/automation/tab_proxy.h"
 #include "net/proxy/proxy_service.h"
@@ -1118,10 +1119,28 @@
   *visible = false;
 
   if (browser_tracker_->ContainsHandle(handle)) {
+#if defined(OS_CHROMEOS)
+    // Chromium OS shows FileBrowse ui rather than download shelf. So we
+    // enumerate all browsers and look for a chrome://filebrowse... pop up.
+    for (BrowserList::const_iterator it = BrowserList::begin();
+         it != BrowserList::end(); ++it) {
+      if ((*it)->type() == Browser::TYPE_POPUP) {
+        const GURL& url =
+            (*it)->GetTabContentsAt((*it)->selected_index())->GetURL();
+
+        if (url.SchemeIs(chrome::kChromeUIScheme) &&
+            url.host() == chrome::kChromeUIFileBrowseHost) {
+          *visible = true;
+          break;
+        }
+      }
+    }
+#else
     Browser* browser = browser_tracker_->GetResource(handle);
     if (browser) {
       *visible = browser->window()->IsDownloadShelfVisible();
     }
+#endif
   }
 }