summaryrefslogtreecommitdiffstats
path: root/WebKit/android/WebCoreSupport/WebRequest.cpp
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-10-28 13:49:52 +0100
committerIain Merrick <husky@google.com>2010-10-28 16:57:42 +0100
commit7d2f6c10941c9083e9ec30fb08444a5755ff8bc9 (patch)
tree2f4ba525a108117b2b53395ababa70faaa44a407 /WebKit/android/WebCoreSupport/WebRequest.cpp
parent279165f3ff7e77ac27d38b497b670a3b3cea5c3f (diff)
downloadexternal_webkit-7d2f6c10941c9083e9ec30fb08444a5755ff8bc9.zip
external_webkit-7d2f6c10941c9083e9ec30fb08444a5755ff8bc9.tar.gz
external_webkit-7d2f6c10941c9083e9ec30fb08444a5755ff8bc9.tar.bz2
Allow Gmail attachments to be viewed.
When displaying attachments, WebKit calls downloadFile() on an Android-specific URL. This was crashing because it expected to have a URLRequest available; however, there's a different code path in WebRequest.cpp for Android URLs that doesn't create a URLRequest. This CL hoists the implementation of downloadFile() into WebUrlLoaderClient, and gets the necessary headers from the WebResponse object in didReceiveResponse (which should always be called before downloadFile). Gmail appends the MIME type to the URL after a ? separator, and we have to extract this to display the file correctly. Tests: - Can display .txt attachments in Gmail (now fixed) - Can download .apk files (checking for regressions) Change-Id: I966220977972da7a2de29e663d7781b1de0e6fd4
Diffstat (limited to 'WebKit/android/WebCoreSupport/WebRequest.cpp')
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp
index cefd541..307a007 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequest.cpp
@@ -99,6 +99,16 @@ WebRequest::~WebRequest()
env->DeleteGlobalRef((_jobject*)m_inputStream);
}
+const std::string& WebRequest::getUrl() const
+{
+ return m_url;
+}
+
+const std::string& WebRequest::getUserAgent() const
+{
+ return m_userAgent;
+}
+
void WebRequest::finish(bool success)
{
ASSERT(m_loadState < Finished, "called finish on an already finished WebRequest (%d)", m_loadState);
@@ -181,9 +191,20 @@ void WebRequest::handleAndroidURL()
}
m_loadState = Response;
- FilePath path(m_url);
- std::string mimeType("");
- net::GetMimeTypeFromFile(path, &mimeType);
+
+ // Get the MIME type from the URL. "text/html" is a last resort, hopefully overridden.
+ std::string mimeType("text/html");
+
+ // Gmail appends the MIME to the end of the URL, with a ? separator.
+ size_t mimeTypeIndex = m_url.find_last_of('?');
+ if (mimeTypeIndex != std::string::npos) {
+ mimeType.assign(m_url.begin() + mimeTypeIndex + 1, m_url.end());
+ } else {
+ // Get the MIME type from the file extension, if any.
+ FilePath path(m_url);
+ net::GetMimeTypeFromFile(path, &mimeType);
+ }
+
OwnPtr<WebResponse> webResponse(new WebResponse(m_url, mimeType, 0, "", 200));
m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, webResponse.release()));
@@ -341,17 +362,6 @@ void WebRequest::cancelAuth()
m_request->CancelAuth();
}
-void WebRequest::downloadFile(WebFrame* frame)
-{
- std::string contentDisposition;
- std::string mimeType;
-
- m_request->GetResponseHeaderByName("content-disposition", &contentDisposition);
- m_request->GetMimeType(&mimeType);
-
- frame->downloadStart(m_request->url().spec(), m_userAgent, contentDisposition, mimeType, m_request->GetExpectedContentSize());
-}
-
void WebRequest::startReading()
{
ASSERT(m_loadState == Response || m_loadState == GotData, "StartReading in state other than RESPONSE and GOTDATA");