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()); | |
| 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 { |
| 39 // For non-JavaScript treated plugins (Flash), always return BLOCK if the | |
| 40 // top level origin is any scheme other HTTP, HTTPS, or FILE. | |
|
raymes
2016/10/02 05:12:56
nit: other than HTTP, ...
raymes
2016/10/02 12:00:05
After thinking about this a bit, I feel like we sh
tommycli
2016/10/03 18:49:28
Done.
tommycli
2016/10/03 18:49:28
Done.
| |
| 41 if (base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins) && | |
| 42 !main_frame_url.SchemeIsHTTPOrHTTPS() && | |
| 43 !main_frame_url.SchemeIsFile()) { | |
| 44 *setting = CONTENT_SETTING_BLOCK; | |
| 45 if (uses_default_content_setting) | |
| 46 *uses_default_content_setting = true; | |
|
raymes
2016/10/02 05:12:56
I think this should be false - it's not necessaril
tommycli
2016/10/03 18:49:28
I preserved the actual is_default and is_managed v
| |
| 47 if (is_managed) | |
| 48 *is_managed = true; | |
|
raymes
2016/10/02 05:12:56
This should only be true if the setting is being o
tommycli
2016/10/03 18:49:28
Done.
| |
| 49 return; | |
| 50 } | |
| 51 | |
| 34 content_settings::SettingInfo specific_info; | 52 content_settings::SettingInfo specific_info; |
| 35 std::unique_ptr<base::Value> specific_setting = | 53 std::unique_ptr<base::Value> specific_setting = |
| 36 host_content_settings_map->GetWebsiteSetting( | 54 host_content_settings_map->GetWebsiteSetting( |
| 37 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, | 55 main_frame_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, |
| 38 &specific_info); | 56 &specific_info); |
| 39 content_settings::SettingInfo general_info; | 57 content_settings::SettingInfo general_info; |
| 40 std::unique_ptr<base::Value> general_setting = | 58 std::unique_ptr<base::Value> general_setting = |
| 41 host_content_settings_map->GetWebsiteSetting( | 59 host_content_settings_map->GetWebsiteSetting( |
| 42 policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, | 60 main_frame_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 43 std::string(), &general_info); | 61 std::string(), &general_info); |
| 44 // If there is a plugin-specific setting, we use it, unless the general | 62 // 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. | 63 // setting was set by policy, in which case it takes precedence. |
| 46 uses_plugin_specific_setting = | 64 uses_plugin_specific_setting = |
| 47 specific_setting && | 65 specific_setting && |
| 48 general_info.source != content_settings::SETTING_SOURCE_POLICY; | 66 general_info.source != content_settings::SETTING_SOURCE_POLICY; |
| 49 if (uses_plugin_specific_setting) { | 67 if (uses_plugin_specific_setting) { |
| 50 value = std::move(specific_setting); | 68 value = std::move(specific_setting); |
| 51 info = specific_info; | 69 info = specific_info; |
| 52 } else { | 70 } else { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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& main_frame_origin, |
| 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( |
| 81 ShouldUseJavaScriptSettingForPlugin(plugin), | 99 host_content_settings_map, ShouldUseJavaScriptSettingForPlugin(plugin), |
| 82 policy_url, plugin_url, resource, setting, | 100 main_frame_origin, 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& main_frame_origin, |
| 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(host_content_settings_map, |
| 94 host_content_settings_map, false /* use_javascript_setting */, policy_url, | 112 false /* use_javascript_setting */, |
| 95 plugin_url, kFlashPluginID, &plugin_setting, nullptr, is_managed); | 113 main_frame_origin, plugin_url, kFlashPluginID, |
| 114 &plugin_setting, nullptr, is_managed); | |
| 96 return plugin_setting; | 115 return plugin_setting; |
| 97 } | 116 } |
| OLD | NEW |