Firefox addon 在firefox插件中列出一台主机的所有indexeddb

Firefox addon 在firefox插件中列出一台主机的所有indexeddb,firefox-addon,firefox-addon-sdk,indexeddb,Firefox Addon,Firefox Addon Sdk,Indexeddb,我想如果devtool都创建了IndexedDB,那么应该有一个API来检索它们 有人知道我是如何借助firefox SDK获得姓名列表的吗?我确实深入研究了代码并查看了源代码。不幸的是,没有任何方便的API可以从一台主机中取出所有数据库 他们这样做的方式是潜伏在user profiles文件夹中,查看.sqlite的所有文件夹和文件,对每个.sqlite进行sql查询(如果有正在进行的事务,则多次查询),并询问数据库名称 这就是和平的密码 // striped down version of:

我想如果devtool都创建了IndexedDB,那么应该有一个API来检索它们


有人知道我是如何借助firefox SDK获得姓名列表的吗?

我确实深入研究了代码并查看了源代码。不幸的是,没有任何方便的API可以从一台主机中取出所有数据库

他们这样做的方式是潜伏在user profiles文件夹中,查看.sqlite的所有文件夹和文件,对每个.sqlite进行sql查询(如果有正在进行的事务,则多次查询),并询问数据库名称

这就是和平的密码

// striped down version of: https://dxr.mozilla.org/mozilla-central/source/devtools/server/actors/storage.js

/* 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/. */

"use strict";

const {async} = require("resource://gre/modules/devtools/async-utils");
const { setTimeout } = require("sdk/timers");
const promise = require("sdk/core/promise");

// A RegExp for characters that cannot appear in a file/directory name. This is
// used to sanitize the host name for indexed db to lookup whether the file is
// present in <profileDir>/storage/default/ location
const illegalFileNameCharacters = [
  "[",
  // Control characters \001 to \036
  "\\x00-\\x24",
  // Special characters
  "/:*?\\\"<>|\\\\",
  "]"
].join("");
const ILLEGAL_CHAR_REGEX = new RegExp(illegalFileNameCharacters, "g");

var OS = require("resource://gre/modules/osfile.jsm").OS;
var Sqlite = require("resource://gre/modules/Sqlite.jsm");

/**
 * An async method equivalent to setTimeout but using Promises
 *
 * @param {number} time
 *        The wait time in milliseconds.
 */
function sleep(time) {
  let deferred = promise.defer();

  setTimeout(() => {
    deferred.resolve(null);
  }, time);

  return deferred.promise;
}

var indexedDBHelpers = {

  /**
   * Fetches all the databases and their metadata for the given `host`.
   */
  getDBNamesForHost: async(function*(host) {
    let sanitizedHost = indexedDBHelpers.getSanitizedHost(host);
    let directory = OS.Path.join(OS.Constants.Path.profileDir, "storage",
                                 "default", sanitizedHost, "idb");

    let exists = yield OS.File.exists(directory);
    if (!exists && host.startsWith("about:")) {
      // try for moz-safe-about directory
      sanitizedHost = indexedDBHelpers.getSanitizedHost("moz-safe-" + host);
      directory = OS.Path.join(OS.Constants.Path.profileDir, "storage",
                               "permanent", sanitizedHost, "idb");
      exists = yield OS.File.exists(directory);
    }
    if (!exists) {
      return [];
    }

    let names = [];
    let dirIterator = new OS.File.DirectoryIterator(directory);
    try {
      yield dirIterator.forEach(file => {
        // Skip directories.
        if (file.isDir) {
          return null;
        }

        // Skip any non-sqlite files.
        if (!file.name.endsWith(".sqlite")) {
          return null;
        }

        return indexedDBHelpers.getNameFromDatabaseFile(file.path).then(name => {
          if (name) {
            names.push(name);
          }
          return null;
        });
      });
    } finally {
      dirIterator.close();
    }
    return names;
  }),

  /**
   * Removes any illegal characters from the host name to make it a valid file
   * name.
   */
  getSanitizedHost: function(host) {
    return host.replace(ILLEGAL_CHAR_REGEX, "+");
  },

  /**
   * Retrieves the proper indexed db database name from the provided .sqlite
   * file location.
   */
  getNameFromDatabaseFile: async(function*(path) {
    let connection = null;
    let retryCount = 0;

    // Content pages might be having an open transaction for the same indexed db
    // which this sqlite file belongs to. In that case, sqlite.openConnection
    // will throw. Thus we retey for some time to see if lock is removed.
    while (!connection && retryCount++ < 25) {
      try {
        connection = yield Sqlite.openConnection({ path: path });
      } catch (ex) {
        // Continuously retrying is overkill. Waiting for 100ms before next try
        yield sleep(100);
      }
    }

    if (!connection) {
      return null;
    }

    let rows = yield connection.execute("SELECT name FROM database");
    if (rows.length != 1) {
      return null;
    }

    let name = rows[0].getResultByName("name");

    yield connection.close();

    return name;
  })

};

