Skip to content

Commit

Permalink
[CSC] Crash fix for browser
Browse files Browse the repository at this point in the history
(cherry picked from commit 758edd6)

Bug: 1453864
Change-Id: I89f057e49f1a8837c9f61f03862fa089e0f74874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4609387
Reviewed-by: Michael Crouse <mcrouse@chromium.org>
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1157666}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4618413
Cr-Commit-Position: refs/branch-heads/5790@{#799}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Shakti Sahu authored and Chromium LUCI CQ committed Jun 15, 2023
1 parent 3be2377 commit f42964e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Browser* GetBrowserForWebContents(content::WebContents* web_contents) {
auto* browser_window =
BrowserWindow::FindBrowserWindowWithWebContents(web_contents);
auto* browser_view = static_cast<BrowserView*>(browser_window);
CHECK(browser_view);
return browser_view->browser();
return browser_view ? browser_view->browser() : nullptr;
}

} // namespace companion
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ void CompanionPageHandler::ShowUI() {
// Calls to the browser need to happen after the ShowUI() call above since
// it is only added to browser hierarchy after the side panel has loaded the
// page.
auto* browser = GetBrowser();
if (!browser) {
return;
}

auto* active_web_contents =
GetBrowser()->tab_strip_model()->GetActiveWebContents();
Observe(active_web_contents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ void SigninDelegateImpl::EnableMsbb(bool enable_msbb) {
}

void SigninDelegateImpl::OpenUrlInBrowser(const GURL& url, bool use_new_tab) {
auto* browser = companion::GetBrowserForWebContents(webui_contents_);
if (!browser) {
return;
}

content::OpenURLParams params(url, content::Referrer(),
use_new_tab
? WindowOpenDisposition::NEW_FOREGROUND_TAB
: WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
/*is_renderer_initiated*/ false);
auto* browser = companion::GetBrowserForWebContents(webui_contents_);
browser->OpenURL(params);
}

Expand Down

0 comments on commit f42964e

Please sign in to comment.