Move OverrideWebkitPrefs to WebContentsPreferences
This commit is contained in:
parent
39975378bb
commit
880dce950d
5 changed files with 44 additions and 34 deletions
|
@ -15,6 +15,7 @@
|
|||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/browser/web_view_constants.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
|
@ -169,7 +170,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
|||
|
||||
NativeWindow* window = NativeWindow::FromWebContents(web_contents);
|
||||
if (window)
|
||||
window->OverrideWebkitPrefs(prefs);
|
||||
WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs);
|
||||
}
|
||||
|
||||
std::string AtomBrowserClient::GetApplicationLocale() {
|
||||
|
@ -231,6 +232,8 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
|||
|
||||
if (owner == OWNER_NATIVE_WINDOW) {
|
||||
window->AppendExtraCommandLineSwitches(command_line);
|
||||
WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||
window->web_contents(), command_line);
|
||||
} else if (owner == OWNER_GUEST_WEB_CONTENTS) {
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kGuestInstanceID, base::IntToString(info.guest_instance_id));
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/renderer_preferences.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gfx/codec/png_codec.h"
|
||||
|
@ -382,34 +380,6 @@ void NativeWindow::AppendExtraCommandLineSwitches(
|
|||
base::DoubleToString(zoom_factor_));
|
||||
}
|
||||
|
||||
void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
|
||||
if (web_preferences_.IsEmpty())
|
||||
return;
|
||||
|
||||
bool b;
|
||||
if (web_preferences_.Get("javascript", &b))
|
||||
prefs->javascript_enabled = b;
|
||||
if (web_preferences_.Get("images", &b))
|
||||
prefs->images_enabled = b;
|
||||
if (web_preferences_.Get("java", &b))
|
||||
prefs->java_enabled = b;
|
||||
if (web_preferences_.Get("text-areas-are-resizable", &b))
|
||||
prefs->text_areas_are_resizable = b;
|
||||
if (web_preferences_.Get("webgl", &b))
|
||||
prefs->experimental_webgl_enabled = b;
|
||||
if (web_preferences_.Get("webaudio", &b))
|
||||
prefs->webaudio_enabled = b;
|
||||
if (web_preferences_.Get("web-security", &b)) {
|
||||
prefs->web_security_enabled = b;
|
||||
prefs->allow_displaying_insecure_content = !b;
|
||||
prefs->allow_running_insecure_content = !b;
|
||||
}
|
||||
if (web_preferences_.Get("allow-displaying-insecure-content", &b))
|
||||
prefs->allow_displaying_insecure_content = b;
|
||||
if (web_preferences_.Get("allow-running-insecure-content", &b))
|
||||
prefs->allow_running_insecure_content = b;
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowClosed() {
|
||||
if (is_closed_)
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,6 @@ class InspectableWebContents;
|
|||
|
||||
namespace content {
|
||||
struct NativeWebKeyboardEvent;
|
||||
struct WebPreferences;
|
||||
}
|
||||
|
||||
namespace gfx {
|
||||
|
@ -191,7 +190,6 @@ class NativeWindow : public content::WebContentsObserver,
|
|||
|
||||
// Called when renderer process is going to be started.
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
|
||||
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
||||
|
||||
// Public API used by platform-dependent delegates and observers to send UI
|
||||
// related notifications.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "ui/gfx/switches.h"
|
||||
|
@ -74,4 +75,34 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
|||
}
|
||||
}
|
||||
|
||||
void WebContentsPreferences::OverrideWebkitPrefs(
|
||||
content::WebContents* web_contents, content::WebPreferences* prefs) {
|
||||
WebContentsPreferences* self = From(web_contents);
|
||||
CHECK(self);
|
||||
|
||||
bool b;
|
||||
if (self->web_preferences_.GetBoolean("javascript", &b))
|
||||
prefs->javascript_enabled = b;
|
||||
if (self->web_preferences_.GetBoolean("images", &b))
|
||||
prefs->images_enabled = b;
|
||||
if (self->web_preferences_.GetBoolean("java", &b))
|
||||
prefs->java_enabled = b;
|
||||
if (self->web_preferences_.GetBoolean("text-areas-are-resizable", &b))
|
||||
prefs->text_areas_are_resizable = b;
|
||||
if (self->web_preferences_.GetBoolean("webgl", &b))
|
||||
prefs->experimental_webgl_enabled = b;
|
||||
if (self->web_preferences_.GetBoolean("webaudio", &b))
|
||||
prefs->webaudio_enabled = b;
|
||||
if (self->web_preferences_.GetBoolean("web-security", &b)) {
|
||||
prefs->web_security_enabled = b;
|
||||
prefs->allow_displaying_insecure_content = !b;
|
||||
prefs->allow_running_insecure_content = !b;
|
||||
}
|
||||
if (self->web_preferences_.GetBoolean("allow-displaying-insecure-content",
|
||||
&b))
|
||||
prefs->allow_displaying_insecure_content = b;
|
||||
if (self->web_preferences_.GetBoolean("allow-running-insecure-content", &b))
|
||||
prefs->allow_running_insecure_content = b;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -12,6 +12,10 @@ namespace base {
|
|||
class CommandLine;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
struct WebPreferences;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
// Stores and applies the preferences of WebContents.
|
||||
|
@ -21,10 +25,14 @@ class WebContentsPreferences
|
|||
// Get the preferences of |web_contents|.
|
||||
static WebContentsPreferences* From(content::WebContents* web_contents);
|
||||
|
||||
// Append command paramters appending to |web_contents|'s preferences.
|
||||
// Append command paramters according to |web_contents|'s preferences.
|
||||
static void AppendExtraCommandLineSwitches(
|
||||
content::WebContents* web_contents, base::CommandLine* command_line);
|
||||
|
||||
// Modify the WebPreferences according to |web_contents|'s preferences.
|
||||
static void OverrideWebkitPrefs(
|
||||
content::WebContents* web_contents, content::WebPreferences* prefs);
|
||||
|
||||
WebContentsPreferences(content::WebContents* web_contents,
|
||||
base::DictionaryValue&& web_preferences);
|
||||
~WebContentsPreferences() override;
|
||||
|
|
Loading…
Add table
Reference in a new issue