module.exports = indexedDBHelpers.getDBNamesForHost;

如果有人构建一个插件,添加
indexedDB.mozzetdatabasenames
以与
indexedDB.webkitGetDatabaseNames
相同的方式工作,我想这会很酷。我不会那么做的。。。如果你愿意,我会让你决定的。将是一个需要的开发工具;)

我确实深入研究了代码并查看了源代码。不幸的是,没有任何方便的API可以从一台主机中取出所有数据库

他们这样做的方式是潜伏在user profiles文件夹中,查看.sqlite的所有文件夹和文件,对每个.sqlite进行sql查询(如果有正在进行的事务,则多次查询),并询问数据库名称

这就是和平的密码

// striped down version of: https://dxr.mozilla.org/mozilla-central/source/devtools/server/actors/storage.js

/* 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/. */

"use strict";

const {async} = require("resource://gre/modules/devtools/async-utils");
const { setTimeout } = require("sdk/timers");
const promise = require("sdk/core/promise");

// A RegExp for characters that cannot appear in a file/directory name. This is
// used to sanitize the host name for indexed db to lookup whether the file is
// present in <profileDir>/storage/default/ location
const illegalFileNameCharacters = [
  "[",
  // Control characters \001 to \036
  "\\x00-\\x24",
  // Special characters
  "/:*?\\\"<>|\\\\",
  "]"
].join("");
const ILLEGAL_CHAR_REGEX = new RegExp(illegalFileNameCharacters, "g");

var OS = require("resource://gre/modules/osfile.jsm").OS;
var Sqlite = require("resource://gre/modules/Sqlite.jsm");

/**
 * An async method equivalent to setTimeout but using Promises
 *
 * @param {number} time
 *        The wait time in milliseconds.
 */
function sleep(time) {
  let deferred = promise.defer();

  setTimeout(() => {
    deferred.resolve(null);
  }, time);

  return deferred.promise;
}

var indexedDBHelpers = {

  /**
   * Fetches all the databases and their metadata for the given `host`.
   */
  getDBNamesForHost: async(function*(host) {
    let sanitizedHost = indexedDBHelpers.getSanitizedHost(host);
    let directory = OS.Path.join(OS.Constants.Path.profileDir, "storage",
                                 "default", sanitizedHost, "idb");

    let exists = yield OS.File.exists(directory);
    if (!exists && host.startsWith("about:")) {
      // try for moz-safe-about directory
      sanitizedHost = indexedDBHelpers.getSanitizedHost("moz-safe-" + host);
      directory = OS.Path.join(OS.Constants.Path.profileDir, "storage",
                               "permanent", sanitizedHost, "idb");
      exists = yield OS.File.exists(directory);
    }
    if (!exists) {
      return [];
    }

    let names = [];
    let dirIterator = new OS.File.DirectoryIterator(directory);
    try {
      yield dirIterator.forEach(file => {
        // Skip directories.
        if (file.isDir) {
          return null;
        }

        // Skip any non-sqlite files.
        if (!file.name.endsWith(".sqlite")) {
          return null;
        }

        return indexedDBHelpers.getNameFromDatabaseFile(file.path).then(name => {
          if (name) {
            names.push(name);
          }
          return null;
        });
      });
    } finally {
      dirIterator.close();
    }
    return names;
  }),

  /**
   * Removes any illegal characters from the host name to make it a valid file
   * name.
   */
  getSanitizedHost: function(host) {
    return host.replace(ILLEGAL_CHAR_REGEX, "+");
  },

  /**
   * Retrieves the proper indexed db database name from the provided .sqlite
   * file location.
   */
  getNameFromDatabaseFile: async(function*(path) {
    let connection = null;
    let retryCount = 0;

    // Content pages might be having an open transaction for the same indexed db
    // which this sqlite file belongs to. In that case, sqlite.openConnection
    // will throw. Thus we retey for some time to see if lock is removed.
    while (!connection && retryCount++ < 25) {
      try {
        connection = yield Sqlite.openConnection({ path: path });
      } catch (ex) {
        // Continuously retrying is overkill. Waiting for 100ms before next try
        yield sleep(100);
      }
    }

    if (!connection) {
      return null;
    }

    let rows = yield connection.execute("SELECT name FROM database");
    if (rows.length != 1) {
      return null;
    }

    let name = rows[0].getResultByName("name");

    yield connection.close();

    return name;
  })

};

module.exports = indexedDBHelpers.getDBNamesForHost;

如果有人构建一个插件,添加
indexedDB.mozzetdatabasenames
以与
indexedDB.webkitGetDatabaseNames
相同的方式工作,我想这会很酷。我不会那么做的。。。如果你愿意,我会让你决定的。将是一个需要的开发工具;)

我想你必须像devtools那样做。他们可能没有api,但是他们应该有一些函数,里面有你可以使用的注释。我想你必须像devtools那样做。它们可能没有api,但应该有一些函数,其中包含您可以使用的注释。