diff options
author | rolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 04:18:58 +0000 |
---|---|---|
committer | rolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 04:18:58 +0000 |
commit | fcb7fd9e3fb31998c9055c63a6b99024e97f211e (patch) | |
tree | 9bd2297b3a58e4e345d17f868f0cc7072b1ef3bc /net/url_request | |
parent | 204758c792daa561ccf691ecd101e6360540360f (diff) | |
download | chromium_src-fcb7fd9e3fb31998c9055c63a6b99024e97f211e.zip chromium_src-fcb7fd9e3fb31998c9055c63a6b99024e97f211e.tar.gz chromium_src-fcb7fd9e3fb31998c9055c63a6b99024e97f211e.tar.bz2 |
Moved patch from 297003 over to committer repository.
Review: http://codereview.chromium.org/297003
BUG=24846
TEST=URLRequestTest.DataURLImageTest, NetUtilTest.GetSuggestedFilename
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-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 |
4 files changed, 101 insertions, 0 deletions
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/9hAAADVklEQVQ4jX2TfUwUBBjG3" + "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" + "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" + "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" + "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" + "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" + "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" + "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" + "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" + "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" + "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" + "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" + "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" + "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" + "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" + "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" + "moRWRNZr/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); |