| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/plugins/flash_download_interception.h" | 5 #include "chrome/browser/plugins/flash_download_interception.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 content::WebContents* source, | 30 content::WebContents* source, |
| 31 const navigation_interception::NavigationParams& params) { | 31 const navigation_interception::NavigationParams& params) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 // TODO(crbug.com/626728): Implement permission prompt logic. | 33 // TODO(crbug.com/626728): Implement permission prompt logic. |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 bool FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 41 HostContentSettingsMap* host_content_settings_map, |
| 42 const GURL& source_url, |
| 43 const GURL& target_url, |
| 44 bool has_user_gesture) { |
| 45 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) |
| 46 return false; |
| 47 |
| 48 if (!has_user_gesture) |
| 49 return false; |
| 50 |
| 51 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, |
| 52 base::CompareCase::INSENSITIVE_ASCII)) { |
| 53 return false; |
| 54 } |
| 55 |
| 56 std::unique_ptr<base::Value> general_setting = |
| 57 host_content_settings_map->GetWebsiteSetting( |
| 58 source_url, source_url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
| 59 nullptr); |
| 60 ContentSetting plugin_setting = |
| 61 content_settings::ValueToContentSetting(general_setting.get()); |
| 62 plugin_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 63 CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting); |
| 64 |
| 65 return plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; |
| 66 } |
| 67 |
| 68 // static |
| 40 std::unique_ptr<NavigationThrottle> | 69 std::unique_ptr<NavigationThrottle> |
| 41 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 70 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
| 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 | 72 |
| 44 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) | 73 // Never intercept Flash Download navigations in a new window. |
| 74 if (handle->GetWebContents()->HasOpener()) |
| 45 return nullptr; | 75 return nullptr; |
| 46 | 76 |
| 47 if (!handle->HasUserGesture()) | |
| 48 return nullptr; | |
| 49 | |
| 50 if (!base::StartsWith(handle->GetURL().GetContent(), kFlashDownloadURL, | |
| 51 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 52 return nullptr; | |
| 53 } | |
| 54 | |
| 55 Profile* profile = Profile::FromBrowserContext( | 77 Profile* profile = Profile::FromBrowserContext( |
| 56 handle->GetWebContents()->GetBrowserContext()); | 78 handle->GetWebContents()->GetBrowserContext()); |
| 57 HostContentSettingsMap* host_content_settings_map = | 79 HostContentSettingsMap* host_content_settings_map = |
| 58 HostContentSettingsMapFactory::GetForProfile(profile); | 80 HostContentSettingsMapFactory::GetForProfile(profile); |
| 59 GURL page_url = handle->GetWebContents()->GetLastCommittedURL(); | 81 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); |
| 60 | 82 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
| 61 std::unique_ptr<base::Value> general_setting = | 83 handle->GetURL(), |
| 62 host_content_settings_map->GetWebsiteSetting( | 84 handle->HasUserGesture())) { |
| 63 page_url, page_url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | |
| 64 nullptr); | |
| 65 ContentSetting plugin_setting = | |
| 66 content_settings::ValueToContentSetting(general_setting.get()); | |
| 67 plugin_setting = PluginsFieldTrial::EffectiveContentSetting( | |
| 68 CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting); | |
| 69 | |
| 70 if (plugin_setting != CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) | |
| 71 return nullptr; | 85 return nullptr; |
| 86 } |
| 72 | 87 |
| 73 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 88 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 74 handle, base::Bind(&ShouldInterceptNavigation), true); | 89 handle, base::Bind(&ShouldInterceptNavigation), true); |
| 75 } | 90 } |
| OLD | NEW |