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(
if (expected_content_size <= INT_MAX)
size = expected_content_size;
info.expected_content_size = size;
info.response_headers = stream->GetResponseHeaders();
scoped_ptr<Event> event(
new Event(streams_private::OnExecuteMimeTypeHandler::kEventName,
......
......@@ -21,6 +21,9 @@ namespace streamsPrivate {
// The amount of data the Stream should contain, if known. If there is no
// information on the size it will be -1.
long expectedContentSize;
// The HTTP response headers of the intercepted request.
DOMString responseHeaders;
};
interface Events {
......
......@@ -11,7 +11,15 @@ chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener(
// meant to be handled by the extension. The extension getting an event with
// the MIME type 'application/msword' means the test has succeeded.
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;
}
......
......@@ -610,6 +610,9 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request,
ResourceResponse* response) {
ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
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;
std::string target_id;
......@@ -636,7 +639,8 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request,
info->GetChildID(),
info->GetRouteID(),
target_id,
handler->stream()->CreateHandle(request->url(), mime_type),
handler->stream()->CreateHandle(request->url(), mime_type,
response_headers),
request->GetExpectedContentSize());
return handler.PassAs<ResourceHandler>();
}
......
......@@ -158,12 +158,15 @@ Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf,
return STREAM_HAS_DATA;
}
scoped_ptr<StreamHandle> Stream::CreateHandle(const GURL& original_url,
const std::string& mime_type) {
scoped_ptr<StreamHandle> Stream::CreateHandle(
const GURL& original_url,
const std::string& mime_type,
const std::string& response_headers) {
CHECK(!stream_handle_);
stream_handle_ = new StreamHandleImpl(weak_ptr_factory_.GetWeakPtr(),
original_url,
mime_type);
mime_type,
response_headers);
return scoped_ptr<StreamHandle>(stream_handle_).Pass();
}
......
......@@ -78,7 +78,8 @@ class CONTENT_EXPORT Stream : public base::RefCountedThreadSafe<Stream> {
StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
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();
// Indicates whether there is space in the buffer to add more data.
......
......@@ -13,11 +13,13 @@ namespace content {
StreamHandleImpl::StreamHandleImpl(const base::WeakPtr<Stream>& stream,
const GURL& original_url,
const std::string& mime_type)
const std::string& mime_type,
const std::string& response_headers)
: stream_(stream),
url_(stream->url()),
original_url_(original_url),
mime_type_(mime_type),
response_headers_(response_headers),
stream_message_loop_(base::MessageLoopProxy::current().get()) {}
StreamHandleImpl::~StreamHandleImpl() {
......@@ -37,4 +39,8 @@ const std::string& StreamHandleImpl::GetMimeType() {
return mime_type_;
}
const std::string& StreamHandleImpl::GetResponseHeaders() {
return response_headers_;
}
} // namespace content
......@@ -21,7 +21,8 @@ class StreamHandleImpl : public StreamHandle {
public:
StreamHandleImpl(const base::WeakPtr<Stream>& stream,
const GURL& original_url,
const std::string& mime_type);
const std::string& mime_type,
const std::string& response_headers);
virtual ~StreamHandleImpl();
private:
......@@ -29,11 +30,13 @@ class StreamHandleImpl : public StreamHandle {
virtual const GURL& GetURL() OVERRIDE;
virtual const GURL& GetOriginalURL() OVERRIDE;
virtual const std::string& GetMimeType() OVERRIDE;
virtual const std::string& GetResponseHeaders() OVERRIDE;
base::WeakPtr<Stream> stream_;
GURL url_;
GURL original_url_;
std::string mime_type_;
std::string response_headers_;
base::MessageLoopProxy* stream_message_loop_;
};
......
......@@ -23,6 +23,9 @@ class CONTENT_EXPORT StreamHandle {
// Get the MIME type associated with this Stream.
virtual const std::string& GetMimeType() = 0;
// Get the HTTP response headers associated with this Stream.
virtual const std::string& GetResponseHeaders() = 0;
};
} // 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