Bug 696520 - Enable add-on installation : part 2/2 XPInstallObserver [r=mfinkle]

This commit is contained in:
Fabrice Desré 2011-10-26 13:21:51 -07:00
Родитель ce57ebf836
Коммит c18cf04dbc
8 изменённых файлов: 85 добавлений и 14 удалений

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

@ -485,6 +485,9 @@ abstract public class GeckoApp
intent = new Intent(this, GeckoPreferences.class); intent = new Intent(this, GeckoPreferences.class);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.addons:
GeckoAppShell.sendEventToGecko(new GeckoEvent("about:addons"));
return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

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

@ -55,6 +55,8 @@
<!ENTITY quit "Quit"> <!ENTITY quit "Quit">
<!ENTITY addons "Add-ons">
<!ENTITY share "Share"> <!ENTITY share "Share">
<!ENTITY saveaspdf "Save as PDF"> <!ENTITY saveaspdf "Save as PDF">

Двоичные данные
embedding/android/resources/drawable/addons.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.0 KiB

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

@ -24,4 +24,8 @@
android:icon="@drawable/quit" android:icon="@drawable/quit"
android:title="@string/quit" /> android:title="@string/quit" />
<item android:id="@+id/addons"
android:icon="@drawable/addons"
android:title="@string/addons"
android:showAsAction="ifRoom"/>
</menu> </menu>

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

@ -64,4 +64,6 @@
<string name="pref_category_history">&pref_category_history;</string> <string name="pref_category_history">&pref_category_history;</string>
<string name="pref_clear_history">&pref_clear_history;</string> <string name="pref_clear_history">&pref_clear_history;</string>
<string name="pref_clear_history_confirm">&pref_clear_history_confirm;</string> <string name="pref_clear_history_confirm">&pref_clear_history_confirm;</string>
<string name="addons">&addons;</string>
</resources> </resources>

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

@ -95,6 +95,20 @@ function resolveGeckoURI(aURI) {
return aURI; return aURI;
} }
/**
* Cache of commonly used string bundles.
*/
var Strings = {};
[
["brand", "chrome://branding/locale/brand.properties"],
["browser", "chrome://browser/locale/browser.properties"]
].forEach(function (aStringBundle) {
let [name, bundle] = aStringBundle;
XPCOMUtils.defineLazyGetter(Strings, name, function() {
return Services.strings.createBundle(bundle);
});
});
var BrowserApp = { var BrowserApp = {
_tabs: [], _tabs: [],
_selectedTab: null, _selectedTab: null,
@ -118,6 +132,9 @@ var BrowserApp = {
Services.obs.addObserver(this, "Preferences:Get", false); Services.obs.addObserver(this, "Preferences:Get", false);
Services.obs.addObserver(this, "Preferences:Set", false); Services.obs.addObserver(this, "Preferences:Set", false);
Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(XPInstallObserver, "addon-install-started", false);
NativeWindow.init(); NativeWindow.init();
let uri = "about:support"; let uri = "about:support";
@ -146,6 +163,9 @@ var BrowserApp = {
shutdown: function shutdown() { shutdown: function shutdown() {
NativeWindow.uninit(); NativeWindow.uninit();
Services.obs.removeObserver(XPInstallObserver, "addon-install-blocked");
Services.obs.removeObserver(XPInstallObserver, "addon-install-started");
}, },
get tabs() { get tabs() {
@ -1218,3 +1238,57 @@ var BrowserEventHandler = {
return scrollX || scrollY; return scrollX || scrollY;
} }
}; };
var XPInstallObserver = {
observe: function xpi_observer(aSubject, aTopic, aData) {
switch (aTopic) {
case "addon-install-started":
NativeWindow.toast.show(Strings.browser.GetStringFromName("alertAddonsDownloading"), "short");
break;
case "addon-install-blocked":
dump("XPInstallObserver addon-install-blocked");
let installInfo = aSubject.QueryInterface(Ci.amIWebInstallInfo);
let host = installInfo.originatingURI.host;
let brandShortName = Strings.brand.GetStringFromName("brandShortName");
let notificationName, buttons, messageString;
let strings = Strings.browser;
let enabled = true;
try {
enabled = Services.prefs.getBoolPref("xpinstall.enabled");
}
catch (e) {}
if (!enabled) {
notificationName = "xpinstall-disabled";
if (Services.prefs.prefIsLocked("xpinstall.enabled")) {
messageString = strings.GetStringFromName("xpinstallDisabledMessageLocked");
buttons = [];
} else {
messageString = strings.formatStringFromName("xpinstallDisabledMessage2", [brandShortName, host], 2);
buttons = [{
label: strings.GetStringFromName("xpinstallDisabledButton"),
callback: function editPrefs() {
Services.prefs.setBoolPref("xpinstall.enabled", true);
return false;
}
}];
}
} else {
notificationName = "xpinstall";
messageString = strings.formatStringFromName("xpinstallPromptWarning2", [brandShortName, host], 2);
buttons = [{
label: strings.GetStringFromName("xpinstallPromptAllowButton"),
callback: function() {
// Kick off the install
installInfo.install();
return false;
}
}];
}
NativeWindow.doorhanger.show(messageString, buttons);
break;
}
}
};

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

@ -37,11 +37,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
var Strings = {};
XPCOMUtils.defineLazyGetter(Strings, "browser", function() {
return Services.strings.createBundle("chrome://browser/locale/browser.properties");
});
const URI_GENERIC_ICON_DOWNLOAD = "drawable://alertdownloads"; const URI_GENERIC_ICON_DOWNLOAD = "drawable://alertdownloads";
var Downloads = { var Downloads = {

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

@ -51,15 +51,6 @@ WebInstallPrompt.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.amIWebInstallPrompt]), QueryInterface: XPCOMUtils.generateQI([Ci.amIWebInstallPrompt]),
confirm: function(aWindow, aURL, aInstalls) { confirm: function(aWindow, aURL, aInstalls) {
// first check if the extensions panel is open : fast path to return true
let browser = Services.wm.getMostRecentWindow("navigator:browser");
if (browser.ExtensionsView.visible) {
aInstalls.forEach(function(install) {
install.install();
});
return;
}
let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
let prompt = Services.prompt; let prompt = Services.prompt;