diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-07 08:35:26 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-07 08:35:26 +0000 |
commit | 2da86252173ef56798a5a2b910ceb245d5bdad99 (patch) | |
tree | a37cfa6d12a3da83c2783db66f8009dc23430a04 | |
parent | 67d7f57516b4dcb915661e8495815cad8fa135a1 (diff) | |
download | chromium_src-2da86252173ef56798a5a2b910ceb245d5bdad99.zip chromium_src-2da86252173ef56798a5a2b910ceb245d5bdad99.tar.gz chromium_src-2da86252173ef56798a5a2b910ceb245d5bdad99.tar.bz2 |
WebUI: Serve mime type in Content-Type header
BUG=315513
Review URL: https://codereview.chromium.org/61783002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233552 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/webui/devtools_ui.cc | 4 | ||||
-rw-r--r-- | content/browser/webui/url_data_manager_backend.cc | 18 | ||||
-rw-r--r-- | content/public/browser/url_data_source.cc | 4 | ||||
-rw-r--r-- | content/public/browser/url_data_source.h | 7 |
4 files changed, 33 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc index f755272..df95d3b 100644 --- a/chrome/browser/ui/webui/devtools_ui.cc +++ b/chrome/browser/ui/webui/devtools_ui.cc @@ -183,6 +183,10 @@ class DevToolsDataSource : public content::URLDataSource { return false; } + virtual bool ShouldServeMimeTypeAsContentTypeHeader() const OVERRIDE { + return true; + } + private: virtual ~DevToolsDataSource() {} scoped_refptr<net::URLRequestContextGetter> request_context_; diff --git a/content/browser/webui/url_data_manager_backend.cc b/content/browser/webui/url_data_manager_backend.cc index 1bcbdb7..1e37800 100644 --- a/content/browser/webui/url_data_manager_backend.cc +++ b/content/browser/webui/url_data_manager_backend.cc @@ -17,6 +17,7 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop/message_loop.h" #include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" #include "content/browser/fileapi/chrome_blob_storage_context.h" #include "content/browser/histogram_internals_request_job.h" #include "content/browser/net/view_blob_internals_job_factory.h" @@ -147,6 +148,10 @@ class URLRequestChromeJob : public net::URLRequestJob, deny_xframe_options_ = deny_xframe_options; } + void set_send_content_type_header(bool send_content_type_header) { + send_content_type_header_ = send_content_type_header; + } + // Returns true when job was generated from an incognito profile. bool is_incognito() const { return is_incognito_; @@ -188,6 +193,9 @@ class URLRequestChromeJob : public net::URLRequestJob, // If true, sets the "X-Frame-Options: DENY" header. bool deny_xframe_options_; + // If true, sets the "Content-Type: <mime-type>" header. + bool send_content_type_header_; + // True when job is generated from an incognito profile. const bool is_incognito_; @@ -211,6 +219,7 @@ URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, content_security_policy_object_source_("object-src 'none';"), content_security_policy_frame_source_("frame-src 'none';"), deny_xframe_options_(true), + send_content_type_header_(false), is_incognito_(is_incognito), backend_(backend), weak_factory_(this) { @@ -267,6 +276,13 @@ void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { if (!allow_caching_) info->headers->AddHeader("Cache-Control: no-cache"); + + if (send_content_type_header_ && !mime_type_.empty()) { + std::string content_type = + base::StringPrintf("%s:%s", net::HttpRequestHeaders::kContentType, + mime_type_.c_str()); + info->headers->AddHeader(content_type); + } } void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { @@ -511,6 +527,8 @@ bool URLDataManagerBackend::StartRequest(const net::URLRequest* request, source->source()->GetContentSecurityPolicyFrameSrc()); job->set_deny_xframe_options( source->source()->ShouldDenyXFrameOptions()); + job->set_send_content_type_header( + source->source()->ShouldServeMimeTypeAsContentTypeHeader()); // Look up additional request info to pass down. int render_process_id = -1; diff --git a/content/public/browser/url_data_source.cc b/content/public/browser/url_data_source.cc index 669f5c8..d9506f5 100644 --- a/content/public/browser/url_data_source.cc +++ b/content/public/browser/url_data_source.cc @@ -52,4 +52,8 @@ bool URLDataSource::ShouldServiceRequest(const net::URLRequest* request) const { return false; } +bool URLDataSource::ShouldServeMimeTypeAsContentTypeHeader() const { + return false; +} + } // namespace content diff --git a/content/public/browser/url_data_source.h b/content/public/browser/url_data_source.h index d6ff1e0..d93e51e 100644 --- a/content/public/browser/url_data_source.h +++ b/content/public/browser/url_data_source.h @@ -108,6 +108,13 @@ class CONTENT_EXPORT URLDataSource { // WebUI scheme support for an embedder. virtual bool ShouldServiceRequest(const net::URLRequest* request) const; + // By default, Content-Type: header is not sent along with the response. + // To start sending mime type returned by GetMimeType in HTTP headers, + // return true. It is useful when tunneling response served from this data + // source programmatically. Or when AppCache is enabled for this source as it + // is for chrome-devtools. + virtual bool ShouldServeMimeTypeAsContentTypeHeader() const; + // Called to inform the source that StartDataRequest() will be called soon. // Gives the source an opportunity to rewrite |path| to incorporate extra // information from the URLRequest prior to serving. |