Chromium Code Reviews| 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/plugins/plugins_field_trial.h" | 11 #include "chrome/browser/permissions/permission_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/chrome_features.h" | 13 #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" | 14 #include "components/navigation_interception/intercept_navigation_throttle.h" |
| 16 #include "components/navigation_interception/navigation_params.h" | 15 #include "components/navigation_interception/navigation_params.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/navigation_handle.h" | 17 #include "content/public/browser/navigation_handle.h" |
| 18 #include "content/public/browser/permission_type.h" | |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" | |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 using content::NavigationHandle; | 23 using content::NavigationHandle; |
| 23 using content::NavigationThrottle; | 24 using content::NavigationThrottle; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kFlashDownloadURL[] = "get.adobe.com/flashplayer"; | 28 const char kFlashDownloadURL[] = "get.adobe.com/flashplayer"; |
| 28 | 29 |
| 30 void DoNothing(blink::mojom::PermissionStatus result) {} | |
|
Bernhard Bauer
2016/09/22 16:59:10
Aside: we should really have a parametrized Ignore
raymes
2016/09/26 03:23:33
Yeah I looked for it but I couldn't find it. I won
| |
| 31 | |
| 29 bool ShouldInterceptNavigation( | 32 bool ShouldInterceptNavigation( |
| 30 content::WebContents* source, | 33 content::WebContents* source, |
| 31 const navigation_interception::NavigationParams& params) { | 34 const navigation_interception::NavigationParams& params) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 // TODO(crbug.com/626728): Implement permission prompt logic. | 36 PermissionManager* manager = PermissionManager::Get( |
| 37 Profile::FromBrowserContext(source->GetBrowserContext())); | |
| 38 manager->RequestPermission( | |
| 39 content::PermissionType::FLASH, source->GetMainFrame(), | |
| 40 source->GetLastCommittedURL(), true, base::Bind(&DoNothing)); | |
| 41 | |
| 34 return true; | 42 return true; |
| 35 } | 43 } |
| 36 | 44 |
| 37 } // namespace | 45 } // namespace |
| 38 | 46 |
| 39 // static | 47 // static |
| 40 std::unique_ptr<NavigationThrottle> | 48 std::unique_ptr<NavigationThrottle> |
| 41 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 49 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
| 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 | 51 |
| 44 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) | 52 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) |
| 45 return nullptr; | 53 return nullptr; |
| 46 | 54 |
| 47 if (!handle->HasUserGesture()) | 55 if (!handle->HasUserGesture()) |
| 48 return nullptr; | 56 return nullptr; |
| 49 | 57 |
| 50 if (!base::StartsWith(handle->GetURL().GetContent(), kFlashDownloadURL, | 58 if (!base::StartsWith(handle->GetURL().GetContent(), kFlashDownloadURL, |
| 51 base::CompareCase::INSENSITIVE_ASCII)) { | 59 base::CompareCase::INSENSITIVE_ASCII)) { |
| 52 return nullptr; | 60 return nullptr; |
| 53 } | 61 } |
| 54 | 62 |
| 63 GURL page_url = handle->GetWebContents()->GetLastCommittedURL(); | |
| 64 | |
| 55 Profile* profile = Profile::FromBrowserContext( | 65 Profile* profile = Profile::FromBrowserContext( |
| 56 handle->GetWebContents()->GetBrowserContext()); | 66 handle->GetWebContents()->GetBrowserContext()); |
| 57 HostContentSettingsMap* host_content_settings_map = | 67 PermissionManager* manager = PermissionManager::Get(profile); |
| 58 HostContentSettingsMapFactory::GetForProfile(profile); | 68 blink::mojom::PermissionStatus status = manager->GetPermissionStatus( |
| 59 GURL page_url = handle->GetWebContents()->GetLastCommittedURL(); | 69 content::PermissionType::FLASH, page_url, page_url); |
| 60 | 70 |
| 61 std::unique_ptr<base::Value> general_setting = | 71 if (status != blink::mojom::PermissionStatus::ASK) |
| 62 host_content_settings_map->GetWebsiteSetting( | |
| 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; | 72 return nullptr; |
| 72 | 73 |
| 73 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 74 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 74 handle, base::Bind(&ShouldInterceptNavigation), true); | 75 handle, base::Bind(&ShouldInterceptNavigation), true); |
| 75 } | 76 } |
| OLD | NEW |