blob: 2f271ba849aeea9d6350b0dc5900ac8f1762336e [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]8a2713682011-08-19 10:36:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]0f5e57f52012-09-20 20:53:185#ifndef CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_
6#define CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_
[email protected]8a2713682011-08-19 10:36:597
Mark Rowe9204545e2023-12-29 14:32:168#include <memory>
Maksim Ivanovab376d52019-04-01 23:58:119#include <string>
[email protected]8a2713682011-08-19 10:36:5910
Keishi Hattori0e45c022021-11-27 09:25:5211#include "base/memory/raw_ptr.h"
Maksim Ivanovab376d52019-04-01 23:58:1112#include "base/memory/scoped_refptr.h"
sdefresne2eb633d2014-10-08 12:31:5613#include "components/keyed_service/core/refcounted_keyed_service.h"
brettwb1fc1b82016-02-02 00:19:0814#include "components/prefs/pref_change_registrar.h"
15#include "components/prefs/pref_service.h"
Lei Zhang9bec86a2021-06-23 19:58:5416#include "ppapi/buildflags/buildflags.h"
17
18#if !BUILDFLAG(ENABLE_PLUGINS)
19#error "Plugins should be enabled"
20#endif
[email protected]8a2713682011-08-19 10:36:5921
[email protected]8a2713682011-08-19 10:36:5922class Profile;
23
[email protected]d7bd3e52013-07-21 04:29:2024namespace content {
[email protected]8a2713682011-08-19 10:36:5925struct WebPluginInfo;
[email protected]8a2713682011-08-19 10:36:5926}
27
tommyclie86b2982015-03-16 20:16:4528// This class stores information about whether a plugin or a plugin group is
[email protected]8a2713682011-08-19 10:36:5929// enabled or disabled.
[email protected]f7be2cba2011-09-15 15:33:4530// Except where otherwise noted, it can be used on every thread.
sdefresne2eb633d2014-10-08 12:31:5631class PluginPrefs : public RefcountedKeyedService {
[email protected]8a2713682011-08-19 10:36:5932 public:
[email protected]e0379d52011-09-02 20:08:4733 // Returns the instance associated with |profile|, creating it if necessary.
[email protected]abc77242012-03-16 04:32:3134 static scoped_refptr<PluginPrefs> GetForProfile(Profile* profile);
[email protected]8a2713682011-08-19 10:36:5935
[email protected]f7be2cba2011-09-15 15:33:4536 // Usually the PluginPrefs associated with a TestingProfile is NULL.
37 // This method overrides that for a given TestingProfile, returning the newly
38 // created PluginPrefs object.
[email protected]abc77242012-03-16 04:32:3139 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile);
[email protected]f7be2cba2011-09-15 15:33:4540
Peter Boströmfadb1752021-09-30 19:17:0141 PluginPrefs(const PluginPrefs&) = delete;
42 PluginPrefs& operator=(const PluginPrefs&) = delete;
43
[email protected]e0379d52011-09-02 20:08:4744 // Creates a new instance. This method should only be used for testing.
45 PluginPrefs();
46
47 // Associates this instance with |prefs|. This enables or disables
48 // plugin groups as defined by the user's preferences.
[email protected]f7be2cba2011-09-15 15:33:4549 // This method should only be called on the UI thread.
[email protected]e0379d52011-09-02 20:08:4750 void SetPrefs(PrefService* prefs);
51
[email protected]8a2713682011-08-19 10:36:5952 // Returns whether the plugin is enabled or not.
[email protected]d7bd3e52013-07-21 04:29:2053 bool IsPluginEnabled(const content::WebPluginInfo& plugin) const;
[email protected]8a2713682011-08-19 10:36:5954
[email protected]45a22e62011-10-12 09:48:0255 void set_profile(Profile* profile) { profile_ = profile; }
56
[email protected]498e0a6e2012-02-15 14:52:1057 // RefCountedProfileKeyedBase method override.
dcheng99b1bc22014-10-22 18:47:4258 void ShutdownOnUIThread() override;
[email protected]498e0a6e2012-02-15 14:52:1059
[email protected]8a2713682011-08-19 10:36:5960 private:
61 friend class base::RefCountedThreadSafe<PluginPrefs>;
Amber Won6b5edc752017-08-17 19:23:5462 friend class PDFIFrameNavigationThrottleTest;
K. Moon370bcbc2022-08-29 22:07:3863 friend class PluginInfoHostImplTest;
[email protected]f7be2cba2011-09-15 15:33:4564 friend class PluginPrefsTest;
pastarmovj8b32e592016-11-21 15:30:4465 friend class PrintPreviewDialogControllerBrowserTest;
[email protected]65a0c612012-09-11 03:35:2466
dcheng99b1bc22014-10-22 18:47:4267 ~PluginPrefs() override;
[email protected]8a2713682011-08-19 10:36:5968
pastarmovjd5e6f662016-10-05 16:52:1769 // Callback for changes to the AlwaysOpenPdfExternally policy.
70 void UpdatePdfPolicy(const std::string& pref_name);
71
pastarmovjd5e6f662016-10-05 16:52:1772 // Allows unit tests to directly set the AlwaysOpenPdfExternally pref.
73 void SetAlwaysOpenPdfExternallyForTests(bool always_open_pdf_externally);
74
Evan Stade53b5a522019-06-25 01:46:5375 bool always_open_pdf_externally_ = false;
[email protected]8a2713682011-08-19 10:36:5976
Christian Xu4f5f7b62023-09-11 03:22:1877 raw_ptr<Profile> profile_ = nullptr;
[email protected]45a22e62011-10-12 09:48:0278
79 // Weak pointer, owned by the profile.
Christian Xu4f5f7b62023-09-11 03:22:1880 raw_ptr<PrefService> prefs_ = nullptr;
[email protected]8a2713682011-08-19 10:36:5981
Mark Rowe9204545e2023-12-29 14:32:1682 std::unique_ptr<PrefChangeRegistrar> registrar_;
[email protected]8a2713682011-08-19 10:36:5983};
84
[email protected]0f5e57f52012-09-20 20:53:1885#endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_