2015-09-04 16:44:22 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
|
|
|
#define SHELL_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2017-01-31 02:43:12 +00:00
|
|
|
#include <string>
|
2016-03-09 12:34:51 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
#include "base/values.h"
|
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
|
|
|
|
2015-09-04 17:04:09 +00:00
|
|
|
namespace base {
|
|
|
|
class CommandLine;
|
|
|
|
}
|
|
|
|
|
2015-09-04 17:12:32 +00:00
|
|
|
namespace content {
|
|
|
|
struct WebPreferences;
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
namespace gin_helper {
|
2015-11-11 02:32:25 +00:00
|
|
|
class Dictionary;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2015-09-04 16:52:29 +00:00
|
|
|
// Stores and applies the preferences of WebContents.
|
2015-09-04 16:44:22 +00:00
|
|
|
class WebContentsPreferences
|
|
|
|
: public content::WebContentsUserData<WebContentsPreferences> {
|
|
|
|
public:
|
2018-03-08 07:12:45 +00:00
|
|
|
// Get self from WebContents.
|
|
|
|
static WebContentsPreferences* From(content::WebContents* web_contents);
|
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
WebContentsPreferences(content::WebContents* web_contents,
|
2019-10-25 13:03:28 +00:00
|
|
|
const gin_helper::Dictionary& web_preferences);
|
2015-09-04 16:44:22 +00:00
|
|
|
~WebContentsPreferences() override;
|
|
|
|
|
2019-05-27 00:44:54 +00:00
|
|
|
// Set WebPreferences defaults onto the JS object.
|
|
|
|
void SetDefaults();
|
|
|
|
|
2018-03-08 07:36:21 +00:00
|
|
|
// A simple way to know whether a Boolean property is enabled.
|
2019-07-25 15:19:04 +00:00
|
|
|
bool IsEnabled(base::StringPiece name, bool default_value = false) const;
|
2018-03-08 07:36:21 +00:00
|
|
|
|
2018-03-08 07:05:12 +00:00
|
|
|
// $.extend(|web_preferences|, |new_web_preferences|).
|
2015-09-05 02:43:30 +00:00
|
|
|
void Merge(const base::DictionaryValue& new_web_preferences);
|
|
|
|
|
2018-03-08 08:01:54 +00:00
|
|
|
// Append command paramters according to preferences.
|
2019-06-20 10:10:56 +00:00
|
|
|
void AppendCommandLineSwitches(base::CommandLine* command_line,
|
|
|
|
bool is_subframe);
|
2018-03-08 08:01:54 +00:00
|
|
|
|
|
|
|
// Modify the WebPreferences according to preferences.
|
|
|
|
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
|
|
|
|
2018-08-03 21:23:07 +00:00
|
|
|
// Clear the current WebPreferences.
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// Return true if the particular preference value exists.
|
2019-07-25 15:19:04 +00:00
|
|
|
bool GetPreference(base::StringPiece name, std::string* value) const;
|
2018-10-13 17:50:07 +00:00
|
|
|
|
2018-08-10 22:19:49 +00:00
|
|
|
// Returns the preload script path.
|
|
|
|
bool GetPreloadPath(base::FilePath::StringType* path) const;
|
|
|
|
|
2015-09-22 13:56:56 +00:00
|
|
|
// Returns the web preferences.
|
2018-08-03 21:23:07 +00:00
|
|
|
base::Value* preference() { return &preference_; }
|
|
|
|
base::Value* last_preference() { return &last_preference_; }
|
2015-09-22 13:56:56 +00:00
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
private:
|
|
|
|
friend class content::WebContentsUserData<WebContentsPreferences>;
|
2018-03-08 07:45:37 +00:00
|
|
|
friend class AtomBrowserClient;
|
|
|
|
|
|
|
|
// Get WebContents according to process ID.
|
|
|
|
static content::WebContents* GetWebContentsFromProcessID(int process_id);
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2018-03-15 04:56:46 +00:00
|
|
|
// Set preference value to given bool if user did not provide value
|
2019-07-25 15:19:04 +00:00
|
|
|
bool SetDefaultBoolIfUndefined(base::StringPiece key, bool val);
|
2018-03-15 04:56:46 +00:00
|
|
|
|
2019-05-27 00:44:54 +00:00
|
|
|
// Set preference value to given bool
|
2019-07-25 15:19:04 +00:00
|
|
|
void SetBool(base::StringPiece key, bool value);
|
2019-05-27 00:44:54 +00:00
|
|
|
|
2016-03-09 12:34:51 +00:00
|
|
|
static std::vector<WebContentsPreferences*> instances_;
|
|
|
|
|
|
|
|
content::WebContents* web_contents_;
|
2018-03-08 07:05:12 +00:00
|
|
|
|
2018-08-03 21:23:07 +00:00
|
|
|
base::Value preference_ = base::Value(base::Value::Type::DICTIONARY);
|
|
|
|
base::Value last_preference_ = base::Value(base::Value::Type::DICTIONARY);
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2019-01-21 16:56:54 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|