#include "weblayer/browser/background_fetch/background_fetch_permission_context.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/web_contents.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
namespace weblayer {
BackgroundFetchPermissionContext::BackgroundFetchPermissionContext(
content::BrowserContext* browser_context)
: PermissionContextBase(browser_context,
ContentSettingsType::BACKGROUND_FETCH,
blink::mojom::PermissionsPolicyFeature::kNotFound) {
}
ContentSetting BackgroundFetchPermissionContext::GetPermissionStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const {
auto* host_content_settings_map =
HostContentSettingsMapFactory::GetForBrowserContext(browser_context());
ContentSetting setting = host_content_settings_map->GetContentSetting(
requesting_origin, requesting_origin,
ContentSettingsType::AUTOMATIC_DOWNLOADS);
if (setting == CONTENT_SETTING_ALLOW &&
(!render_frame_host || render_frame_host->GetParent())) {
setting = CONTENT_SETTING_ASK;
}
return setting;
}
}