Repository navigation
Implement initial, experimental BrowserView API - #9166
Conversation
e6f2a69 to
8395be3
Compare
| } | ||
|
|
||
| if (args->Length() > 1) { | ||
| args->ThrowError(); |
There was a problem hiding this comment.
Mind be nice to have a message here.
| void BrowserView::Init(v8::Isolate* isolate, | ||
| v8::Local<v8::Object> wrapper, | ||
| const mate::Dictionary& options) { | ||
| mate::Handle<class api::WebContents> web_contents; |
There was a problem hiding this comment.
Super minor, but you don't need the api:: prefix here since you are already in that namespace, same with line 38.
|
|
||
| Resizes and moves the view to the supplied bounds relative to the window. | ||
|
|
||
| #### `win.setBackgroundColor()` _Experimental_ |
There was a problem hiding this comment.
Missing the argument here?
|
|
||
| #### `win.setBackgroundColor()` _Experimental_ | ||
|
|
||
| Resizes and moves the view to the supplied bounds relative to the window. |
There was a problem hiding this comment.
I think this needs to be updated 🍝
|
|
||
| #### `win.setBrowserView(browserView)` _Experimental_ | ||
|
|
||
| * `browserView` BrowserView |
There was a problem hiding this comment.
Maybe make this [BrowserView](browser-view.md) for easier navigation?
| 'lib/browser/api/protocol.js', | ||
| 'lib/browser/api/session.js', | ||
| 'lib/browser/api/screen.js', | ||
| 'lib/browser/api/session.js', |
There was a problem hiding this comment.
Thanks for cleaning these up 👍
| BrowserView::BrowserView(v8::Isolate* isolate, | ||
| v8::Local<v8::Object> wrapper, | ||
| const mate::Dictionary& options) | ||
| : api_web_contents_() { |
There was a problem hiding this comment.
What do you think about making it api_web_contents_(nullptr) ? Tells its a raw pointer at glance.
| 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)) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Should the property isBrowserView be set here ?
| switch (val) { | ||
| case Type::BACKGROUND_PAGE: type = "backgroundPage"; break; | ||
| case Type::BROWSER_WINDOW: type = "window"; break; | ||
| case Type::BROWSER_VIEW: |
There was a problem hiding this comment.
Can be aligned to a one-liner.
|
This would be pretty great for Slack, considering our current team-switching approach is basically a stack of
|
962a5fb to
d39312f
Compare
|
@CharlieHess Yeah, Btw. I just added autoresizing support for smooth resizing! |
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.
Right now,
<webview>is the only way to embed additional content in aBrowserWindow. 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 calledBrowserView, which...is a thin wrapper around
api::WebContents(so bugs inBrowserViewwilllikely also be bugs in
BrowserWindowweb contents)is instantiated in the main process like
BrowserWindow(and unlike<webview>, which lives in the DOM of aBrowserWindowweb contents)needs to be added to a
BrowserWindowto display something on the screenThis 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.