Only reset preferences when conversion succeeds

This commit is contained in:
Kevin Sawicki 2017-07-10 17:04:07 -07:00
parent 3925bfde8e
commit fdb1fddc26

View file

@ -102,14 +102,18 @@ Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
#endif
if (options.Get("webContents", &web_contents)) {
// Set webPreferences from options if using existing webContents
// Set webPreferences from options if using an existing webContents.
// These preferences will be used when the webContent launches new
// render processes.
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);
if (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.
web_contents = WebContents::Create(isolate, web_preferences);