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

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: Rebase and move the friend decl in the ifdef. Created 4 years, 3 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
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..50332f5eb1d2bed0fb42f5bae292419131be2d04 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,6 +230,12 @@ void PluginPrefs::EnablePluginInternal(
PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin(
const base::string16& name) const {
base::AutoLock auto_lock(lock_);
+
+ // Special handling for PDF based on its specific policy.
+ if (IsPDFViewerPlugin(name) && always_open_pdf_externally_) {
+ return POLICY_DISABLED;
Bernhard Bauer 2016/09/29 08:44:35 Nit: I think it's more common to leave out braces
pastarmovj 2016/09/29 12:14:41 Yup. Copy-paste relict.
+ }
+
if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) {
return POLICY_ENABLED;
} else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
Bernhard Bauer 2016/09/29 08:44:35 Remove these else's?
pastarmovj 2016/09/29 12:14:41 Done.
@@ -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::kAlwaysOpenPdfExternally);
+
+ 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::kAlwaysOpenPdfExternally);
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::kAlwaysOpenPdfExternally,
+ base::Bind(&PluginPrefs::UpdatePdfPolicy,
+ base::Unretained(this)));
NotifyPluginStatusChanged();
}
@@ -447,7 +471,8 @@ void PluginPrefs::ShutdownOnUIThread() {
registrar_.RemoveAll();
}
-PluginPrefs::PluginPrefs() : profile_(NULL),
+PluginPrefs::PluginPrefs() : always_open_pdf_externally_(false),
+ profile_(NULL),
prefs_(NULL) {
}
@@ -463,6 +488,11 @@ void PluginPrefs::SetPolicyEnforcedPluginPatterns(
policy_enabled_plugin_patterns_ = enabled_patterns;
}
+void PluginPrefs::SetAlwaysOpenPdfExternally(bool always_open_pdf_externally) {
+ always_open_pdf_externally_ = always_open_pdf_externally;
+}
+
+
void PluginPrefs::OnUpdatePreferences(
const std::vector<content::WebPluginInfo>& plugins) {
if (!prefs_)

Powered by Google App Engine
This is Rietveld 408576698