diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-28 07:13:19 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-28 07:13:19 +0000 |
commit | e53db4462779be3af76c63404314afe7a1464657 (patch) | |
tree | 9c90fa8655cf542bdc35a4819fea2327804a84ef /chrome | |
parent | 06294933c1ae46a2c6aa22bb0b6eac48582330f6 (diff) | |
download | chromium_src-e53db4462779be3af76c63404314afe7a1464657.zip chromium_src-e53db4462779be3af76c63404314afe7a1464657.tar.gz chromium_src-e53db4462779be3af76c63404314afe7a1464657.tar.bz2 |
Add the ability to specify a default MIME type when loading a resource. We'll need this to correctly load stylesheets that lack a Content-Type header in standards mode.
We're waiting on https://bugs.webkit.org/show_bug.cgi?id=24904 upstream before this works fully. This change, as it stands, is a no-op.
R=wtc
BUG=7448
Review URL: http://codereview.chromium.org/55049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12739 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/renderer_host/buffered_resource_handler.cc | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.h | 7 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 8 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.cc | 5 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.h | 1 | ||||
-rw-r--r-- | chrome/plugin/chrome_plugin_host.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/media/data_source_impl.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/renderer_glue.cc | 5 |
9 files changed, 37 insertions, 2 deletions
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc index e8a86ee..3418666 100644 --- a/chrome/browser/renderer_host/buffered_resource_handler.cc +++ b/chrome/browser/renderer_host/buffered_resource_handler.cc @@ -180,6 +180,11 @@ bool BufferedResourceHandler::ShouldBuffer(const GURL& url, bool BufferedResourceHandler::KeepBuffering(int bytes_read) { DCHECK(read_buffer_); + + ResourceDispatcherHost::ExtraRequestInfo* info = + ResourceDispatcherHost::ExtraInfoForRequest(request_); + DCHECK(info); + if (my_buffer_) { // We are using our own buffer to read, update the main buffer. CHECK(bytes_read + bytes_read_ < read_buffer_size_); @@ -193,6 +198,9 @@ bool BufferedResourceHandler::KeepBuffering(int bytes_read) { std::string type_hint, new_type; request_->GetMimeType(&type_hint); + if (type_hint.empty()) + type_hint = info->default_mime_type; + if (!net::SniffMimeType(read_buffer_->data(), bytes_read_, request_->url(), type_hint, &new_type)) { // SniffMimeType() returns false if there is not enough data to determine diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 998850d5..8293a3e 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -395,6 +395,7 @@ void ResourceDispatcherHost::BeginRequest( request_id, request_data.frame_origin, request_data.main_frame_origin, + request_data.default_mime_type, request_data.resource_type, upload_size); extra_info->allow_download = @@ -531,6 +532,7 @@ void ResourceDispatcherHost::BeginDownload(const GURL& url, request_id_, "null", // frame_origin "null", // main_frame_origin + "", // default_mime_type ResourceType::SUB_RESOURCE, 0 /* upload_size */); extra_info->allow_download = true; @@ -585,6 +587,7 @@ void ResourceDispatcherHost::BeginSaveFile(const GURL& url, request_id_, "null", // frame_origin "null", // main_frame_origin + "", // default_mime_type ResourceType::SUB_RESOURCE, 0 /* upload_size */); // Just saving some resources we need, disallow downloading. diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index 052c157..07c532c 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -79,6 +79,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { int request_id, std::string frame_origin, std::string main_frame_origin, + std::string default_mime_type, ResourceType::Type resource_type, uint64 upload_size) : resource_handler(handler), @@ -93,6 +94,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { pause_count(0), frame_origin(frame_origin), main_frame_origin(main_frame_origin), + default_mime_type(default_mime_type), resource_type(resource_type), filter_policy(FilterPolicy::DONT_FILTER), last_load_state(net::LOAD_STATE_IDLE), @@ -141,6 +143,11 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // this request. std::string main_frame_origin; + // The MIME type to use if this request lacks a Content-Type response + // header. If |default_mime_type| is "", then use the default sniffing + // algorithm. + std::string default_mime_type; + ResourceType::Type resource_type; // Whether the content for this request should be filtered (on the renderer diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 28dd519a..284ac51 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -253,6 +253,10 @@ struct ViewHostMsg_Resource_Request { // Additional HTTP request headers. std::string headers; + // The default MIME type to use if the response lacks a Content-Type header. + // Use the empty string here if you don't want special MIME type handling. + std::string default_mime_type; + // URLRequest load flags (0 by default). int load_flags; @@ -1333,6 +1337,7 @@ struct ParamTraits<ViewHostMsg_Resource_Request> { WriteParam(m, p.frame_origin); WriteParam(m, p.main_frame_origin); WriteParam(m, p.headers); + WriteParam(m, p.default_mime_type); WriteParam(m, p.load_flags); WriteParam(m, p.origin_pid); WriteParam(m, p.resource_type); @@ -1348,6 +1353,7 @@ struct ParamTraits<ViewHostMsg_Resource_Request> { ReadParam(m, iter, &r->frame_origin) && ReadParam(m, iter, &r->main_frame_origin) && ReadParam(m, iter, &r->headers) && + ReadParam(m, iter, &r->default_mime_type) && ReadParam(m, iter, &r->load_flags) && ReadParam(m, iter, &r->origin_pid) && ReadParam(m, iter, &r->resource_type) && @@ -1366,6 +1372,8 @@ struct ParamTraits<ViewHostMsg_Resource_Request> { l->append(L", "); LogParam(p.main_frame_origin, l); l->append(L", "); + LogParam(p.default_mime_type, l); + l->append(L", "); LogParam(p.load_flags, l); l->append(L", "); LogParam(p.origin_pid, l); diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc index 1af4ab1..08ace17 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/chrome/common/resource_dispatcher.cc @@ -50,6 +50,7 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge { const std::string& frame_origin, const std::string& main_frame_origin, const std::string& headers, + const std::string& default_mime_type, int load_flags, int origin_pid, ResourceType::Type resource_type, @@ -103,6 +104,7 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge( const std::string& frame_origin, const std::string& main_frame_origin, const std::string& headers, + const std::string& default_mime_type, int load_flags, int origin_pid, ResourceType::Type resource_type, @@ -120,6 +122,7 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge( request_.frame_origin = frame_origin; request_.main_frame_origin = main_frame_origin; request_.headers = headers; + request_.default_mime_type = default_mime_type; request_.load_flags = load_flags; request_.origin_pid = origin_pid; request_.resource_type = resource_type; @@ -522,6 +525,7 @@ webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( const std::string& frame_origin, const std::string& main_frame_origin, const std::string& headers, + const std::string& default_mime_type, int flags, int origin_pid, ResourceType::Type resource_type, @@ -530,6 +534,7 @@ webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( return new webkit_glue::IPCResourceLoaderBridge(this, method, url, policy_url, referrer, frame_origin, main_frame_origin, headers, + default_mime_type, flags, origin_pid, resource_type, request_context, route_id); diff --git a/chrome/common/resource_dispatcher.h b/chrome/common/resource_dispatcher.h index 1374577..73d0a8b3 100644 --- a/chrome/common/resource_dispatcher.h +++ b/chrome/common/resource_dispatcher.h @@ -42,6 +42,7 @@ class ResourceDispatcher { const std::string& frame_origin, const std::string& main_frame_origin, const std::string& headers, + const std::string& default_mime_type, int load_flags, int origin_pid, ResourceType::Type resource_type, diff --git a/chrome/plugin/chrome_plugin_host.cc b/chrome/plugin/chrome_plugin_host.cc index 48f975a..adf1860 100644 --- a/chrome/plugin/chrome_plugin_host.cc +++ b/chrome/plugin/chrome_plugin_host.cc @@ -147,6 +147,7 @@ class PluginRequestHandlerProxy "null", // frame_origin "null", // main_frame_origin extra_headers_, + "", // default_mime_type load_flags_, GetCurrentProcessId(), ResourceType::OBJECT, diff --git a/chrome/renderer/media/data_source_impl.cc b/chrome/renderer/media/data_source_impl.cc index 93a4f5c..ba78743 100644 --- a/chrome/renderer/media/data_source_impl.cc +++ b/chrome/renderer/media/data_source_impl.cc @@ -200,6 +200,7 @@ void DataSourceImpl::OnInitialize(std::string uri) { "null", // TODO(abarth): provide frame_origin "null", // TODO(abarth): provide main_frame_origin std::string(), // Provide no header. + "", // default_mime_type // Prefer to load from cache, also enable downloading the file, the // resource will be saved to a single response data file if it's possible. net::LOAD_PREFERRING_CACHE | net::LOAD_ENABLE_DOWNLOAD_FILE, diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index b6a1a11..e8d3c53 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -235,6 +235,7 @@ ResourceLoaderBridge* ResourceLoaderBridge::Create( const std::string& frame_origin, const std::string& main_frame_origin, const std::string& headers, + const std::string& default_mime_type, int load_flags, int origin_pid, ResourceType::Type resource_type, @@ -242,8 +243,8 @@ ResourceLoaderBridge* ResourceLoaderBridge::Create( ResourceDispatcher* dispatch = RenderThread::current()->resource_dispatcher(); return dispatch->CreateBridge(method, url, policy_url, referrer, frame_origin, main_frame_origin, headers, - load_flags, origin_pid, resource_type, - 0, routing_id); + default_mime_type, load_flags, origin_pid, + resource_type, 0, routing_id); } void NotifyCacheStats() { |