diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 06:05:31 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 06:05:31 +0000 |
commit | c347c436757c3e37179854861107e1de9ee510a3 (patch) | |
tree | 9baca4c051d9f66355927066f4ceeb1cf8eceaba /android_webview/browser | |
parent | c8a26f18938cc35ab25e9992c2b61326804af346 (diff) | |
download | chromium_src-c347c436757c3e37179854861107e1de9ee510a3.zip chromium_src-c347c436757c3e37179854861107e1de9ee510a3.tar.gz chromium_src-c347c436757c3e37179854861107e1de9ee510a3.tar.bz2 |
(Re)implement Android WebView downloads
Current plan for Android WebView downloads is to only support existing
DownloadListener API. This is a very simple API that cancels all
Chromium side downloads and passes the request information to the
listener.
This independence from Chrome on Android's more sophisticated
implementation (support Http POST downloads etc) will allow the Chrome
impelmentation to be refactored more cleanly.
BUG=
Android only change. Ran through Android trybots.
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/11418301
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/browser')
8 files changed, 146 insertions, 7 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index cfdb350..c476fe8 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -70,10 +70,7 @@ content::ResourceContext* AwBrowserContext::GetResourceContext() { content::DownloadManagerDelegate* AwBrowserContext::GetDownloadManagerDelegate() { - // TODO(boliu): Implement intercepting downloads for DownloadListener and - // maybe put a NOTREACHED if it is indeed never needed. - NOTIMPLEMENTED(); - return NULL; + return &download_manager_delegate_; } content::GeolocationPermissionContext* diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index edbafa0..d184cde 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -5,10 +5,10 @@ #ifndef ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_ #define ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_ -#include "content/public/browser/browser_context.h" - +#include "android_webview/browser/aw_download_manager_delegate.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" +#include "content/public/browser/browser_context.h" namespace android_webview { @@ -52,6 +52,8 @@ class AwBrowserContext : public content::BrowserContext { scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_; + AwDownloadManagerDelegate download_manager_delegate_; + DISALLOW_COPY_AND_ASSIGN(AwBrowserContext); }; diff --git a/android_webview/browser/aw_content_browser_client.cc b/android_webview/browser/aw_content_browser_client.cc index 62f92ec..e897a79 100644 --- a/android_webview/browser/aw_content_browser_client.cc +++ b/android_webview/browser/aw_content_browser_client.cc @@ -302,7 +302,11 @@ void AwContentBrowserClient::ClearCookies(content::RenderViewHost* rvh) { } FilePath AwContentBrowserClient::GetDefaultDownloadDirectory() { - NOTREACHED() << "Android WebView does not use chromium downloads"; + // Android WebView does not currently use the Chromium downloads system. + // Download requests are cancelled immedately when recognized; see + // AwResourceDispatcherHost::CreateResourceHandlerForDownload. However the + // download system still tries to start up and calls this before recognizing + // the request has been cancelled. return FilePath(); } diff --git a/android_webview/browser/aw_contents_io_thread_client.h b/android_webview/browser/aw_contents_io_thread_client.h index fad8a1a..9edab2d 100644 --- a/android_webview/browser/aw_contents_io_thread_client.h +++ b/android_webview/browser/aw_contents_io_thread_client.h @@ -5,6 +5,8 @@ #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ +#include <string> + #include "base/memory/scoped_ptr.h" class GURL; @@ -72,6 +74,15 @@ class AwContentsIoThreadClient { // Retrieve the BlockNetworkLoads setting value of this AwContents. // This method is called on the IO thread only. virtual bool ShouldBlockNetworkLoads() const = 0; + + // Called when ResourceDispathcerHost detects a download request. + // The download is already cancelled when this is called, since + // relevant for DownloadListener is already extracted. + virtual void NewDownload(const GURL& url, + const std::string& user_agent, + const std::string& content_disposition, + const std::string& mime_type, + int64 content_length) = 0; }; } // namespace android_webview diff --git a/android_webview/browser/aw_download_manager_delegate.cc b/android_webview/browser/aw_download_manager_delegate.cc new file mode 100644 index 0000000..9eca137 --- /dev/null +++ b/android_webview/browser/aw_download_manager_delegate.cc @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/browser/aw_download_manager_delegate.h" + +#include "base/file_path.h" +#include "content/public/browser/download_danger_type.h" +#include "content/public/browser/download_item.h" + + +namespace android_webview { + +AwDownloadManagerDelegate::~AwDownloadManagerDelegate() {} + +bool AwDownloadManagerDelegate::DetermineDownloadTarget( + content::DownloadItem* item, + const content::DownloadTargetCallback& callback) { + // Note this cancel is independent of the URLRequest cancel in + // AwResourceDispatcherHostDelegate::DownloadStarting. The request + // could have already finished by the time DownloadStarting is called. + callback.Run(FilePath() /* Empty file path for cancel */, + content::DownloadItem::TARGET_DISPOSITION_OVERWRITE, + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, + FilePath()); + return true; +} + +bool AwDownloadManagerDelegate::ShouldCompleteDownload( + content::DownloadItem* item, + const base::Closure& complete_callback) { + NOTREACHED(); + return true; +} + +bool AwDownloadManagerDelegate::ShouldOpenDownload( + content::DownloadItem* item, + const content::DownloadOpenDelayedCallback& callback) { + NOTREACHED(); + return true; +} + +} // namespace android_webview diff --git a/android_webview/browser/aw_download_manager_delegate.h b/android_webview/browser/aw_download_manager_delegate.h new file mode 100644 index 0000000..3ddddc7 --- /dev/null +++ b/android_webview/browser/aw_download_manager_delegate.h @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_BROWSER_AW_DOWNLOAD_MANAGER_DELEGATE_H_ +#define ANDROID_WEBVIEW_BROWSER_AW_DOWNLOAD_MANAGER_DELEGATE_H_ + +#include "content/public/browser/download_manager_delegate.h" + +namespace content { +class DownloadItem; +} // namespace content + +namespace android_webview { + +// Android WebView does not use Chromium downloads, so implement methods here to +// unconditionally cancel the download. +class AwDownloadManagerDelegate : public content::DownloadManagerDelegate { + public: + virtual ~AwDownloadManagerDelegate(); + + // content::DownloadManagerDelegate implementation. + virtual bool DetermineDownloadTarget( + content::DownloadItem* item, + const content::DownloadTargetCallback& callback) OVERRIDE; + virtual bool ShouldCompleteDownload( + content::DownloadItem* item, + const base::Closure& complete_callback) OVERRIDE; + virtual bool ShouldOpenDownload( + content::DownloadItem* item, + const content::DownloadOpenDelayedCallback& callback) OVERRIDE; +}; + +} // anemspace android_webview + +#endif // ANDROID_WEBVIEW_BROWSER_AW_DOWNLOAD_MANAGER_DELEGATE_H_ diff --git a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc index fcabd97..db605c3 100644 --- a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc +++ b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc @@ -4,6 +4,8 @@ #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h" +#include <string> + #include "android_webview/browser/aw_contents_io_thread_client.h" #include "android_webview/browser/aw_login_delegate.h" #include "android_webview/common/url_constants.h" @@ -228,6 +230,41 @@ void AwResourceDispatcherHostDelegate::RequestBeginning( } } +void AwResourceDispatcherHostDelegate::DownloadStarting( + net::URLRequest* request, + content::ResourceContext* resource_context, + int child_id, + int route_id, + int request_id, + bool is_content_initiated, + ScopedVector<content::ResourceThrottle>* throttles) { + GURL url(request->url()); + std::string user_agent; + std::string content_disposition; + std::string mime_type; + int64 content_length = request->GetExpectedContentSize(); + + request->GetResponseHeaderByName("content-disposition", &content_disposition); + request->extra_request_headers().GetHeader( + net::HttpRequestHeaders::kUserAgent, &user_agent); + request->GetResponseHeaderByName("mime-type", &mime_type); + + request->Cancel(); + + scoped_ptr<AwContentsIoThreadClient> io_client = + AwContentsIoThreadClient::FromID(child_id, route_id); + + // POST request cannot be repeated in general, so prevent client from + // retrying the same request, even if it is with a GET. + if ("GET" == request->method() && io_client) { + io_client->NewDownload(url, + user_agent, + content_disposition, + mime_type, + content_length); + } +} + bool AwResourceDispatcherHostDelegate::AcceptAuthRequest( net::URLRequest* request, net::AuthChallengeInfo* auth_info) { diff --git a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h index 48ab0a5..3a80a37 100644 --- a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h +++ b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h @@ -34,6 +34,15 @@ class AwResourceDispatcherHostDelegate bool is_continuation_of_transferred_request, ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE; + virtual void DownloadStarting( + net::URLRequest* request, + content::ResourceContext* resource_context, + int child_id, + int route_id, + int request_id, + bool is_content_initiated, + ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE; + virtual bool AcceptAuthRequest(net::URLRequest* request, net::AuthChallengeInfo* auth_info) OVERRIDE; |