Dealt with the Add-Ons Manager change. Gonna have to bug Unfocused to make "view extension" work properly.

This commit is contained in:
satyr 2010-05-16 04:51:03 +09:00
Родитель d6c2420b6a
Коммит 17730f00c6
5 изменённых файлов: 62 добавлений и 38 удалений

Просмотреть файл

@ -341,15 +341,26 @@ var noun_type_awesomebar = {
var noun_type_extension = {
label: "name",
noExternalCalls: true,
suggest: function nt_ext_suggest(text) CmdUtils.grepSuggs(text, this._list),
suggest: function nt_ext_suggest(text, html, cb) {
if (this._list.length) return CmdUtils.grepSuggs(text, this._list);
var fakeReq = {readyState: 2};
("AddonManager" in Utils
? Utils.AddonManager.getAllAddons(setList)
: setList(Utils.ExtensionManager.getItemList(2, {})));
function setList(exts) {
var {escapeHtml} = Utils;
this._list = [
let (h = escapeHtml(ext.name)) {
text: ext.name, data: ext, html: h, summary: h}
for each(ext in exts)];
fakeReq.readyState = 4;
cb(CmdUtils.grepSuggs(text, this._list));
}
return [fakeReq];
},
_list: [],
};
Utils.defineLazyProperty(noun_type_extension, function _list() {
var {escapeHtml} = Utils;
return [
let (h = escapeHtml(ext.name)) {
text: ext.name, data: ext, html: h, summary: h}
for each (ext in Utils.ExtensionManager.getItemList(2, {}))];
});
// === {{{ noun_type_common_URI_scheme }}} ===
// Suggests common URI schemes, which are the IANA-registered ones
@ -646,7 +657,7 @@ var noun_type_bookmarklet = {
for (var i = root.childCount; i--;) {
var node = root.getChild(i);
if (/^javascript:/.test(node.uri) &&
!bookmarks.getKeywordForBookmark(node.itemId))
!bookmarks.getKeywordForBookmark(node.itemId))
list.push(CmdUtils.makeSugg(node.title, null, node.uri));
}
root.containerOpen = false;
@ -689,7 +700,7 @@ var noun_type_date = {
return [this._sugg(date, score)];
},
_sugg: function nt_date__sugg(date, score)
CmdUtils.makeSugg(date.toString("yyyy-MM-dd"), null, date, score)
CmdUtils.makeSugg(date.toString("yyyy-MM-dd"), null, date, score),
};
var noun_type_time = {
@ -711,7 +722,7 @@ var noun_type_time = {
return [this._sugg(date, score)];
},
_sugg: function nt_time__sugg(date, score)
CmdUtils.makeSugg(date.toString("hh:mm:ss tt"), null, date, score)
CmdUtils.makeSugg(date.toString("hh:mm:ss tt"), null, date, score),
};
var noun_type_date_time = {
@ -803,7 +814,7 @@ function getYahooContacts(callback) {
prog: "ymdc",
tags: "short",
attrs: "1",
xf: "sf,mf"
xf: "sf,mf",
};
return jQuery.get(url, params, function (data) {
var contacts = [];
@ -1166,14 +1177,14 @@ function getRestaurants(query, callback, selectionIndices) {
for each (let business in allBusinesses) {
if (business.name.indexOf(queryToMatch) !== -1 ||
queryToMatch.indexOf(business.name) !== -1) {
callback([CmdUtils.makeSugg(query, null, null, .9,
selectionIndices)]);
return;
callback([CmdUtils.makeSugg(query, null, null, .9,
selectionIndices)]);
return;
}
else {
for each (let category in business.categories) {
if (category.name.indexOf(queryToMatch) !== -1 ||
queryToMatch.indexOf(category.name) !== -1) {
queryToMatch.indexOf(category.name) !== -1) {
callback([CmdUtils.makeSugg(query, null, null, .9,
selectionIndices)]);
return;
@ -1269,7 +1280,7 @@ for (let [old, now] in new Iterator({
commands: noun_type_command,
emailservice: noun_type_email_service,
searchengine: noun_type_search_engine,
async_address: noun_type_geo_address
async_address: noun_type_geo_address,
})) {
let sym = "noun_type_" + old;
this[sym] = now;

Просмотреть файл

@ -102,15 +102,6 @@ var UbiquitySetup = {
source: "search.xhtml",
title: "Mozilla Web Search Commands"}],
__getExtDir: function __getExtDir() {
let extMgr = (Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager));
let loc = extMgr.getInstallLocation("ubiquity@labs.mozilla.com");
let extDir = loc.getItemLocation("ubiquity@labs.mozilla.com");
return extDir;
},
__modifyUserAgent: function __modifyUserAgent() {
// This is temporary code to fix old versions of Ubiquity that
// modified the User-Agent string without uninstalling cleanly.
@ -184,13 +175,12 @@ var UbiquitySetup = {
}
},
getBaseUri: function getBaseUri()
Utils.IOService.newFileURI(this.__getExtDir()).spec,
getBaseUri: function getBaseUri() this.baseUrl,
isInstalledAsXpi: function isInstalledAsXpi() {
let profileDir = Utils.DirectoryService.get("ProfD", Ci.nsIFile);
let extDir = this.__getExtDir();
return profileDir.contains(extDir, false);
let profileUrl = Utils.IOService.newFileURI(profileDir).spec;
return !this.baseUrl.lastIndexOf(profileUrl, 0);
},
preload: function preload(callback) {
@ -200,7 +190,21 @@ var UbiquitySetup = {
}
this.__maybeReset();
gWebJsModule = new WebJsModule(callback);
const ID = "ubiquity@labs.mozilla.com", ME = this;
("AddonManager" in Utils
? Utils.AddonManager.getAddonByID(ID, setAddonInfo)
: setAddonInfo(Utils.ExtensionManager.getItemForID(ID)));
function setAddonInfo(addon) {
ME.version = addon.version;
ME.baseUrl = (
"getResourceURL" in addon
? addon.getResourceURL("")
: Utils.IOService.newFileURI(Utils.ExtensionManager
.getInstallLocation(ID)
.getItemLocation(ID)).spec);
gWebJsModule = new WebJsModule(callback);
}
},
get isResetScheduled()
@ -322,9 +326,6 @@ var UbiquitySetup = {
get parserVersion()
gPrefs.getValue("extensions.ubiquity.parserVersion", 2),
get version()
Utils.ExtensionManager.getItemForID("ubiquity@labs.mozilla.com").version,
};
function DisabledCmdStorage(prefName) {
var disabledCommands = JSON.parse(gPrefs.getValue(prefName, "{}"));

Просмотреть файл

@ -106,8 +106,11 @@ delete Utils.QueryInterface;
// === {{{ Utils.ExtensionManager }}} ===
// Shortcut to {{{nsIExtensionManager}}}.
function ExtensionManager()
Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager),
function ExtensionManager() {
try { return (Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager)); }
catch ([]) {}
},
// === {{{ Utils.IOService }}} ===
// Shortcut to {{{nsIIOService}}}.
@ -163,6 +166,9 @@ delete Utils.QueryInterface;
].reduce(defineLazyProperty, Utils);
try { Cu.import("resource://gre/modules/AddonManager.jsm", Utils); }
catch ([]) {}
// === {{{ Utils.log(a, b, c, ...) }}} ===
// One of the most useful functions to know both for development and debugging.
// This logging function takes an arbitrary number of arguments and

Просмотреть файл

@ -478,7 +478,7 @@ CmdUtils.CreateCommand({
preview: function ve_preview(pb, {object: {data}}) {
if (!data) return void this.previewDefault(pb);
var xdata = this._extraData(data.id);
var xdata = this._extraData(data.id) || data;
XML.prettyPrinting = XML.ignoreWhitespace = false;
var div = <div class="extension"><style><![CDATA[
.disabled {opacity:0.7}
@ -527,6 +527,11 @@ CmdUtils.CreateCommand({
},
_urn: function ve__urn(id) "urn:mozilla:item:" + id,
_open: function ve__open(self, id) {
if ("AddonManager" in Utils) {
Utils.focusUrlInBrowser("about:addons");
//TODO: how do you select it in the new view?
return;
}
const Pane = "extensions";
var em = Utils.WindowMediator.getMostRecentWindow("Extension:Manager");
if (em) {
@ -546,6 +551,8 @@ CmdUtils.CreateCommand({
em.gExtensionsView.selectItem(em.document.getElementById(self._urn(id)));
},
_extraData: function ve__extraData(id) {
if ("AddonManager" in Utils) return null;
const {NS_EM} = Utils;
var rdfs =
Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);

Просмотреть файл

@ -196,7 +196,6 @@ CmdUtils.CreateCommand({
* TODO: implement modifier to support private posting
* TODO: handle error codes from delicious, not just HTTP itself
*/
var uext = Application.extensions.get("ubiquity@labs.mozilla.com");
var cookie_mgr = (
Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager));