• Robert Knight's avatar
    Replace `document.title` as a fallback for title in PDFs · 40eaf5c9
    Robert Knight authored
    Replace the usage of `document.title` as a way to get the document title
    if the PDF has no embedded title in either its _document info
    dictionary_ or _metadata stream_.
    
    In top-level frames using `document.title` (where `document` is the
    global HTML document, not the PDF) works because PDF.js sets the title
    based on the first non-empty value from:
    
     1. The embedded title
     2. The filename from the `Content-Disposition` header
     3. The last segment of the URL's path (eg. "test.pdf" in
        "https://example.com/test.pdf")
    
    When PDF.js is embedded in an iframe however, it does not set
    `document.title` by default. As a result, documents were ending up in
    Hypothesis with a generic "PDF.js viewer" title.
    
    This commit implements (roughly) the same logic that PDF.js uses to
    determine the value used to set `document.title`, in the case where the
    PDF has no embedded title. This means implementing steps (2) and (3)
    from the above list. The `Content-Disposition` filename is not exposed
    as a public property on `PDFViewerApplication`, so
    `PDFMetadata#getMetadata` was refactored to call the
    `pdfDocument.getMetadata` instead.
    
    Fixes https://github.com/hypothesis/client/issues/3372
    40eaf5c9
Name
Last commit
Last update
..
annotator Loading commit data...
boot Loading commit data...
images/icons Loading commit data...
shared Loading commit data...
sidebar Loading commit data...
styles Loading commit data...
test-util Loading commit data...
types Loading commit data...
.eslintrc Loading commit data...
karma.config.js Loading commit data...
tsconfig.json Loading commit data...