Skip to content

Allow downloading PDFs instead of opening them in Brave. #941

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

Merged
merged 1 commit into from
Dec 14, 2018

Conversation

mkarolin
Copy link
Collaborator

@mkarolin mkarolin commented Nov 21, 2018

Fixes brave/brave-browser#1531

The fix does the following:

  1. Makes the initial decision on whether to load PDFJS extension based
    on the value of kPluginsAlwaysOpenPdfExternally profile preference in
    addition to the command line switch.

  2. Watches profile preference value kPluginsAlwaysOpenPdfExternally and
    adds/removes PDFJS component when the value changes.

  3. Modifies js behind the chrome://settings/content/pdfDocuments so that
    if the PDFJS extension is disabled from the command line the option to
    download PDF files instead of opening them in Brave is set to ON and the
    toggle is disabled.

  4. Adds an alternative call for whitelisted extensions in
    extensions/common/manifest_handlers/mime_types_handler.h that removes
    Chrome's PDF Extension ID from whitelisted IDs and patches
    chrome/browser/plugins/plugin_utils.cc to use the alternative call. This
    is done because on Linux that extension is not removed from profile
    enabled extensions (because there is no extensions install verification)
    and it ends up being picked as a handler for PDFs. If our PDFJS extension
    is disabled via command line, this causes a PDF to be neither displayed
    nor downloaded.

Note, that this fix doesn't address being able to turn off opening PDFs
in Brave in Guest/Tor profiles. The web ui setting to do so is not
available in these profiles.

The command line switch to not load PDFJS already applies to all profile
types.

Adds browser tests to check that Chromium's PDF extension is not
considered for handling PDFs and if the PDFJS extension is not loaded or
disabled from command line a download is initiated when navigating to a
PDF URL. Also adds test to verify that when PDF download preference is
toggled the component loader will take an appropriate action (add or
remove PDFJS extension).

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

Automated testing
npm run test -- brave_browser_tests --filter=BravePDFDownloadTest.*
npm run test -- brave_browser_tests --filter=BravePDFExtensionTest.ToggleDownloadPDFs
npm run test -- brave_browser_tests --filter=BravePDFExtensionDisabledTest.ToggleDownloadPDFs

Manual testing

  1. Test that PDF is downloaded if the Download PDF files... setting is turned on
  • Start Brave browser and navigate to chrome://settings/content/pdfDocuments,
  • Toggle the Download PDF files... setting to ON,
  • In a new tab, navigate to a PDF URL (e.g. http://www.pdf995.com/samples/pdf.pdf),
  • Verify that the PDF is not shown in Brave and is instead being downloaded,
  • In the settings tab, toggle the switch back to OFF,
  • In a new tab, navigate to the same PDF URL,
  • Verify that the PDF is now show in Brave.
  1. Test that command line switch is correctly interpreted in the settings UI
  • Start Brave browser from the command line with the --disable-pdfjs-extension switch,
  • Navigate to chrome://settings/content/pdfDocuments and verify that the Download PDF files... setting is set to ON and is disabled,
  • In a new tab, navigate to a PDF URL (e.g. http://www.pdf995.com/samples/pdf.pdf),
  • Verify that the PDF is not shown in Brave and is instead being downloaded.

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

@mkarolin mkarolin force-pushed the maxk-toggle-pdf-download branch 2 times, most recently from afce7b0 to 359075c Compare November 26, 2018 20:36
@mkarolin mkarolin self-assigned this Nov 26, 2018
@mkarolin mkarolin force-pushed the maxk-toggle-pdf-download branch 2 times, most recently from a9b15c2 to c0ce5c8 Compare November 27, 2018 17:52
@mkarolin mkarolin force-pushed the maxk-toggle-pdf-download branch 3 times, most recently from aefe129 to 1c2c7af Compare December 4, 2018 18:58
@mkarolin mkarolin changed the title WIP: Allow downloading PDFs instead of opening them in Brave. Allow downloading PDFs instead of opening them in Brave. Dec 4, 2018
@mkarolin mkarolin requested review from bbondy, yrliou and emerick December 4, 2018 20:37
@mkarolin mkarolin force-pushed the maxk-toggle-pdf-download branch 3 times, most recently from 34dbfa5 to 7487150 Compare December 6, 2018 22:24
Fixes brave/brave-browser#1531

The fix does the following:

1. Makes the initial decision on whether to load PDFJS extension based
on the value of kPluginsAlwaysOpenPdfExternally profile preference in
addition to the command line switch.

2. Watches profile preference value kPluginsAlwaysOpenPdfExternally and
adds/removes PDFJS component when the value changes.

3. Modifies js behind the chrome://settings/content/pdfDocuments so that
if the PDFJS extension is disabled from the command line the option to
download PDF files instead of opening them in Brave is set to ON and the
toggle is disabled.

4. Adds an alternative call for whitelisted extensions in
extensions/common/manifest_handlers/mime_types_handler.h that removes
Chrome's PDF Extension ID from whitelisted IDs and patches
chrome/browser/plugins/plugin_utils.cc to use the alternative call. This
is done because on Linux that extension is not removed from profile
enabled extensions (because there is no extensions install verification)
and it ends up being picked as a handler for PDFs. If our PDFJS extension
is disabled via command line, this causes a PDF to be neither displayed
nor downloaded.

Note, that this fix doesn't address being able to turn off opening PDFs
in Brave in Guest/Tor profiles. The web ui setting to do so is not
available in these profiles.

The command line switch to not load PDFJS already applies to all profile
types.

Adds browser tests to check that Chromium's PDF extension is not
considered for handling PDFs and if the PDFJS extension is not loaded or
disabled from command line a download is initiated when navigating to a
PDF URL. Also adds test to verify that when PDF download preference is
toggled the component loader will take an appropriate action (add or
remove PDFJS extension).
@mkarolin mkarolin force-pushed the maxk-toggle-pdf-download branch from 7487150 to 06c2c83 Compare December 6, 2018 22:35
Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

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

looks good!

@mkarolin mkarolin merged commit dab4abb into master Dec 14, 2018
@mkarolin mkarolin deleted the maxk-toggle-pdf-download branch December 14, 2018 17:27
mkarolin added a commit that referenced this pull request Dec 14, 2018
Allow downloading PDFs instead of opening them in Brave.
mkarolin added a commit that referenced this pull request Dec 14, 2018
Allow downloading PDFs instead of opening them in Brave.
@mkarolin
Copy link
Collaborator Author

master: dab4abb
0.60.x: fc54d67
0.59.x: fad1fc2

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.

Unable to download pdf instead opening them in brave. Unable to disable pdf.js via command line.
3 participants