Skip to content
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

Restore deleted tab context menu #3836

Merged
merged 1 commit into from
Nov 4, 2019
Merged

Restore deleted tab context menu #3836

merged 1 commit into from
Nov 4, 2019

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Oct 31, 2019

Fix brave/brave-browser#6513

Reopen closed tab, Close other tabs and Bookmark all tabs items
are restored to tab context menu.

Chromium removed some items from tab context menu by below CL.

CL: https://chromium-review.googlesource.com/c/chromium/src/+/1761666
Issue: https://bugs.chromium.org/p/chromium/issues/detail?id=515930

Update tab and frame context menus to match most recent UX specs.

This removes four entries from the tab context menu; changes the text on several
others to stop saying "tab(s)" explicitly; adds one entry to the frame context
menu; and changes the bookmark-related menu entry strings from "page" to "tab"
for consistency.

Most of the file changes here are due to renaming enums/APIs to match the string
changes.

image

Submitter Checklist:

Test Plan:

Enabled state of Bookmark all tabs and Reopen closed tab are same as frame's same context menu.
Close other tabs is enabled only when closing candidates exists.

yarn test brave_browser_tests --filter=*BraveTabMenuModelTest*

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@simonhong simonhong added this to the 0.73.x - Nightly milestone Oct 31, 2019
@simonhong simonhong self-assigned this Oct 31, 2019
@simonhong simonhong force-pushed the tab_menu_model branch 4 times, most recently from 6f49623 to 8daa441 Compare October 31, 2019 21:57
@simonhong simonhong marked this pull request as ready for review October 31, 2019 22:26
@simonhong
Copy link
Member Author

Oh, there are some lint error and missing deps. updating now.

@simonhong simonhong force-pushed the tab_menu_model branch 2 times, most recently from 616fec5 to 30eb667 Compare October 31, 2019 23:39
@simonhong
Copy link
Member Author

Ready to review.

@bsclifton
Copy link
Member

@simonhong can you link to the Chromium details (in the commit message)?
This was captured in Chromium tracker with https://bugs.chromium.org/p/chromium/issues/detail?id=515930

And then I believe it was removed with https://chromium.googlesource.com/chromium/src.git/+/32bb26026fb3fd768dda878f9193a5080593d5ec

@simonhong simonhong force-pushed the tab_menu_model branch 2 times, most recently from 23d4293 to e3db310 Compare November 1, 2019 07:32
tab_strip_model_(tab_strip_model) {
// Take owner ship of TabMenuModelDelegateProxy instance.
// There is no way to instantiate it before calling ctor of base class.
delegate_proxy_.reset(TabMenuModel::delegate());
Copy link
Member

Choose a reason for hiding this comment

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

is this needed anymore? (how is delegate_proxy_ used?)

Copy link
Member Author

Choose a reason for hiding this comment

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

It needs because SimpleMenuModel doesn't own delegate.
BraveTabMenuModel should manage proxy's lifecycle.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This definitely does not look right to me. The TabMenuModel is not supposed to take ownership of the delegate and this seems likely to cause a crash at some point

Copy link
Collaborator

Choose a reason for hiding this comment

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

The delegate is owned by the BrowserTabStripController and I'm fairly certain that this will crash if you close a window with a context menu open. At the very least it breaks the cancel behavior here

BrowserTabStripController::~BrowserTabStripController() {
  // When we get here the TabStrip is being deleted. We need to explicitly
  // cancel the menu, otherwise it may try to invoke something on the tabstrip
  // from its destructor.
  if (context_menu_contents_.get())
    context_menu_contents_->Cancel();

  model_->RemoveObserver(this);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

so I just noticed that you're creating a new proxy delegate there, but that's also a potential problem. Let's dm and discuss when you're available

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this creates a bit of a convoluted chain of ownership and while it may or may not be ok, it seems like it would be easier to subclass BrowserTabStripController in BrowserViews and implement ShowContextMenuForTab. Then we can create our own delegate from the start with our own TabMenuModel and calling back into our own ExecuteCommandForTab. Then we can check the command ids in our BrowserTabStripController and either delegate to the TabStripModel or call the command in BraveBrowserTabStripController

Copy link
Collaborator

Choose a reason for hiding this comment

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

then at least the commands have the same flow at least through ExecuteCommandForTab
and there are no confusing ownership chains

@simonhong
Copy link
Member Author

Kindly ping to @bridiver :)

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

++

Reopen closed tab, Close other tabs and Bookmark all tabs items
are restored to tab context menu.

Chromium removed some items from tab context menu by below CL.

CL: https://chromium-review.googlesource.com/c/chromium/src/+/1761666
Issue: https://bugs.chromium.org/p/chromium/issues/detail?id=515930

Update tab and frame context menus to match most recent UX specs.

This removes four entries from the tab context menu; changes the text on several
others to stop saying "tab(s)" explicitly; adds one entry to the frame context
menu; and changes the bookmark-related menu entry strings from "page" to "tab"
for consistency.

Most of the file changes here are due to renaming enums/APIs to match the string
changes.
@bsclifton bsclifton merged commit 7723f74 into master Nov 4, 2019
@bsclifton bsclifton deleted the tab_menu_model branch November 4, 2019 19:37
bsclifton added a commit that referenced this pull request Nov 4, 2019
This reverts commit 7723f74, reversing
changes made to 4de8e57.

private:
FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, GetIndicesClosedByCommand);
+ friend class TabMenuModelDelegateProxy;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why this friend is needed. Can you explain?

Copy link
Member

Choose a reason for hiding this comment

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

If this is needed, @bridiver added an example for how to do it cleaner under https://github.com/brave/brave-browser/wiki/Patching-Chromium#subclass-and-override

bsclifton added a commit that referenced this pull request Nov 4, 2019
Revert "Merge pull request #3836 from brave/tab_menu_model"
@bsclifton
Copy link
Member

Reverted with #3874 after conversation with @bridiver

}

bool TabMenuModelDelegateProxy::IsCommandIdChecked(int command_id) const {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be returning delegate_->IsCommandIdChecked

@bsclifton bsclifton mentioned this pull request Nov 4, 2019
32 tasks
return indices;
}

bool TabMenuModelDelegateProxy::IsBraveCommandIds(int command_id) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: IsBraveCommandIds -> IsBraveCommandId
the use of Ids here is not grammatically correct

}
}

std::vector<int> TabMenuModelDelegateProxy::GetIndicesClosed(int index) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method name is confused to me. Maybe it should be GetIndicesToClose?

@bsclifton
Copy link
Member

bsclifton commented Nov 4, 2019

Re-opened PR at #3875

cc: @simonhong on the above review comments

fmarier pushed a commit to fmarier/brave-core that referenced this pull request Nov 6, 2019
This reverts commit 7723f74, reversing
changes made to 4de8e57.
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.

restore tab context menu items
3 participants