| 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" |
| 11 #include "chrome/browser/permissions/permission_manager.h" |
| 12 #include "chrome/browser/plugins/plugin_utils.h" |
| 11 #include "chrome/browser/plugins/plugins_field_trial.h" | 13 #include "chrome/browser/plugins/plugins_field_trial.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/chrome_features.h" | 15 #include "chrome/common/chrome_features.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 15 #include "components/navigation_interception/intercept_navigation_throttle.h" | 16 #include "components/navigation_interception/intercept_navigation_throttle.h" |
| 16 #include "components/navigation_interception/navigation_params.h" | 17 #include "components/navigation_interception/navigation_params.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
| 20 #include "content/public/browser/permission_type.h" |
| 19 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 20 | 23 |
| 21 using content::BrowserThread; | 24 using content::BrowserThread; |
| 22 using content::NavigationHandle; | 25 using content::NavigationHandle; |
| 23 using content::NavigationThrottle; | 26 using content::NavigationThrottle; |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 const char kFlashDownloadURL[] = "get.adobe.com/flash"; | 30 const char kFlashDownloadURL[] = "get.adobe.com/flash"; |
| 28 | 31 |
| 32 void DoNothing(blink::mojom::PermissionStatus result) {} |
| 33 |
| 29 bool ShouldInterceptNavigation( | 34 bool ShouldInterceptNavigation( |
| 30 content::WebContents* source, | 35 content::WebContents* source, |
| 31 const navigation_interception::NavigationParams& params) { | 36 const navigation_interception::NavigationParams& params) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 // TODO(crbug.com/626728): Implement permission prompt logic. | 38 PermissionManager* manager = PermissionManager::Get( |
| 39 Profile::FromBrowserContext(source->GetBrowserContext())); |
| 40 manager->RequestPermission( |
| 41 content::PermissionType::FLASH, source->GetMainFrame(), |
| 42 source->GetLastCommittedURL(), true, base::Bind(&DoNothing)); |
| 43 |
| 34 return true; | 44 return true; |
| 35 } | 45 } |
| 36 | 46 |
| 37 } // namespace | 47 } // namespace |
| 38 | 48 |
| 39 // static | 49 // static |
| 40 bool FlashDownloadInterception::ShouldStopFlashDownloadAction( | 50 bool FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 41 HostContentSettingsMap* host_content_settings_map, | 51 HostContentSettingsMap* host_content_settings_map, |
| 42 const GURL& source_url, | 52 const GURL& source_url, |
| 43 const GURL& target_url, | 53 const GURL& target_url, |
| 44 bool has_user_gesture) { | 54 bool has_user_gesture) { |
| 45 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) | 55 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) |
| 46 return false; | 56 return false; |
| 47 | 57 |
| 48 if (!has_user_gesture) | 58 if (!has_user_gesture) |
| 49 return false; | 59 return false; |
| 50 | 60 |
| 51 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, | 61 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, |
| 52 base::CompareCase::INSENSITIVE_ASCII)) { | 62 base::CompareCase::INSENSITIVE_ASCII)) { |
| 53 return false; | 63 return false; |
| 54 } | 64 } |
| 55 | 65 |
| 56 std::unique_ptr<base::Value> general_setting = | 66 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
| 57 host_content_settings_map->GetWebsiteSetting( | 67 host_content_settings_map, source_url, source_url); |
| 58 source_url, source_url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | 68 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 59 nullptr); | 69 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); |
| 60 ContentSetting plugin_setting = | |
| 61 content_settings::ValueToContentSetting(general_setting.get()); | |
| 62 plugin_setting = PluginsFieldTrial::EffectiveContentSetting( | |
| 63 CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting); | |
| 64 | 70 |
| 65 return plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; | 71 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; |
| 66 } | 72 } |
| 67 | 73 |
| 68 // static | 74 // static |
| 69 std::unique_ptr<NavigationThrottle> | 75 std::unique_ptr<NavigationThrottle> |
| 70 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 76 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 72 | 78 |
| 73 // Never intercept Flash Download navigations in a new window. | 79 // Never intercept Flash Download navigations in a new window. |
| 74 if (handle->GetWebContents()->HasOpener()) | 80 if (handle->GetWebContents()->HasOpener()) |
| 75 return nullptr; | 81 return nullptr; |
| 76 | 82 |
| 77 Profile* profile = Profile::FromBrowserContext( | 83 Profile* profile = Profile::FromBrowserContext( |
| 78 handle->GetWebContents()->GetBrowserContext()); | 84 handle->GetWebContents()->GetBrowserContext()); |
| 79 HostContentSettingsMap* host_content_settings_map = | 85 HostContentSettingsMap* host_content_settings_map = |
| 80 HostContentSettingsMapFactory::GetForProfile(profile); | 86 HostContentSettingsMapFactory::GetForProfile(profile); |
| 81 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); | 87 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); |
| 82 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 88 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
| 83 handle->GetURL(), | 89 handle->GetURL(), |
| 84 handle->HasUserGesture())) { | 90 handle->HasUserGesture())) { |
| 85 return nullptr; | 91 return nullptr; |
| 86 } | 92 } |
| 87 | 93 |
| 88 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 94 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 89 handle, base::Bind(&ShouldInterceptNavigation), true); | 95 handle, base::Bind(&ShouldInterceptNavigation), true); |
| 90 } | 96 } |
| OLD | NEW |