Commit 999fbba8 authored by Jian Li's avatar Jian Li Committed by Commit Bot

Intercept page download as offline page

This works for network service both enabled and disabled.

Bug: 938696
Change-Id: I2210f44861976b14508c1eff8401bc12958dc87c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504692
Commit-Queue: Jian Li <jianli@chromium.org>
Reviewed-by: default avatarDmitry Titov <dimich@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638288}
parent 0101b70e
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/download/public/common/download_interrupt_reasons.h" #include "components/download/public/common/download_interrupt_reasons.h"
#include "components/download/public/common/download_item.h" #include "components/download/public/common/download_item.h"
#include "components/offline_pages/buildflags/buildflags.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -93,6 +94,12 @@ ...@@ -93,6 +94,12 @@
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#endif #endif
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
#include "chrome/browser/offline_pages/offline_page_utils.h"
#include "components/offline_pages/core/client_namespace_constants.h"
#include "services/network/public/cpp/features.h"
#endif
using content::BrowserThread; using content::BrowserThread;
using content::DownloadManager; using content::DownloadManager;
using download::DownloadItem; using download::DownloadItem;
...@@ -579,6 +586,19 @@ bool ChromeDownloadManagerDelegate::InterceptDownloadIfApplicable( ...@@ -579,6 +586,19 @@ bool ChromeDownloadManagerDelegate::InterceptDownloadIfApplicable(
const std::string& request_origin, const std::string& request_origin,
int64_t content_length, int64_t content_length,
content::WebContents* web_contents) { content::WebContents* web_contents) {
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (offline_pages::OfflinePageUtils::CanDownloadAsOfflinePage(url,
mime_type)) {
offline_pages::OfflinePageUtils::ScheduleDownload(
web_contents, offline_pages::kDownloadNamespace, url,
offline_pages::OfflinePageUtils::DownloadUIActionFlags::ALL,
request_origin);
return true;
}
}
#endif
return false; return false;
} }
......
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