summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authorjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 21:48:21 +0000
committerjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 21:48:21 +0000
commit91c95c4374d2fb81cfd9994bbe85f7a9837ee483 (patch)
tree34ffefe0e11a50bf4f89258be978f9392b9ab9c5 /chrome/browser/ui
parenteaf10dc5d0fd4d093bb92445207dc9e0679222c7 (diff)
downloadchromium_src-91c95c4374d2fb81cfd9994bbe85f7a9837ee483.zip
chromium_src-91c95c4374d2fb81cfd9994bbe85f7a9837ee483.tar.gz
chromium_src-91c95c4374d2fb81cfd9994bbe85f7a9837ee483.tar.bz2
Make Panel downloads use DownloadShelf in a tabbed browser.
BUG=None TEST=PanelBrowserTest.Download* Review URL: http://codereview.chromium.org/7384013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser.cc12
-rw-r--r--chrome/browser/ui/panels/panel.cc25
-rw-r--r--chrome/browser/ui/panels/panel.h2
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc149
-rw-r--r--chrome/browser/ui/window_sizer.cc5
5 files changed, 183 insertions, 10 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index e5e5eb8..bb1acf2 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -3360,7 +3360,8 @@ void Browser::OnStartDownload(TabContents* source, DownloadItem* download) {
ActiveDownloadsUI::OpenPopup(profile_);
#else
// GetDownloadShelf creates the download shelf if it was not yet created.
- window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download));
+ DownloadShelf* shelf = window()->GetDownloadShelf();
+ shelf->AddDownload(new DownloadItemModel(download));
// Don't show the animation for "Save file" downloads.
if (download->total_bytes() <= 0)
@@ -3371,11 +3372,14 @@ void Browser::OnStartDownload(TabContents* source, DownloadItem* download) {
!ExtensionService::IsDownloadFromMiniGallery(download->GetURL()))
return;
- TabContents* current_tab = GetSelectedTabContents();
+ // Show animation in same window as the download shelf. Download shelf
+ // may not be in the same window that initiated the download, e.g. Panels.
+ TabContents* shelf_tab = shelf->browser()->GetSelectedTabContents();
+
// We make this check for the case of minimized windows, unit tests, etc.
- if (platform_util::IsVisible(current_tab->GetNativeView()) &&
+ if (platform_util::IsVisible(shelf_tab->GetNativeView()) &&
ui::Animation::ShouldRenderRichAnimation()) {
- DownloadStartedAnimation::Show(current_tab);
+ DownloadStartedAnimation::Show(shelf_tab);
}
#endif
diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc
index db2bdae..cbc4e25 100644
--- a/chrome/browser/ui/panels/panel.cc
+++ b/chrome/browser/ui/panels/panel.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
+#include "chrome/browser/ui/window_sizer.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/extensions/extension.h"
#include "ui/gfx/rect.h"
@@ -26,7 +27,8 @@ const Extension* Panel::GetExtension(Browser* browser) {
}
Panel::Panel(Browser* browser, const gfx::Rect& bounds)
- : native_panel_(NULL),
+ : browser_(browser),
+ native_panel_(NULL),
expansion_state_(EXPANDED) {
native_panel_ = CreateNativePanel(browser, this, bounds);
}
@@ -261,13 +263,28 @@ void Panel::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
}
bool Panel::IsDownloadShelfVisible() const {
- NOTIMPLEMENTED();
return false;
}
DownloadShelf* Panel::GetDownloadShelf() {
- NOTIMPLEMENTED();
- return NULL;
+ Profile* profile = browser_->GetProfile();
+ Browser* browser = Browser::GetTabbedBrowser(profile, true);
+
+ if (!browser) {
+ // Set initial bounds so window will not be positioned at an offset
+ // to this panel as panels are at the bottom of the screen.
+ gfx::Rect window_bounds;
+ bool maximized;
+ WindowSizer::GetBrowserWindowBounds(std::string(), gfx::Rect(),
+ browser_, &window_bounds, &maximized);
+ Browser::CreateParams params(Browser::TYPE_TABBED, profile);
+ params.initial_bounds = window_bounds;
+ browser = Browser::CreateWithParams(params);
+ browser->NewTab();
+ }
+
+ browser->window()->Show(); // Ensure download shelf is visible.
+ return browser->window()->GetDownloadShelf();
}
void Panel::ShowRepostFormWarningDialog(TabContents* tab_contents) {
diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h
index 85cdb6f..974a302 100644
--- a/chrome/browser/ui/panels/panel.h
+++ b/chrome/browser/ui/panels/panel.h
@@ -171,6 +171,8 @@ class Panel : public BrowserWindow {
// not allowed for Panel.
void SetPanelBounds(const gfx::Rect& bounds);
+ Browser* browser_; // Weak, owned by native_panel.
+
// Platform specifc implementation for panels. It'd be one of
// PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa.
NativePanel* native_panel_; // Weak, owns us.
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index 83dfa5e..bcb3d30 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -3,12 +3,17 @@
// found in the LICENSE file.
#include "base/command_line.h"
+#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/panels/panel_manager.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "content/browser/net/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
class PanelBrowserTest : public InProcessBrowserTest {
@@ -41,3 +46,147 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
panel_browser->window()->Close();
EXPECT_EQ(0, panel_manager->active_count());
}
+
+class DownloadObserver : public DownloadManager::Observer {
+ public:
+ explicit DownloadObserver(Profile* profile)
+ : download_manager_(profile->GetDownloadManager()),
+ saw_download_(false),
+ waiting_(false) {
+ download_manager_->AddObserver(this);
+ }
+
+ ~DownloadObserver() {
+ download_manager_->RemoveObserver(this);
+ }
+
+ void WaitForDownload() {
+ if (!saw_download_) {
+ waiting_ = true;
+ ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(saw_download_);
+ waiting_ = false;
+ }
+ }
+
+ // DownloadManager::Observer
+ virtual void ModelChanged() {
+ std::vector<DownloadItem*> downloads;
+ download_manager_->GetCurrentDownloads(FilePath(), &downloads);
+ if (downloads.empty())
+ return;
+
+ EXPECT_EQ(1U, downloads.size());
+ downloads.front()->Cancel(false); // Don't actually need to download it.
+
+ saw_download_ = true;
+ EXPECT_TRUE(waiting_);
+ MessageLoopForUI::current()->Quit();
+ }
+
+ private:
+ DownloadManager* download_manager_;
+ bool saw_download_;
+ bool waiting_;
+};
+
+// Verify that the download shelf is opened in the existing tabbed browser
+// when a download is started in a Panel.
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, Download) {
+ Profile* profile = browser()->profile();
+ Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
+ "PanelTest",
+ gfx::Rect(),
+ profile);
+ EXPECT_EQ(2U, BrowserList::size());
+ ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible());
+ ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
+
+ FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
+ GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
+
+ scoped_ptr<DownloadObserver> observer(new DownloadObserver(profile));
+ ui_test_utils::NavigateToURLWithDisposition(
+ panel_browser,
+ download_url,
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+ observer->WaitForDownload();
+
+#if defined(OS_CHROMEOS)
+ // ChromeOS uses a download panel instead of a download shelf.
+ EXPECT_EQ(3U, BrowserList::size());
+ ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible());
+
+ std::set<Browser*> original_browsers;
+ original_browsers.insert(browser());
+ original_browsers.insert(panel_browser);
+ Browser* added = ui_test_utils::GetBrowserNotInSet(original_browsers);
+ ASSERT_TRUE(added->is_type_panel());
+ ASSERT_FALSE(added->window()->IsDownloadShelfVisible());
+#else
+ EXPECT_EQ(2U, BrowserList::size());
+ ASSERT_TRUE(browser()->window()->IsDownloadShelfVisible());
+#endif
+
+ EXPECT_EQ(1, browser()->tab_count());
+ EXPECT_EQ(1, panel_browser->tab_count());
+ ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
+
+ panel_browser->CloseWindow();
+ browser()->CloseWindow();
+}
+
+// Verify that a new tabbed browser is created to display a download
+// shelf when a download is started in a Panel and there is no existing
+// tabbed browser.
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DownloadNoTabbedBrowser) {
+ Profile* profile = browser()->profile();
+ Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
+ "PanelTest",
+ gfx::Rect(),
+ profile);
+ EXPECT_EQ(2U, BrowserList::size());
+ ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible());
+ ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
+
+ ui_test_utils::WindowedNotificationObserver signal(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ Source<Browser>(browser()));
+ browser()->CloseWindow();
+ signal.Wait();
+ ASSERT_EQ(1U, BrowserList::size());
+ ASSERT_EQ(NULL, Browser::GetTabbedBrowser(profile, false));
+
+ FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
+ GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
+
+ scoped_ptr<DownloadObserver> observer(new DownloadObserver(profile));
+ ui_test_utils::NavigateToURLWithDisposition(
+ panel_browser,
+ download_url,
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+ observer->WaitForDownload();
+
+ EXPECT_EQ(2U, BrowserList::size());
+
+#if defined(OS_CHROMEOS)
+ // ChromeOS uses a download panel instead of a download shelf.
+ std::set<Browser*> original_browsers;
+ original_browsers.insert(panel_browser);
+ Browser* added = ui_test_utils::GetBrowserNotInSet(original_browsers);
+ ASSERT_TRUE(added->is_type_panel());
+ ASSERT_FALSE(added->window()->IsDownloadShelfVisible());
+#else
+ Browser* tabbed_browser = Browser::GetTabbedBrowser(profile, false);
+ EXPECT_EQ(1, tabbed_browser->tab_count());
+ ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible());
+ tabbed_browser->CloseWindow();
+#endif
+
+ EXPECT_EQ(1, panel_browser->tab_count());
+ ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
+
+ panel_browser->CloseWindow();
+}
diff --git a/chrome/browser/ui/window_sizer.cc b/chrome/browser/ui/window_sizer.cc
index 245f4c7..24a19cb 100644
--- a/chrome/browser/ui/window_sizer.cc
+++ b/chrome/browser/ui/window_sizer.cc
@@ -73,10 +73,11 @@ class DefaultStateProvider : public WindowSizer::StateProvider {
return false;
// If a reference browser is set, use its window. Otherwise find last
- // active.
+ // active. Panels are never used as reference browsers as panels are
+ // specially positioned.
BrowserWindow* window = NULL;
// Window may be null if browser is just starting up.
- if (browser_ && browser_->window()) {
+ if (browser_ && !browser_->is_type_panel() && browser_->window()) {
window = browser_->window();
} else {
BrowserList::const_reverse_iterator it = BrowserList::begin_last_active();