diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5b45a75 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +### 1.0.0 +- initial release +- add full Pale Moon compatibility \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..14e2f77 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcf8ca6 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# MozArchiver +Extension to allow the creation and viewing of MAFF and MHT archive files within Pale Moon. Fork of the extension [Mozilla Archive Format](https://addons.mozilla.org/en-US/firefox/addon/mozilla-archive-format/) by Christopher Ottley and Paolo Amadini for Pale Moon. + +## Building +Simply download the contents of the "src" folder and pack the contents into a .zip file. Then, rename the file to .xpi and drag into the browser. diff --git a/src/chrome.manifest b/src/chrome.manifest new file mode 100644 index 0000000..8496961 --- /dev/null +++ b/src/chrome.manifest @@ -0,0 +1,55 @@ +content mza chrome/content/ + +locale mza en-US chrome/locale/en-US/ + +locale mza cs chrome/locale/cs/ +locale mza da chrome/locale/da/ +locale mza de chrome/locale/de/ +locale mza es-ES chrome/locale/es-ES/ +locale mza fr chrome/locale/fr/ +locale mza hu chrome/locale/hu/ +locale mza hy-AM chrome/locale/hy-AM/ +locale mza it chrome/locale/it/ +locale mza ja-JP chrome/locale/ja-JP/ +locale mza ko-KR chrome/locale/ko-KR/ +locale mza mk-MK chrome/locale/mk-MK/ +locale mza pl chrome/locale/pl/ +locale mza pt-BR chrome/locale/pt-BR/ +locale mza ro chrome/locale/ro/ +locale mza ru chrome/locale/ru/ +locale mza sv-SE chrome/locale/sv-SE/ +locale mza tr chrome/locale/tr/ +locale mza zh-CN chrome/locale/zh-CN/ +locale mza zh-TW chrome/locale/zh-TW/ + +skin mza classic/1.0 chrome/skin/ +skin mza-icons classic/1.0 ./ + +component {3b2f1177-d918-44ee-91a6-ba95954064bb} components/DocumentLoaderFactory.js +contract @mozarchiver/document-loader-factory;1 {3b2f1177-d918-44ee-91a6-ba95954064bb} + +component {37116274-8df3-4d48-8533-00eae60c844c} components/Startup.js +contract @mozarchiver/startup;1 {37116274-8df3-4d48-8533-00eae60c844c} +category profile-after-change MozArchiver @mozarchiver/startup;1 + +component {7380f280-ab36-4a23-b213-35c64f8586a0} components/ContentPolicy.js +contract @mozarchiver/content-policy;1 {7380f280-ab36-4a23-b213-35c64f8586a0} +category content-policy MozArchiver @mozarchiver/content-policy;1 + +# Integration with the browsing windows +overlay chrome://browser/content/browser.xul chrome://mza/content/integration/mafBaseBrowserOverlay.xul + +# Integration with the "Multiple Tab Handler" extension +overlay chrome://multipletab/content/multipletab.xul chrome://mza/content/integration/mafMultipleTabOverlay.xul + +# The Archives dialog +overlay chrome://mza/content/archives/archivesDialog.xul chrome://mza/content/archives/archivesDialogBrowserOverlay.xul application={8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4} + +# The preferences dialog +overlay chrome://mza/content/preferences/prefsDialog.xul chrome://mza/content/preferences/prefsDialogBrowserOverlay.xul application={8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4} + +# Use the preferences image file from the current theme +override chrome://mza/skin/preferences/Options.png chrome://browser/skin/preferences/Options.png application={8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4} + +# Once loaded, use the 48x48 pixels application icon instead of the 32x32 pixels one +override chrome://mza-icons/skin/icon.png chrome://mza-icons/skin/icon48.png diff --git a/src/chrome/content/MozillaArchiveFormat.jsm b/src/chrome/content/MozillaArchiveFormat.jsm new file mode 100644 index 0000000..4bdf6b7 --- /dev/null +++ b/src/chrome/content/MozillaArchiveFormat.jsm @@ -0,0 +1,96 @@ +/** + * Exports all the common JavaScript objects for Mozilla Archive Format. + */ + +const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); + +let objectsByFolder = { + general: [ + "AsyncEnumerator", + "DataSourceWrapper", + "Interface", + "PersistBundle", + "PersistFolder", + "PersistResource", + "SourceFragment", + "CssSourceFragment", + "HtmlSourceFragment", + "TagSourceFragment", + "UrlListSourceFragment", + "UrlSourceFragment", + ], + archives: [ + "ArchiveAnnotations", + "ArchiveHistoryObserver", + ], + convert: [ + "Candidate", + "CandidateFinder", + "CandidateLocation", + "CandidatesDataSource", + ], + engine: [ + "Archive", + "ArchiveCache", + "ArchivePage", + "MaffArchive", + "MaffArchivePage", + "MaffDataSource", + "MhtmlArchive", + "MhtmlArchivePage", + "MimePart", + "MimeSupport", + "MultipartMimePart", + "ZipCreator", + "ZipDirectory", + ], + integration: [ + "FileFilters", + "TabsDataSource", + ], + loading: [ + "ArchiveLoader", + "ArchiveStreamConverter", + ], + preferences: [ + "DynamicPrefs", + "FileAssociations", + "Prefs", + ], + savecomplete: [ + "MafSaveComplete", + "SaveCompletePersist", + ], + saving: [ + "Job", + "JobRunner", + "ExactPersistInitialJob", + "ExactPersistJob", + "ExactPersist", + "ExactPersistParsedJob", + "ExactPersistReference", + "ExactPersistUnparsedJob", + "MafArchivePersist", + "MafWebProgressListener", + "SaveArchiveJob", + "SaveContentJob", + "SaveJob", + ], + startup: [ + "HelperAppsWrapper", + "StartupEvents", + "StartupInitializer", + ], +}; + +let EXPORTED_SYMBOLS = []; +for (let folderName of Object.keys(objectsByFolder)) { + for (let objectName of objectsByFolder[folderName]) { + EXPORTED_SYMBOLS.push(objectName); + Services.scriptloader.loadSubScript("chrome://mza/content/" + folderName + + "/" + objectName + ".js"); + } +} diff --git a/src/chrome/content/archives/ArchiveAnnotations.js b/src/chrome/content/archives/ArchiveAnnotations.js new file mode 100644 index 0000000..f4c949d --- /dev/null +++ b/src/chrome/content/archives/ArchiveAnnotations.js @@ -0,0 +1,208 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Archive Format. + * + * The Initial Developer of the Original Code is + * Paolo Amadini . + * Portions created by the Initial Developer are Copyright (C) 2009 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/** + * This object handles annotations on archive pages for this session. + * + * Annotations are used to query and display information about the known + * archives using the Places interfaces. At present, the actual annotations are + * only used to sort the results properly in the Places view of the Archives + * dialog. For more information, see + * + * (retrieved 2009-05-23). + */ +var ArchiveAnnotations = { + + /** MAF annotation names */ + MAFANNO_TITLE: "maf/title", + MAFANNO_ORIGINALURL: "maf/originalurl", + MAFANNO_DATEARCHIVED: "maf/datearchived", + MAFANNO_ARCHIVENAME: "maf/archivename", + MAFANNO_TEMPURI: "maf/tempuri", + MAFANNO_DIRECTARCHIVEURI: "maf/directarchiveuri", + + /** + * Sets all the annotations associated with the given ArchivePage object. + */ + setAnnotationsForPage: function(aPage) { + try { + // For all the possible annotations + [ + [ArchiveAnnotations.MAFANNO_TITLE, aPage.title], + [ArchiveAnnotations.MAFANNO_ORIGINALURL, aPage.originalUrl], + [ArchiveAnnotations.MAFANNO_DATEARCHIVED, aPage.dateArchived], + [ArchiveAnnotations.MAFANNO_ARCHIVENAME, aPage.archive.name], + [ArchiveAnnotations.MAFANNO_TEMPURI, + (aPage.tempUri ? aPage.tempUri.spec : "")], + [ArchiveAnnotations.MAFANNO_DIRECTARCHIVEURI, + (aPage.directArchiveUri ? aPage.directArchiveUri.spec : "")], + ].forEach(function([annotationName, annotationValue]) { + // Set the annotation while handling the data types correctly. + ArchiveAnnotations._setAnnotationForPage(aPage, annotationName, + annotationValue); + }); + } catch (e if (e instanceof Ci.nsIException && (e.result == + Cr.NS_ERROR_INVALID_ARG))) { + // This error is raised if the page is not present in history when the + // functions that set annotations are called. In this case, we set a flag + // on the page object indicating that the history observer should add the + // annotations after the page visit information is added. + aPage.annotationsPending = true; + } + }, + + /** + * Removes all the annotations associated with the given ArchivePage object. + */ + removeAnnotationsForPage: function(aPage) { + // For all the possible annotations + [ + ArchiveAnnotations.MAFANNO_TITLE, + ArchiveAnnotations.MAFANNO_ORIGINALURL, + ArchiveAnnotations.MAFANNO_DATEARCHIVED, + ArchiveAnnotations.MAFANNO_ARCHIVENAME, + ArchiveAnnotations.MAFANNO_TEMPURI, + ArchiveAnnotations.MAFANNO_DIRECTARCHIVEURI, + ].forEach(function(annotationName) { + try { + // Clear the annotation if present on the page's specific archive URI. + ArchiveAnnotations._annotationService.removePageAnnotation( + aPage.archiveUri, annotationName); + } catch (e if (e instanceof Ci.nsIException && (e.result == + Cr.NS_ERROR_INVALID_ARG))) { + // Ignore errors due to the fact that the page is not in history. + } + }); + }, + + /** + * Returns the value of an annotation for the given ArchivePage object. + * + * This function returns a Date object for annotations that represent dates. + * + * In order to avoid problems due to the asynchronous adding of history + * entries, the annotation values are not actually read using the Places + * services, but extracted from the provided object. + */ + getAnnotationForPage: function(aPage, aAnnotationName) { + var annotationValue; + switch (aAnnotationName) { + case ArchiveAnnotations.MAFANNO_TITLE: + annotationValue = aPage.title; + break; + case ArchiveAnnotations.MAFANNO_ORIGINALURL: + annotationValue = aPage.originalUrl; + break; + case ArchiveAnnotations.MAFANNO_DATEARCHIVED: + annotationValue = aPage.dateArchived; + break; + case ArchiveAnnotations.MAFANNO_ARCHIVENAME: + annotationValue = aPage.archive.name; + break; + case ArchiveAnnotations.MAFANNO_TEMPURI: + annotationValue = (aPage.tempUri ? aPage.tempUri.spec : ""); + break; + case ArchiveAnnotations.MAFANNO_DIRECTARCHIVEURI: + annotationValue = (aPage.directArchiveUri ? + aPage.directArchiveUri.spec : ""); + break; + } + // If the value represents an URI, store this information in the value + // itself. This allows for properly displaying the value later. The + // annotation should not be added if the value is empty, otherwise the tests + // to detect this condition will provide incorrect results. + if (annotationValue && ArchiveAnnotations.annotationIsEscapedAsUri( + aAnnotationName)) { + annotationValue = new String(annotationValue); + annotationValue.isEscapedAsUri = true; + } + // Return the string, numeric or date value. + return annotationValue; + }, + + /** + * Returns True if the specified annotation represents a date. + */ + annotationIsDate: function(aAnnotationName) { + return (aAnnotationName === ArchiveAnnotations.MAFANNO_DATEARCHIVED); + }, + + /** + * Returns True if the specified annotation represents an URI or part of it. + */ + annotationIsEscapedAsUri: function(aAnnotationName) { + return [ + ArchiveAnnotations.MAFANNO_ORIGINALURL, + ArchiveAnnotations.MAFANNO_ARCHIVENAME, + ArchiveAnnotations.MAFANNO_TEMPURI, + ArchiveAnnotations.MAFANNO_DIRECTARCHIVEURI, + ].indexOf(aAnnotationName) >= 0; + }, + + /** + * Sets the value of an annotation for the given ArchivePage object. + * + * This function accepts a Date object for annotations that represent dates. + */ + _setAnnotationForPage: function(aPage, aAnnotationName, aAnnotationValue) { + var annotationValue = aAnnotationValue; + // If this annotation represents a date, convert the Date object to a + // comparable numeric value. If the date is unspecified, store the numeric + // value 0 in the annotation. + if (ArchiveAnnotations.annotationIsDate(aAnnotationName)) { + annotationValue = annotationValue ? annotationValue.getTime() : 0; + // In order for the sorting to work correctly, we must store the + // annotation as a string, and not a numeric value. Dates before 01 + // January, 1970 UTC are not supported at present. + annotationValue = (annotationValue < 0) ? 0 : annotationValue; + annotationValue = ("000000000000000" + annotationValue).slice(-16); + } + // Set the annotation on the page's specific archive URI. The annotations + // will expire when the current session terminates. + ArchiveAnnotations._annotationService.setPageAnnotation( + aPage.archiveUri, aAnnotationName, annotationValue || "", 0, + Ci.nsIAnnotationService.EXPIRE_SESSION); + }, + + /** + * Returns a reference to the annotation service. + */ + get _annotationService() { + return Cc["@mozilla.org/browser/annotation-service;1"]. + getService(Ci.nsIAnnotationService); + }, +}; diff --git a/src/chrome/content/archives/ArchiveHistoryObserver.js b/src/chrome/content/archives/ArchiveHistoryObserver.js new file mode 100644 index 0000000..7cde431 --- /dev/null +++ b/src/chrome/content/archives/ArchiveHistoryObserver.js @@ -0,0 +1,63 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Archive Format. + * + * The Initial Developer of the Original Code is + * Paolo Amadini . + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/** + * This object listens for new page history additions and sets the required + * Places annotations for all pages that were loaded and for which this + * operation is still pending. + */ +var ArchiveHistoryObserver = { + QueryInterface: XPCOMUtils.generateQI([ + Ci.nsINavHistoryObserver, + ]), + onBeginUpdateBatch: function() { }, + onEndUpdateBatch: function() { }, + onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, + aTransitionType, aGUID, aAdded) { + // If the page that was just visited is waiting for adding annotations + var page = ArchiveCache.pageFromUri(aURI); + if (page && page.annotationsPending) { + delete page.annotationsPending; + ArchiveAnnotations.setAnnotationsForPage(page); + } + }, + onTitleChanged: function(aURI, aPageTitle) { }, + onDeleteURI: function(aURI, aGUID) { }, + onClearHistory: function() { }, + onPageChanged: function(aURI, aWhat, aValue) { }, + onDeleteVisits: function(aURI, aVisitTime, aGUID) { }, +}; diff --git a/src/chrome/content/archives/archivesDialog.js b/src/chrome/content/archives/archivesDialog.js new file mode 100644 index 0000000..e9998eb --- /dev/null +++ b/src/chrome/content/archives/archivesDialog.js @@ -0,0 +1,622 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Archive Format. + * + * The Initial Developer of the Original Code is + * Paolo Amadini . + * Portions created by the Initial Developer are Copyright (C) 2009 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +let { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +Cu.import("chrome://mza/content/MozillaArchiveFormat.jsm"); + +/** + * Handles the MAF dialog that displays information about the known archives. + */ +var ArchivesDialog = { + + /** + * The tree element that lists the known archive pages. + */ + archivesTree: null, + + // --- Interactive dialog functions and events --- + + /** + * Initializes the dialog when the window is opened initially. + * + * This function prepares the initial Places view. For more information, see + * + * (retrieved 2009-05-23). + */ + onLoadDialog: function() { + // Execute the initialization functions that are specific to SeaMonkey. + if (window.onNavigatorLoadDialog) { + window.onNavigatorLoadDialog(); + } + + // Get a reference to the tree that will display the main Places view. + ArchivesDialog.archivesTree = document.getElementById("treeArchives"); + + // Customize the Places view and the operations that can be performed on it. + ArchivesDialog.customizePlacesView(); + ArchivesDialog.customizePlacesController(); + + // Rename the "delete" command in the Places context menu to reflect the + // actual operation it performs on the customized Places tree. + var btnDelete = document.getElementById("btnDelete"); + var contextMenuItem = + document.getElementById("placesContext_delete_history") || + document.getElementById("placesContext_delete"); + contextMenuItem.setAttribute("label", btnDelete.getAttribute("label")); + contextMenuItem.setAttribute("accesskey", btnDelete.getAttribute( + "cxtaccesskey")); + + // Remove the original history handling commands in the Places context menu + // because their presence in the Archives view is confusing. + for (var [, commandName] in Iterator([ + "placesContext_deleteHost", + "placesContext_deleteByHostname", + "placesContext_deleteByDomain" + ])) { + var element = document.getElementById(commandName); + if (element) { + document.getElementById("placesContext").removeChild(element); + } + } + + // Execute the initial update of the controls. + ArchivesDialog.checkShowMore(); + ArchivesDialog.checkPlaceInfo(); + }, + + /** + * Updates the displayed information on the current selection in the tree. + */ + onTreeSelect: function(aEvent) { + ArchivesDialog.checkPlaceInfo(); + }, + + /** + * Opens the selected node when return is pressed. + */ + onTreeKeyPress: function(aEvent) { + if (aEvent.keyCode != KeyEvent.DOM_VK_RETURN) + return; + + // Open the page represented by the selected node in the archives tree. + PlacesUIUtils.openNodeWithEvent(ArchivesDialog.archivesTree.selectedNode, + aEvent); + }, + + /** + * Opens the selected node on middle click. + */ + onTreeClick: function(aEvent) { + if (aEvent.target.localName != "treechildren" || aEvent.button != 1) + return; + + // Open the page represented by the selected node in the archives tree. + PlacesUIUtils.openNodeWithEvent(ArchivesDialog.archivesTree.selectedNode, + aEvent); + }, + + /** + * Opens the selected node on double click. + */ + onTreeDblClick: function(aEvent) { + if (aEvent.target.localName != "treechildren") + return; + + // Open the page represented by the selected node in the archives tree. + PlacesUIUtils.openNodeWithEvent(ArchivesDialog.archivesTree.selectedNode, + aEvent); + }, + + /** + * Toggles the visibility of the additional archive page details. + */ + onShowMoreClick: function() { + // Update the "hidden" attribute on the broadcaster. + var brShowMore = document.getElementById("brShowMore"); + brShowMore.setAttribute("hidden", brShowMore.hidden ? "false" : "true"); + // Update the label on the button. + ArchivesDialog.checkShowMore(); + }, + + /** + * Loads information about archive files, without opening them in the browser. + */ + onAddClick: function(aEvent) { + // Determine the title of the file picker dialog. + var title = document.getElementById("btnAdd").getAttribute("fptitle"); + + // Initialize a new file picker with filters for web archives. + var filePicker = Cc["@mozilla.org/filepicker;1"]. + createInstance(Ci.nsIFilePicker); + filePicker.init(window, title, Ci.nsIFilePicker.modeOpenMultiple); + FileFilters.openFilters.forEach(function(curFilter) { + filePicker.appendFilter(curFilter.title, curFilter.extensionString); + }); + filePicker.appendFilters(Ci.nsIFilePicker.filterAll); + + // Show the file picker and exit now if canceled. + if (filePicker.show() !== Ci.nsIFilePicker.returnOK) { + return; + } + + // For every selected file + var filesEnumerator = filePicker.files; + while (filesEnumerator.hasMoreElements()) + { + var file = filesEnumerator.getNext().QueryInterface(Ci.nsILocalFile); + // Attempt to load the archive and register it in the cache. + try { + var archive = ArchiveLoader.extractAndRegister(file); + for (var [, page] in Iterator(archive.pages)) { + // Ensure that a history visit is added for the page, otherwise the + // page would not appear in the Places view. The visit is recorded as + // a top level typed entry, so that history listeners are able to be + // notified about the new entry. + PlacesUtils.asyncHistory.updatePlaces({ + uri: page.archiveUri, + visits: [{ + transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED, + visitDate: Date.now() * 1000, + }], + }); + } + } catch (e) { + // If opening the archive failed, skip it and report the error. + Cu.reportError(e); + } + } + + // Ensure that the archives tree is refreshed immediately. + ArchivesDialog.requeryPlaces(); + }, + + /** + * Invokes the delete command on the tree view. + */ + onDeleteClick: function(aEvent) { + ArchivesDialog.deleteSelection(); + }, + + /** + * Opens the selected nodes in tabs, using the URLs from the column associated + * with the button. + */ + onOpenTabsClick: function(aEvent) { + // Determine the column for which the command has been invoked. + var columnId = "tc" + aEvent.target.id.slice("btnOpenTabs".length); + // Open the associated URLs if possible. + ArchivesDialog.openSelectionInTabs(columnId, aEvent); + }, + + // --- Functions that handle and customize the Places tree --- + + /** + * Refreshes the archives tree. + */ + requeryPlaces: function() { + // Execute the same query on the Places database again. + ArchivesDialog.archivesTree.place = ArchivesDialog.archivesTree.place; + // Since the above call restores the standard view, we must apply our + // customization again. The list of controllers on the tree is unaffected. + ArchivesDialog.customizePlacesView(); + }, + + /** + * Replaces the Places view on the archives tree with a customized one. For + * more information, see + * + * (retrieved 2009-05-23). + */ + customizePlacesView: function() { + // Create a new default Places view and override some of its functions. The + // functions are copied, not referenced, from the ArchivesDialog object. + var view = new PlacesTreeView(false, null, + ArchivesDialog.archivesTree.view._controller); + + view._originalGetCellText = view.getCellText; + view._originalCycleHeader = view.cycleHeader; + view.getCellText = ArchivesDialog.viewGetCellText; + view.cycleHeader = ArchivesDialog.viewCycleHeader; + view.sortingChanged = function() { }; + + // Get a reference to the current query result object, created by the + // standard Places tree. Ensure that the required interface is available on + // the object, since this is not done by the standard Places tree. + var result = ArchivesDialog.getResult(); + + // Before detaching the old view from the tree, ensure that its reference to + // the tree is removed. Failing to do this would cause the new view to + // malfunction. + ArchivesDialog.archivesTree.view.QueryInterface(Ci.nsITreeView). + setTree(null); + + // Apply the new view to the appropriate objects. + if (result.addObserver) { + result.addObserver(view, false); + } else { + result.viewer = view; + } + ArchivesDialog.archivesTree.view = view; + }, + + /** + * Adds a custom controller on the archives tree for overriding the clipboard + * commands and disabling history management commands. For more information, + * see (retrieved + * 2009-05-24). + */ + customizePlacesController: function() { + ArchivesDialog.archivesTree.controllers.insertControllerAt(0, { + supportsCommand: function(aCommand) { + // This object takes control of all the clipboard commands. + return [ + "cmd_cut", "cmd_copy", "cmd_paste", "cmd_delete" + ].indexOf(aCommand) >= 0; + }, + isCommandEnabled: function(aCommand) { + // The cut and the paste commands are always disabled. + if (["cmd_cut", "cmd_paste"].indexOf(aCommand) >= 0) { + return false; + } + // Other commands require that at least one item is selected. + return ArchivesDialog.archivesTree.hasSelection; + }, + doCommand: function(aCommand) { + switch (aCommand) { + // Copy information about the selected nodes to the clipboard. + case "cmd_copy": + ArchivesDialog.copySelection(); + break; + // Forget the information about the selected archives. + case "cmd_delete": + ArchivesDialog.deleteSelection(); + break; + } + }, + onEvent: function(aEventName) { }, + }); + ArchivesDialog.archivesTree.controllers.insertControllerAt(0, { + supportsCommand: function(aCommand) { + // Disable all the history handling commands. + return [ + "placesCmd_deleteDataHost", "placesCmd_delete:hostname", + "placesCmd_delete:domain" + ].indexOf(aCommand) >= 0; + }, + isCommandEnabled: function(aCommand) { + return false; + }, + doCommand: function(aCommand) { }, + onEvent: function(aEventName) { }, + }); + }, + + /** + * This function is copied to the Places view object to handle the special + * columns that display the MAF annotations. In this function, "this" refers + * to the Places view object. + */ + viewGetCellText: function(aRow, aCol) { + // Get the annotation value with the appropriate data type. + var value = ArchivesDialog.getNodeValue(this.nodeForTreeIndex(aRow), + aCol.element.id); + // Display localized short dates or plain string values. + return Interface.formatValueForDisplay(value, true); + }, + + /** + * This function is copied to the Places view object to handle the special + * columns that display the MAF annotations. In this function, "this" refers + * to the Places view object. + */ + viewCycleHeader: function(aCol) { + const kAsc = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING; + const kDesc = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING; + + // Handle the columns that display custom annotations. + var annotationName = ArchivesDialog.getColumnAnnotationName(aCol.element); + if (annotationName) { + // Get a reference to the current query result. + var result = ArchivesDialog.getResult(); + // If the result was already sorted using the selected annotation, just + // reverse the sort order. + if (result.sortingMode == kAsc && + result.sortingAnnotation == annotationName) { + result.sortingMode = kDesc; + } else if (result.sortingMode == kDesc && + result.sortingAnnotation == annotationName) { + result.sortingMode = kAsc; + } else { + // Sort in ascending order using the specified annotation. + result.sortingAnnotation = annotationName; + result.sortingMode = kAsc; + } + return; + } + + // If this is not a custom column, forward the call to the original function. + this._originalCycleHeader(aCol); + }, + + // --- Functions that execute the custom commands on the tree --- + + /** + * Copies to the clipboard the details about the selected nodes, in various + * formats. The original location of the page is used instead of its local + * archive URL. + * + * This function is similar to the standard Places function implemented in + * "controller.js", except that history nodes are handled and no entry is + * generated for the flavor TYPE_X_MOZ_PLACE, since the override URL has no + * effect for that flavor. For more information, see + * + * (retrieved 2009-05-25). + */ + copySelection: function() { + // Find the selected nodes, and exit now if no node is selected. + var selectedNodes = ArchivesDialog.getSelectedNodes(); + if (!selectedNodes.length) + return; + + // Create a new object to hold the data to be copied. + var transferable = Cc["@mozilla.org/widget/transferable;1"]. + createInstance(Ci.nsITransferable); + if (transferable.init) { + transferable.init(null); + } + + // Add the data flavors to the object in the appropriate order. + [ + PlacesUtils.TYPE_X_MOZ_URL, + PlacesUtils.TYPE_UNICODE, + PlacesUtils.TYPE_HTML, + ].forEach(function(type) { + // For every node in the selection + var dataString = ""; + for (var [, node] in Iterator(selectedNodes)) { + // Add the concatenation separator if necessary. + if (dataString) { + dataString += NEWLINE; + } + // Use the original location of the page when copying the node. If the + // original location is unspecified, the page archive URL will be used. + var overrideUri = ArchivesDialog.getNodeValue(node, "tcMafOriginalUrl"); + // Add the current node's data to the string. + dataString += PlacesUtils.wrapNode(node, type, overrideUri); + } + // Convert the string type for the transferable object. + var dataSupportsString = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + dataSupportsString.data = dataString; + // Add the concatenated data to the transferable object. + transferable.addDataFlavor(type); + transferable.setTransferData(type, dataSupportsString, + dataString.length * 2); + }); + + // Copy the data to the clipboard. + PlacesUIUtils.clipboard.setData(transferable, null, + Ci.nsIClipboard.kGlobalClipboard); + }, + + /** + * Removes from the cache the archives containing the selected pages. + */ + deleteSelection: function() { + // Find the selected nodes, and exit now if no node is selected. + var selectedNodes = ArchivesDialog.getSelectedNodes(); + if (!selectedNodes.length) + return; + + // For every node in the selection + for (var [, node] in Iterator(selectedNodes)) { + // Find a reference to the page from the archives cache. + var page = this.getNodePage(node); + // If the page is still cached, remove its archive from the cache. + if (page) { + ArchiveCache.unregisterArchive(page.archive); + } + } + + // Ensure that the archives tree is refreshed immediately. + ArchivesDialog.requeryPlaces(); + }, + + /** + * Opens the selected nodes in tabs, using the URLs from the specified column. + */ + openSelectionInTabs: function(aColumnId, aEvent) { + // Find the selected nodes, and exit now if no node is selected. + var selectedNodes = ArchivesDialog.getSelectedNodes(); + if (!selectedNodes.length) + return; + + // For every node in the selection + var urlsToOpen = []; + for (var [, node] in Iterator(selectedNodes)) { + // Find the associated URL, and add it to the list if actually specified. + var value = ArchivesDialog.getNodeValue(node, aColumnId); + if (value) { + urlsToOpen.push({ uri: value, isBookmark: false }); + } + } + + // If the operation resulted in actual URLs to be opened + if (urlsToOpen.length) { + // Open the URLs using a private function of the standard Places + // utilities for JavaScript. + PlacesUIUtils._openTabset(urlsToOpen, aEvent); + } + }, + + // --- Dialog state check functions --- + + /** + * Update the label of the button that toggles the visibility of the + * additional archive page details. + */ + checkShowMore: function() { + var brShowMore = document.getElementById("brShowMore"); + var btnShowMore = document.getElementById("btnShowMore"); + btnShowMore.setAttribute("label", btnShowMore.getAttribute( + brShowMore.hidden ? "morelabel" : "lesslabel")); + btnShowMore.setAttribute("accesskey", btnShowMore.getAttribute( + brShowMore.hidden ? "moreaccesskey" : "lessaccesskey")); + }, + + /** + * Updates the displayed information on the current selection in the tree. + */ + checkPlaceInfo: function() { + var selectedNodes = ArchivesDialog.getSelectedNodes(); + + // Disable the buttons that require a selection. + document.getElementById("btnDelete").disabled = !selectedNodes.length; + + // For all the possible columns in the archives tree + var column = ArchivesDialog.archivesTree.columns.getFirstColumn(); + do { + // Find the elements associated with the current column. + var fieldName = column.id.slice("tc".length); + var txtValue = document.getElementById("txt" + fieldName); + var btnOpenTabs = document.getElementById("btnOpenTabs" + fieldName); + + // Assume that the value is missing, for example if no element is + // selected. + var displayValue = ""; + var actionDisabled = true; + + // Find the first node for which a value is actually present. + for (var [, node] in Iterator(selectedNodes)) { + // Get the node value with the appropriate data type. + var value = ArchivesDialog.getNodeValue(node, column.id); + if (value) { + // Enable the action associated with the column. + actionDisabled = false; + if (selectedNodes.length == 1) { + // Display a localized long date or the plain string value. + displayValue = Interface.formatValueForDisplay(value, false); + } else { + // Display a placeholder for multiple nodes. + displayValue = txtValue.getAttribute("multivalue"); + } + break; + } + } + + // Update the elements. + txtValue.value = displayValue; + if (btnOpenTabs) { + btnOpenTabs.disabled = actionDisabled; + } + } while ((column = column.getNext())); + }, + + // --- Dialog support functions --- + + /** + * Returns the current query result of the Places view. + */ + getResult: function() { + var result = ArchivesDialog.archivesTree.result || + ArchivesDialog.archivesTree.getResult(); + return result.QueryInterface(Ci.nsINavHistoryResult); + }, + + /** + * Returns the currently selected nodes in the Places view. + */ + getSelectedNodes: function() { + return ArchivesDialog.archivesTree.selectedNodes || + ArchivesDialog.archivesTree.getSelectionNodes(); + }, + + /** + * Returns the name of the custom annotation associated with the given tree + * column element, or false if the column is a standard one. + */ + getColumnAnnotationName: function(aElement) { + var useAnnotation = (aElement.id.slice(0, "tcMaf".length) === "tcMaf"); + return useAnnotation && aElement.getAttribute("sort"); + }, + + /** + * Returns the value associated with the given column identifier for the + * provided Places result node. The JavaScript type of the returned value + * depends on the column. If data for the requested item is not available, + * null is returned. + */ + getNodeValue: function(aNode, aColumnId) { + // If this is a standard column that is actually present in the Places view, + // access the associated property of the node directly. + if (aColumnId === "tcPlacesTitle") { + return aNode.title; + } else if (aColumnId === "tcPlacesUrl") { + var annotationValue = new String(aNode.uri); + annotationValue.isEscapedAsUri = true; + return annotationValue; + } + // Get a reference to the page object associated with the node. If the page + // is not available anymore, exit now. + var page = this.getNodePage(aNode); + if (!page) { + return null; + } + // Access the value of the annotation associated with the column. + var element = document.getElementById(aColumnId); + var annotationName = ArchivesDialog.getColumnAnnotationName(element); + return ArchiveAnnotations.getAnnotationForPage(page, annotationName); + }, + + /** + * Returns the ArchivePage object associated with the given Places result + * node, or null if the page is not cached or the URI of the Places item is + * not valid anymore. + */ + getNodePage: function(aNode) { + var nodeUri; + try { + nodeUri = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService).newURI(aNode.uri, null, null); + } catch (e) { + // Return null if the URI is invalid. + return null; + } + return ArchiveCache.pageFromUri(nodeUri); + }, +} diff --git a/src/chrome/content/archives/archivesDialog.xul b/src/chrome/content/archives/archivesDialog.xul new file mode 100644 index 0000000..6953dd6 --- /dev/null +++ b/src/chrome/content/archives/archivesDialog.xul @@ -0,0 +1,394 @@ + + + + + + + + + +