mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 696520 - Enable add-on installation : part 2/2 XPInstallObserver [r=mfinkle]
This commit is contained in:
parent
ce57ebf836
commit
c18cf04dbc
@ -485,6 +485,9 @@ abstract public class GeckoApp
|
||||
intent = new Intent(this, GeckoPreferences.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.addons:
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent("about:addons"));
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -55,6 +55,8 @@
|
||||
|
||||
<!ENTITY quit "Quit">
|
||||
|
||||
<!ENTITY addons "Add-ons">
|
||||
|
||||
<!ENTITY share "Share">
|
||||
<!ENTITY saveaspdf "Save as PDF">
|
||||
|
||||
|
BIN
embedding/android/resources/drawable/addons.png
Normal file
BIN
embedding/android/resources/drawable/addons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -24,4 +24,8 @@
|
||||
android:icon="@drawable/quit"
|
||||
android:title="@string/quit" />
|
||||
|
||||
<item android:id="@+id/addons"
|
||||
android:icon="@drawable/addons"
|
||||
android:title="@string/addons"
|
||||
android:showAsAction="ifRoom"/>
|
||||
</menu>
|
||||
|
@ -64,4 +64,6 @@
|
||||
<string name="pref_category_history">&pref_category_history;</string>
|
||||
<string name="pref_clear_history">&pref_clear_history;</string>
|
||||
<string name="pref_clear_history_confirm">&pref_clear_history_confirm;</string>
|
||||
|
||||
<string name="addons">&addons;</string>
|
||||
</resources>
|
||||
|
@ -95,6 +95,20 @@ function resolveGeckoURI(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 = {
|
||||
_tabs: [],
|
||||
_selectedTab: null,
|
||||
@ -118,6 +132,9 @@ var BrowserApp = {
|
||||
Services.obs.addObserver(this, "Preferences:Get", 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();
|
||||
|
||||
let uri = "about:support";
|
||||
@ -146,6 +163,9 @@ var BrowserApp = {
|
||||
|
||||
shutdown: function shutdown() {
|
||||
NativeWindow.uninit();
|
||||
|
||||
Services.obs.removeObserver(XPInstallObserver, "addon-install-blocked");
|
||||
Services.obs.removeObserver(XPInstallObserver, "addon-install-started");
|
||||
},
|
||||
|
||||
get tabs() {
|
||||
@ -1218,3 +1238,57 @@ var BrowserEventHandler = {
|
||||
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 ***** */
|
||||
|
||||
var Strings = {};
|
||||
XPCOMUtils.defineLazyGetter(Strings, "browser", function() {
|
||||
return Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
||||
});
|
||||
|
||||
const URI_GENERIC_ICON_DOWNLOAD = "drawable://alertdownloads";
|
||||
|
||||
var Downloads = {
|
||||
|
@ -51,15 +51,6 @@ WebInstallPrompt.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.amIWebInstallPrompt]),
|
||||
|
||||
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 prompt = Services.prompt;
|
||||
|
Loading…
Reference in New Issue
Block a user