зеркало из https://github.com/mozilla/gecko-dev.git
Bug 854478: remove support for automatically converting Sherlock-format search engines that were dropped into the profile directory, r=MattN
--HG-- extra : transplant_source : 2%EBl%CE1W%3E%A2%B3JK0%10M%0B%AF%87%C5H%AB
This commit is contained in:
Родитель
c1fe9f539b
Коммит
dcf437ef1a
|
@ -2996,17 +2996,7 @@ SearchService.prototype = {
|
|||
}
|
||||
|
||||
if (fileExtension == SHERLOCK_FILE_EXT) {
|
||||
if (isWritable) {
|
||||
try {
|
||||
this._convertSherlockFile(addedEngine, fileURL.fileBaseName);
|
||||
} catch (ex) {
|
||||
LOG("_loadEnginesFromDir: Failed to convert: " + fileURL.path + "\n" + ex + "\n" + ex.stack);
|
||||
// The engine couldn't be converted, mark it as read-only
|
||||
addedEngine._readOnly = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the engine still doesn't have an icon, see if we can find one
|
||||
// See if we can find an icon
|
||||
if (!addedEngine._iconURI) {
|
||||
var icon = this._findSherlockIcon(file, fileURL.fileBaseName);
|
||||
if (icon)
|
||||
|
@ -3206,97 +3196,6 @@ SearchService.prototype = {
|
|||
return this.__sortedEngines = this.__sortedEngines.concat(alphaEngines);
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a Sherlock file and its icon into the custom XML format used by
|
||||
* the Search Service. Saves the engine's icon (if present) into the XML as a
|
||||
* data: URI and changes the extension of the source file from ".src" to
|
||||
* ".xml". The engine data is then written to the file as XML.
|
||||
* @param aEngine
|
||||
* The Engine object that needs to be converted.
|
||||
* @param aBaseName
|
||||
* The basename of the Sherlock file.
|
||||
* Example: "foo" for file "foo.src".
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE if the file could not be converted.
|
||||
*
|
||||
* @see nsIURL::fileBaseName
|
||||
*/
|
||||
_convertSherlockFile: function SRCH_SVC_convertSherlock(aEngine, aBaseName) {
|
||||
ENSURE_WARN(aEngine._file, "can't convert an engine with no file",
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
var oldSherlockFile = aEngine._file;
|
||||
|
||||
// Back up the old file
|
||||
try {
|
||||
var backupDir = oldSherlockFile.parent;
|
||||
backupDir.append("searchplugins-backup");
|
||||
|
||||
if (!backupDir.exists())
|
||||
backupDir.create(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
|
||||
|
||||
oldSherlockFile.copyTo(backupDir, null);
|
||||
} catch (ex) {
|
||||
// Just bail. Engines that can't be backed up won't be converted, but
|
||||
// engines that aren't converted are loaded as readonly.
|
||||
FAIL("_convertSherlockFile: Couldn't back up " + oldSherlockFile.path +
|
||||
":\n" + ex, Cr.NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
// Rename the file, but don't clobber existing files
|
||||
var newXMLFile = oldSherlockFile.parent.clone();
|
||||
newXMLFile.append(aBaseName + "." + XML_FILE_EXT);
|
||||
|
||||
if (newXMLFile.exists()) {
|
||||
// There is an existing file with this name, create a unique file
|
||||
newXMLFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, PERMS_FILE);
|
||||
}
|
||||
|
||||
// Rename the .src file to .xml
|
||||
oldSherlockFile.moveTo(null, newXMLFile.leafName);
|
||||
|
||||
aEngine._file = newXMLFile;
|
||||
|
||||
// Write the converted engine to disk
|
||||
aEngine._serializeToFile();
|
||||
|
||||
// Update the engine's _type.
|
||||
aEngine._type = SEARCH_TYPE_MOZSEARCH;
|
||||
|
||||
// See if it has a corresponding icon
|
||||
try {
|
||||
var icon = this._findSherlockIcon(aEngine._file, aBaseName);
|
||||
if (icon && icon.fileSize < MAX_ICON_SIZE) {
|
||||
// Use this as the engine's icon
|
||||
var bStream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
var fileInStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
|
||||
fileInStream.init(icon, MODE_RDONLY, PERMS_FILE, 0);
|
||||
bStream.setInputStream(fileInStream);
|
||||
|
||||
var bytes = [];
|
||||
while (bStream.available() != 0)
|
||||
bytes = bytes.concat(bStream.readByteArray(bStream.available()));
|
||||
bStream.close();
|
||||
|
||||
// Convert the byte array to a base64-encoded string
|
||||
var str = btoa(String.fromCharCode.apply(null, bytes));
|
||||
|
||||
aEngine._iconURI = makeURI(ICON_DATAURL_PREFIX + str);
|
||||
LOG("_importSherlockEngine: Set sherlock iconURI to: \"" +
|
||||
aEngine._iconURL + "\"");
|
||||
|
||||
// Write the engine to disk to save changes
|
||||
aEngine._serializeToFile();
|
||||
|
||||
// Delete the icon now that we're sure everything's been saved
|
||||
icon.remove(false);
|
||||
}
|
||||
} catch (ex) { LOG("_convertSherlockFile: Error setting icon:\n" + ex); }
|
||||
},
|
||||
|
||||
/**
|
||||
* Finds an icon associated to a given Sherlock file. Searches the provided
|
||||
* file's parent directory looking for files with the same base name and one
|
||||
|
|
Загрузка…
Ссылка в новой задаче