Update web preferences when creating with existing webContents
This commit is contained in:
parent
61167ca296
commit
34c5abfe43
1 changed files with 28 additions and 18 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
|
@ -77,30 +78,39 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
const mate::Dictionary& options) {
|
const mate::Dictionary& options) {
|
||||||
mate::Handle<class WebContents> web_contents;
|
mate::Handle<class WebContents> web_contents;
|
||||||
// If no WebContents was passed to the constructor, create it from options.
|
|
||||||
if (!options.Get("webContents", &web_contents)) {
|
|
||||||
// Use options.webPreferences to create WebContents.
|
|
||||||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
|
||||||
options.Get(options::kWebPreferences, &web_preferences);
|
|
||||||
|
|
||||||
// Copy the backgroundColor to webContents.
|
// Use options.webPreferences in WebContents.
|
||||||
v8::Local<v8::Value> value;
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||||
if (options.Get(options::kBackgroundColor, &value))
|
options.Get(options::kWebPreferences, &web_preferences);
|
||||||
web_preferences.Set(options::kBackgroundColor, value);
|
|
||||||
|
|
||||||
v8::Local<v8::Value> transparent;
|
// Copy the backgroundColor to webContents.
|
||||||
if (options.Get("transparent", &transparent))
|
v8::Local<v8::Value> value;
|
||||||
web_preferences.Set("transparent", transparent);
|
if (options.Get(options::kBackgroundColor, &value))
|
||||||
|
web_preferences.Set(options::kBackgroundColor, value);
|
||||||
|
|
||||||
|
v8::Local<v8::Value> transparent;
|
||||||
|
if (options.Get("transparent", &transparent))
|
||||||
|
web_preferences.Set("transparent", transparent);
|
||||||
|
|
||||||
#if defined(ENABLE_OSR)
|
#if defined(ENABLE_OSR)
|
||||||
// Offscreen windows are always created frameless.
|
// Offscreen windows are always created frameless.
|
||||||
bool offscreen;
|
bool offscreen;
|
||||||
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
||||||
auto window_options = const_cast<mate::Dictionary&>(options);
|
auto window_options = const_cast<mate::Dictionary&>(options);
|
||||||
window_options.Set(options::kFrame, false);
|
window_options.Set(options::kFrame, false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (options.Get("webContents", &web_contents)) {
|
||||||
|
// Set webPreferences from options if using existing webContents
|
||||||
|
auto* existing_preferences =
|
||||||
|
WebContentsPreferences::FromWebContents(web_contents->web_contents());
|
||||||
|
base::DictionaryValue web_preferences_dict;
|
||||||
|
mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
||||||
|
&web_preferences_dict);
|
||||||
|
existing_preferences->web_preferences()->Clear();
|
||||||
|
existing_preferences->Merge(web_preferences_dict);
|
||||||
|
} else {
|
||||||
// Creates the WebContents used by BrowserWindow.
|
// Creates the WebContents used by BrowserWindow.
|
||||||
web_contents = WebContents::Create(isolate, web_preferences);
|
web_contents = WebContents::Create(isolate, web_preferences);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue