New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: multi browser views support for BrowserWindow #16064
feat: multi browser views support for BrowserWindow #16064
Conversation
Add functions addBrowserView, removeBroserView, getBrowserViews to BrowserWindow class. Existing API as setBrowserView and getBrowserView not changed and keep working in single BrowserView mode.
…tream-labs/electron into sl_multi_browser_views_support
💖 Thanks for opening this pull request! 💖 We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
atom/browser/api/atom_api_window.cc
Outdated
@@ -914,6 +915,65 @@ void Window::ResetBrowserView() { | |||
browser_view_.Reset(); | |||
} | |||
|
|||
void Window::AddBrowserView(v8::Local<v8::Value> value) { | |||
mate::Handle<BrowserView> browser_view; | |||
if (value->IsNull() || value->IsUndefined()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to check null
, type check can be done with:
if (mate::ConvertFromV8(isolate(), value, &browser_view)) {
} else {
// Throw type error.
}
Window::RemoveBrowserView
can also be modified in the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Work of ConvertFromV8 is done by template implementation for corresponding type. For most types this indeed have check for null. But mate::Handle<> FromV8 converter does something opposite.
if (val->IsNull() || val->IsUndefined()) {
*out = mate::Handle<T>();
return true;
}
And that lead to crash if null is passed. So I have to add check back.
But change it to value->IsObject()
Is it OK?
Do I have to add "Throw type error"? Prev API does not do it and as AddBrowserView works now as fall back for SetBrowserView. Then SetBrowserView start to throwing error too. But sending null to setBrowserView is required way to remove BrowserView what was set before.
atom/browser/api/atom_api_window.cc
Outdated
} | ||
|
||
void Window::ResetBrowserViews() { | ||
for (auto views_iter = browser_views_.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use range-based for loop here:
for (auto item : browser_views_) {
item.second.Reset()
}
Other for loops can also be modified as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
atom/browser/native_window.h
Outdated
@@ -156,6 +156,8 @@ class NativeWindow : public base::SupportsUserData, | |||
virtual void SetMenu(AtomMenuModel* menu); | |||
virtual void SetParentWindow(NativeWindow* parent); | |||
virtual void SetBrowserView(NativeBrowserView* browser_view) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the NativeWindow::SetBrowserView
implementation, and add a simple fallback for it by reusing the new API:
BrowserWindow.prototype.setBrowserView = (view) => {
this.resetBrowserViews()
this.addBrowserView(view)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried to keep APIs separate to simplify usage in old code and new code written with new API. Even thinking about more explicit way what code can request new functionality.
Your suggestion is good as it is let add new API without keeping legacy code and will not affect
existing user code.
I have changed code in accordance with your suggestion.
|
||
* `browserView` [BrowserView](browser-view.md) | ||
|
||
Replacement API for setBrowserView supporting work with multi browser views. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a clear definition on the behavior when using setBrowserView
and addBrowserView
together, and have it documented. I suggest:
- Make
setBrowserView
an alias forremoveAllBrowserViews() && addBrowserView(view)
. - Make
getBrowserView
throw if there are multiple browser views, and returngetBrowserViews()[0]
as fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation updated
for loops changed to range based setBrowserView replaced with removeall and addone
Sorry I just noticed that this PR is targeted for 2.0.x. According to our versioning policy, we will not add new features to 2.0.x: https://www.electronjs.org/docs/tutorial/electron-versioning. Do you mind rebasing your changes on This code itself looks good to me now. |
Will it goes only to electron 4 from master or it can be backported to 3-0-x too? |
New features will be included in 5.0, currently we don't have plans to publish minor updates for 3.x/4.x for new features. |
feature code has been moved to a branch originated from master and new PR #16148 submitted. |
Description of Change
new feature: multi browser views support for BrowserWindow
Add functions addBrowserView, removeBroserView, getBrowserViews to BrowserWindow class.
Existing API setBrowserView and getBrowserView changed to use new API inside.
This functionality was mentioned in the initial BrowserView feature PR #9166 . And asked few times since then. Recently in a discussion #10622 .
Checklist
npm test
passes fornpm run test -match=BrowserView
,all-test
run have few fails even on unchanged2-0-x
branch.Release Notes
Notes: multi browser views support for BrowserWindow