Commit fdf211f0 authored by tommycli's avatar tommycli Committed by Commit bot

[HBD] Only use Flash Download interception for DETECT content setting.

Previously, when the HBD feature flag was on, Flash downloads would be
intercepted in any case. This CL makes it only happen when the user
has the DETECT content setting on.

In the ALLOW case, Flash should already be installed, so there is no
need to install. In the BLOCK case, the user has already decided to not
run Flash, so there is no need to display a prompt to ask.

BUG=641619

Review-Url: https://codereview.chromium.org/2340123002
Cr-Commit-Position: refs/heads/master@{#418911}
parent 4400be71
bauerb@chromium.org
per-file flash*=tommycli@chromium.org
per-file plugin_power_saver*=tommycli@chromium.org
......@@ -7,7 +7,11 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/plugins/plugins_field_trial.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/navigation_interception/intercept_navigation_throttle.h"
#include "components/navigation_interception/navigation_params.h"
#include "content/public/browser/browser_thread.h"
......@@ -48,6 +52,24 @@ FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) {
return nullptr;
}
Profile* profile = Profile::FromBrowserContext(
handle->GetWebContents()->GetBrowserContext());
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile);
GURL page_url = handle->GetWebContents()->GetLastCommittedURL();
std::unique_ptr<base::Value> general_setting =
host_content_settings_map->GetWebsiteSetting(
page_url, page_url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
nullptr);
ContentSetting plugin_setting =
content_settings::ValueToContentSetting(general_setting.get());
plugin_setting = PluginsFieldTrial::EffectiveContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting);
if (plugin_setting != CONTENT_SETTING_DETECT_IMPORTANT_CONTENT)
return nullptr;
return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>(
handle, base::Bind(&ShouldInterceptNavigation), true);
}
......@@ -5,8 +5,11 @@
#include "chrome/browser/plugins/flash_download_interception.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/navigation_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......@@ -46,7 +49,7 @@ TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) {
EXPECT_EQ(nullptr, throttle);
}
TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOn) {
TEST_F(FlashDownloadInterceptionTest, DownloadUrlVariations) {
std::unique_ptr<NavigationThrottle> throttle;
std::unique_ptr<NavigationHandle> flash_slash_navigation_handle =
NavigationHandle::CreateNavigationHandleForTesting(
......@@ -106,3 +109,40 @@ TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOn) {
example_flash_navigation_handle.get());
EXPECT_EQ(nullptr, throttle);
}
TEST_F(FlashDownloadInterceptionTest, OnlyInterceptOnDetectContentSetting) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
flash_navigation_handle_->CallWillStartRequestForTesting(
true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false);
// Default Setting (which is DETECT)
std::unique_ptr<NavigationThrottle> throttle =
FlashDownloadInterception::MaybeCreateThrottleFor(
flash_navigation_handle_.get());
EXPECT_NE(nullptr, throttle);
ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
throttle->WillStartRequest());
// ALLOW and BLOCK Settings
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile());
map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
CONTENT_SETTING_ALLOW);
EXPECT_EQ(nullptr, FlashDownloadInterception::MaybeCreateThrottleFor(
flash_navigation_handle_.get()));
map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
CONTENT_SETTING_BLOCK);
EXPECT_EQ(nullptr, FlashDownloadInterception::MaybeCreateThrottleFor(
flash_navigation_handle_.get()));
// Explicit DETECT
map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
throttle = FlashDownloadInterception::MaybeCreateThrottleFor(
flash_navigation_handle_.get());
EXPECT_NE(nullptr, throttle);
ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
throttle->WillStartRequest());
}
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