summaryrefslogtreecommitdiffstats
path: root/WebKit
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-01-13 18:41:41 +0000
committerBen Murdoch <benm@google.com>2011-01-14 16:47:02 +0000
commite95b4a7d9ed67e6d6960e33e794e653aa0bd3887 (patch)
treef05dc9135143443e575fd648f5439a2852f144df /WebKit
parentbf16cf132cbd54cc70f003ec6f7500e3dd39dbbb (diff)
downloadexternal_webkit-e95b4a7d9ed67e6d6960e33e794e653aa0bd3887.zip
external_webkit-e95b4a7d9ed67e6d6960e33e794e653aa0bd3887.tar.gz
external_webkit-e95b4a7d9ed67e6d6960e33e794e653aa0bd3887.tar.bz2
Resolve MIME types for CacheResult in the same way as WebResponse.
Change-Id: I972bbdabc8491a94eabd676dd13f09fcccb6ba88
Diffstat (limited to 'WebKit')
-rw-r--r--WebKit/android/WebCoreSupport/CacheResult.cpp10
-rw-r--r--WebKit/android/WebCoreSupport/CacheResult.h4
-rw-r--r--WebKit/android/WebCoreSupport/WebCache.cpp2
-rw-r--r--WebKit/android/WebCoreSupport/WebResponse.cpp46
-rw-r--r--WebKit/android/WebCoreSupport/WebResponse.h2
5 files changed, 39 insertions, 25 deletions
diff --git a/WebKit/android/WebCoreSupport/CacheResult.cpp b/WebKit/android/WebCoreSupport/CacheResult.cpp
index 8193ac1..91c0ede 100644
--- a/WebKit/android/WebCoreSupport/CacheResult.cpp
+++ b/WebKit/android/WebCoreSupport/CacheResult.cpp
@@ -26,8 +26,10 @@
#include "config.h"
#include "CacheResult.h"
+#include "WebResponse.h"
#include "WebUrlLoaderClient.h"
#include <platform/FileSystem.h>
+#include <wtf/text/CString.h>
using namespace base;
using namespace disk_cache;
@@ -47,10 +49,11 @@ enum {
kResponseContentIndex
};
-CacheResult::CacheResult(disk_cache::Entry* entry)
+CacheResult::CacheResult(disk_cache::Entry* entry, String url)
: m_entry(entry)
, m_onResponseHeadersDoneCallback(this, &CacheResult::onResponseHeadersDone)
, m_onReadNextChunkDoneCallback(this, &CacheResult::onReadNextChunkDone)
+ , m_url(url)
{
ASSERT(m_entry);
}
@@ -83,7 +86,10 @@ bool CacheResult::firstResponseHeader(const char* name, String* result, bool all
String CacheResult::mimeType() const
{
string mimeType;
- responseHeaders()->GetMimeType(&mimeType);
+ if (responseHeaders())
+ responseHeaders()->GetMimeType(&mimeType);
+ if (!mimeType.length() && m_url.length())
+ mimeType = WebResponse::resolveMimeType(std::string(m_url.utf8().data(), m_url.length()));
return String(mimeType.c_str());
}
diff --git a/WebKit/android/WebCoreSupport/CacheResult.h b/WebKit/android/WebCoreSupport/CacheResult.h
index 02dced2..c39570c 100644
--- a/WebKit/android/WebCoreSupport/CacheResult.h
+++ b/WebKit/android/WebCoreSupport/CacheResult.h
@@ -38,7 +38,7 @@ namespace android {
class CacheResult : public base::RefCountedThreadSafe<CacheResult> {
public:
// Takes ownership of the Entry passed to the constructor.
- CacheResult(disk_cache::Entry*);
+ CacheResult(disk_cache::Entry*, String url);
~CacheResult();
int64 contentSize() const;
@@ -77,6 +77,8 @@ private:
net::CompletionCallbackImpl<CacheResult> m_onResponseHeadersDoneCallback;
net::CompletionCallbackImpl<CacheResult> m_onReadNextChunkDoneCallback;
+
+ String m_url;
};
} // namespace android
diff --git a/WebKit/android/WebCoreSupport/WebCache.cpp b/WebKit/android/WebCoreSupport/WebCache.cpp
index 0b9d150..be9a700 100644
--- a/WebKit/android/WebCoreSupport/WebCache.cpp
+++ b/WebKit/android/WebCoreSupport/WebCache.cpp
@@ -197,7 +197,7 @@ scoped_refptr<CacheResult> WebCache::getCacheResult(String url)
if (!m_entry)
return 0;
- return new CacheResult(m_entry);
+ return new CacheResult(m_entry, url);
}
void WebCache::getEntryImpl()
diff --git a/WebKit/android/WebCoreSupport/WebResponse.cpp b/WebKit/android/WebCoreSupport/WebResponse.cpp
index 113fb05..52297b2 100644
--- a/WebKit/android/WebCoreSupport/WebResponse.cpp
+++ b/WebKit/android/WebCoreSupport/WebResponse.cpp
@@ -114,31 +114,35 @@ void WebResponse::setUrl(const string& url)
// TODO: can we return a WTF::String directly? Need to check all callsites.
const string& WebResponse::getMimeType()
{
- if (!m_mime.length() && m_url.length()) {
- // Use "text/html" as a default (matching the behaviour of the Apache
- // HTTP stack -- see guessMimeType() in LoadListener.java).
- m_mime = "text/html";
-
- // Try to guess a better MIME type from the URL. We call
- // getMIMETypeForExtension rather than getMIMETypeForPath because the
- // latter defaults to "application/octet-stream" on failure.
- WebCore::KURL kurl(WebCore::ParsedURLString, m_url.c_str());
- WTF::String path = kurl.path();
- size_t extensionPos = path.reverseFind('.');
- if (extensionPos != WTF::notFound) {
- // We found a file extension.
- path.remove(0, extensionPos + 1);
- WTF::String mime = WebCore::MIMETypeRegistry::getMIMETypeForExtension(path);
- if (!mime.isEmpty()) {
- // Great, we found a MIME type.
- m_mime = std::string(mime.utf8().data(), mime.length());
- }
- }
- }
+ if (!m_mime.length() && m_url.length())
+ m_mime = resolveMimeType(m_url);
return m_mime;
}
+const string WebResponse::resolveMimeType(string url)
+{
+ // Use "text/html" as a default (matching the behaviour of the Apache
+ // HTTP stack -- see guessMimeType() in LoadListener.java).
+ string mimeType = "text/html";
+ // Try to guess a better MIME type from the URL. We call
+ // getMIMETypeForExtension rather than getMIMETypeForPath because the
+ // latter defaults to "application/octet-stream" on failure.
+ WebCore::KURL kurl(WebCore::ParsedURLString, url.c_str());
+ WTF::String path = kurl.path();
+ size_t extensionPos = path.reverseFind('.');
+ if (extensionPos != WTF::notFound) {
+ // We found a file extension.
+ path.remove(0, extensionPos + 1);
+ WTF::String mime = WebCore::MIMETypeRegistry::getMIMETypeForExtension(path);
+ if (!mime.isEmpty()) {
+ // Great, we found a MIME type.
+ mimeType = std::string(mime.utf8().data(), mime.length());
+ }
+ }
+ return mimeType;
+}
+
bool WebResponse::getHeader(const string& header, string* result) const
{
map<string, string>::const_iterator iter = m_headerFields.find(header);
diff --git a/WebKit/android/WebCoreSupport/WebResponse.h b/WebKit/android/WebCoreSupport/WebResponse.h
index 9f7d448..e30779f 100644
--- a/WebKit/android/WebCoreSupport/WebResponse.h
+++ b/WebKit/android/WebCoreSupport/WebResponse.h
@@ -59,6 +59,8 @@ public:
WebCore::ResourceResponse createResourceResponse();
WebCore::ResourceError createResourceError();
+ static const std::string resolveMimeType(std::string url);
+
private:
net::Error m_error;
std::string m_encoding;