Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4852)

Unified Diff: chrome/browser/plugins/plugin_prefs.cc

Issue 2369353002: Adds a pref and a policy to decide if PDFs should always be opened externally. (Closed)
Patch Set: Remove changes leaked in from the dependent branch. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/plugins/plugin_prefs.h ('k') | chrome/browser/plugins/plugin_prefs_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/plugins/plugin_prefs.cc
diff --git a/chrome/browser/plugins/plugin_prefs.cc b/chrome/browser/plugins/plugin_prefs.cc
index 66ae98016bb07de481bbd4f8e6a97dd4195974bb..85862139b88122b5dc6937ba9bc975cfb8d69c6a 100644
--- a/chrome/browser/plugins/plugin_prefs.cc
+++ b/chrome/browser/plugins/plugin_prefs.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/plugins/plugin_prefs_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -60,6 +61,10 @@ bool IsComponentUpdatedPepperFlash(const base::FilePath& plugin) {
return false;
}
+bool IsPDFViewerPlugin(const base::string16& plugin_name) {
+ return plugin_name == base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName);
+}
+
} // namespace
PluginPrefs::PluginState::PluginState() {
@@ -225,15 +230,21 @@ void PluginPrefs::EnablePluginInternal(
PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin(
const base::string16& name) const {
base::AutoLock auto_lock(lock_);
- if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) {
+
+ // Special handling for PDF based on its specific policy.
+ if (IsPDFViewerPlugin(name) && always_open_pdf_externally_)
+ return POLICY_DISABLED;
+
+ if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_))
return POLICY_ENABLED;
- } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
- !IsStringMatchedInSet(
- name, policy_disabled_plugin_exception_patterns_)) {
+
+ if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
+ !IsStringMatchedInSet(
+ name, policy_disabled_plugin_exception_patterns_)) {
return POLICY_DISABLED;
- } else {
- return NO_POLICY;
}
+
+ return NO_POLICY;
}
bool PluginPrefs::IsPluginEnabled(const content::WebPluginInfo& plugin) const {
@@ -287,6 +298,14 @@ void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns,
NotifyPluginStatusChanged();
}
+void PluginPrefs::UpdatePdfPolicy(const std::string& pref_name) {
+ base::AutoLock auto_lock(lock_);
+ always_open_pdf_externally_ =
+ prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally);
+
+ NotifyPluginStatusChanged();
+}
+
/*static*/
bool PluginPrefs::IsStringMatchedInSet(
const base::string16& name,
@@ -419,6 +438,8 @@ void PluginPrefs::SetPrefs(PrefService* prefs) {
&policy_disabled_plugin_exception_patterns_);
ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins),
&policy_enabled_plugin_patterns_);
+ always_open_pdf_externally_ =
+ prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally);
registrar_.Init(prefs_);
@@ -438,6 +459,9 @@ void PluginPrefs::SetPrefs(PrefService* prefs) {
base::Bind(&PluginPrefs::UpdatePatternsAndNotify,
base::Unretained(this),
&policy_enabled_plugin_patterns_));
+ registrar_.Add(prefs::kPluginsAlwaysOpenPdfExternally,
+ base::Bind(&PluginPrefs::UpdatePdfPolicy,
+ base::Unretained(this)));
NotifyPluginStatusChanged();
}
@@ -447,14 +471,15 @@ void PluginPrefs::ShutdownOnUIThread() {
registrar_.RemoveAll();
}
-PluginPrefs::PluginPrefs() : profile_(NULL),
+PluginPrefs::PluginPrefs() : always_open_pdf_externally_(false),
+ profile_(NULL),
prefs_(NULL) {
}
PluginPrefs::~PluginPrefs() {
}
-void PluginPrefs::SetPolicyEnforcedPluginPatterns(
+void PluginPrefs::SetPolicyEnforcedPluginPatternsForTests(
const std::set<base::string16>& disabled_patterns,
const std::set<base::string16>& disabled_exception_patterns,
const std::set<base::string16>& enabled_patterns) {
@@ -463,6 +488,12 @@ void PluginPrefs::SetPolicyEnforcedPluginPatterns(
policy_enabled_plugin_patterns_ = enabled_patterns;
}
+void PluginPrefs::SetAlwaysOpenPdfExternallyForTests(
+ bool always_open_pdf_externally) {
+ always_open_pdf_externally_ = always_open_pdf_externally;
+}
+
+
void PluginPrefs::OnUpdatePreferences(
const std::vector<content::WebPluginInfo>& plugins) {
if (!prefs_)
« no previous file with comments | « chrome/browser/plugins/plugin_prefs.h ('k') | chrome/browser/plugins/plugin_prefs_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698