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/render_frame_host.h" | |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" | |
| 20 | 22 |
| 21 using content::BrowserThread; | 23 using content::BrowserThread; |
| 22 using content::NavigationHandle; | 24 using content::NavigationHandle; |
| 23 using content::NavigationThrottle; | 25 using content::NavigationThrottle; |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 const char kFlashDownloadURL[] = "get.adobe.com/flashplayer"; | 29 const char kFlashDownloadURL[] = "get.adobe.com/flashplayer"; |
| 28 | 30 |
| 31 void DoNothing(blink::mojom::PermissionStatus result) {} | |
|
tommycli
2016/09/19 16:44:26
Don't we need to refresh the page after getting th
raymes
2016/09/21 05:46:06
This happens in FlashPermissionContext::UpdateTabC
tommycli
2016/09/23 23:27:26
Sounds good. The CL as-is makes sense, but I think
| |
| 32 | |
| 29 bool ShouldInterceptNavigation( | 33 bool ShouldInterceptNavigation( |
| 30 content::WebContents* source, | 34 content::WebContents* source, |
| 31 const navigation_interception::NavigationParams& params) { | 35 const navigation_interception::NavigationParams& params) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 // TODO(crbug.com/626728): Implement permission prompt logic. | 37 PermissionManager* manager = PermissionManager::Get( |
| 38 Profile::FromBrowserContext(source->GetBrowserContext())); | |
| 39 content::RenderFrameHost* rfh = source->GetMainFrame(); | |
|
dominickn
2016/09/19 05:54:22
Nit: inline source->GetMainFrame() and use source-
raymes
2016/09/21 05:46:05
Done.
| |
| 40 manager->RequestPermission(content::PermissionType::PLUGINS, rfh, | |
| 41 rfh->GetLastCommittedURL(), true, | |
| 42 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 std::unique_ptr<NavigationThrottle> | 50 std::unique_ptr<NavigationThrottle> |
| 41 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 51 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
| 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 52 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 | 53 |
| 44 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) | 54 if (!base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) |
| 45 return nullptr; | 55 return nullptr; |
| 46 | 56 |
| 47 if (!handle->HasUserGesture()) | 57 if (!handle->HasUserGesture()) |
| 48 return nullptr; | 58 return nullptr; |
| 49 | 59 |
| 50 if (!base::StartsWith(handle->GetURL().GetContent(), kFlashDownloadURL, | 60 if (!base::StartsWith(handle->GetURL().GetContent(), kFlashDownloadURL, |
| 51 base::CompareCase::INSENSITIVE_ASCII)) { | 61 base::CompareCase::INSENSITIVE_ASCII)) { |
| 52 return nullptr; | 62 return nullptr; |
| 53 } | 63 } |
| 54 | 64 |
| 65 GURL page_url = handle->GetWebContents()->GetLastCommittedURL(); | |
| 66 | |
| 55 Profile* profile = Profile::FromBrowserContext( | 67 Profile* profile = Profile::FromBrowserContext( |
| 56 handle->GetWebContents()->GetBrowserContext()); | 68 handle->GetWebContents()->GetBrowserContext()); |
| 57 HostContentSettingsMap* host_content_settings_map = | 69 PermissionManager* manager = PermissionManager::Get(profile); |
| 58 HostContentSettingsMapFactory::GetForProfile(profile); | 70 blink::mojom::PermissionStatus status = manager->GetPermissionStatus( |
| 59 GURL page_url = handle->GetWebContents()->GetLastCommittedURL(); | 71 content::PermissionType::PLUGINS, page_url, page_url); |
| 60 | 72 |
| 61 std::unique_ptr<base::Value> general_setting = | 73 if (status != blink::mojom::PermissionStatus::ASK) |
|
tommycli
2016/09/19 16:44:26
As I understand it, the code was moved because the
raymes
2016/09/21 05:46:05
Correct - the code is pretty much needed there so
| |
| 62 host_content_settings_map->GetWebsiteSetting( | |
| 63 page_url, page_url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | |
|
raymes
2016/09/19 05:40:28
We need to decide if we should be passing the reso
| |
| 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; | 74 return nullptr; |
| 72 | 75 |
| 73 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 76 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 74 handle, base::Bind(&ShouldInterceptNavigation), true); | 77 handle, base::Bind(&ShouldInterceptNavigation), true); |
| 75 } | 78 } |
| OLD | NEW |