Route Download bubble file open to OnOpenURLFromTab (fixes #3750)

Some downloaded file types [1] default to opening in a Browser. Open
requests for these file types originating from the Download bubble UI
should route to the source Browser (call OnOpenURLFromTab). If
OnOpenURLFromTab is unhandled proceed with the default Chrome behavior
of opening the URL in a new default Browser.

[1] PDF, html, etc. For the complete list of file types see
ChromeDownloadManagerDelegate::IsOpenInBrowserPreferredForFile.
This commit is contained in:
Marshall Greenblatt
2024-08-08 16:34:44 -04:00
parent 87f49de296
commit a5544b6fb1
6 changed files with 80 additions and 42 deletions

View File

@@ -526,7 +526,7 @@ void ChromeBrowserDelegate::WebContentsCreated(
/*is_devtools_popup=*/false, opener);
}
content::WebContents* ChromeBrowserDelegate::OpenURLFromTabEx(
bool ChromeBrowserDelegate::OpenURLFromTabEx(
content::WebContents* source,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>&
@@ -535,17 +535,31 @@ content::WebContents* ChromeBrowserDelegate::OpenURLFromTabEx(
// Reading List sidebar. In that case we default to using the Browser's
// currently active WebContents.
if (!source) {
// GetActiveWebContents() may return nullptr if we're in a new Browser
// created using ScopedTabbedBrowserDisplayer. This new Browser does
// not have a WebContents yet.
source = browser_->tab_strip_model()->GetActiveWebContents();
DCHECK(source);
}
if (!source) {
LOG(WARNING) << "Failed to identify target browser for "
<< params.url.spec();
// Proceed with default chrome handling.
return true;
}
// Return nullptr to cancel the navigation. Otherwise, proceed with default
// chrome handling.
if (auto delegate = GetDelegateForWebContents(source)) {
return delegate->OpenURLFromTabEx(source, params,
navigation_handle_callback);
// Returns nullptr to cancel the navigation.
const bool cancel =
delegate->OpenURLFromTabEx(source, params,
navigation_handle_callback) == nullptr;
if (cancel) {
// Cancel the navigation.
return false;
}
}
return nullptr;
// Proceed with default chrome handling.
return true;
}
void ChromeBrowserDelegate::LoadingStateChanged(content::WebContents* source,