Skip to content

Instantly share code, notes, and snippets.

@fbennett
Created March 29, 2010 09:17
Show Gist options
  • Save fbennett/347637 to your computer and use it in GitHub Desktop.
Save fbennett/347637 to your computer and use it in GitHub Desktop.
diff -r -b -u zoteroORIG/content/zotero/webpagedump/domsaver.js zoteroNEW/content/zotero/webpagedump/domsaver.js
--- zoteroORIG/content/zotero/webpagedump/domsaver.js 2008-09-23 11:11:56.000000000 +0900
+++ zoteroNEW/content/zotero/webpagedump/domsaver.js 2010-03-29 18:00:30.000000000 +0900
@@ -176,8 +176,11 @@
// Added by Dan S. for Zotero, replacing three lines below
this.document = document;
this.setFrameList(document.defaultView);
+ if (document.location) {
this.baseURL = document.location.href;
-
+ } else {
+ this.baseURL = "about:blank";
+ }
// Set the document and frames
//this.document = top.window._content.document;
@@ -1056,7 +1059,11 @@
{
// we have to set a new current url which is the
// base reference url (necessary for frame processing)
+ if (aDocument.location) {
this.currentURL = aDocument.location.href;
+ } else {
+ this.currentURL = "about:blank";
+ }
// distinguish between HTML Documents and other
// embedded files like flash, video or images...
diff -r -b -u zoteroORIG/content/zotero/xpcom/attachments.js zoteroNEW/content/zotero/xpcom/attachments.js
--- zoteroORIG/content/zotero/xpcom/attachments.js 2010-02-09 02:56:43.000000000 +0900
+++ zoteroNEW/content/zotero/xpcom/attachments.js 2010-03-29 17:59:21.000000000 +0900
@@ -488,6 +488,7 @@
* Save a snapshot -- uses synchronous WebPageDump or asynchronous saveURI()
*/
function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs, callback, libraryID) {
+ var url, bases, base, pos, len;
Zotero.debug('Importing attachment from document');
if (sourceItemID && parentCollectionIDs) {
@@ -497,7 +498,33 @@
parentCollectionIDs = undefined;
}
- var url = document.location.href;
+ if (document.location) {
+ url = document.location.href;
+ } else {
+ //
+ // For documents generated internally with createDocument(),
+ // attempts to query the document URL produce the following
+ // results:
+ //
+ // document.baseURIObject.spec: about:blank
+ // document.location: null
+ //
+ // To process XHTML documents of this kind as attachments,
+ // set a base element inside the HEAD node of the document.
+ // If no base element is present, a generated attachment
+ // document will fail.
+ //
+ url = "about:blank";
+ bases = document.getElementsByTagName("base");
+ len = bases.length;
+ for (pos = 0; pos < len; pos += 1) {
+ base = bases.item(pos);
+ if (base.hasAttribute("href")) {
+ url = base.getAttribute("href");
+ break;
+ }
+ }
+ }
var title = forceTitle ? forceTitle : document.title;
var mimeType = document.contentType;
var charsetID = Zotero.CharacterSets.getID(document.characterSet);
@@ -563,6 +590,7 @@
}
if (mimeType == 'text/html') {
+ Zotero.debug('Saving with wpdDOMSaver.saveHTMLDocument()');
var sync = true;
// Load WebPageDump code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment