Bug 1071238 - UI Tour: add ability to put a widget in the toolbar. r=mattn
--- a/browser/modules/UITour.jsm
+++ b/browser/modules/UITour.jsm
@@ -93,17 +93,20 @@ this.UITour = {
"class",
"toolbarbutton-icon");
},
widgetName: "PanelUI-customize",
}],
["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", {
query: "#searchbar",
widgetName: "search-container",
}],
["searchProvider", {
query: (aDocument) => {
@@ -429,16 +432,25 @@ this.UITour = {
break;
}
case "resetFirefox": {
// Open a reset profile dialog window.
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))
this.originTabs.set(window, new Set());
this.originTabs.get(window).add(tab);
tab.addEventListener("TabClose", this);
tab.addEventListener("TabBecomingWindow", this);
@@ -693,16 +705,17 @@ this.UITour = {
}
deferred.resolve({
addTargetListener: targetObject.addTargetListener,
node: node,
removeTargetListener: targetObject.removeTargetListener,
targetName: aTargetName,
widgetName: targetObject.widgetName,
+ allowAdd: targetObject.allowAdd,
});
}).then(null, Cu.reportError);
return deferred.promise;
},
targetIsInAppMenu: function(aTarget) {
let placement = CustomizableUI.getPlacementOfWidget(aTarget.widgetName || aTarget.node.id);
if (placement && placement.area == CustomizableUI.AREA_PANEL) {
@@ -1172,16 +1185,34 @@ this.UITour = {
}, (err) => {
Cu.reportError(err);
this.sendPageCallback(aContentDocument, aCallbackID, {
targets: [],
});
});
},
+ 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);
if (observer) {
return;
}
let win = aPanelEl.ownerDocument.defaultView;
observer = new win.MutationObserver(this._annotationMutationCallback);
--- a/browser/modules/test/browser_UITour.js
+++ b/browser/modules/test/browser_UITour.js
@@ -272,15 +272,40 @@ let tests = [
ok(typeof(result[property]) !== undefined, "Check " + property + " isn't undefined.");
is(result[property], Services.appinfo[property], "Should have the same " + property + " property.");
}
done();
}
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) {
gContentAPI.showMenu("appMenu");
done();
},
];
--- a/browser/modules/test/uitour.js
+++ b/browser/modules/test/uitour.js
@@ -178,9 +178,16 @@ if (typeof Mozilla == 'undefined') {
Mozilla.UITour.showFirefoxAccounts = function() {
_sendEvent('showFirefoxAccounts');
};
Mozilla.UITour.resetFirefox = function() {
_sendEvent('resetFirefox');
};
+ Mozilla.UITour.addNavBarWidget= function(name, callback) {
+ _sendEvent('addNavBarWidget', {
+ name: name,
+ callbackID: _waitForCallback(callback),
+ });
+ };
+
})();