| 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_permission_context.h" | 5 #include "chrome/browser/plugins/flash_permission_context.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 8 #include "chrome/browser/permissions/permission_request_id.h" | 8 #include "chrome/browser/permissions/permission_request_id.h" |
| 9 #include "chrome/browser/plugins/flash_temporary_permission_tracker.h" |
| 9 #include "chrome/browser/plugins/plugin_utils.h" | 10 #include "chrome/browser/plugins/plugin_utils.h" |
| 10 #include "chrome/browser/plugins/plugins_field_trial.h" | 11 #include "chrome/browser/plugins/plugins_field_trial.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 12 #include "components/content_settings/core/common/content_settings_pattern.h" | 15 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 13 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 16 #include "url/origin.h" | 19 #include "url/origin.h" |
| 17 | 20 |
| 21 namespace { |
| 22 |
| 23 bool PluginsEnterpriseSettingEnabled( |
| 24 HostContentSettingsMap* host_content_settings_map) { |
| 25 std::string provider_id; |
| 26 host_content_settings_map->GetDefaultContentSetting( |
| 27 CONTENT_SETTINGS_TYPE_PLUGINS, &provider_id); |
| 28 return provider_id == site_settings::kPolicyProviderId; |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 18 FlashPermissionContext::FlashPermissionContext(Profile* profile) | 33 FlashPermissionContext::FlashPermissionContext(Profile* profile) |
| 19 : PermissionContextBase(profile, | 34 : PermissionContextBase(profile, |
| 20 content::PermissionType::FLASH, | 35 content::PermissionType::FLASH, |
| 21 CONTENT_SETTINGS_TYPE_PLUGINS) {} | 36 CONTENT_SETTINGS_TYPE_PLUGINS) {} |
| 22 | 37 |
| 23 FlashPermissionContext::~FlashPermissionContext() {} | 38 FlashPermissionContext::~FlashPermissionContext() {} |
| 24 | 39 |
| 25 ContentSetting FlashPermissionContext::GetPermissionStatus( | 40 ContentSetting FlashPermissionContext::GetPermissionStatus( |
| 26 const GURL& requesting_origin, | 41 const GURL& requesting_origin, |
| 27 const GURL& embedding_origin) const { | 42 const GURL& embedding_origin) const { |
| 28 HostContentSettingsMap* host_content_settings_map = | 43 HostContentSettingsMap* host_content_settings_map = |
| 29 HostContentSettingsMapFactory::GetForProfile(profile()); | 44 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 30 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 45 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
| 31 host_content_settings_map, url::Origin(embedding_origin), | 46 host_content_settings_map, url::Origin(embedding_origin), |
| 32 requesting_origin, nullptr); | 47 requesting_origin, nullptr); |
| 33 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 48 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 34 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); | 49 host_content_settings_map, content_settings_type(), flash_setting); |
| 35 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) | 50 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) |
| 36 return CONTENT_SETTING_ASK; | 51 return CONTENT_SETTING_ASK; |
| 37 return flash_setting; | 52 return flash_setting; |
| 38 } | 53 } |
| 39 | 54 |
| 40 void FlashPermissionContext::UpdateTabContext(const PermissionRequestID& id, | 55 void FlashPermissionContext::UpdateTabContext(const PermissionRequestID& id, |
| 41 const GURL& requesting_origin, | 56 const GURL& requesting_origin, |
| 42 bool allowed) { | 57 bool allowed) { |
| 43 if (!allowed) | 58 if (!allowed) |
| 44 return; | 59 return; |
| 45 // Automatically refresh the page. | 60 |
| 46 content::WebContents* web_contents = | 61 content::WebContents* web_contents = |
| 47 content::WebContents::FromRenderFrameHost( | 62 content::WebContents::FromRenderFrameHost( |
| 48 content::RenderFrameHost::FromID(id.render_process_id(), | 63 content::RenderFrameHost::FromID(id.render_process_id(), |
| 49 id.render_frame_id())); | 64 id.render_frame_id())); |
| 65 |
| 66 if (PluginsEnterpriseSettingEnabled( |
| 67 HostContentSettingsMapFactory::GetForProfile(profile()))) { |
| 68 // Enable the grant temporarily. |
| 69 FlashTemporaryPermissionTracker::Get(profile())->FlashEnabledForWebContents( |
| 70 web_contents); |
| 71 } |
| 72 |
| 73 // Automatically refresh the page. |
| 50 web_contents->GetController().Reload(true /* check_for_repost */); | 74 web_contents->GetController().Reload(true /* check_for_repost */); |
| 51 } | 75 } |
| 52 | 76 |
| 53 void FlashPermissionContext::UpdateContentSetting( | 77 void FlashPermissionContext::UpdateContentSetting( |
| 54 const GURL& requesting_origin, | 78 const GURL& requesting_origin, |
| 55 const GURL& embedding_origin, | 79 const GURL& embedding_origin, |
| 56 ContentSetting content_setting) { | 80 ContentSetting content_setting) { |
| 57 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 81 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); |
| 58 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); | 82 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); |
| 59 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 83 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 60 content_setting == CONTENT_SETTING_BLOCK); | 84 content_setting == CONTENT_SETTING_BLOCK); |
| 61 | 85 |
| 86 HostContentSettingsMap* host_content_settings_map = |
| 87 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 88 // If there is an enterprise ASK setting in effect, don't store the setting as |
| 89 // it won't have any effect anyway. |
| 90 if (PluginsEnterpriseSettingEnabled(host_content_settings_map)) |
| 91 return; |
| 92 |
| 62 // If the request was for a file scheme, allow or deny all file:/// URLs. | 93 // If the request was for a file scheme, allow or deny all file:/// URLs. |
| 63 ContentSettingsPattern pattern; | 94 ContentSettingsPattern pattern; |
| 64 if (embedding_origin.SchemeIsFile()) | 95 if (embedding_origin.SchemeIsFile()) |
| 65 pattern = ContentSettingsPattern::FromString("file:///*"); | 96 pattern = ContentSettingsPattern::FromString("file:///*"); |
| 66 else | 97 else |
| 67 pattern = ContentSettingsPattern::FromURLNoWildcard(embedding_origin); | 98 pattern = ContentSettingsPattern::FromURLNoWildcard(embedding_origin); |
| 68 | 99 host_content_settings_map->SetContentSettingCustomScope( |
| 69 HostContentSettingsMapFactory::GetForProfile(profile()) | 100 pattern, ContentSettingsPattern::Wildcard(), content_settings_type(), |
| 70 ->SetContentSettingCustomScope( | 101 std::string(), content_setting); |
| 71 pattern, ContentSettingsPattern::Wildcard(), content_settings_type(), | |
| 72 std::string(), content_setting); | |
| 73 } | 102 } |
| 74 | 103 |
| 75 bool FlashPermissionContext::IsRestrictedToSecureOrigins() const { | 104 bool FlashPermissionContext::IsRestrictedToSecureOrigins() const { |
| 76 return false; | 105 return false; |
| 77 } | 106 } |
| OLD | NEW |