Bug 1071238 - UI Tour: add ability to put a widget in the toolbar. r=mattn

This commit is contained in:
Justin Dolske 2014-10-06 15:49:30 -07:00
parent 57cfa5fc7b
commit ea46ae6a5d
3 changed files with 64 additions and 1 deletions

View File

@ -98,7 +98,10 @@ this.UITour = {
["help", {query: "#PanelUI-help"}],
["home", {query: "#home-button"}],
["loop", {query: "#loop-call-button"}],
["forget", {query: "#panic-button"}],
["forget", {
query: "#panic-button",
widgetName: "panic-button",
allowAdd: true }],
["privateWindow", {query: "#privatebrowsing-button"}],
["quit", {query: "#PanelUI-quit"}],
["search", {
@ -434,6 +437,15 @@ this.UITour = {
ResetProfile.openConfirmationDialog(window);
break;
}
case "addNavBarWidget": {
// Add a widget to the toolbar
let targetPromise = this.getTarget(window, data.name);
targetPromise.then(target => {
this.addNavBarWidget(target, contentDocument, data.callbackID);
}).then(null, Cu.reportError);
break;
}
}
if (!this.originTabs.has(window))
@ -698,6 +710,7 @@ this.UITour = {
removeTargetListener: targetObject.removeTargetListener,
targetName: aTargetName,
widgetName: targetObject.widgetName,
allowAdd: targetObject.allowAdd,
});
}).then(null, Cu.reportError);
return deferred.promise;
@ -1177,6 +1190,24 @@ this.UITour = {
});
},
addNavBarWidget: function (aTarget, aContentDocument, aCallbackID) {
if (aTarget.node) {
Cu.reportError("UITour: can't add a widget already present: " + data.target);
return;
}
if (!aTarget.allowAdd) {
Cu.reportError("UITour: not allowed to add this widget: " + data.target);
return;
}
if (!aTarget.widgetName) {
Cu.reportError("UITour: can't add a widget without a widgetName property: " + data.target);
return;
}
CustomizableUI.addWidgetToArea(aTarget.widgetName, CustomizableUI.AREA_NAVBAR);
this.sendPageCallback(aContentDocument, aCallbackID);
},
_addAnnotationPanelMutationObserver: function(aPanelEl) {
#ifdef XP_LINUX
let observer = this._annotationPanelMutationObservers.get(aPanelEl);

View File

@ -277,6 +277,31 @@ let tests = [
gContentAPI.getConfiguration("appinfo", callback);
},
function test_addToolbarButton(done) {
let placement = CustomizableUI.getPlacementOfWidget("panic-button");
is(placement, null, "default UI has panic button in the palette");
gContentAPI.getConfiguration("availableTargets", (data) => {
let available = (data.targets.indexOf("forget") != -1);
ok(!available, "Forget button should not be available by default");
gContentAPI.addNavBarWidget("forget", () => {
info("addNavBarWidget callback successfully called");
let placement = CustomizableUI.getPlacementOfWidget("panic-button");
is(placement.area, CustomizableUI.AREA_NAVBAR);
gContentAPI.getConfiguration("availableTargets", (data) => {
let available = (data.targets.indexOf("forget") != -1);
ok(available, "Forget button should now be available");
// Cleanup
CustomizableUI.removeWidgetFromArea("panic-button");
done();
});
});
});
},
// Make sure this test is last in the file so the appMenu gets left open and done will confirm it got tore down.
function cleanupMenus(done) {

View File

@ -183,4 +183,11 @@ if (typeof Mozilla == 'undefined') {
_sendEvent('resetFirefox');
};
Mozilla.UITour.addNavBarWidget= function(name, callback) {
_sendEvent('addNavBarWidget', {
name: name,
callbackID: _waitForCallback(callback),
});
};
})();