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/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& main_frame_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 main_frame_url = | |
| 29 main_frame_origin.unique() ? GURL() : GURL(main_frame_origin.Serialize()); | |
|
nasko
2016/10/05 21:14:31
main_frame_origin.GetURL()
tommycli
2016/10/05 21:41:22
Done.
| |
| 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 main_frame_url, main_frame_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 32 &info); | 37 std::string(), &info); |
| 33 } else { | 38 } else { |
| 34 content_settings::SettingInfo specific_info; | 39 content_settings::SettingInfo specific_info; |
| 35 std::unique_ptr<base::Value> specific_setting = | 40 std::unique_ptr<base::Value> specific_setting = |
| 36 host_content_settings_map->GetWebsiteSetting( | 41 host_content_settings_map->GetWebsiteSetting( |
| 37 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, | 42 main_frame_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, |
| 38 &specific_info); | 43 &specific_info); |
| 39 content_settings::SettingInfo general_info; | 44 content_settings::SettingInfo general_info; |
| 40 std::unique_ptr<base::Value> general_setting = | 45 std::unique_ptr<base::Value> general_setting = |
| 41 host_content_settings_map->GetWebsiteSetting( | 46 host_content_settings_map->GetWebsiteSetting( |
| 42 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, | 47 main_frame_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 43 std::string(), &general_info); | 48 std::string(), &general_info); |
| 44 // If there is a plugin-specific setting, we use it, unless the general | 49 // 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. | 50 // setting was set by policy, in which case it takes precedence. |
| 46 uses_plugin_specific_setting = | 51 uses_plugin_specific_setting = |
| 47 specific_setting && | 52 specific_setting && |
| 48 general_info.source != content_settings::SETTING_SOURCE_POLICY; | 53 general_info.source != content_settings::SETTING_SOURCE_POLICY; |
| 49 if (uses_plugin_specific_setting) { | 54 if (uses_plugin_specific_setting) { |
| 50 value = std::move(specific_setting); | 55 value = std::move(specific_setting); |
| 51 info = specific_info; | 56 info = specific_info; |
| 52 } else { | 57 } else { |
| 53 value = std::move(general_setting); | 58 value = std::move(general_setting); |
| 54 info = general_info; | 59 info = general_info; |
| 55 } | 60 } |
| 56 } | 61 } |
| 57 *setting = content_settings::ValueToContentSetting(value.get()); | 62 *setting = content_settings::ValueToContentSetting(value.get()); |
| 58 if (uses_default_content_setting) { | 63 if (uses_default_content_setting) { |
| 59 *uses_default_content_setting = | 64 *uses_default_content_setting = |
| 60 !uses_plugin_specific_setting && | 65 !uses_plugin_specific_setting && |
| 61 info.primary_pattern == ContentSettingsPattern::Wildcard() && | 66 info.primary_pattern == ContentSettingsPattern::Wildcard() && |
| 62 info.secondary_pattern == ContentSettingsPattern::Wildcard(); | 67 info.secondary_pattern == ContentSettingsPattern::Wildcard(); |
| 63 } | 68 } |
| 64 if (is_managed) | 69 if (is_managed) |
| 65 *is_managed = info.source == content_settings::SETTING_SOURCE_POLICY; | 70 *is_managed = info.source == content_settings::SETTING_SOURCE_POLICY; |
| 71 | |
| 72 // For non-JavaScript treated plugins (Flash): unless the user has explicitly | |
| 73 // ALLOWed plugins, return BLOCK for any non-HTTP and non-FILE origin. | |
| 74 if (!use_javascript_setting && *setting != CONTENT_SETTING_ALLOW && | |
| 75 base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins) && | |
| 76 !main_frame_url.SchemeIsHTTPOrHTTPS() && !main_frame_url.SchemeIsFile()) { | |
| 77 *setting = CONTENT_SETTING_BLOCK; | |
| 78 } | |
| 66 } | 79 } |
| 67 | 80 |
| 68 } // namespace | 81 } // namespace |
| 69 | 82 |
| 70 // static | 83 // static |
| 71 void PluginUtils::GetPluginContentSetting( | 84 void PluginUtils::GetPluginContentSetting( |
| 72 const HostContentSettingsMap* host_content_settings_map, | 85 const HostContentSettingsMap* host_content_settings_map, |
| 73 const content::WebPluginInfo& plugin, | 86 const content::WebPluginInfo& plugin, |
| 74 const GURL& policy_url, | 87 const url::Origin& main_frame_origin, |
| 75 const GURL& plugin_url, | 88 const GURL& plugin_url, |
| 76 const std::string& resource, | 89 const std::string& resource, |
| 77 ContentSetting* setting, | 90 ContentSetting* setting, |
| 78 bool* uses_default_content_setting, | 91 bool* uses_default_content_setting, |
| 79 bool* is_managed) { | 92 bool* is_managed) { |
| 80 GetPluginContentSettingInternal(host_content_settings_map, | 93 GetPluginContentSettingInternal( |
| 81 ShouldUseJavaScriptSettingForPlugin(plugin), | 94 host_content_settings_map, ShouldUseJavaScriptSettingForPlugin(plugin), |
| 82 policy_url, plugin_url, resource, setting, | 95 main_frame_origin, plugin_url, resource, setting, |
| 83 uses_default_content_setting, is_managed); | 96 uses_default_content_setting, is_managed); |
| 84 } | 97 } |
| 85 | 98 |
| 86 // static | 99 // static |
| 87 ContentSetting PluginUtils::GetFlashPluginContentSetting( | 100 ContentSetting PluginUtils::GetFlashPluginContentSetting( |
| 88 const HostContentSettingsMap* host_content_settings_map, | 101 const HostContentSettingsMap* host_content_settings_map, |
| 89 const GURL& policy_url, | 102 const url::Origin& main_frame_origin, |
| 90 const GURL& plugin_url, | 103 const GURL& plugin_url, |
| 91 bool* is_managed) { | 104 bool* is_managed) { |
| 92 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; | 105 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; |
| 93 GetPluginContentSettingInternal( | 106 GetPluginContentSettingInternal(host_content_settings_map, |
| 94 host_content_settings_map, false /* use_javascript_setting */, policy_url, | 107 false /* use_javascript_setting */, |
| 95 plugin_url, kFlashPluginID, &plugin_setting, nullptr, is_managed); | 108 main_frame_origin, plugin_url, kFlashPluginID, |
| 109 &plugin_setting, nullptr, is_managed); | |
| 96 return plugin_setting; | 110 return plugin_setting; |
| 97 } | 111 } |
| OLD | NEW |