-
Notifications
You must be signed in to change notification settings - Fork 3.2k
WIP Bugfix FXIOS-15339 [Tab management] Tab closed crashes when media presentations is present #33032
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
base: main
Are you sure you want to change the base?
WIP Bugfix FXIOS-15339 [Tab management] Tab closed crashes when media presentations is present #33032
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3490,13 +3490,17 @@ class BrowserViewController: UIViewController, | |
| store.dispatch(action) | ||
| } | ||
|
|
||
| // TODO: FXIOS-TODO - Make closeAllPrivateTabs async | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to create a ticket once this PR is approved. I think |
||
| func closeAllPrivateTabs() { | ||
| tabManager.removeTabs(tabManager.privateTabs) | ||
| guard let tab = mostRecentTab(inTabs: tabManager.normalTabs) else { | ||
| tabManager.selectTab(tabManager.addTab()) | ||
| return | ||
| Task { @MainActor in | ||
| await tabManager.removeTabs(tabManager.privateTabs) | ||
|
|
||
| guard let tab = mostRecentTab(inTabs: tabManager.normalTabs) else { | ||
| tabManager.selectTab(tabManager.addTab()) | ||
| return | ||
| } | ||
| tabManager.selectTab(tab) | ||
| } | ||
| tabManager.selectTab(tab) | ||
| } | ||
|
|
||
| func switchToTabForURLOrOpen( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,13 +119,15 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| copyURL(tabID: tabUUID, uuid: action.windowUUID) | ||
|
|
||
| case TabPeekActionType.closeTab: | ||
| // TODO: verify if this works for closing a tab from an unselected tab panel | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the todo since this is working since a long time, and there's no ticket number |
||
| guard let tabsState = state.componentState(TabsPanelState.self, | ||
| for: .tabsPanel, | ||
| window: action.windowUUID) else { return } | ||
| tabPeekCloseTab(with: tabUUID, | ||
| uuid: action.windowUUID, | ||
| isPrivate: tabsState.isPrivateMode) | ||
|
|
||
| Task { | ||
| await tabPeekCloseTab(with: tabUUID, | ||
| uuid: action.windowUUID, | ||
| isPrivate: tabsState.isPrivateMode) | ||
| } | ||
| default: | ||
| break | ||
| } | ||
|
|
@@ -222,9 +224,11 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
|
|
||
| case TabPanelViewActionType.closeTab: | ||
| guard let tabUUID = action.tabUUID else { return } | ||
| closeTabFromTabPanel(with: tabUUID, | ||
| uuid: action.windowUUID, | ||
| isPrivate: action.panelType == .privateTabs) | ||
| Task { | ||
| await closeTabFromTabPanel(with: tabUUID, | ||
| uuid: action.windowUUID, | ||
| isPrivate: action.panelType == .privateTabs) | ||
| } | ||
|
|
||
| case TabPanelViewActionType.undoClose: | ||
| undoCloseTab(state: state, uuid: action.windowUUID) | ||
|
|
@@ -236,11 +240,15 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| ) | ||
|
|
||
| case TabPanelViewActionType.confirmCloseAllTabs: | ||
| closeAllTabs(state: state, uuid: action.windowUUID) | ||
| Task { | ||
| await closeAllTabs(state: state, uuid: action.windowUUID) | ||
| } | ||
|
|
||
| case TabPanelViewActionType.deleteTabsOlderThan: | ||
| guard let period = action.deleteTabPeriod else { return } | ||
| deleteNormalTabsOlderThan(period: period, uuid: action.windowUUID) | ||
| Task { | ||
| await deleteNormalTabsOlderThan(period: period, uuid: action.windowUUID) | ||
| } | ||
|
|
||
| case TabPanelViewActionType.undoCloseAllTabs: | ||
| undoCloseAllTabs(uuid: action.windowUUID) | ||
|
|
@@ -424,7 +432,7 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| /// - Parameters: | ||
| /// - tabUUID: UUID of the tab to be closed/removed | ||
| /// - Returns: If is the last tab to be closed used to trigger dismissTabTray action | ||
| private func closeTab(with tabUUID: TabUUID, uuid: WindowUUID, isPrivate: Bool) -> Bool { | ||
| private func closeTab(with tabUUID: TabUUID, uuid: WindowUUID, isPrivate: Bool) async -> Bool { | ||
| tabsPanelTelemetry.tabClosed(mode: isPrivate ? .private : .normal) | ||
| let tabManager = tabManager(for: uuid) | ||
| // In non-private mode, if: | ||
|
|
@@ -434,14 +442,14 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| let isLastActiveTab = isPrivate | ||
| ? tabManager.privateTabs.count == 1 | ||
| : tabManager.normalTabs.count == 1 | ||
| tabManager.removeTab(tabUUID) | ||
| await tabManager.removeTab(tabUUID) | ||
| return isLastActiveTab | ||
| } | ||
|
|
||
| /// Close tab and trigger refresh | ||
| /// - Parameter tabUUID: UUID of the tab to be closed/removed | ||
| private func closeTabFromTabPanel(with tabUUID: TabUUID, uuid: WindowUUID, isPrivate: Bool) { | ||
| let shouldDismiss = self.closeTab(with: tabUUID, uuid: uuid, isPrivate: isPrivate) | ||
| private func closeTabFromTabPanel(with tabUUID: TabUUID, uuid: WindowUUID, isPrivate: Bool) async { | ||
| let shouldDismiss = await closeTab(with: tabUUID, uuid: uuid, isPrivate: isPrivate) | ||
| triggerRefresh(uuid: uuid, isPrivate: isPrivate) | ||
|
|
||
| if isPrivate && tabManager(for: uuid).privateTabs.isEmpty { | ||
|
|
@@ -539,14 +547,14 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| store.dispatch(scrollAction) | ||
| } | ||
|
|
||
| private func closeAllTabs(state: AppState, uuid: WindowUUID) { | ||
| private func closeAllTabs(state: AppState, uuid: WindowUUID) async { | ||
| let tabManager = tabManager(for: uuid) | ||
| guard let tabsState = state.componentState(TabsPanelState.self, for: .tabsPanel, window: uuid) else { return } | ||
|
|
||
| tabsPanelTelemetry.closeAllTabsSheetOptionSelected(option: .all, mode: tabsState.isPrivateMode ? .private : .normal) | ||
| let normalCount = tabManager.normalTabs.count | ||
| let privateCount = tabManager.privateTabs.count | ||
| tabManager.removeAllTabs(isPrivateMode: tabsState.isPrivateMode) | ||
| await tabManager.removeAllTabs(isPrivateMode: tabsState.isPrivateMode) | ||
|
|
||
| triggerRefresh(uuid: uuid, isPrivate: tabsState.isPrivateMode) | ||
|
|
||
|
|
@@ -572,10 +580,10 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| } | ||
| } | ||
|
|
||
| private func deleteNormalTabsOlderThan(period: TabsDeletionPeriod, uuid: WindowUUID) { | ||
| private func deleteNormalTabsOlderThan(period: TabsDeletionPeriod, uuid: WindowUUID) async { | ||
| tabsPanelTelemetry.deleteNormalTabsSheetOptionSelected(period: period) | ||
| let tabManager = tabManager(for: uuid) | ||
| tabManager.removeNormalTabsOlderThan(period: period, currentDate: .now) | ||
| await tabManager.removeNormalTabsOlderThan(period: period, currentDate: .now) | ||
|
|
||
| // We are not closing the tab tray, so we need to refresh the tabs on screen | ||
| let model = getTabsDisplayModel(for: false, uuid: uuid) | ||
|
|
@@ -692,8 +700,8 @@ final class TabManagerMiddleware: FeatureFlaggable, | |
| UIPasteboard.general.url = tabManager.getTabForUUID(uuid: tabID)?.canonicalURL | ||
| } | ||
|
|
||
| private func tabPeekCloseTab(with tabID: TabUUID, uuid: WindowUUID, isPrivate: Bool) { | ||
| closeTabFromTabPanel(with: tabID, uuid: uuid, isPrivate: isPrivate) | ||
| private func tabPeekCloseTab(with tabID: TabUUID, uuid: WindowUUID, isPrivate: Bool) async { | ||
| await closeTabFromTabPanel(with: tabID, uuid: uuid, isPrivate: isPrivate) | ||
| } | ||
|
|
||
| private func changePanel(_ panel: TabTrayPanelType, appState: AppState, uuid: WindowUUID) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,9 +338,14 @@ class TopTabDisplayManager: NSObject { | |
| func performCloseAction(for tab: Tab) { | ||
| guard !isDragging else { return } | ||
|
|
||
| // TODO: FXIOS-TODO - Why do we call get tabs here, can we remove it | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to create a ticket for this, I don't understand what this |
||
| _ = getTabs() | ||
| tabsPanelTelemetry.tabClosed(mode: tab.isPrivate ? .private : .normal) | ||
| tabManager.removeTab(tab.tabUUID) | ||
|
|
||
| // TODO: FXIOS-TODO Make performCloseAction async | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to create a ticket once this PR is approved. I think |
||
| Task { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. async-await question here we use |
||
| await tabManager.removeTab(tab.tabUUID) | ||
| } | ||
| } | ||
|
|
||
| // When using 'Close All', hide all the tabs so they don't animate their deletion individually | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -600,12 +600,16 @@ class Tab: NSObject, | |
| guard let currentlyOpenUrl = lastKnownUrl ?? historyList.last else { return } | ||
|
|
||
| url = currentlyOpenUrl | ||
| close() | ||
|
|
||
| // TODO: FXIOS-TODO Make clearAndResetTabHistory async | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to create a ticket once this PR is approved. I think |
||
| Task { | ||
| await close() | ||
| } | ||
| } | ||
|
|
||
| func close() { | ||
| webView?.pauseAllMediaPlayback {} | ||
| webView?.closeAllMediaPresentations {} | ||
| func close() async { | ||
| await webView?.pauseAllMediaPlayback() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is what originates most of the changes I guess?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah exactly! |
||
| await webView?.closeAllMediaPresentations() | ||
| webView?.stopLoading() | ||
|
Comment on lines
+610
to
613
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix for the bug. We need to await that media are closed before deiniting the tab. A completion handler version is also available, but as I said in the description I think we should move towards async/await instead. Let me know what you think |
||
|
|
||
| contentScriptManager.uninstall(tab: self) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,18 +74,18 @@ protocol TabManager: AnyObject { | |
|
|
||
| /// Remove tab option using tabUUID. | ||
| /// - Parameter tabUUID: UUID from the tab | ||
| func removeTab(_ tabUUID: TabUUID) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically anything that wants to remove a tab in the tab manager will be async now |
||
| func removeTab(_ tabUUID: TabUUID) async | ||
|
|
||
| /// Remove all tabs indicating if is on private mode or not | ||
| /// - Parameter isPrivateMode: Is private mode enabled or not | ||
| func removeAllTabs(isPrivateMode: Bool) | ||
| func removeAllTabs(isPrivateMode: Bool) async | ||
|
|
||
| /// Removes all tabs matching the urls, used when other clients request to close tabs on this device. | ||
| func removeTabs(by urls: [URL]) | ||
| func removeTabs(_ tabs: [Tab]) | ||
| func removeTabs(by urls: [URL]) async | ||
| func removeTabs(_ tabs: [Tab]) async | ||
|
|
||
| /// Remove normal tabs older than a certain period of time | ||
| func removeNormalTabsOlderThan(period: TabsDeletionPeriod, currentDate: Date) | ||
| func removeNormalTabsOlderThan(period: TabsDeletionPeriod, currentDate: Date) async | ||
|
|
||
| // MARK: - Undo Close | ||
| func undoCloseTab() | ||
|
|
||
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.
Clean up comment 😄