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/plugin_utils.h" | 5 #include "chrome/browser/plugins/plugin_utils.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/common/chrome_features.h" |
8 #include "chrome/common/plugin_utils.h" | 9 #include "chrome/common/plugin_utils.h" |
9 #include "components/content_settings/core/browser/host_content_settings_map.h" | 10 #include "components/content_settings/core/browser/host_content_settings_map.h" |
10 #include "content/public/common/webplugininfo.h" | 11 #include "content/public/common/webplugininfo.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "url/origin.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 const char kFlashPluginID[] = "adobe-flash-player"; | 17 const char kFlashPluginID[] = "adobe-flash-player"; |
16 | 18 |
17 void GetPluginContentSettingInternal( | 19 void GetPluginContentSettingInternal( |
18 const HostContentSettingsMap* host_content_settings_map, | 20 const HostContentSettingsMap* host_content_settings_map, |
19 bool use_javascript_setting, | 21 bool use_javascript_setting, |
20 const GURL& policy_url, | 22 const url::Origin& policy_origin, |
21 const GURL& plugin_url, | 23 const GURL& plugin_url, |
22 const std::string& resource, | 24 const std::string& resource, |
23 ContentSetting* setting, | 25 ContentSetting* setting, |
24 bool* uses_default_content_setting, | 26 bool* uses_default_content_setting, |
25 bool* is_managed) { | 27 bool* is_managed) { |
| 28 GURL policy_url = |
| 29 policy_origin.unique() ? GURL() : GURL(policy_origin.Serialize()); |
| 30 |
26 std::unique_ptr<base::Value> value; | 31 std::unique_ptr<base::Value> value; |
27 content_settings::SettingInfo info; | 32 content_settings::SettingInfo info; |
28 bool uses_plugin_specific_setting = false; | 33 bool uses_plugin_specific_setting = false; |
29 if (use_javascript_setting) { | 34 if (use_javascript_setting) { |
30 value = host_content_settings_map->GetWebsiteSetting( | 35 value = host_content_settings_map->GetWebsiteSetting( |
31 policy_url, policy_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), | 36 policy_url, policy_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), |
32 &info); | 37 &info); |
33 } else { | 38 } else { |
| 39 // For non-JavaScript treated plugins (Flash), always return BLOCK if the |
| 40 // top level origin is any scheme other HTTP, HTTPS, or FILE. |
| 41 if (base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins) && |
| 42 !policy_url.SchemeIsHTTPOrHTTPS() && !policy_url.SchemeIsFile()) { |
| 43 *setting = CONTENT_SETTING_BLOCK; |
| 44 if (uses_default_content_setting) |
| 45 *uses_default_content_setting = true; |
| 46 if (is_managed) |
| 47 *is_managed = true; |
| 48 return; |
| 49 } |
| 50 |
34 content_settings::SettingInfo specific_info; | 51 content_settings::SettingInfo specific_info; |
35 std::unique_ptr<base::Value> specific_setting = | 52 std::unique_ptr<base::Value> specific_setting = |
36 host_content_settings_map->GetWebsiteSetting( | 53 host_content_settings_map->GetWebsiteSetting( |
37 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, | 54 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, |
38 &specific_info); | 55 &specific_info); |
39 content_settings::SettingInfo general_info; | 56 content_settings::SettingInfo general_info; |
40 std::unique_ptr<base::Value> general_setting = | 57 std::unique_ptr<base::Value> general_setting = |
41 host_content_settings_map->GetWebsiteSetting( | 58 host_content_settings_map->GetWebsiteSetting( |
42 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, | 59 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, |
43 std::string(), &general_info); | 60 std::string(), &general_info); |
44 // If there is a plugin-specific setting, we use it, unless the general | 61 // If there is a plugin-specific setting, we use it, unless the general |
45 // setting was set by policy, in which case it takes precedence. | 62 // setting was set by policy, in which case it takes precedence. |
46 uses_plugin_specific_setting = | 63 uses_plugin_specific_setting = |
47 specific_setting && | 64 specific_setting && |
48 general_info.source != content_settings::SETTING_SOURCE_POLICY; | 65 general_info.source != content_settings::SETTING_SOURCE_POLICY; |
49 if (uses_plugin_specific_setting) { | 66 if (uses_plugin_specific_setting) { |
50 value = std::move(specific_setting); | 67 value = std::move(specific_setting); |
51 info = specific_info; | 68 info = specific_info; |
52 } else { | 69 } else { |
53 value = std::move(general_setting); | 70 value = std::move(general_setting); |
54 info = general_info; | 71 info = general_info; |
55 } | 72 } |
56 } | 73 } |
57 *setting = content_settings::ValueToContentSetting(value.get()); | 74 *setting = content_settings::ValueToContentSetting(value.get()); |
| 75 |
58 if (uses_default_content_setting) { | 76 if (uses_default_content_setting) { |
59 *uses_default_content_setting = | 77 *uses_default_content_setting = |
60 !uses_plugin_specific_setting && | 78 !uses_plugin_specific_setting && |
61 info.primary_pattern == ContentSettingsPattern::Wildcard() && | 79 info.primary_pattern == ContentSettingsPattern::Wildcard() && |
62 info.secondary_pattern == ContentSettingsPattern::Wildcard(); | 80 info.secondary_pattern == ContentSettingsPattern::Wildcard(); |
63 } | 81 } |
64 if (is_managed) | 82 if (is_managed) |
65 *is_managed = info.source == content_settings::SETTING_SOURCE_POLICY; | 83 *is_managed = info.source == content_settings::SETTING_SOURCE_POLICY; |
66 } | 84 } |
67 | 85 |
68 } // namespace | 86 } // namespace |
69 | 87 |
70 // static | 88 // static |
71 void PluginUtils::GetPluginContentSetting( | 89 void PluginUtils::GetPluginContentSetting( |
72 const HostContentSettingsMap* host_content_settings_map, | 90 const HostContentSettingsMap* host_content_settings_map, |
73 const content::WebPluginInfo& plugin, | 91 const content::WebPluginInfo& plugin, |
74 const GURL& policy_url, | 92 const url::Origin& policy_url, |
75 const GURL& plugin_url, | 93 const GURL& plugin_url, |
76 const std::string& resource, | 94 const std::string& resource, |
77 ContentSetting* setting, | 95 ContentSetting* setting, |
78 bool* uses_default_content_setting, | 96 bool* uses_default_content_setting, |
79 bool* is_managed) { | 97 bool* is_managed) { |
80 GetPluginContentSettingInternal(host_content_settings_map, | 98 GetPluginContentSettingInternal(host_content_settings_map, |
81 ShouldUseJavaScriptSettingForPlugin(plugin), | 99 ShouldUseJavaScriptSettingForPlugin(plugin), |
82 policy_url, plugin_url, resource, setting, | 100 policy_url, plugin_url, resource, setting, |
83 uses_default_content_setting, is_managed); | 101 uses_default_content_setting, is_managed); |
84 } | 102 } |
85 | 103 |
86 // static | 104 // static |
87 ContentSetting PluginUtils::GetFlashPluginContentSetting( | 105 ContentSetting PluginUtils::GetFlashPluginContentSetting( |
88 const HostContentSettingsMap* host_content_settings_map, | 106 const HostContentSettingsMap* host_content_settings_map, |
89 const GURL& policy_url, | 107 const url::Origin& policy_url, |
90 const GURL& plugin_url, | 108 const GURL& plugin_url, |
91 bool* is_managed) { | 109 bool* is_managed) { |
92 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; | 110 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; |
93 GetPluginContentSettingInternal( | 111 GetPluginContentSettingInternal( |
94 host_content_settings_map, false /* use_javascript_setting */, policy_url, | 112 host_content_settings_map, false /* use_javascript_setting */, policy_url, |
95 plugin_url, kFlashPluginID, &plugin_setting, nullptr, is_managed); | 113 plugin_url, kFlashPluginID, &plugin_setting, nullptr, is_managed); |
96 return plugin_setting; | 114 return plugin_setting; |
97 } | 115 } |
OLD | NEW |