Commit be5cf44a authored by raymes@chromium.org's avatar raymes@chromium.org

Pass http response headers to the streamsPrivate API callback

This passes the response headers through to the API callback allowing the
application to access the headers without having to make an additional
http request.

BUG=303491

Review URL: https://codereview.chromium.org/185663002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255593 0039d316-1c4b-4281-b951-d872f2087c98
parent 231057f4
...@@ -55,6 +55,7 @@ void StreamsPrivateAPI::ExecuteMimeTypeHandler( ...@@ -55,6 +55,7 @@ void StreamsPrivateAPI::ExecuteMimeTypeHandler(
if (expected_content_size <= INT_MAX) if (expected_content_size <= INT_MAX)
size = expected_content_size; size = expected_content_size;
info.expected_content_size = size; info.expected_content_size = size;
info.response_headers = stream->GetResponseHeaders();
scoped_ptr<Event> event( scoped_ptr<Event> event(
new Event(streams_private::OnExecuteMimeTypeHandler::kEventName, new Event(streams_private::OnExecuteMimeTypeHandler::kEventName,
......
...@@ -21,6 +21,9 @@ namespace streamsPrivate { ...@@ -21,6 +21,9 @@ namespace streamsPrivate {
// The amount of data the Stream should contain, if known. If there is no // The amount of data the Stream should contain, if known. If there is no
// information on the size it will be -1. // information on the size it will be -1.
long expectedContentSize; long expectedContentSize;
// The HTTP response headers of the intercepted request.
DOMString responseHeaders;
}; };
interface Events { interface Events {
......
...@@ -11,7 +11,15 @@ chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener( ...@@ -11,7 +11,15 @@ chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener(
// meant to be handled by the extension. The extension getting an event with // meant to be handled by the extension. The extension getting an event with
// the MIME type 'application/msword' means the test has succeeded. // the MIME type 'application/msword' means the test has succeeded.
if (params.mimeType == 'application/msword') { if (params.mimeType == 'application/msword') {
chrome.test.notifyPass(); var headers = params.responseHeaders;
if (headers.indexOf('Content-Type: application/msword') == -1 ||
headers.indexOf('HTTP/1.1 200 OK') == -1) {
chrome.test.notifyFail(
'HTTP request header did not contain expected attributes.');
hasFailed = true;
} else {
chrome.test.notifyPass();
}
return; return;
} }
......
...@@ -610,6 +610,9 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request, ...@@ -610,6 +610,9 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request,
ResourceResponse* response) { ResourceResponse* response) {
ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
const std::string& mime_type = response->head.mime_type; const std::string& mime_type = response->head.mime_type;
std::string response_headers;
if (response->head.headers)
response->head.headers->GetNormalizedHeaders(&response_headers);
GURL origin; GURL origin;
std::string target_id; std::string target_id;
...@@ -636,7 +639,8 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request, ...@@ -636,7 +639,8 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request,
info->GetChildID(), info->GetChildID(),
info->GetRouteID(), info->GetRouteID(),
target_id, target_id,
handler->stream()->CreateHandle(request->url(), mime_type), handler->stream()->CreateHandle(request->url(), mime_type,
response_headers),
request->GetExpectedContentSize()); request->GetExpectedContentSize());
return handler.PassAs<ResourceHandler>(); return handler.PassAs<ResourceHandler>();
} }
......
...@@ -158,12 +158,15 @@ Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf, ...@@ -158,12 +158,15 @@ Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf,
return STREAM_HAS_DATA; return STREAM_HAS_DATA;
} }
scoped_ptr<StreamHandle> Stream::CreateHandle(const GURL& original_url, scoped_ptr<StreamHandle> Stream::CreateHandle(
const std::string& mime_type) { const GURL& original_url,
const std::string& mime_type,
const std::string& response_headers) {
CHECK(!stream_handle_); CHECK(!stream_handle_);
stream_handle_ = new StreamHandleImpl(weak_ptr_factory_.GetWeakPtr(), stream_handle_ = new StreamHandleImpl(weak_ptr_factory_.GetWeakPtr(),
original_url, original_url,
mime_type); mime_type,
response_headers);
return scoped_ptr<StreamHandle>(stream_handle_).Pass(); return scoped_ptr<StreamHandle>(stream_handle_).Pass();
} }
......
...@@ -78,7 +78,8 @@ class CONTENT_EXPORT Stream : public base::RefCountedThreadSafe<Stream> { ...@@ -78,7 +78,8 @@ class CONTENT_EXPORT Stream : public base::RefCountedThreadSafe<Stream> {
StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url, scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url,
const std::string& mime_type); const std::string& mime_type,
const std::string& response_headers);
void CloseHandle(); void CloseHandle();
// Indicates whether there is space in the buffer to add more data. // Indicates whether there is space in the buffer to add more data.
......
...@@ -13,11 +13,13 @@ namespace content { ...@@ -13,11 +13,13 @@ namespace content {
StreamHandleImpl::StreamHandleImpl(const base::WeakPtr<Stream>& stream, StreamHandleImpl::StreamHandleImpl(const base::WeakPtr<Stream>& stream,
const GURL& original_url, const GURL& original_url,
const std::string& mime_type) const std::string& mime_type,
const std::string& response_headers)
: stream_(stream), : stream_(stream),
url_(stream->url()), url_(stream->url()),
original_url_(original_url), original_url_(original_url),
mime_type_(mime_type), mime_type_(mime_type),
response_headers_(response_headers),
stream_message_loop_(base::MessageLoopProxy::current().get()) {} stream_message_loop_(base::MessageLoopProxy::current().get()) {}
StreamHandleImpl::~StreamHandleImpl() { StreamHandleImpl::~StreamHandleImpl() {
...@@ -37,4 +39,8 @@ const std::string& StreamHandleImpl::GetMimeType() { ...@@ -37,4 +39,8 @@ const std::string& StreamHandleImpl::GetMimeType() {
return mime_type_; return mime_type_;
} }
const std::string& StreamHandleImpl::GetResponseHeaders() {
return response_headers_;
}
} // namespace content } // namespace content
...@@ -21,7 +21,8 @@ class StreamHandleImpl : public StreamHandle { ...@@ -21,7 +21,8 @@ class StreamHandleImpl : public StreamHandle {
public: public:
StreamHandleImpl(const base::WeakPtr<Stream>& stream, StreamHandleImpl(const base::WeakPtr<Stream>& stream,
const GURL& original_url, const GURL& original_url,
const std::string& mime_type); const std::string& mime_type,
const std::string& response_headers);
virtual ~StreamHandleImpl(); virtual ~StreamHandleImpl();
private: private:
...@@ -29,11 +30,13 @@ class StreamHandleImpl : public StreamHandle { ...@@ -29,11 +30,13 @@ class StreamHandleImpl : public StreamHandle {
virtual const GURL& GetURL() OVERRIDE; virtual const GURL& GetURL() OVERRIDE;
virtual const GURL& GetOriginalURL() OVERRIDE; virtual const GURL& GetOriginalURL() OVERRIDE;
virtual const std::string& GetMimeType() OVERRIDE; virtual const std::string& GetMimeType() OVERRIDE;
virtual const std::string& GetResponseHeaders() OVERRIDE;
base::WeakPtr<Stream> stream_; base::WeakPtr<Stream> stream_;
GURL url_; GURL url_;
GURL original_url_; GURL original_url_;
std::string mime_type_; std::string mime_type_;
std::string response_headers_;
base::MessageLoopProxy* stream_message_loop_; base::MessageLoopProxy* stream_message_loop_;
}; };
......
...@@ -23,6 +23,9 @@ class CONTENT_EXPORT StreamHandle { ...@@ -23,6 +23,9 @@ class CONTENT_EXPORT StreamHandle {
// Get the MIME type associated with this Stream. // Get the MIME type associated with this Stream.
virtual const std::string& GetMimeType() = 0; virtual const std::string& GetMimeType() = 0;
// Get the HTTP response headers associated with this Stream.
virtual const std::string& GetResponseHeaders() = 0;
}; };
} // namespace content } // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment