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:
|
2016-03-09 12:34:51 +00:00
|
|
|
// Get WebContents according to process ID.
|
2016-05-27 00:20:46 +00:00
|
|
|
// FIXME(zcbenz): This method does not belong here.
|
2016-03-09 12:34:51 +00:00
|
|
|
static content::WebContents* GetWebContentsFromProcessID(int process_id);
|
|
|
|
|
2015-09-04 17:12:32 +00:00
|
|
|
// Append command paramters according to |web_contents|'s preferences.
|
2015-09-04 17:04:09 +00:00
|
|
|
static void AppendExtraCommandLineSwitches(
|
|
|
|
content::WebContents* web_contents, base::CommandLine* command_line);
|
|
|
|
|
2017-05-22 07:08:47 +00:00
|
|
|
static bool IsPreferenceEnabled(const std::string& attribute_name,
|
2017-05-19 09:51:12 +00:00
|
|
|
content::WebContents* web_contents);
|
2016-08-15 10:59:08 +00:00
|
|
|
static bool IsSandboxed(content::WebContents* web_contents);
|
2017-03-19 08:41:20 +00:00
|
|
|
static bool UsesNativeWindowOpen(content::WebContents* web_contents);
|
2017-05-23 22:59:17 +00:00
|
|
|
static bool DisablePopups(content::WebContents* web_contents);
|
2017-05-17 13:45:24 +00:00
|
|
|
static bool IsPluginsEnabled(content::WebContents* web_contents);
|
2016-08-15 10:59:08 +00:00
|
|
|
|
2015-09-04 17:12:32 +00:00
|
|
|
// Modify the WebPreferences according to |web_contents|'s preferences.
|
|
|
|
static void OverrideWebkitPrefs(
|
|
|
|
content::WebContents* web_contents, content::WebPreferences* prefs);
|
|
|
|
|
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;
|
|
|
|
|
2015-09-05 02:43:30 +00:00
|
|
|
// $.extend(|web_preferences_|, |new_web_preferences|).
|
|
|
|
void Merge(const base::DictionaryValue& new_web_preferences);
|
|
|
|
|
2015-09-22 13:56:56 +00:00
|
|
|
// Returns the web preferences.
|
|
|
|
base::DictionaryValue* web_preferences() { return &web_preferences_; }
|
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
private:
|
|
|
|
friend class content::WebContentsUserData<WebContentsPreferences>;
|
|
|
|
|
2017-12-05 06:59:15 +00:00
|
|
|
// Get preferences value as integer possibly coercing it from a string
|
|
|
|
bool GetInteger(const std::string& attributeName, int* intValue);
|
|
|
|
|
2016-03-09 12:34:51 +00:00
|
|
|
static std::vector<WebContentsPreferences*> instances_;
|
|
|
|
|
|
|
|
content::WebContents* web_contents_;
|
2015-09-04 16:44:22 +00:00
|
|
|
base::DictionaryValue web_preferences_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|