Ticket #1808: Diff-enable-dom-object-save.patch

File Diff-enable-dom-object-save.patch, 3.6 KB (added by fbennett, 6 years ago)
  • chrome/content/zotero/xpcom/attachments.js

     
    492492         * Save a snapshot -- uses synchronous WebPageDump or asynchronous saveURI() 
    493493         */ 
    494494        function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs, callback, libraryID) { 
     495                var url, bases, base, pos, len; 
    495496                Zotero.debug('Importing attachment from document'); 
    496497                 
    497498                if (sourceItemID && parentCollectionIDs) { 
     
    501502                        parentCollectionIDs = undefined; 
    502503                } 
    503504                 
    504                 var url = document.location.href; 
     505                if (document.location) { 
     506                        url = document.location.href; 
     507                } else { 
     508                        // 
     509                        // For documents generated internally with createDocument(), 
     510                        // attempts to query the document URL produce the following 
     511                        // results: 
     512                        // 
     513                        //   document.baseURIObject.spec:  about:blank 
     514                        //   document.location:            null 
     515                        // 
     516                        // To process XHTML documents of this kind as attachments, 
     517                        // set a base element inside the HEAD node of the document. 
     518                        // If no base element is present, a generated attachment 
     519                        // document will fail. 
     520                        // 
     521                        url = "about:blank"; 
     522                        var html = document.getElementsByTagName("html")[0]; 
     523                        bases = html.getElementsByTagName("base"); 
     524                        len = bases.length; 
     525                        for (pos = 0; pos < len; pos += 1) { 
     526                                base = bases.item(pos); 
     527                                if (base.hasAttribute("href")) { 
     528                                        url = base.getAttribute("href"); 
     529                                        break; 
     530                                } 
     531                        } 
     532                } 
    505533                var title = forceTitle ? forceTitle : document.title; 
    506534                var mimeType = document.contentType; 
    507535                var charsetID = Zotero.CharacterSets.getID(document.characterSet); 
     
    567595                        } 
    568596                         
    569597                        if (mimeType == 'text/html') { 
     598                                Zotero.debug('Saving with wpdDOMSaver.saveHTMLDocument()'); 
    570599                                var sync = true; 
    571600                                 
    572601                                // Load WebPageDump code 
  • chrome/content/zotero/webpagedump/domsaver.js

     
    176176                // Added by Dan S. for Zotero, replacing three lines below 
    177177                this.document = document; 
    178178                this.setFrameList(document.defaultView); 
    179                 this.baseURL = document.location.href; 
     179                if (document.location) { 
     180                        this.baseURL = document.location.href; 
     181                } else { 
     182                        this.baseURL = "about:blank"; 
     183                } 
    180184                 
    181185                 
    182186                // Set the document and frames                                           
     
    732736                        this.fileInfo[newFileName] = new Array("url","downloaded"); 
    733737                        this.fileInfo[newFileName]["url"] = aURLSpec;                 
    734738                        this.fileInfo[newFileName]["downloaded"] = true; 
    735                         if (aDownload)  
    736                           this.fileInfo[newFileName]["downloaded"] = wpdCommon.downloadFile(aURLSpec,this.currentDir+newFileName);                 
     739                        if (aDownload) { 
     740                                this.fileInfo[newFileName]["downloaded"] = wpdCommon.downloadFile(aURLSpec,this.currentDir+newFileName); 
     741                        } 
    737742                  }                                                                                     
    738743                  return newFileName;                              
    739744                } catch(ex) {   
     
    10581063        { 
    10591064    // we have to set a new current url which is the  
    10601065    // base reference url (necessary for frame processing) 
    1061                 this.currentURL = aDocument.location.href;     
     1066                if (aDocument.location) { 
     1067                        this.currentURL = aDocument.location.href;     
     1068                } else { 
     1069                        this.currentURL = "about:blank"; 
     1070                } 
    10621071                                                                                     
    10631072                // distinguish between HTML Documents and other  
    10641073                // embedded files like flash, video or images...