开发者

Plugin capabilities for Firefox

I am wondering what is the extent of functionality that add-ons/plugi开发者_运维知识库ns can provide with Firefox. For example, can we edit the way Firefox reads and writes to its Sqlite database?

I am considering a project where we would encrypt the contents of this database when writing to it, and decrypt from it when reading from it. It would be cool if we could do this through the use of a plugin or add-on. Does anyone know if this is feasible or not?


You can create a new SQLLite DB and write to it via a firefox plugin. See https://developer.mozilla.org/en/storage

I've done this previously for a Firebug plugin that I've created. From your plugin you do something like this:

 var file = Components.classes["@mozilla.org/file/directory_service;1"]
    .getService(Components.interfaces.nsIProperties)
    .get("ProfD", Components.interfaces.nsIFile);
    file.append("rttplog.sqlite");

    var storageService = Components.classes["@mozilla.org/storage/service;1"]
           .getService(Components.interfaces.mozIStorageService);
    this.mDBConn = storageService.openDatabase(file);
    this.mDBConn.executeSimpleSQL("CREATE TEMP TABLE log (id INTEGER, type VARCHAR, message TEXT)");

Inserting:

 var statement = this.mDBConn.createStatement("INSERT INTO log VALUES(:id, :type, :message)");
        statement.params.id = id;
        statement.params.type = type;
        statement.params.message = message;
        statement.execute();

Selecting:

var statement = this.mDBConn.createStatement("SELECT id FROM log WHERE message LIKE :query ESCAPE '/' ");
        var escaped = statement.escapeStringForLIKE(query, "/");
        statement.params.query = "%" + escaped + "%";
        return statement.executeAsync(callback);

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