refactor: address TODO for WebContents type parsing (#18158)
This commit is contained in:
parent
7e2cbf528e
commit
89105e7e57
6 changed files with 10 additions and 19 deletions
|
@ -68,7 +68,7 @@ void BrowserView::Init(v8::Isolate* isolate,
|
||||||
const mate::Dictionary& options) {
|
const mate::Dictionary& options) {
|
||||||
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);
|
||||||
web_preferences.Set("isBrowserView", true);
|
web_preferences.Set("type", "browserView");
|
||||||
mate::Handle<class WebContents> web_contents =
|
mate::Handle<class WebContents> web_contents =
|
||||||
WebContents::Create(isolate, web_preferences);
|
WebContents::Create(isolate, web_preferences);
|
||||||
|
|
||||||
|
|
|
@ -297,20 +297,12 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
// Read options.
|
// Read options.
|
||||||
options.Get("backgroundThrottling", &background_throttling_);
|
options.Get("backgroundThrottling", &background_throttling_);
|
||||||
|
|
||||||
// FIXME(zcbenz): We should read "type" parameter for better design, but
|
// Get type
|
||||||
// on Windows we have encountered a compiler bug that if we read "type"
|
options.Get("type", &type_);
|
||||||
// from |options| and then set |type_|, a memory corruption will happen
|
|
||||||
// and Electron will soon crash.
|
|
||||||
// Remvoe this after we upgraded to use VS 2015 Update 3.
|
|
||||||
bool b = false;
|
bool b = false;
|
||||||
if (options.Get("isGuest", &b) && b)
|
|
||||||
type_ = Type::WEB_VIEW;
|
|
||||||
else if (options.Get("isBackgroundPage", &b) && b)
|
|
||||||
type_ = Type::BACKGROUND_PAGE;
|
|
||||||
else if (options.Get("isBrowserView", &b) && b)
|
|
||||||
type_ = Type::BROWSER_VIEW;
|
|
||||||
#if BUILDFLAG(ENABLE_OSR)
|
#if BUILDFLAG(ENABLE_OSR)
|
||||||
else if (options.Get(options::kOffscreen, &b) && b)
|
if (options.Get(options::kOffscreen, &b) && b)
|
||||||
type_ = Type::OFF_SCREEN;
|
type_ = Type::OFF_SCREEN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2266,7 +2258,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription)
|
.SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription)
|
||||||
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
||||||
.SetMethod("startDrag", &WebContents::StartDrag)
|
.SetMethod("startDrag", &WebContents::StartDrag)
|
||||||
.SetMethod("isGuest", &WebContents::IsGuest)
|
|
||||||
.SetMethod("attachToIframe", &WebContents::AttachToIframe)
|
.SetMethod("attachToIframe", &WebContents::AttachToIframe)
|
||||||
.SetMethod("detachFromOuterFrame", &WebContents::DetachFromOuterFrame)
|
.SetMethod("detachFromOuterFrame", &WebContents::DetachFromOuterFrame)
|
||||||
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
|
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
|
||||||
|
|
|
@ -108,8 +108,8 @@ WebContentsPreferences::WebContentsPreferences(
|
||||||
mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
|
mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
|
||||||
// Following fields should not be stored.
|
// Following fields should not be stored.
|
||||||
copied.Delete("embedder");
|
copied.Delete("embedder");
|
||||||
copied.Delete("isGuest");
|
|
||||||
copied.Delete("session");
|
copied.Delete("session");
|
||||||
|
copied.Delete("type");
|
||||||
|
|
||||||
mate::ConvertFromV8(isolate, copied.GetHandle(), &preference_);
|
mate::ConvertFromV8(isolate, copied.GetHandle(), &preference_);
|
||||||
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
||||||
|
|
|
@ -93,7 +93,7 @@ const startBackgroundPages = function (manifest) {
|
||||||
|
|
||||||
const contents = webContents.create({
|
const contents = webContents.create({
|
||||||
partition: 'persist:__chrome_extension',
|
partition: 'persist:__chrome_extension',
|
||||||
isBackgroundPage: true,
|
type: 'backgroundPage',
|
||||||
sandbox: true,
|
sandbox: true,
|
||||||
enableRemoteModule: false
|
enableRemoteModule: false
|
||||||
})
|
})
|
||||||
|
|
|
@ -59,7 +59,7 @@ const createGuest = function (embedder, params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const guest = webContents.create({
|
const guest = webContents.create({
|
||||||
isGuest: true,
|
type: 'webview',
|
||||||
partition: params.partition,
|
partition: params.partition,
|
||||||
embedder: embedder
|
embedder: embedder
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,7 @@ const mergeOptions = function (child, parent, visited) {
|
||||||
|
|
||||||
visited.add(parent)
|
visited.add(parent)
|
||||||
for (const key in parent) {
|
for (const key in parent) {
|
||||||
if (key === 'isBrowserView') continue
|
if (key === 'type') continue
|
||||||
if (!hasProp.call(parent, key)) continue
|
if (!hasProp.call(parent, key)) continue
|
||||||
if (key in child && key !== 'webPreferences') continue
|
if (key in child && key !== 'webPreferences') continue
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ ipcMainInternal.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', functio
|
||||||
options = mergeBrowserWindowOptions(event.sender, options)
|
options = mergeBrowserWindowOptions(event.sender, options)
|
||||||
event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures, referrer)
|
event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures, referrer)
|
||||||
const { newGuest } = event
|
const { newGuest } = event
|
||||||
if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) {
|
if ((event.sender.getType() === 'webview' && !event.sender.allowPopups) || event.defaultPrevented) {
|
||||||
if (newGuest != null) {
|
if (newGuest != null) {
|
||||||
if (options.webContents === newGuest.webContents) {
|
if (options.webContents === newGuest.webContents) {
|
||||||
// the webContents is not changed, so set defaultPrevented to false to
|
// the webContents is not changed, so set defaultPrevented to false to
|
||||||
|
|
Loading…
Add table
Reference in a new issue