From 7911c3f54e13fc70b49ed513e2be226129cd4ea7 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Tue, 14 Dec 2010 16:35:23 +0000 Subject: Fix WebView form submission CTS failure. When we try to resolve the MIME type from the URL path, we need to be sure to pass just the path so strip off any fragment or query strings. Otherwise this wreaks havoc when we try and extract the file extension to deduce the MIME type. Bug:3241908 Change-Id: I592ae7ba0acc7478789599aeb6973675ed415a37 --- WebKit/android/WebCoreSupport/WebResponse.cpp | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'WebKit/android/WebCoreSupport/WebResponse.cpp') diff --git a/WebKit/android/WebCoreSupport/WebResponse.cpp b/WebKit/android/WebCoreSupport/WebResponse.cpp index 8f68a6a..e564215 100644 --- a/WebKit/android/WebCoreSupport/WebResponse.cpp +++ b/WebKit/android/WebCoreSupport/WebResponse.cpp @@ -46,7 +46,6 @@ WebResponse::WebResponse(URLRequest* request) m_url = request->url().spec(); m_host = request->url().HostNoBrackets(); request->GetMimeType(&m_mime); - setMimeType(m_mime); request->GetCharset(&m_encoding); m_expectedSize = request->GetExpectedContentSize(); @@ -73,12 +72,11 @@ WebResponse::WebResponse(const string &url, const string &mimeType, long long ex , m_mime(mimeType) , m_url(url) { - setMimeType(mimeType); } WebCore::ResourceResponse WebResponse::createResourceResponse() { - WebCore::ResourceResponse resourceResponse(createKurl(), m_mime.c_str(), m_expectedSize, m_encoding.c_str(), ""); + WebCore::ResourceResponse resourceResponse(createKurl(), getMimeType().c_str(), m_expectedSize, m_encoding.c_str(), ""); resourceResponse.setHTTPStatusCode(m_httpStatusCode); resourceResponse.setHTTPStatusText(m_httpStatusText.c_str()); @@ -112,20 +110,26 @@ void WebResponse::setUrl(const string& url) m_url = url; } -const string& WebResponse::getMimeType() const +// Calls WebCore APIs so should only be called from the WebCore thread. +// TODO: can we return a WTF::String directly? Need to check all callsites. +const string& WebResponse::getMimeType() { - return m_mime; -} - -void WebResponse::setMimeType(const std::string &mimeType) -{ - if (mimeType.length() == 0 && m_url.length() > 0) { + if (!m_mime.length() && m_url.length()) { WTF::String wtfMime(m_url.c_str(), m_url.length()); + // Need to strip fragment and/or query if present. + size_t position = wtfMime.reverseFind('#'); + if (position != WTF::notFound) + wtfMime.truncate(position); + + position = wtfMime.reverseFind('?'); + if (position != WTF::notFound) + wtfMime.truncate(position); + wtfMime = WebCore::MIMETypeRegistry::getMIMETypeForPath(wtfMime); m_mime = std::string(wtfMime.utf8().data(), wtfMime.length()); - } else { - m_mime = mimeType; } + + return m_mime; } bool WebResponse::getHeader(const string& header, string* result) const -- cgit v1.1