diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/net_util.cc | 15 | ||||
-rw-r--r-- | net/base/net_util_unittest.cc | 16 | ||||
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/url_request/url_request_data_job.cc | 33 | ||||
-rw-r--r-- | net/url_request/url_request_data_job.h | 29 | ||||
-rw-r--r-- | net/url_request/url_request_job_manager.cc | 2 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 37 |
7 files changed, 133 insertions, 1 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 05f5841..f75184f 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1036,6 +1036,18 @@ std::wstring GetSuggestedFilename(const GURL& url, const std::string& content_disposition, const std::string& referrer_charset, const std::wstring& default_name) { + // TODO(rolandsteiner): as pointed out by darin in the code review, this is + // hardly ideal. "download" should be translated, or another solution found. + // (cf. http://code.google.com/p/chromium/issues/detail?id=25289) + const wchar_t kFinalFallbackName[] = L"download"; + + // about: and data: URLs don't have file names, but esp. data: URLs may + // contain parts that look like ones (i.e., contain a slash). + // Therefore we don't attempt to divine a file name out of them. + if (url.SchemeIs("about") || url.SchemeIs("data")) + return default_name.empty() ? std::wstring(kFinalFallbackName) + : default_name; + std::wstring filename = GetFileNameFromCD(content_disposition, referrer_charset); if (!filename.empty()) { @@ -1065,7 +1077,8 @@ std::wstring GetSuggestedFilename(const GURL& url, // Some schemes (e.g. file) do not have a hostname. Even though it's // not likely to reach here, let's hardcode the last fallback name. // TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451) - filename = url.host().empty() ? L"download" : UTF8ToWide(url.host()); + filename = url.host().empty() ? std::wstring(kFinalFallbackName) + : UTF8ToWide(url.host()); } else { NOTREACHED(); } diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index 22d467c..eddbd16 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -972,6 +972,22 @@ TEST(NetUtilTest, GetSuggestedFilename) { "", L"", L"test.html"}, + // about: and data: URLs + {"about:chrome", + "", + "", + L"", + L"download"}, + {"data:,looks/like/a.path", + "", + "", + L"", + L"download"}, + {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", + "", + "", + L"", + L"download"}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { std::wstring filename = net::GetSuggestedFilename( diff --git a/net/net.gyp b/net/net.gyp index 9d5a056..f7dbe0e0 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -416,6 +416,8 @@ 'url_request/url_request_about_job.cc', 'url_request/url_request_about_job.h', 'url_request/url_request_context.h', + 'url_request/url_request_data_job.cc', + 'url_request/url_request_data_job.h', 'url_request/url_request_error_job.cc', 'url_request/url_request_error_job.h', 'url_request/url_request_file_dir_job.cc', diff --git a/net/url_request/url_request_data_job.cc b/net/url_request/url_request_data_job.cc new file mode 100644 index 0000000..ff52bb3 --- /dev/null +++ b/net/url_request/url_request_data_job.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Simple implementation of a data: protocol handler. + +#include "net/url_request/url_request_data_job.h" + +#include "net/base/data_url.h" +#include "net/url_request/url_request.h" + +// static +URLRequestJob* URLRequestDataJob::Factory(URLRequest* request, + const std::string& scheme) { + return new URLRequestDataJob(request); +} + +URLRequestDataJob::URLRequestDataJob(URLRequest* request) + : URLRequestSimpleJob(request) { +} + + +bool URLRequestDataJob::GetData(std::string* mime_type, + std::string* charset, + std::string* data) const { + // Check if data URL is valid. If not, don't bother to try to extract data. + // Otherwise, parse the data from the data URL. + const GURL& url = request_->url(); + if (!url.is_valid()) + return false; + return net::DataURL::Parse(url, mime_type, charset, data); +} + diff --git a/net/url_request/url_request_data_job.h b/net/url_request/url_request_data_job.h new file mode 100644 index 0000000..44dc327 --- /dev/null +++ b/net/url_request/url_request_data_job.h @@ -0,0 +1,29 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_URL_REQUEST_URL_REQUEST_DATA_JOB_H_ +#define NET_URL_REQUEST_URL_REQUEST_DATA_JOB_H_ + +#include <string> + +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_simple_job.h" + +class URLRequest; + +class URLRequestDataJob : public URLRequestSimpleJob { + public: + explicit URLRequestDataJob(URLRequest* request); + + virtual bool GetData(std::string* mime_type, + std::string* charset, + std::string* data) const; + + static URLRequest::ProtocolFactory Factory; + + DISALLOW_COPY_AND_ASSIGN(URLRequestDataJob); +}; + +#endif // NET_URL_REQUEST_URL_REQUEST_DATA_JOB_H_ + diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc index 616ce30..0b300d1 100644 --- a/net/url_request/url_request_job_manager.cc +++ b/net/url_request/url_request_job_manager.cc @@ -11,6 +11,7 @@ #include "net/base/load_flags.h" #include "net/base/net_errors.h" #include "net/url_request/url_request_about_job.h" +#include "net/url_request/url_request_data_job.h" #include "net/url_request/url_request_error_job.h" #include "net/url_request/url_request_file_job.h" #if defined(OS_WIN) @@ -40,6 +41,7 @@ static const SchemeToFactory kBuiltinFactories[] = { { "ftp", URLRequestNewFtpJob::Factory }, #endif { "about", URLRequestAboutJob::Factory }, + { "data", URLRequestDataJob::Factory }, }; URLRequestJobManager::URLRequestJobManager() { diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index a9a5b0a..21fd22b 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -716,6 +716,43 @@ TEST_F(URLRequestTest, AboutBlankTest) { } } +TEST_F(URLRequestTest, DataURLImageTest) { + TestDelegate d; + { + // Use our nice little Chrome logo. + TestURLRequest r(GURL( + "data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBj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RWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" + "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), + &d); + + r.Start(); + EXPECT_TRUE(r.is_pending()); + + MessageLoop::current()->Run(); + + EXPECT_TRUE(!r.is_pending()); + EXPECT_FALSE(d.received_data_before_response()); + EXPECT_EQ(d.bytes_received(), 911); + } +} + TEST_F(URLRequestTest, FileTest) { FilePath app_path; PathService::Get(base::FILE_EXE, &app_path); |