From cff355deca25a0c85e3243890f4017ebbfe9a1eb Mon Sep 17 00:00:00 2001 From: johnson Date: Wed, 5 Nov 2014 10:06:45 +0800 Subject: [PATCH] [Android] Fix XWALK unable to support download behavior Several bugs reported that Xwalk not able to support "download" attribute from anchor since XWALK4 Changes in this commit 1) Implement onDownloadStart method in XWalkContentsClientBridge to call download listener method 2) Ignore render_frame_id which is set to MSG_ROUTING_NONE from content for download request 3) In runtime_download_manager_deledate, return the suggested path to content 4) In runtime_resource_dispatcher_host_delegate_android, don't cancel request, because content will use it later on to futher operation(rename, trunk..etc) BUG=https://crosswalk-project.org/jira/browse/XWALK-1079 --- .../internal/XWalkContentsClientBridge.java | 6 +++++- .../xwalk_contents_io_thread_client_impl.cc | 17 +++++++++++++++-- .../runtime_download_manager_delegate.cc | 2 +- ...resource_dispatcher_host_delegate_android.cc | 2 -- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContentsClientBridge.java b/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContentsClientBridge.java index e33d52b354..112baac8fc 100644 --- a/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContentsClientBridge.java +++ b/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContentsClientBridge.java @@ -373,12 +373,16 @@ public void onDownloadStart(String url, String contentDisposition, String mimeType, long contentLength) { + if (mDownloadListener != null) { + mDownloadListener.onDownloadStart(url, userAgent, contentDisposition, + mimeType, contentLength); + } } @Override public boolean onCreateWindow(boolean isDialog, boolean isUserGesture) { if (isDialog) return false; - + XWalkUIClientInternal.InitiateByInternal initiator = XWalkUIClientInternal.InitiateByInternal.BY_JAVASCRIPT; if (isUserGesture) { diff --git a/runtime/browser/android/xwalk_contents_io_thread_client_impl.cc b/runtime/browser/android/xwalk_contents_io_thread_client_impl.cc index 51fd5fa7a4..82de5a593a 100644 --- a/runtime/browser/android/xwalk_contents_io_thread_client_impl.cc +++ b/runtime/browser/android/xwalk_contents_io_thread_client_impl.cc @@ -89,8 +89,21 @@ void RfhToIoThreadClientMap::Set(pair rfh_id, bool RfhToIoThreadClientMap::Get( pair rfh_id, IoThreadClientData* client) { base::AutoLock lock(map_lock_); - RenderFrameHostToIoThreadClientType::iterator iterator = - rfh_to_io_thread_client_.find(rfh_id); + RenderFrameHostToIoThreadClientType::iterator iterator; + + if (rfh_id.second != MSG_ROUTING_NONE) { + iterator = rfh_to_io_thread_client_.find(rfh_id); + } else { + // Content use render_frame_id= MSG_ROUTING_NONE for download request + // So just find the matched process_id + iterator = rfh_to_io_thread_client_.begin(); + while (iterator != rfh_to_io_thread_client_.end()) { + if (iterator->first.first == rfh_id.first) + break; + iterator++; + } + } + if (iterator == rfh_to_io_thread_client_.end()) return false; diff --git a/runtime/browser/runtime_download_manager_delegate.cc b/runtime/browser/runtime_download_manager_delegate.cc index baa63bfd92..4602be4357 100644 --- a/runtime/browser/runtime_download_manager_delegate.cc +++ b/runtime/browser/runtime_download_manager_delegate.cc @@ -164,7 +164,7 @@ void RuntimeDownloadManagerDelegate::ChooseDownloadPath( if (GetSaveFileName(&save_as)) result = base::FilePath(std::wstring(save_as.lpstrFile)); #else - NOTIMPLEMENTED(); + result = suggested_path; #endif callback.Run(result, content::DownloadItem::TARGET_DISPOSITION_PROMPT, diff --git a/runtime/browser/runtime_resource_dispatcher_host_delegate_android.cc b/runtime/browser/runtime_resource_dispatcher_host_delegate_android.cc index ba63063c60..e5a816df08 100644 --- a/runtime/browser/runtime_resource_dispatcher_host_delegate_android.cc +++ b/runtime/browser/runtime_resource_dispatcher_host_delegate_android.cc @@ -259,8 +259,6 @@ void RuntimeResourceDispatcherHostDelegateAndroid::DownloadStarting( response_headers->GetMimeType(&mime_type); } - request->Cancel(); - const content::ResourceRequestInfo* request_info = content::ResourceRequestInfo::ForRequest(request);