Skip to content

Commit

Permalink
Allow PDF viewer to navigate to file: URLs
Browse files Browse the repository at this point in the history
PDF viewer extension require navigation to file URLs, since some local
PDF files have links to file: URLs, which should be allowed.

(cherry picked from commit 70226cc)

Bug: 1490387
Change-Id: I286f5094ed3c4af6ffcfeec963170a8d38c4c526
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4920241
Auto-Submit: Jun Kokatsu <jkokatsu@google.com>
Reviewed-by: David Bertoni <dbertoni@chromium.org>
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1207958}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4943758
Commit-Queue: Jun Kokatsu <jkokatsu@google.com>
Cr-Commit-Position: refs/branch-heads/5993@{#1308}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
shhnjk authored and Chromium LUCI CQ committed Oct 16, 2023
1 parent 401bc15 commit eb9ece8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/extensions/extension_tab_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,8 @@ base::expected<GURL, std::string> ExtensionTabUtil::PrepareURLForNavigation(
// navigation as such contexts are trusted and do not have a concept of file
// access.
if (extension && url.SchemeIsFile() &&
// PDF viewer extension can navigate to file URLs.
extension->id() != extension_misc::kPdfExtensionId &&
!util::AllowFileAccess(extension->id(), browser_context) &&
base::FeatureList::IsEnabled(
extensions_features::kRestrictFileURLNavigation)) {
Expand Down
12 changes: 12 additions & 0 deletions chrome/browser/extensions/extension_tab_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ TEST_F(ChromeExtensionNavigationTest, PrepareURLForNavigation) {
}
}

TEST_F(ChromeExtensionNavigationTest, PrepareURLForNavigationWithPDFViewer) {
// Set ID for PDF viewer extension.
auto extension =
ExtensionBuilder("test").SetID(extension_misc::kPdfExtensionId).Build();

// File URLs are returned when the extension has access to file.
const std::string kFileURLWithPDFViewer("file:///etc/passwd");
auto url = ExtensionTabUtil::PrepareURLForNavigation(
kFileURLWithPDFViewer, extension.get(), browser_context());
EXPECT_THAT(url, base::test::ValueIs(GURL(kFileURLWithPDFViewer)));
}

TEST_F(ChromeExtensionNavigationTest, PrepareURLForNavigationOnDevtools) {
const std::string kDevtoolsURL(
"devtools://devtools/bundled/devtools_app.html");
Expand Down

0 comments on commit eb9ece8

Please sign in to comment.