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.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
|
|
|
#define ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-11-11 02:32:25 +00:00
|
|
|
namespace mate {
|
|
|
|
class Dictionary;
|
|
|
|
}
|
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
namespace atom {
|
|
|
|
|
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,
|
2015-11-11 02:32:25 +00:00
|
|
|
const mate::Dictionary& web_preferences);
|
2015-09-04 16:44:22 +00:00
|
|
|
~WebContentsPreferences() override;
|
|
|
|
|
2018-03-08 07:36:21 +00:00
|
|
|
// A simple way to know whether a Boolean property is enabled.
|
2018-08-03 21:23:07 +00:00
|
|
|
bool IsEnabled(const 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.
|
|
|
|
void AppendCommandLineSwitches(base::CommandLine* command_line);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
bool GetPreference(const base::StringPiece& name, std::string* value) const;
|
|
|
|
|
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;
|
|
|
|
|
2018-08-29 18:14:04 +00:00
|
|
|
enum class Status { Deprecated, Stable };
|
|
|
|
|
2018-03-08 07:45:37 +00:00
|
|
|
// 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
|
2018-08-29 18:14:04 +00:00
|
|
|
bool SetDefaultBoolIfUndefined(const base::StringPiece& key,
|
|
|
|
bool val,
|
|
|
|
Status status = Status::Stable);
|
2018-03-15 04:56:46 +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
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|