Skip to content

Conversation

@pfrazee
Copy link
Contributor

@pfrazee pfrazee commented Oct 14, 2016

Per #7431 and #2749, this PR adds a webpreferences attribute to the webview tag. The string is implemented using the same parsing logic as the features string in window.open.

}

// parse the 'webpreferences' attribute string, if set
// this uses the same parsing rules as window.open uses for its features
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to use a common helper method for this so the parsing stays consistent between the two APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I factored out the function into the /lib/common dir, but I can't seem to make the require('../common/parse-features-string') happen in /lib/browser/guest-view-manager.js. I'm guessing this is due to changes to the require search paths. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions?

After looking into this a bit more, the code for each wouldn't be the exact same since window.open handles additional features as well which the webpreferences would not, so it might not make sense to have a common function between the two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thought, but I did find a way to make it work, that I think is pretty clean. I just need to solve the require() situation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfrazee want to push it up and I'll take a look at the require issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfrazee The issue was that new JS files need to be added to filenames.gypi to be included in the built version.

I pushed a couple changes to this pull request, please let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I did find a way to make it work, that I think is pretty clean

Yeah, I really like the way you did it, it makes both use cases easy to follow 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah looks much better.

@kevinsawicki kevinsawicki self-assigned this Oct 24, 2016
if (typeof params.webpreferences === 'string') {
// split the attribute's value by ','
let i, len
let webpreferencesTokens = params.webpreferences.split(/,\s*/)
Copy link
Contributor

@kevinsawicki kevinsawicki Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code from window.open that parses this is left-over from when Electron was using CoffeeScript so it might be nicer to write this new code using ES2015, such as:

params.webpreferences.split(/,\s*/).forEach((pref) => {
  let [name, value] = pref.split(/\s*=/)
  if (!name) return
  value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
  if (value === undefined) {
    value = true
  }
  webPreferences[name] = value
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can not set webpreferences to a object

@kevinsawicki
Copy link
Contributor

Thanks @pfrazee for implementing this 👍 🚢 :shipit:

@kevinsawicki kevinsawicki merged commit 39a5c7d into electron:master Oct 25, 2016
@kevinsawicki
Copy link
Contributor

@pfrazee
Copy link
Contributor Author

pfrazee commented Oct 25, 2016

Thanks @pfrazee for implementing this 👍 🚢 :shipit:

@kevinsawicki you bet!

@pfrazee beaker looks really cool, interested in adding it to http://electron.atom.io/apps/ ?

Yeah that'd be great!

@ea2973929
Copy link

Hi, this seemed to be exactly what I would need to change the default font of a webview using webpreferences. However, the setting is defaultFontFamily takes an object as argument (https://github.com/electron/electron/blob/master/docs/api/browser-window.md). How can I encode that as a parameter for the webpreferences attribute?

jviotti pushed a commit to balena-io/etcher that referenced this pull request Apr 25, 2017
Some changes that we're particularly interested in:

- electron/electron#8590
- electron/electron#8852
- electron/electron#7631

Note that the `electron-prebuilt` packaged has been renamed to
`electron`.

Change-Type: patch
Changelog-Entry: Upgrade Electron to v1.6.6.
Signed-off-by: Juan Cruz Viotti <[email protected]>
jviotti pushed a commit to balena-io/etcher that referenced this pull request Apr 25, 2017
Some changes that we're particularly interested in:

- electron/electron#8590
- electron/electron#8852
- electron/electron#7631

Note that the `electron-prebuilt` packaged has been renamed to
`electron`.

Change-Type: patch
Changelog-Entry: Upgrade Electron to v1.6.6.
Signed-off-by: Juan Cruz Viotti <[email protected]>
@lihang1870719
Copy link

I also account the same things like ea29738929。Is anyone figure out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants