Bug 1155521 - Migrate Pocket add-on and social provider users to the new Pocket button (part 2, migration). r=jaws

This commit is contained in:
Drew Willcoxon 2015-05-05 17:23:59 -07:00
parent c831107cdb
commit 579004be29
5 changed files with 86 additions and 3 deletions

View File

@ -730,9 +730,9 @@
fullscreentoolbar="true" mode="icons" customizable="true"
iconsize="small"
#ifdef MOZ_DEV_EDITION
defaultset="urlbar-container,search-container,developer-button,bookmarks-menu-button,downloads-button,home-button,loop-button"
defaultset="urlbar-container,search-container,developer-button,bookmarks-menu-button,pocket-button,downloads-button,home-button,loop-button"
#else
defaultset="urlbar-container,search-container,bookmarks-menu-button,downloads-button,home-button,loop-button"
defaultset="urlbar-container,search-container,bookmarks-menu-button,pocket-button,downloads-button,home-button,loop-button"
#endif
customizationtarget="nav-bar-customization-target"
overflowable="true"

View File

@ -208,6 +208,15 @@ let CustomizableUIInternal = {
"loop-button",
];
// Insert the Pocket button after the bookmarks button if it's present.
for (let widgetDefinition of CustomizableWidgets) {
if (widgetDefinition.id == "pocket-button") {
let idx = navbarPlacements.indexOf("bookmarks-menu-button") + 1;
navbarPlacements.splice(idx, 0, widgetDefinition.id);
break;
}
}
if (Services.prefs.getBoolPref(kPrefWebIDEInNavbar)) {
navbarPlacements.push("webide-button");
}
@ -288,7 +297,9 @@ let CustomizableUIInternal = {
},
_introduceNewBuiltinWidgets: function() {
if (!gSavedState || gSavedState.currentVersion >= kVersion) {
// We should still enter even if gSavedState.currentVersion >= kVersion
// because the per-widget pref facility is independent of versioning.
if (!gSavedState) {
return;
}
@ -2106,6 +2117,14 @@ let CustomizableUIInternal = {
// opened - so we know there's no build areas to handle. Also, builtin
// widgets are expected to be (mostly) static, so shouldn't affect the
// current placement settings.
// This allows a widget to be both built-in by default but also able to be
// destroyed based on criteria that may not be available when the widget is
// created -- for example, because some other feature in the browser
// supersedes the widget.
let conditionalDestroyPromise = aData.conditionalDestroyPromise || null;
delete aData.conditionalDestroyPromise;
let widget = this.normalizeWidget(aData, CustomizableUI.SOURCE_BUILTIN);
if (!widget) {
ERROR("Error creating builtin widget: " + aData.id);
@ -2114,6 +2133,16 @@ let CustomizableUIInternal = {
LOG("Creating built-in widget with id: " + widget.id);
gPalette.set(widget.id, widget);
if (conditionalDestroyPromise) {
conditionalDestroyPromise.then(shouldDestroy => {
if (shouldDestroy) {
this.destroyWidget(widget.id);
}
}, err => {
Cu.reportError(err);
});
}
},
// Returns true if the area will eventually lazily restore (but hasn't yet).

View File

@ -26,6 +26,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "CharsetMenu",
"resource://gre/modules/CharsetMenu.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "SocialService",
"resource://gre/modules/SocialService.jsm");
XPCOMUtils.defineLazyGetter(this, "CharsetBundle", function() {
const kCharsetBundle = "chrome://global/locale/charsetMenu.properties";
@ -1081,16 +1085,44 @@ if (Services.prefs.getBoolPref("browser.pocket.enabled")) {
if (isEnabledForLocale) {
let pocketButton = {
id: "pocket-button",
defaultArea: CustomizableUI.AREA_NAVBAR,
introducedInVersion: "pref",
type: "view",
viewId: "PanelUI-pocketView",
label: PocketBundle.GetStringFromName("pocket-button.label"),
tooltiptext: PocketBundle.GetStringFromName("pocket-button.tooltiptext"),
onViewShowing: Pocket.onPanelViewShowing,
onViewHiding: Pocket.onPanelViewHiding,
// If the user has the "classic" Pocket add-on installed, use that instead
// and destroy the widget.
conditionalDestroyPromise: new Promise(resolve => {
AddonManager.getAddonByID("isreaditlater@ideashower.com", addon => {
resolve(addon && addon.isActive);
});
}),
};
CustomizableWidgets.push(pocketButton);
CustomizableUI.addListener(pocketButton);
// Uninstall the Pocket social provider if it exists, but only if we haven't
// already uninstalled it in this manner. That way the user can reinstall
// it if they prefer it without its being uninstalled every time they start
// the browser.
let origin = "https://getpocket.com";
SocialService.getProvider(origin, provider => {
if (provider) {
let pref = "social.backup.getpocket-com";
if (!Services.prefs.prefHasUserValue(pref)) {
let str = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
str.data = JSON.stringify(provider.manifest);
Services.prefs.setComplexValue(pref, Ci.nsISupportsString, str);
SocialService.uninstallProvider(origin, () => {});
}
}
});
}
}

View File

@ -71,6 +71,27 @@ function test() {
ok(haveNavbarPlacements, "Should have placements for nav-bar");
if (haveNavbarPlacements) {
let placements = [...gFuturePlacements.get(CustomizableUI.AREA_NAVBAR)];
// Ignore widgets that are placed using the pref facility and not the
// versioned facility. They're independent of kVersion and the saved
// state's current version, so they may be present in the placements.
for (let i = 0; i < placements.length; ) {
if (placements[i] == testWidgetNew.id) {
i++;
continue;
}
let pref = "browser.toolbarbuttons.introduced." + placements[i];
let introduced = false;
try {
introduced = Services.prefs.getBoolPref(pref);
} catch (ex) {}
if (!introduced) {
i++;
continue;
}
placements.splice(i, 1);
}
is(placements.length, 1, "Should have 1 newly placed widget in nav-bar");
is(placements[0], testWidgetNew.id, "Should have our test widget to be placed in nav-bar");
}

View File

@ -49,6 +49,7 @@ XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREA_PLACEMENTS", function() {
"urlbar-container",
"search-container",
"bookmarks-menu-button",
"pocket-button",
"downloads-button",
"home-button",
"social-share-button",