| 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/ui/webui/plugins/plugins_handler.h" | 5 #include "chrome/browser/ui/webui/plugins/plugins_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 | 36 |
| 37 using content::WebPluginInfo; | 37 using content::WebPluginInfo; |
| 38 // Holds grouped plugins. The key is the group identifier and | 38 // Holds grouped plugins. The key is the group identifier and |
| 39 // the value is the list of plugins belonging to the group. | 39 // the value is the list of plugins belonging to the group. |
| 40 using PluginGroups = | 40 using PluginGroups = |
| 41 base::hash_map<std::string, std::vector<const content::WebPluginInfo*>>; | 41 base::hash_map<std::string, std::vector<const content::WebPluginInfo*>>; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // Callback function to process result of EnablePlugin method. | |
| 46 void AssertPluginEnabled(bool did_enable) { | |
| 47 DCHECK(did_enable); | |
| 48 } | |
| 49 | |
| 50 base::string16 PluginTypeToString(int type) { | 45 base::string16 PluginTypeToString(int type) { |
| 51 // The type is stored as an |int|, but doing the switch on the right | 46 // The type is stored as an |int|, but doing the switch on the right |
| 52 // enumeration type gives us better build-time error checking (if someone adds | 47 // enumeration type gives us better build-time error checking (if someone adds |
| 53 // a new type). | 48 // a new type). |
| 54 switch (static_cast<WebPluginInfo::PluginType>(type)) { | 49 switch (static_cast<WebPluginInfo::PluginType>(type)) { |
| 55 case WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS: | 50 case WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS: |
| 56 return l10n_util::GetStringUTF16(IDS_PLUGINS_PPAPI_IN_PROCESS); | 51 return l10n_util::GetStringUTF16(IDS_PLUGINS_PPAPI_IN_PROCESS); |
| 57 case WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS: | 52 case WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS: |
| 58 return l10n_util::GetStringUTF16(IDS_PLUGINS_PPAPI_OUT_OF_PROCESS); | 53 return l10n_util::GetStringUTF16(IDS_PLUGINS_PPAPI_OUT_OF_PROCESS); |
| 59 case WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN: | 54 case WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 show_details_.Init(prefs::kPluginsShowDetails, prefs); | 108 show_details_.Init(prefs::kPluginsShowDetails, prefs); |
| 114 | 109 |
| 115 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 110 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 116 content::Source<Profile>(profile)); | 111 content::Source<Profile>(profile)); |
| 117 } | 112 } |
| 118 | 113 |
| 119 PluginsPageHandler::~PluginsPageHandler() {} | 114 PluginsPageHandler::~PluginsPageHandler() {} |
| 120 | 115 |
| 121 void PluginsPageHandler::SetPluginEnabled(const std::string& plugin_path, | 116 void PluginsPageHandler::SetPluginEnabled(const std::string& plugin_path, |
| 122 bool enable) { | 117 bool enable) { |
| 123 Profile* profile = Profile::FromWebUI(web_ui_); | 118 // TODO(http://crbug.com/615738): Remove this page altogether. |
| 124 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | |
| 125 plugin_prefs->EnablePlugin( | |
| 126 enable, base::FilePath( | |
| 127 mojo::String(plugin_path).To<base::FilePath::StringType>()), | |
| 128 base::Bind(&AssertPluginEnabled)); | |
| 129 } | 119 } |
| 130 | 120 |
| 131 void PluginsPageHandler::SetPluginGroupEnabled(const std::string& group_name, | 121 void PluginsPageHandler::SetPluginGroupEnabled(const std::string& group_name, |
| 132 bool enable) { | 122 bool enable) { |
| 133 Profile* profile = Profile::FromWebUI(web_ui_); | 123 // TODO(http://crbug.com/615738): Remove this page altogether. |
| 134 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | |
| 135 base::string16 group_name_as_string16 = base::UTF8ToUTF16(group_name); | |
| 136 plugin_prefs->EnablePluginGroup(enable, group_name_as_string16); | |
| 137 if (!enable) { | |
| 138 return; | |
| 139 } | |
| 140 | |
| 141 // See http://crbug.com/50105 for background. | |
| 142 base::string16 adobereader = | |
| 143 base::ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName); | |
| 144 base::string16 internalpdf = | |
| 145 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); | |
| 146 if (group_name_as_string16 == adobereader) | |
| 147 plugin_prefs->EnablePluginGroup(false, internalpdf); | |
| 148 else if (group_name_as_string16 == internalpdf) | |
| 149 plugin_prefs->EnablePluginGroup(false, adobereader); | |
| 150 } | 124 } |
| 151 | 125 |
| 152 void PluginsPageHandler::GetShowDetails( | 126 void PluginsPageHandler::GetShowDetails( |
| 153 const GetShowDetailsCallback& callback) { | 127 const GetShowDetailsCallback& callback) { |
| 154 callback.Run(show_details_.GetValue()); | 128 callback.Run(show_details_.GetValue()); |
| 155 } | 129 } |
| 156 | 130 |
| 157 void PluginsPageHandler::SaveShowDetailsToPrefs(bool details_mode) { | 131 void PluginsPageHandler::SaveShowDetailsToPrefs(bool details_mode) { |
| 158 show_details_.SetValue(details_mode); | 132 show_details_.SetValue(details_mode); |
| 159 } | 133 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 339 } |
| 366 | 340 |
| 367 if (plugins_enabled_by_policy) | 341 if (plugins_enabled_by_policy) |
| 368 return "enabledByPolicy"; | 342 return "enabledByPolicy"; |
| 369 if (plugins_disabled_by_policy) | 343 if (plugins_disabled_by_policy) |
| 370 return "disabledByPolicy"; | 344 return "disabledByPolicy"; |
| 371 if (plugins_managed_by_policy) | 345 if (plugins_managed_by_policy) |
| 372 return "managedByPolicy"; | 346 return "managedByPolicy"; |
| 373 return group_enabled ? "enabledByUser" : "disabledByUser"; | 347 return group_enabled ? "enabledByUser" : "disabledByUser"; |
| 374 } | 348 } |
| OLD | NEW |