Commit f09ba40d authored by Min Qin's avatar Min Qin Committed by Commit Bot

Fix an issue that pdf is not auto-opened when typing from URL bar

When network service is enabled by default, page transition type is
not propagated to download when intercepting a navigation. This
CL fixes the issue by sending the transition type from
NavigationRequest, and also fixes an issue that we only check for
DownloadItem::HasUserGesture() when new download backend is enabled.

BUG=1014451

Change-Id: Ie3d7614fbfc007a221c86125ac124087ac09a75d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879612Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709176}
parent ab93b409
......@@ -130,20 +130,6 @@ DownloadManagerService* DownloadManagerService::GetInstance() {
ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
JNIEnv* env,
download::DownloadItem* item) {
bool user_initiated =
(item->GetTransitionType() & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) ||
PageTransitionCoreTypeIs(item->GetTransitionType(),
ui::PAGE_TRANSITION_TYPED) ||
PageTransitionCoreTypeIs(item->GetTransitionType(),
ui::PAGE_TRANSITION_AUTO_BOOKMARK) ||
PageTransitionCoreTypeIs(item->GetTransitionType(),
ui::PAGE_TRANSITION_GENERATED) ||
PageTransitionCoreTypeIs(item->GetTransitionType(),
ui::PAGE_TRANSITION_RELOAD) ||
PageTransitionCoreTypeIs(item->GetTransitionType(),
ui::PAGE_TRANSITION_KEYWORD);
bool has_user_gesture = item->HasUserGesture() || user_initiated;
base::TimeDelta time_delta;
bool time_remaining_known = item->TimeRemaining(&time_delta);
std::string original_url = item->GetOriginalUrl().SchemeIs(url::kDataScheme)
......@@ -160,8 +146,8 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
item->GetReceivedBytes(), item->GetTotalBytes(),
browser_context ? browser_context->IsOffTheRecord() : false,
item->GetState(), item->PercentComplete(), item->IsPaused(),
has_user_gesture, item->CanResume(), item->IsParallelDownload(),
ConvertUTF8ToJavaString(env, original_url),
DownloadUtils::IsDownloadUserInitiated(item), item->CanResume(),
item->IsParallelDownload(), ConvertUTF8ToJavaString(env, original_url),
ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()),
time_remaining_known ? time_delta.InMilliseconds()
: kUnknownRemainingTime,
......
......@@ -115,7 +115,7 @@ bool DownloadUtils::ShouldAutoOpenDownload(download::DownloadItem* item) {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_DownloadUtils_shouldAutoOpenDownload(
env, ConvertUTF8ToJavaString(env, item->GetMimeType()),
item->HasUserGesture());
IsDownloadUserInitiated(item));
}
// static
......@@ -132,3 +132,17 @@ void DownloadUtils::ShowDownloadManager(bool show_prefetched_content,
env, nullptr, nullptr, static_cast<jint>(open_source),
static_cast<jboolean>(show_prefetched_content));
}
bool DownloadUtils::IsDownloadUserInitiated(download::DownloadItem* download) {
ui::PageTransition page_transition = download->GetTransitionType();
return download->HasUserGesture() ||
(page_transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) ||
PageTransitionCoreTypeIs(page_transition, ui::PAGE_TRANSITION_TYPED) ||
PageTransitionCoreTypeIs(page_transition,
ui::PAGE_TRANSITION_AUTO_BOOKMARK) ||
PageTransitionCoreTypeIs(page_transition,
ui::PAGE_TRANSITION_GENERATED) ||
PageTransitionCoreTypeIs(page_transition,
ui::PAGE_TRANSITION_RELOAD) ||
PageTransitionCoreTypeIs(page_transition, ui::PAGE_TRANSITION_KEYWORD);
}
......@@ -34,6 +34,7 @@ class DownloadUtils {
// of the action.
static void ShowDownloadManager(bool show_prefetched_content,
DownloadOpenSource open_source);
static bool IsDownloadUserInitiated(download::DownloadItem* download);
};
#endif // CHROME_BROWSER_DOWNLOAD_ANDROID_DOWNLOAD_UTILS_H_
......@@ -230,6 +230,8 @@ void ResourceDownloader::OnResponseStarted(
download_create_info->render_frame_id = render_frame_id_;
download_create_info->has_user_gesture = resource_request_->has_user_gesture;
download_create_info->is_content_initiated = is_content_initiated_;
download_create_info->transition_type =
ui::PageTransitionFromInt(resource_request_->transition_type);
delegate_task_runner_->PostTask(
FROM_HERE,
......
......@@ -2253,7 +2253,7 @@ void NavigationRequest::OnWillProcessResponseChecksComplete(
// DownloadManager, and cancel the navigation.
if (is_download_) {
// TODO(arthursonzogni): Pass the real ResourceRequest. For the moment
// only these 4 parameters will be used, but it may evolve quickly.
// only these parameters will be used, but it may evolve quickly.
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = common_params_->url;
resource_request->method = common_params_->method;
......@@ -2261,6 +2261,7 @@ void NavigationRequest::OnWillProcessResponseChecksComplete(
resource_request->referrer = common_params_->referrer->url;
resource_request->has_user_gesture = common_params_->has_user_gesture;
resource_request->mode = network::mojom::RequestMode::kNavigate;
resource_request->transition_type = common_params_->transition;
BrowserContext* browser_context =
frame_tree_node_->navigator()->GetController()->GetBrowserContext();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment