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,9 +78,8 @@ 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 in WebContents.
|
||||||
// Use options.webPreferences to create WebContents.
|
|
||||||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||||
options.Get(options::kWebPreferences, &web_preferences);
|
options.Get(options::kWebPreferences, &web_preferences);
|
||||||
|
|
||||||
|
@ -101,6 +101,16 @@ Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
}
|
}
|
||||||
#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