| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const GURL& source_url) { | 50 const GURL& source_url) { |
| 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 52 | 52 |
| 53 Profile* profile = | 53 Profile* profile = |
| 54 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 54 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 55 HostContentSettingsMap* host_content_settings_map = | 55 HostContentSettingsMap* host_content_settings_map = |
| 56 HostContentSettingsMapFactory::GetForProfile(profile); | 56 HostContentSettingsMapFactory::GetForProfile(profile); |
| 57 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 57 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
| 58 host_content_settings_map, url::Origin(source_url), source_url, nullptr); | 58 host_content_settings_map, url::Origin(source_url), source_url, nullptr); |
| 59 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 59 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 60 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); | 60 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); |
| 61 | 61 |
| 62 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { | 62 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { |
| 63 PermissionManager* manager = PermissionManager::Get(profile); | 63 PermissionManager* manager = PermissionManager::Get(profile); |
| 64 manager->RequestPermission( | 64 manager->RequestPermission( |
| 65 content::PermissionType::FLASH, web_contents->GetMainFrame(), | 65 content::PermissionType::FLASH, web_contents->GetMainFrame(), |
| 66 web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing)); | 66 web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing)); |
| 67 } else if (flash_setting == CONTENT_SETTING_BLOCK) { | 67 } else if (flash_setting == CONTENT_SETTING_BLOCK) { |
| 68 TabSpecificContentSettings::FromWebContents(web_contents) | 68 TabSpecificContentSettings::FromWebContents(web_contents) |
| 69 ->FlashDownloadBlocked(); | 69 ->FlashDownloadBlocked(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // If the content setting has been already changed, do nothing. | 72 // If the content setting has been already changed, do nothing. |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 bool FlashDownloadInterception::ShouldStopFlashDownloadAction( | 76 bool FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 77 HostContentSettingsMap* host_content_settings_map, | 77 HostContentSettingsMap* host_content_settings_map, |
| 78 const GURL& source_url, | 78 const GURL& source_url, |
| 79 const GURL& target_url, | 79 const GURL& target_url, |
| 80 bool has_user_gesture) { | 80 bool has_user_gesture) { |
| 81 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) | 81 if (!PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map)) |
| 82 return false; | 82 return false; |
| 83 | 83 |
| 84 if (!has_user_gesture) | 84 if (!has_user_gesture) |
| 85 return false; | 85 return false; |
| 86 | 86 |
| 87 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, | 87 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, |
| 88 base::CompareCase::INSENSITIVE_ASCII)) { | 88 base::CompareCase::INSENSITIVE_ASCII)) { |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 92 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
| 93 host_content_settings_map, url::Origin(source_url), source_url, nullptr); | 93 host_content_settings_map, url::Origin(source_url), source_url, nullptr); |
| 94 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 94 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 95 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); | 95 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); |
| 96 | 96 |
| 97 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || | 97 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || |
| 98 flash_setting == CONTENT_SETTING_BLOCK; | 98 flash_setting == CONTENT_SETTING_BLOCK; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // static | 101 // static |
| 102 std::unique_ptr<NavigationThrottle> | 102 std::unique_ptr<NavigationThrottle> |
| 103 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 103 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 105 | 105 |
| 106 // Never intercept Flash Download navigations in a new window. | 106 // Never intercept Flash Download navigations in a new window. |
| 107 if (handle->GetWebContents()->HasOpener()) | 107 if (handle->GetWebContents()->HasOpener()) |
| 108 return nullptr; | 108 return nullptr; |
| 109 | 109 |
| 110 Profile* profile = Profile::FromBrowserContext( | 110 Profile* profile = Profile::FromBrowserContext( |
| 111 handle->GetWebContents()->GetBrowserContext()); | 111 handle->GetWebContents()->GetBrowserContext()); |
| 112 HostContentSettingsMap* host_content_settings_map = | 112 HostContentSettingsMap* host_content_settings_map = |
| 113 HostContentSettingsMapFactory::GetForProfile(profile); | 113 HostContentSettingsMapFactory::GetForProfile(profile); |
| 114 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); | 114 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); |
| 115 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 115 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
| 116 handle->GetURL(), | 116 handle->GetURL(), |
| 117 handle->HasUserGesture())) { | 117 handle->HasUserGesture())) { |
| 118 return nullptr; | 118 return nullptr; |
| 119 } | 119 } |
| 120 | 120 |
| 121 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 121 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 122 handle, base::Bind(&InterceptNavigation, source_url), true); | 122 handle, base::Bind(&InterceptNavigation, source_url), true); |
| 123 } | 123 } |
| OLD | NEW |