summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 04:28:10 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 04:28:10 +0000
commit51c2e9ad1b2e61ef88fb616c00be7ee11491fd9f (patch)
treec3c4942aa341601d85526dfe92999fae670eb492 /chrome/browser/download
parentf9e3dde240ede48387fe1ad5dc8ef7a51a2446b7 (diff)
downloadchromium_src-51c2e9ad1b2e61ef88fb616c00be7ee11491fd9f.zip
chromium_src-51c2e9ad1b2e61ef88fb616c00be7ee11491fd9f.tar.gz
chromium_src-51c2e9ad1b2e61ef88fb616c00be7ee11491fd9f.tar.bz2
Don't show downloads from web intents picker in shelf
This CL adds a new attribute to DownloadItem that can be used to suppress the download shelf. This attribute is set the by web intent picker to hide extension downloads. BUG=152010 TBR=sky@chromium.org TEST=Go to http://webintents.org. Click share. Click "Add to Chrome". Verify that the download shelf is not shown. Review URL: https://chromiumcodereview.appspot.com/11016022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_browsertest.cc34
-rw-r--r--chrome/browser/download/download_util.cc25
-rw-r--r--chrome/browser/download/download_util.h6
3 files changed, 65 insertions, 0 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index bedf202..0d60101 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -203,6 +203,13 @@ bool WasAutoOpened(DownloadItem* item) {
return item->GetAutoOpened();
}
+// Called when a download starts. Marks the download as hidden.
+void SetHiddenDownloadCallback(scoped_refptr<DownloadManager> download_manager,
+ DownloadItem* item,
+ net::Error error) {
+ download_util::SetShouldShowInShelf(item, false);
+}
+
} // namespace
// While an object of this class exists, it will mock out download
@@ -2244,3 +2251,30 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) {
std::string expected_contents = test_server()->GetURL("").spec();
ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, HiddenDownload) {
+ FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
+ GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
+
+ scoped_refptr<DownloadManager> download_manager =
+ DownloadManagerForBrowser(browser());
+ scoped_ptr<content::DownloadTestObserver> observer(
+ new content::DownloadTestObserverTerminal(
+ download_manager,
+ 1,
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
+ content::DownloadSaveInfo save_info;
+ save_info.prompt_for_save_location = false;
+
+ // Download and set IsHiddenDownload to true.
+ WebContents* web_contents = chrome::GetActiveWebContents(browser());
+ scoped_ptr<DownloadUrlParameters> params(
+ DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
+ params->set_callback(
+ base::Bind(&SetHiddenDownloadCallback, download_manager));
+ download_manager->DownloadUrl(params.Pass());
+ observer->WaitForFinished();
+
+ // Verify that download shelf is not shown.
+ EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
+}
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index d043c22..3c8b59d 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -75,6 +75,21 @@
namespace {
+// Key used to attach ShowInShelfData to a DownloadItem.
+const char kShowInShelfKey[] = "chrome.download_util.show_in_shelf";
+
+// Class that tracks the "show in download shelf" setting for a download item.
+class ShowInShelfData : public base::SupportsUserData::Data {
+ public:
+ explicit ShowInShelfData(bool should_show) : should_show_(should_show) {
+ }
+
+ bool should_show() const { return should_show_; }
+
+ private:
+ const bool should_show_;
+};
+
// Get the opacity based on |animation_progress|, with values in [0.0, 1.0].
// Range of return value is [0, 255].
int GetOpacity(double animation_progress) {
@@ -480,4 +495,14 @@ void RecordDownloadSource(ChromeDownloadSource source) {
"Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
}
+bool ShouldShowInShelf(content::DownloadItem* item) {
+ ShowInShelfData* data =
+ static_cast<ShowInShelfData*>(item->GetUserData(kShowInShelfKey));
+ return !data || data->should_show();
+}
+
+void SetShouldShowInShelf(content::DownloadItem* item, bool should_show) {
+ item->SetUserData(kShowInShelfKey, new ShowInShelfData(should_show));
+}
+
} // namespace download_util
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 8f75749..6d98314 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -188,6 +188,12 @@ void RecordDownloadCount(ChromeDownloadCountTypes type);
// Record initiation of a download from a specific source.
void RecordDownloadSource(ChromeDownloadSource source);
+// Check whether a download should be displayed in the download shelf.
+bool ShouldShowInShelf(content::DownloadItem* item);
+
+// Set whether a download should be displayed in the download shelf.
+void SetShouldShowInShelf(content::DownloadItem* item, bool should_show);
+
} // namespace download_util
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_