Skip to content

Implement initial, experimental BrowserView API - #9166

Merged
poiru merged 5 commits into
masterfrom
browserview
Apr 13, 2017
Merged

poiru merged 5 commits into
masterfrom
browserview

Conversation

@poiru

@poiru poiru commented Apr 11, 2017 •

Copy link
Copy Markdown
Contributor

Right now, <webview> is the only way to embed additional content in a BrowserWindow. Unfortunately <webview> suffers from a number of problems. To make matters worse, many of these are upstream Chromium bugs instead of Electron-specific bugs.

For us at Figma, the main issue is very slow performance.

Despite the upstream improvements to <webview> through the OOPIF work, it is probable that there will continue to be <webview>-specific bugs in the future.

Therefore, this introduces a <webview> alternative to called BrowserView, which...

  • is a thin wrapper around api::WebContents (so bugs in BrowserView will
    likely also be bugs in BrowserWindow web contents)

  • is instantiated in the main process like BrowserWindow (and unlike
    <webview>, which lives in the DOM of a BrowserWindow web contents)

  • needs to be added to a BrowserWindow to display something on the screen

This implements the most basic API. The API is expected to evolve and change in the near future and has consequently been marked as experimental. Please do not use this API in production unless you are prepared to deal with breaking changes.

In the future, we will want to change the API to support multiple BrowserViews per window. We will also want to consider z-ordering, auto-resizing, and possibly even nested views.

@poiru
poiru force-pushed the browserview branch 2 times, most recently from e6f2a69 to 8395be3 Compare April 11, 2017 18:08
}

if (args->Length() > 1) {
args->ThrowError();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mind be nice to have a message here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

void BrowserView::Init(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options) {
mate::Handle<class api::WebContents> web_contents;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Super minor, but you don't need the api:: prefix here since you are already in that namespace, same with line 38.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@kevinsawicki kevinsawicki self-assigned this Apr 11, 2017
Comment thread docs/api/browser-view.md Outdated

Resizes and moves the view to the supplied bounds relative to the window.

#### `win.setBackgroundColor()` _Experimental_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing the argument here?

Comment thread docs/api/browser-view.md Outdated

#### `win.setBackgroundColor()` _Experimental_

Resizes and moves the view to the supplied bounds relative to the window.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this needs to be updated 🍝

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Derp, fixed!

Comment thread docs/api/browser-window.md Outdated

#### `win.setBrowserView(browserView)` _Experimental_

* `browserView` BrowserView

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe make this [BrowserView](browser-view.md) for easier navigation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread filenames.gypi
'lib/browser/api/protocol.js',
'lib/browser/api/session.js',
'lib/browser/api/screen.js',
'lib/browser/api/session.js',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning these up 👍

BrowserView::BrowserView(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options)
: api_web_contents_() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think about making it api_web_contents_(nullptr) ? Tells its a raw pointer at glance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

const mate::Dictionary& options) {
mate::Handle<class WebContents> web_contents;
// If no WebContents was passed to the constructor, create it from options.
if (!options.Get("webContents", &web_contents)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although this option is not documented, if someone tried to pass an already owned webContents what should happen in that scenario ? Might be worth checking the type of webContents ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just removed that option.

// If no WebContents was passed to the constructor, create it from options.
if (!options.Get("webContents", &web_contents)) {
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the property isBrowserView be set here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, good catch!

switch (val) {
case Type::BACKGROUND_PAGE: type = "backgroundPage"; break;
case Type::BROWSER_WINDOW: type = "window"; break;
case Type::BROWSER_VIEW:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be aligned to a one-liner.

@CharlieHess

Copy link
Copy Markdown
Contributor

This would be pretty great for Slack, considering our current team-switching approach is basically a stack of webview tags (and resizing them on the fly, which often results in layout jitter). If there is z-index support that would be 💎. A few questions:

  • Will we be able to disable nodeintegration in the same manner as the webview?
  • Would there be any other security loopholes opened by using this instead of webviews?

@poiru
poiru force-pushed the browserview branch 2 times, most recently from 962a5fb to d39312f Compare April 12, 2017 22:08
@poiru

poiru commented Apr 12, 2017

Copy link
Copy Markdown
Contributor Author

@CharlieHess Yeah, new BrowserView({ webPreferences: { nodeintegration: false }}) works fine. This should be fine for remote content, but please wait until the experimental tag has been removed before using it for that purpose.

Btw. I just added autoresizing support for smooth resizing!

poiru added 5 commits April 13, 2017 01:27
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.

For us at [Figma](https://www.figma.com), the main issue is very slow
performance.

Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.

Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...

- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
  likely also be bugs in `BrowserWindow` web contents)

- is instantiated in the main process like `BrowserWindow` (and unlike
  `<webview>`, which lives in the DOM of a `BrowserWindow` web contents)

- needs to be added to a `BrowserWindow` to display something on the screen

This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.

In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM , thanks @poiru !

@poiru
poiru merged commit 7f4bd79 into master Apr 13, 2017
@poiru
poiru deleted the browserview branch April 13, 2017 08:00
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