Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Enable saving of data: urls.
Browse files Browse the repository at this point in the history
1. Add data: to the list of savable urls, for "save page as" path
   (used for text and html files).
2. Instead of suggesting the whole url as file name for dataurls,
   suggest just "dataurl". That's at least shorter.
3. Remove explicit blacklisting of data: urls from download path
   (used for images)

BUG=97108,119129
TEST=Open |data:text/plain;charset=ascii,hello|, hit cmd-s. Should save.
Open |data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==|,
hit cmd-s. Should save.

TBR=avi

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134314 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thakis@chromium.org committed Apr 27, 2012
1 parent c11c766 commit d21cdf1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 83 deletions.
66 changes: 0 additions & 66 deletions chrome/browser/download/download_browsertest.cc
Expand Up @@ -14,7 +14,6 @@
#include "base/stl_util.h"
#include "base/stringprintf.h"
#include "base/test/test_file_util.h"
#include "base/test/thread_test_helper.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -45,7 +44,6 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_persistent_store_info.h"
Expand Down Expand Up @@ -318,12 +316,6 @@ class DownloadTest : public InProcessBrowserTest {
return test_dir_.Append(file);
}

GURL OriginFileUrl(FilePath file) {
std::string file_str = test_dir_.Append(file).MaybeAsASCII();
DCHECK(!file_str.empty()); // We only expect ASCII paths in tests.
return GURL("file://" + file_str);
}

// Location of the file destination (place to which it is downloaded).
FilePath DestinationFile(Browser* browser, FilePath file) {
return GetDownloadDirectory(browser).Append(file);
Expand Down Expand Up @@ -2447,61 +2439,3 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) {
EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
}

IN_PROC_BROWSER_TEST_F(DownloadTest, TestDataBlocker) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url("data:application/octet-stream,abcdefghijklmnop%01%02%03l");

// Navigate & block until navigation is done.
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);

// Do a round trip to the IO thread to increase chances of any download
// showing up on the UI thread.
// Using DownloadTestFlushObserver is overkill, but it'll do the job.
scoped_refptr<DownloadTestFlushObserver> flush_observer(
new DownloadTestFlushObserver(
DownloadManagerForBrowser(browser())));
flush_observer->WaitForFlush();

// Confirm no downloads
std::vector<DownloadItem*> downloads;
GetDownloads(browser(), &downloads);
EXPECT_EQ(0u, downloads.size());

DownloadManagerForBrowser(browser())->RemoveAllDownloads();

// Try the same thing with a direct download. Also check that the
// callback gives the right error.
WebContents* web_contents = browser()->GetSelectedWebContents();
ASSERT_TRUE(web_contents);
scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
new DownloadTestItemCreationObserver);
// Only for cleanup if a download is actually created.
DownloadTestObserverTerminal backup_observer(
DownloadManagerForBrowser(browser()),
1,
false,
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);

DownloadManagerForBrowser(browser())->DownloadUrl(
url, GURL(), "", false, -1, content::DownloadSaveInfo(),
web_contents, creation_observer->callback());

creation_observer->WaitForDownloadItemCreation();

EXPECT_FALSE(creation_observer->succeeded());
EXPECT_EQ(net::ERR_DISALLOWED_URL_SCHEME, creation_observer->error());
EXPECT_EQ(content::DownloadId::Invalid(), creation_observer->download_id());
downloads.clear();
GetDownloads(browser(), &downloads);
EXPECT_EQ(0u, downloads.size());

if (creation_observer->succeeded()) {
// Wait until the download is done. We don't care how it's finished.
backup_observer.WaitForFinished();
}
DownloadManagerForBrowser(browser())->RemoveAllDownloads();
}
8 changes: 5 additions & 3 deletions chrome/test/data/extensions/api_test/downloads/test.js
Expand Up @@ -702,11 +702,13 @@ chrome.test.getConfig(function(testConfig) {
}));
},

function downloadDontAllowDataURLs() {
// We block downloading from data URLs.
function downloadAllowDataURLs() {
var downloadId = getNextId();
downloads.download(
{'url': 'data:text/plain,hello'},
chrome.test.callbackFail("net::ERR_DISALLOWED_URL_SCHEME"));
chrome.test.callback(function(id) {
chrome.test.assertEq(downloadId, id);
}));
},

function downloadAllowFileURLs() {
Expand Down
5 changes: 0 additions & 5 deletions content/browser/download/download_resource_handler.cc
Expand Up @@ -98,11 +98,6 @@ bool DownloadResourceHandler::OnResponseStarted(
<< " request_id = " << request_id;
download_start_time_ = base::TimeTicks::Now();

if (request_->url().scheme() == "data") {
CallStartedCB(download_id_, net::ERR_DISALLOWED_URL_SCHEME);
return false;
}

// If it's a download, we don't want to poison the cache with it.
request_->StopCaching();

Expand Down
22 changes: 13 additions & 9 deletions content/browser/download/save_package.cc
Expand Up @@ -1106,17 +1106,21 @@ FilePath SavePackage::GetSuggestedNameForSaveAs(
// similarly).
if (title_ == net::FormatUrl(page_url_, accept_langs)) {
std::string url_path;
std::vector<std::string> url_parts;
base::SplitString(page_url_.path(), '/', &url_parts);
if (!url_parts.empty()) {
for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) {
url_path = url_parts[i];
if (!url_path.empty())
break;
if (!page_url_.SchemeIs(chrome::kDataScheme)) {
std::vector<std::string> url_parts;
base::SplitString(page_url_.path(), '/', &url_parts);
if (!url_parts.empty()) {
for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) {
url_path = url_parts[i];
if (!url_path.empty())
break;
}
}
if (url_path.empty())
url_path = page_url_.host();
} else {
url_path = "dataurl";
}
if (url_path.empty())
url_path = page_url_.host();
name_with_proper_ext = FilePath::FromWStringHack(UTF8ToWide(url_path));
}

Expand Down
1 change: 1 addition & 0 deletions content/public/common/url_constants.cc
Expand Up @@ -19,6 +19,7 @@ const char* kDefaultSavableSchemes[] = {
chrome::kFtpScheme,
chrome::kChromeDevToolsScheme,
chrome::kChromeUIScheme,
chrome::kDataScheme,
NULL
};
char** g_savable_schemes = const_cast<char**>(kDefaultSavableSchemes);
Expand Down

0 comments on commit d21cdf1

Please sign in to comment.