Bug 862143: remove support for loading sherlock files from disk, r=MattN

This commit is contained in:
Gavin Sharp
2013-06-07 10:19:32 -07:00
parent e9b57cb990
commit 284beccfae

View File

@@ -84,10 +84,6 @@ const SEARCH_TYPE_SHERLOCK = Ci.nsISearchEngine.TYPE_SHERLOCK;
const SEARCH_DATA_XML = Ci.nsISearchEngine.DATA_XML;
const SEARCH_DATA_TEXT = Ci.nsISearchEngine.DATA_TEXT;
// File extensions for search plugin description files
const XML_FILE_EXT = "xml";
const SHERLOCK_FILE_EXT = "src";
// Delay for lazy serialization (ms)
const LAZY_SERIALIZE_DELAY = 100;
@@ -100,9 +96,6 @@ const CACHE_VERSION = 7;
const ICON_DATAURL_PREFIX = "data:image/x-icon;base64,";
// Supported extensions for Sherlock plugin icons
const SHERLOCK_ICON_EXTENSIONS = [".gif", ".png", ".jpg", ".jpeg"];
const NEW_LINES = /(\r\n|\r|\n)/;
// Set an arbitrary cap on the maximum icon size. Without this, large icons can
@@ -718,7 +711,7 @@ function getBoolPref(aName, aDefault) {
* unique sanitized name.
*/
function getSanitizedFile(aName) {
var fileName = sanitizeName(aName) + "." + XML_FILE_EXT;
var fileName = sanitizeName(aName) + ".xml";
var file = getDir(NS_APP_USER_SEARCH_DIR);
file.append(fileName);
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, PERMS_FILE);
@@ -1194,18 +1187,9 @@ Engine.prototype = {
"text/xml");
this._data = doc.documentElement;
break;
case SEARCH_DATA_TEXT:
var binaryInStream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
binaryInStream.setInputStream(fileInStream);
var bytes = binaryInStream.readByteArray(binaryInStream.available());
this._data = bytes;
break;
default:
ERROR("Bogus engine _dataType: \"" + this._dataType + "\"",
ERROR("Unsuppored engine _dataType in _initFromFile: \"" + this._dataType + "\"",
Cr.NS_ERROR_UNEXPECTED);
}
fileInStream.close();
@@ -2973,37 +2957,20 @@ SearchService.prototype = {
var fileExtension = fileURL.fileExtension.toLowerCase();
var isWritable = isInProfile && file.isWritable();
var dataType;
switch (fileExtension) {
case XML_FILE_EXT:
dataType = SEARCH_DATA_XML;
break;
case SHERLOCK_FILE_EXT:
dataType = SEARCH_DATA_TEXT;
break;
default:
// Not an engine
continue;
if (fileExtension != "xml") {
// Not an engine
continue;
}
var addedEngine = null;
try {
addedEngine = new Engine(file, dataType, !isWritable);
addedEngine = new Engine(file, SEARCH_DATA_XML, !isWritable);
addedEngine._initFromFile();
} catch (ex) {
LOG("_loadEnginesFromDir: Failed to load " + file.path + "!\n" + ex);
continue;
}
if (fileExtension == SHERLOCK_FILE_EXT) {
// See if we can find an icon
if (!addedEngine._iconURI) {
var icon = this._findSherlockIcon(file, fileURL.fileBaseName);
if (icon)
addedEngine._iconURI = NetUtil.ioService.newFileURI(icon);
}
}
this._addEngineToStore(addedEngine);
}
},
@@ -3196,27 +3163,6 @@ SearchService.prototype = {
return this.__sortedEngines = this.__sortedEngines.concat(alphaEngines);
},
/**
* 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
* of the file extensions in SHERLOCK_ICON_EXTENSIONS.
* @param aEngineFile
* The Sherlock plugin file.
* @param aBaseName
* The basename of the Sherlock file.
* Example: "foo" for file "foo.src".
* @see nsIURL::fileBaseName
*/
_findSherlockIcon: function SRCH_SVC_findSherlock(aEngineFile, aBaseName) {
for (var i = 0; i < SHERLOCK_ICON_EXTENSIONS.length; i++) {
var icon = aEngineFile.parent.clone();
icon.append(aBaseName + SHERLOCK_ICON_EXTENSIONS[i]);
if (icon.exists() && icon.isFile())
return icon;
}
return null;
},
/**
* Get a sorted array of engines.
* @param aWithHidden