[Pale-Moon] Issue #1737 - Part 2: Clean up base/content p.2

This commit is contained in:
Pale Moon 2020-03-08 13:58:47 +01:00 • committed by Roy Tam
commit b017678cf0
9 changed files with 662 additions and 442 deletions

View file

@ -134,19 +134,22 @@ var FullZoom = {
} }
let browser = gBrowser.selectedBrowser; let browser = gBrowser.selectedBrowser;
if (!browser.currentURI) if (!browser.currentURI) {
return; return;
}
let ctxt = this._loadContextFromBrowser(browser); let ctxt = this._loadContextFromBrowser(browser);
let domain = this._cps2.extractDomain(browser.currentURI.spec); let domain = this._cps2.extractDomain(browser.currentURI.spec);
if (aGroup) { if (aGroup) {
if (aGroup == domain && ctxt.usePrivateBrowsing == aIsPrivate) if (aGroup == domain && ctxt.usePrivateBrowsing == aIsPrivate) {
this._applyPrefToZoom(aValue, browser); this._applyPrefToZoom(aValue, browser);
}
return; return;
} }
this._globalValue = aValue === undefined ? aValue : this._globalValue = aValue === undefined ?
this._ensureValid(aValue); aValue :
this._ensureValid(aValue);
// If the current page doesn't have a site-specific preference, then its // If the current page doesn't have a site-specific preference, then its
// zoom should be set to the new global preference now that the global // zoom should be set to the new global preference now that the global
@ -156,8 +159,9 @@ var FullZoom = {
this._cps2.getByDomainAndName(browser.currentURI.spec, this.name, ctxt, { this._cps2.getByDomainAndName(browser.currentURI.spec, this.name, ctxt, {
handleResult: function() { hasPref = true; }, handleResult: function() { hasPref = true; },
handleCompletion: function() { handleCompletion: function() {
if (!hasPref && token.isCurrent) if (!hasPref && token.isCurrent) {
this._applyPrefToZoom(undefined, browser); this._applyPrefToZoom(undefined, browser);
}
}.bind(this) }.bind(this)
}); });
}, },
@ -358,8 +362,9 @@ var FullZoom = {
Services.obs.notifyObservers(browser, "browser-fullZoom:zoomChange", ""); Services.obs.notifyObservers(browser, "browser-fullZoom:zoomChange", "");
if (!this.siteSpecific || if (!this.siteSpecific ||
gInPrintPreviewMode || gInPrintPreviewMode ||
browser.isSyntheticDocument) browser.isSyntheticDocument) {
return; return;
}
this._cps2.set(browser.currentURI.spec, this.name, this._cps2.set(browser.currentURI.spec, this.name,
ZoomManager.getZoomForBrowser(browser), ZoomManager.getZoomForBrowser(browser),
@ -377,8 +382,9 @@ var FullZoom = {
*/ */
_removePref: function(browser) { _removePref: function(browser) {
Services.obs.notifyObservers(browser, "browser-fullZoom:zoomReset", ""); Services.obs.notifyObservers(browser, "browser-fullZoom:zoomReset", "");
if (browser.isSyntheticDocument) if (browser.isSyntheticDocument) {
return; return;
}
let ctxt = this._loadContextFromBrowser(browser); let ctxt = this._loadContextFromBrowser(browser);
this._cps2.removeByDomainAndName(browser.currentURI.spec, this.name, ctxt, { this._cps2.removeByDomainAndName(browser.currentURI.spec, this.name, ctxt, {
handleCompletion: function() { handleCompletion: function() {
@ -403,8 +409,9 @@ var FullZoom = {
*/ */
_getBrowserToken: function(browser) { _getBrowserToken: function(browser) {
let map = this._browserTokenMap; let map = this._browserTokenMap;
if (!map.has(browser)) if (!map.has(browser)) {
map.set(browser, 0); map.set(browser, 0);
}
return { return {
token: map.get(browser), token: map.get(browser),
get isCurrent() { get isCurrent() {
@ -431,13 +438,15 @@ var FullZoom = {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
if (target instanceof window.XULElement && if (target instanceof window.XULElement &&
target.localName == "browser" && target.localName == "browser" &&
target.namespaceURI == XUL_NS) target.namespaceURI == XUL_NS) {
return target; return target;
}
// With in-process content browsers, the event's target is the content // With in-process content browsers, the event's target is the content
// document. // document.
if (target.nodeType == Node.DOCUMENT_NODE) if (target.nodeType == Node.DOCUMENT_NODE) {
return gBrowser.getBrowserForDocument(target); return gBrowser.getBrowserForDocument(target);
}
throw new Error("Unexpected ZoomChangeUsingMouseWheel event source"); throw new Error("Unexpected ZoomChangeUsingMouseWheel event source");
}, },
@ -457,14 +466,17 @@ var FullZoom = {
_ensureValid: function(aValue) { _ensureValid: function(aValue) {
// Note that undefined is a valid value for aValue that indicates a known- // Note that undefined is a valid value for aValue that indicates a known-
// not-to-exist value. // not-to-exist value.
if (isNaN(aValue)) if (isNaN(aValue)) {
return 1; return 1;
}
if (aValue < ZoomManager.MIN) if (aValue < ZoomManager.MIN) {
return ZoomManager.MIN; return ZoomManager.MIN;
}
if (aValue > ZoomManager.MAX) if (aValue > ZoomManager.MAX) {
return ZoomManager.MAX; return ZoomManager.MAX;
}
return aValue; return aValue;
}, },
@ -519,8 +531,9 @@ var FullZoom = {
}, },
_executeSoon: function(callback) { _executeSoon: function(callback) {
if (!callback) if (!callback) {
return; return;
}
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL); Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
}, },
}; };

View file

@ -31,8 +31,9 @@ var gGestureSupport = {
"RotateGestureStart", "RotateGestureUpdate", "RotateGesture", "RotateGestureStart", "RotateGestureUpdate", "RotateGesture",
"TapGesture", "PressTapGesture"]; "TapGesture", "PressTapGesture"];
let addRemove = aAddListener ? window.addEventListener : let addRemove = aAddListener ?
window.removeEventListener; window.addEventListener :
window.removeEventListener;
for (let event of gestureEvents) { for (let event of gestureEvents) {
addRemove("Moz" + event, this, true); addRemove("Moz" + event, this, true);
@ -54,8 +55,9 @@ var gGestureSupport = {
} }
// Create a preference object with some defaults // Create a preference object with some defaults
let def = (aThreshold, aLatched) => let def = function(aThreshold, aLatched) {
({ threshold: aThreshold, latched: !!aLatched }); return { threshold: aThreshold, latched: !!aLatched };
}
switch (aEvent.type) { switch (aEvent.type) {
case "MozSwipeGestureMayStart": case "MozSwipeGestureMayStart":
@ -126,8 +128,9 @@ var gGestureSupport = {
*/ */
_setupGesture: function(aEvent, aGesture, aPref, aInc, aDec) { _setupGesture: function(aEvent, aGesture, aPref, aInc, aDec) {
// Try to load user-set values from preferences // Try to load user-set values from preferences
for (let [pref, def] in Iterator(aPref)) for (let [pref, def] in Iterator(aPref)) {
aPref[pref] = this._getPref(aGesture + "." + pref, def); aPref[pref] = this._getPref(aGesture + "." + pref, def);
}
// Keep track of the total deltas and latching behavior // Keep track of the total deltas and latching behavior
let offset = 0; let offset = 0;
@ -170,10 +173,8 @@ var gGestureSupport = {
* @return true if the swipe event may navigate the history, false othwerwise. * @return true if the swipe event may navigate the history, false othwerwise.
*/ */
_swipeNavigatesHistory: function(aEvent) { _swipeNavigatesHistory: function(aEvent) {
return this._getCommand(aEvent, ["swipe", "left"]) return this._getCommand(aEvent, ["swipe", "left"]) == "Browser:BackOrBackDuplicate" &&
== "Browser:BackOrBackDuplicate" && this._getCommand(aEvent, ["swipe", "right"]) == "Browser:ForwardOrForwardDuplicate";
this._getCommand(aEvent, ["swipe", "right"])
== "Browser:ForwardOrForwardDuplicate";
}, },
/** /**
@ -186,19 +187,24 @@ var gGestureSupport = {
* otherwise. * otherwise.
*/ */
_shouldDoSwipeGesture: function(aEvent) { _shouldDoSwipeGesture: function(aEvent) {
if (!this._swipeNavigatesHistory(aEvent)) if (!this._swipeNavigatesHistory(aEvent)) {
return false; return false;
}
let canGoBack = gHistorySwipeAnimation.canGoBack(); let canGoBack = gHistorySwipeAnimation.canGoBack();
let canGoForward = gHistorySwipeAnimation.canGoForward(); let canGoForward = gHistorySwipeAnimation.canGoForward();
let isLTR = gHistorySwipeAnimation.isLTR; let isLTR = gHistorySwipeAnimation.isLTR;
if (canGoBack) if (canGoBack) {
aEvent.allowedDirections |= isLTR ? aEvent.DIRECTION_LEFT : aEvent.allowedDirections |= isLTR ?
aEvent.DIRECTION_RIGHT; aEvent.DIRECTION_LEFT :
if (canGoForward) aEvent.DIRECTION_RIGHT;
aEvent.allowedDirections |= isLTR ? aEvent.DIRECTION_RIGHT : }
aEvent.DIRECTION_LEFT; if (canGoForward) {
aEvent.allowedDirections |= isLTR ?
aEvent.DIRECTION_RIGHT :
aEvent.DIRECTION_LEFT;
}
return true; return true;
}, },
@ -222,8 +228,8 @@ var gGestureSupport = {
this._doEnd = function(aEvent) { this._doEnd = function(aEvent) {
gHistorySwipeAnimation.swipeEndEventReceived(); gHistorySwipeAnimation.swipeEndEventReceived();
this._doUpdate = function(aEvent) {}; this._doUpdate = function(aEvent) { };
this._doEnd = function(aEvent) {}; this._doEnd = function(aEvent) { };
} }
}, },
@ -241,8 +247,9 @@ var gGestureSupport = {
while (--num >= 0) { while (--num >= 0) {
// Only select array elements where the current bit is set // Only select array elements where the current bit is set
yield aArray.reduce(function(aPrev, aCurr, aIndex) { yield aArray.reduce(function(aPrev, aCurr, aIndex) {
if (num & 1 << aIndex) if (num & 1 << aIndex) {
aPrev.push(aCurr); aPrev.push(aCurr);
}
return aPrev; return aPrev;
}, []); }, []);
} }
@ -279,8 +286,9 @@ var gGestureSupport = {
// command for both don't exist) // command for both don't exist)
let keyCombos = []; let keyCombos = [];
["shift", "alt", "ctrl", "meta"].forEach(function(key) { ["shift", "alt", "ctrl", "meta"].forEach(function(key) {
if (aEvent[key + "Key"]) if (aEvent[key + "Key"]) {
keyCombos.push(key); keyCombos.push(key);
}
}); });
// Try each combination of key presses in decreasing order for commands // Try each combination of key presses in decreasing order for commands
@ -291,10 +299,12 @@ var gGestureSupport = {
let command; let command;
try { try {
command = this._getPref(aGesture.concat(subCombo).join(".")); command = this._getPref(aGesture.concat(subCombo).join("."));
} catch (e) {} } catch(e) {
}
if (command) if (command) {
return command; return command;
}
} }
return null; return null;
}, },
@ -318,8 +328,7 @@ var gGestureSupport = {
node.dispatchEvent(cmdEvent); node.dispatchEvent(cmdEvent);
} }
} } else {
else {
goDoCommand(aCommand); goDoCommand(aCommand);
} }
}, },
@ -331,7 +340,7 @@ var gGestureSupport = {
* @param aEvent * @param aEvent
* The continual motion update event to handle * The continual motion update event to handle
*/ */
_doUpdate: function(aEvent) {}, _doUpdate: function(aEvent) { },
/** /**
* Handle gesture end events. This function will be set by _setupSwipe. * Handle gesture end events. This function will be set by _setupSwipe.
@ -339,7 +348,7 @@ var gGestureSupport = {
* @param aEvent * @param aEvent
* The gesture end event to handle * The gesture end event to handle
*/ */
_doEnd: function(aEvent) {}, _doEnd: function(aEvent) { },
/** /**
* Convert the swipe gesture into a browser action based on the direction. * Convert the swipe gesture into a browser action based on the direction.
@ -380,13 +389,11 @@ var gGestureSupport = {
* @param aDir * @param aDir
* The direction for the swipe event * The direction for the swipe event
*/ */
_coordinateSwipeEventWithAnimation: _coordinateSwipeEventWithAnimation: function(aEvent, aDir) {
function(aEvent, aDir) {
if ((gHistorySwipeAnimation.isAnimationRunning()) && if ((gHistorySwipeAnimation.isAnimationRunning()) &&
(aDir == "RIGHT" || aDir == "LEFT")) { (aDir == "RIGHT" || aDir == "LEFT")) {
gHistorySwipeAnimation.processSwipeEvent(aEvent, aDir); gHistorySwipeAnimation.processSwipeEvent(aEvent, aDir);
} } else {
else {
this.processSwipeEvent(aEvent, aDir); this.processSwipeEvent(aEvent, aDir);
} }
}, },
@ -406,11 +413,13 @@ var gGestureSupport = {
try { try {
// Determine what type of data to load based on default value's type // Determine what type of data to load based on default value's type
let type = typeof aDef; let type = typeof aDef;
let getFunc = "get" + (type == "boolean" ? "Bool" : let getFunc = "get" + (type == "boolean" ?
type == "number" ? "Int" : "Char") + "Pref"; "Bool" :
type == "number" ?
"Int" :
"Char") + "Pref";
return gPrefService[getFunc](branch + aPref); return gPrefService[getFunc](branch + aPref);
} } catch(e) {
catch (e) {
return aDef; return aDef;
} }
}, },
@ -422,15 +431,18 @@ var gGestureSupport = {
* The MozRotateGestureUpdate event triggering this call * The MozRotateGestureUpdate event triggering this call
*/ */
rotate: function(aEvent) { rotate: function(aEvent) {
if (!(content.document instanceof ImageDocument)) if (!(content.document instanceof ImageDocument)) {
return; return;
}
let contentElement = content.document.body.firstElementChild; let contentElement = content.document.body.firstElementChild;
if (!contentElement) if (!contentElement) {
return; return;
}
// If we're currently snapping, cancel that snap // If we're currently snapping, cancel that snap
if (contentElement.classList.contains("completeRotation")) if (contentElement.classList.contains("completeRotation")) {
this._clearCompleteRotation(); this._clearCompleteRotation();
}
this.rotation = Math.round(this.rotation + aEvent.delta); this.rotation = Math.round(this.rotation + aEvent.delta);
contentElement.style.transform = "rotate(" + this.rotation + "deg)"; contentElement.style.transform = "rotate(" + this.rotation + "deg)";
@ -441,37 +453,41 @@ var gGestureSupport = {
* Perform a rotation end for ImageDocuments * Perform a rotation end for ImageDocuments
*/ */
rotateEnd: function() { rotateEnd: function() {
if (!(content.document instanceof ImageDocument)) if (!(content.document instanceof ImageDocument)) {
return; return;
}
let contentElement = content.document.body.firstElementChild; let contentElement = content.document.body.firstElementChild;
if (!contentElement) if (!contentElement) {
return; return;
}
let transitionRotation = 0; let transitionRotation = 0;
// The reason that 360 is allowed here is because when rotating between // The reason that 360 is allowed here is because when rotating between
// 315 and 360, setting rotate(0deg) will cause it to rotate the wrong // 315 and 360, setting rotate(0deg) will cause it to rotate the wrong
// direction around--spinning wildly. // direction around--spinning wildly.
if (this.rotation <= 45) if (this.rotation <= 45) {
transitionRotation = 0; transitionRotation = 0;
else if (this.rotation > 45 && this.rotation <= 135) } else if (this.rotation > 45 && this.rotation <= 135) {
transitionRotation = 90; transitionRotation = 90;
else if (this.rotation > 135 && this.rotation <= 225) } else if (this.rotation > 135 && this.rotation <= 225) {
transitionRotation = 180; transitionRotation = 180;
else if (this.rotation > 225 && this.rotation <= 315) } else if (this.rotation > 225 && this.rotation <= 315) {
transitionRotation = 270; transitionRotation = 270;
else } else {
transitionRotation = 360; transitionRotation = 360;
}
// If we're going fast enough, and we didn't already snap ahead of rotation, // If we're going fast enough, and we didn't already snap ahead of rotation,
// then snap ahead of rotation to simulate momentum // then snap ahead of rotation to simulate momentum
if (this._lastRotateDelta > this._rotateMomentumThreshold && if (this._lastRotateDelta > this._rotateMomentumThreshold &&
this.rotation > transitionRotation) this.rotation > transitionRotation) {
transitionRotation += 90; transitionRotation += 90;
else if (this._lastRotateDelta < -1 * this._rotateMomentumThreshold && } else if (this._lastRotateDelta < -1 * this._rotateMomentumThreshold &&
this.rotation < transitionRotation) this.rotation < transitionRotation) {
transitionRotation -= 90; transitionRotation -= 90;
}
// Only add the completeRotation class if it is is necessary // Only add the completeRotation class if it is is necessary
if (transitionRotation != this.rotation) { if (transitionRotation != this.rotation) {
@ -499,8 +515,9 @@ var gGestureSupport = {
*/ */
set rotation(aVal) { set rotation(aVal) {
this._currentRotation = aVal % 360; this._currentRotation = aVal % 360;
if (this._currentRotation < 0) if (this._currentRotation < 0) {
this._currentRotation += 360; this._currentRotation += 360;
}
return this._currentRotation; return this._currentRotation;
}, },
@ -509,8 +526,9 @@ var gGestureSupport = {
* image * image
*/ */
restoreRotationState: function() { restoreRotationState: function() {
if (!(content.document instanceof ImageDocument)) if (!(content.document instanceof ImageDocument)) {
return; return;
}
let contentElement = content.document.body.firstElementChild; let contentElement = content.document.body.firstElementChild;
let transformValue = content.window.getComputedStyle(contentElement, null) let transformValue = content.window.getComputedStyle(contentElement, null)
@ -538,8 +556,9 @@ var gGestureSupport = {
content.document instanceof ImageDocument && content.document instanceof ImageDocument &&
content.document.body && content.document.body &&
content.document.body.firstElementChild; content.document.body.firstElementChild;
if (!contentElement) if (!contentElement) {
return; return;
}
contentElement.classList.remove("completeRotation"); contentElement.classList.remove("completeRotation");
contentElement.removeEventListener("transitionend", this._clearCompleteRotation); contentElement.removeEventListener("transitionend", this._clearCompleteRotation);
}, },
@ -556,11 +575,12 @@ var gHistorySwipeAnimation = {
* by the platform/configuration. * by the platform/configuration.
*/ */
init: function() { init: function() {
if (!this._isSupported()) if (!this._isSupported()) {
return; return;
}
this.active = false; this.active = false;
this.isLTR = document.documentElement.matches(":-moz-locale-dir(ltr)"); this.isLTR = document.documentElement.mozMatchesSelector(":-moz-locale-dir(ltr)");
this._trackedSnapshots = []; this._trackedSnapshots = [];
this._historyIndex = -1; this._historyIndex = -1;
this._boxWidth = -1; this._boxWidth = -1;
@ -604,8 +624,7 @@ var gHistorySwipeAnimation = {
this._canGoBack = this.canGoBack(); this._canGoBack = this.canGoBack();
this._canGoForward = this.canGoForward(); this._canGoForward = this.canGoForward();
this._handleFastSwiping(); this._handleFastSwiping();
} } else {
else {
this._historyIndex = gBrowser.webNavigation.sessionHistory.index; this._historyIndex = gBrowser.webNavigation.sessionHistory.index;
this._canGoBack = this.canGoBack(); this._canGoBack = this.canGoBack();
this._canGoForward = this.canGoForward(); this._canGoForward = this.canGoForward();
@ -635,18 +654,22 @@ var gHistorySwipeAnimation = {
* swipe gesture. * swipe gesture.
*/ */
updateAnimation: function(aVal) { updateAnimation: function(aVal) {
if (!this.isAnimationRunning()) if (!this.isAnimationRunning()) {
return; return;
}
if ((aVal >= 0 && this.isLTR) || if ((aVal >= 0 && this.isLTR) ||
(aVal <= 0 && !this.isLTR)) { (aVal <= 0 && !this.isLTR)) {
if (aVal > 1) if (aVal > 1) {
aVal = 1; // Cap value to avoid sliding the page further than allowed. // Cap value to avoid sliding the page further than allowed.
aVal = 1;
}
if (this._canGoBack) if (this._canGoBack) {
this._prevBox.collapsed = false; this._prevBox.collapsed = false;
else } else {
this._prevBox.collapsed = true; this._prevBox.collapsed = true;
}
// The current page is pushed to the right (LTR) or left (RTL), // The current page is pushed to the right (LTR) or left (RTL),
// the intention is to go back. // the intention is to go back.
@ -655,10 +678,12 @@ var gHistorySwipeAnimation = {
// The forward page should be pushed offscreen all the way to the right. // The forward page should be pushed offscreen all the way to the right.
this._positionBox(this._nextBox, 1); this._positionBox(this._nextBox, 1);
} } else {
else { if (aVal < -1) {
if (aVal < -1) // Cap value to avoid sliding the page further than allowed.
aVal = -1; // Cap value to avoid sliding the page further than allowed. aVal = -1;
}
// The intention is to go forward. If there is a page to go forward to, // The intention is to go forward. If there is a page to go forward to,
// it should slide in from the right (LTR) or left (RTL). // it should slide in from the right (LTR) or left (RTL).
// Otherwise, the current page should slide to the left (LTR) or // Otherwise, the current page should slide to the left (LTR) or
@ -670,8 +695,7 @@ var gHistorySwipeAnimation = {
let offset = this.isLTR ? 1 : -1; let offset = this.isLTR ? 1 : -1;
this._positionBox(this._curBox, 0); this._positionBox(this._curBox, 0);
this._positionBox(this._nextBox, offset + aVal); // aval is negative this._positionBox(this._nextBox, offset + aVal); // aval is negative
} } else {
else {
this._prevBox.collapsed = true; this._prevBox.collapsed = true;
this._positionBox(this._curBox, aVal); this._positionBox(this._curBox, aVal);
} }
@ -736,12 +760,13 @@ var gHistorySwipeAnimation = {
* The direction for the swipe event * The direction for the swipe event
*/ */
processSwipeEvent: function(aEvent, aDir) { processSwipeEvent: function(aEvent, aDir) {
if (aDir == "RIGHT") if (aDir == "RIGHT") {
this._historyIndex += this.isLTR ? 1 : -1; this._historyIndex += this.isLTR ? 1 : -1;
else if (aDir == "LEFT") } else if (aDir == "LEFT") {
this._historyIndex += this.isLTR ? -1 : 1; this._historyIndex += this.isLTR ? -1 : 1;
else } else {
return; return;
}
this._lastSwipeDir = aDir; this._lastSwipeDir = aDir;
}, },
@ -751,8 +776,9 @@ var gHistorySwipeAnimation = {
* @return true if there is a previous page in history, false otherwise. * @return true if there is a previous page in history, false otherwise.
*/ */
canGoBack: function() { canGoBack: function() {
if (this.isAnimationRunning()) if (this.isAnimationRunning()) {
return this._doesIndexExistInHistory(this._historyIndex - 1); return this._doesIndexExistInHistory(this._historyIndex - 1);
}
return gBrowser.webNavigation.canGoBack; return gBrowser.webNavigation.canGoBack;
}, },
@ -762,8 +788,9 @@ var gHistorySwipeAnimation = {
* @return true if there is a next page in history, false otherwise. * @return true if there is a next page in history, false otherwise.
*/ */
canGoForward: function() { canGoForward: function() {
if (this.isAnimationRunning()) if (this.isAnimationRunning()) {
return this._doesIndexExistInHistory(this._historyIndex + 1); return this._doesIndexExistInHistory(this._historyIndex + 1);
}
return gBrowser.webNavigation.canGoForward; return gBrowser.webNavigation.canGoForward;
}, },
@ -773,10 +800,11 @@ var gHistorySwipeAnimation = {
* any. This will also result in the animation overlay to be torn down. * any. This will also result in the animation overlay to be torn down.
*/ */
swipeEndEventReceived: function() { swipeEndEventReceived: function() {
if (this._lastSwipeDir != "") if (this._lastSwipeDir != "") {
this._navigateToHistoryIndex(); this._navigateToHistoryIndex();
else } else {
this.stopAnimation(); this.stopAnimation();
}
}, },
/** /**
@ -789,8 +817,7 @@ var gHistorySwipeAnimation = {
_doesIndexExistInHistory: function(aIndex) { _doesIndexExistInHistory: function(aIndex) {
try { try {
gBrowser.webNavigation.sessionHistory.getEntryAtIndex(aIndex, false); gBrowser.webNavigation.sessionHistory.getEntryAtIndex(aIndex, false);
} } catch(ex) {
catch(ex) {
return false; return false;
} }
return true; return true;
@ -860,8 +887,9 @@ var gHistorySwipeAnimation = {
this._curBox = null; this._curBox = null;
this._prevBox = null; this._prevBox = null;
this._nextBox = null; this._nextBox = null;
if (this._container) if (this._container) {
this._container.parentNode.removeChild(this._container); this._container.parentNode.removeChild(this._container);
}
this._container = null; this._container = null;
this._boxWidth = -1; this._boxWidth = -1;
}, },
@ -958,16 +986,16 @@ var gHistorySwipeAnimation = {
* @param aCanvas * @param aCanvas
* The snapshot to add to the list and compress. * The snapshot to add to the list and compress.
*/ */
_assignSnapshotToCurrentBrowser: _assignSnapshotToCurrentBrowser: function(aCanvas) {
function(aCanvas) {
let browser = gBrowser.selectedBrowser; let browser = gBrowser.selectedBrowser;
let currIndex = browser.webNavigation.sessionHistory.index; let currIndex = browser.webNavigation.sessionHistory.index;
this._removeTrackedSnapshot(currIndex, browser); this._removeTrackedSnapshot(currIndex, browser);
this._addSnapshotRefToArray(currIndex, browser); this._addSnapshotRefToArray(currIndex, browser);
if (!("snapshots" in browser)) if (!("snapshots" in browser)) {
browser.snapshots = []; browser.snapshots = [];
}
let snapshots = browser.snapshots; let snapshots = browser.snapshots;
// Temporarily store the canvas as the compressed snapshot. // Temporarily store the canvas as the compressed snapshot.
// This avoids a blank page if the user swipes quickly // This avoids a blank page if the user swipes quickly
@ -1024,10 +1052,13 @@ var gHistorySwipeAnimation = {
(aIndex < 0 || aIndex == arr[i].index)) { (aIndex < 0 || aIndex == arr[i].index)) {
delete aBrowser.snapshots[arr[i].index]; delete aBrowser.snapshots[arr[i].index];
arr.splice(i, 1); arr.splice(i, 1);
if (requiresExactIndexMatch) if (requiresExactIndexMatch) {
return; // Found and removed the only element. // Found and removed the only element.
i--; // Make sure to revisit the index that we just removed an return;
// element at. }
// Make sure to revisit the index that we just removed an
// element at.
i--;
} }
} }
}, },
@ -1041,8 +1072,7 @@ var gHistorySwipeAnimation = {
* @param aBrowser * @param aBrowser
* The browser the new snapshot was taken in. * The browser the new snapshot was taken in.
*/ */
_addSnapshotRefToArray: _addSnapshotRefToArray: function(aIndex, aBrowser) {
function(aIndex, aBrowser) {
let id = { index: aIndex, let id = { index: aIndex,
browser: aBrowser }; browser: aBrowser };
let arr = this._trackedSnapshots; let arr = this._trackedSnapshots;
@ -1067,12 +1097,14 @@ var gHistorySwipeAnimation = {
* @return A new Image object representing the converted blob. * @return A new Image object representing the converted blob.
*/ */
_convertToImg: function(aBlob) { _convertToImg: function(aBlob) {
if (!aBlob) if (!aBlob) {
return null; return null;
}
// Return aBlob if it's still a canvas and not a compressed blob yet. // Return aBlob if it's still a canvas and not a compressed blob yet.
if (aBlob instanceof HTMLCanvasElement) if (aBlob instanceof HTMLCanvasElement) {
return aBlob; return aBlob;
}
let img = new Image(); let img = new Image();
let url = ""; let url = "";
@ -1122,12 +1154,11 @@ var gHistorySwipeAnimation = {
* The snapshot to set the current page to. If this parameter is null, * The snapshot to set the current page to. If this parameter is null,
* the previously stored snapshot for this index (if any) will be used. * the previously stored snapshot for this index (if any) will be used.
*/ */
_installCurrentPageSnapshot: _installCurrentPageSnapshot: function(aCanvas) {
function(aCanvas) {
let currSnapshot = aCanvas; let currSnapshot = aCanvas;
let scale = window.devicePixelRatio; let scale = window.devicePixelRatio;
if (!currSnapshot) { if (!currSnapshot) {
let snapshots = gBrowser.selectedBrowser.snapshots || {}; let snapshots = gBrowser.selectedBrowser.snapshots || { };
let currIndex = this._historyIndex; let currIndex = this._historyIndex;
if (currIndex in snapshots) { if (currIndex in snapshots) {
currSnapshot = this._convertToImg(snapshots[currIndex].image); currSnapshot = this._convertToImg(snapshots[currIndex].image);
@ -1144,8 +1175,7 @@ var gHistorySwipeAnimation = {
* Sets the snapshots of the previous and next pages to the snapshots * Sets the snapshots of the previous and next pages to the snapshots
* previously stored for their respective indeces. * previously stored for their respective indeces.
*/ */
_installPrevAndNextSnapshots: _installPrevAndNextSnapshots: function() {
function() {
let snapshots = gBrowser.selectedBrowser.snapshots || []; let snapshots = gBrowser.selectedBrowser.snapshots || [];
let currIndex = this._historyIndex; let currIndex = this._historyIndex;
let prevIndex = currIndex - 1; let prevIndex = currIndex - 1;

View file

@ -23,7 +23,7 @@ var browserMenuDragging = {
count:[], count:[],
init: function(){ init: function() {
window.removeEventListener('load', this, false); window.removeEventListener('load', this, false);
window.addEventListener('unload', this, false); window.addEventListener('unload', this, false);
this.addPrefListener(this.PrefListener); this.addPrefListener(this.PrefListener);
@ -34,7 +34,7 @@ var browserMenuDragging = {
this.delayedStartup(); this.delayedStartup();
}, },
uninit: function(){ uninit: function() {
window.removeEventListener('unload', this, false); window.removeEventListener('unload', this, false);
this.removePrefListener(this.PrefListener); this.removePrefListener(this.PrefListener);
@ -50,7 +50,7 @@ var browserMenuDragging = {
}, },
initPref: function(){ initPref: function() {
this.STAY_OPEN_ONDRAGEXIT = this.STAY_OPEN_ONDRAGEXIT =
Services.prefs.getBoolPref('browser.menu.dragging.stayOpen', false); Services.prefs.getBoolPref('browser.menu.dragging.stayOpen', false);
this.DEBUG = this.DEBUG =
@ -58,12 +58,12 @@ var browserMenuDragging = {
}, },
//delayed startup //delayed startup
delayedStartup: function(){ delayedStartup: function() {
//wait until construction of bookmarksBarContent is completed. //wait until construction of bookmarksBarContent is completed.
for (var i = 0; i < this.menupopup.length; i++){ for (var i = 0; i < this.menupopup.length; i++) {
this.count[i] = 0; this.count[i] = 0;
this.timer[i] = setInterval(function(self, i){ this.timer[i] = setInterval(function(self, i) {
if(++self.count[i] > 50 || document.getElementById(self.menupopup[i])){ if(++self.count[i] > 50 || document.getElementById(self.menupopup[i])) {
clearInterval(self.timer[i]); clearInterval(self.timer[i]);
var menupopup = document.getElementById(self.menupopup[i]); var menupopup = document.getElementById(self.menupopup[i]);
if (menupopup) { if (menupopup) {
@ -75,7 +75,7 @@ var browserMenuDragging = {
} }
}, },
handleEvent: function(event){ handleEvent: function(event) {
switch (event.type) { switch (event.type) {
case 'popupshowing': case 'popupshowing':
this.popupshowing(event); this.popupshowing(event);
@ -105,12 +105,14 @@ var browserMenuDragging = {
// leaves button depressed/sunken when hovered // leaves button depressed/sunken when hovered
menupopup.parentNode.parentNode._openedMenuButton = null; menupopup.parentNode.parentNode._openedMenuButton = null;
if (!PlacesControllerDragHelper.getSession()) if (!PlacesControllerDragHelper.getSession()) {
// Clear the dragover attribute if present, if we are dragging into a // Clear the dragover attribute if present, if we are dragging into a
// folder in the hierachy of current opened popup we don't clear // folder in the hierachy of current opened popup we don't clear
// this attribute on clearOverFolder. See Notify for closeTimer. // this attribute on clearOverFolder. See Notify for closeTimer.
if (menupopup.parentNode.hasAttribute('dragover')) if (menupopup.parentNode.hasAttribute('dragover')) {
menupopup.parentNode.removeAttribute('dragover'); menupopup.parentNode.removeAttribute('dragover');
}
}
} }
}, },
@ -120,10 +122,11 @@ var browserMenuDragging = {
var parentPopup = menupopup.parentNode.parentNode; var parentPopup = menupopup.parentNode.parentNode;
if (!!parentPopup.openNode){ if (!!parentPopup.openNode) {
try { try {
parentPopup.openNode.hidePopup(); parentPopup.openNode.hidePopup();
} catch(e){} } catch(e) {
}
} }
parentPopup.openNode = menupopup; parentPopup.openNode = menupopup;
@ -138,12 +141,16 @@ var browserMenuDragging = {
var target = event.originalTarget; var target = event.originalTarget;
while (target) { while (target) {
if (/menupopup/.test(target.localName)) if (/menupopup/.test(target.localName)) {
break; break;
}
target = target.parentNode; target = target.parentNode;
} }
if (this != target)
if (this != target) {
return; return;
}
event.stopPropagation(); event.stopPropagation();
browserMenuDragging.debug("onDragOver " + "\n" + this.parentNode.getAttribute('label')); browserMenuDragging.debug("onDragOver " + "\n" + this.parentNode.getAttribute('label'));
@ -201,13 +208,13 @@ var browserMenuDragging = {
if (scrollDir == 0) { if (scrollDir == 0) {
let elt = this.firstChild; let elt = this.firstChild;
while (elt && event.screenY > elt.boxObject.screenY + while (elt && event.screenY > elt.boxObject.screenY +
elt.boxObject.height / 2) elt.boxObject.height / 2) {
elt = elt.nextSibling; elt = elt.nextSibling;
newMarginTop = elt ? elt.boxObject.screenY - sbo.screenY : }
sbo.height; newMarginTop = elt ? elt.boxObject.screenY - sbo.screenY : sbo.height;
} } else if (scrollDir == 1) {
else if (scrollDir == 1)
newMarginTop = sbo.height; newMarginTop = sbo.height;
}
// Set the new marginTop based on arrowscrollbox. // Set the new marginTop based on arrowscrollbox.
newMarginTop += sbo.y - this._scrollBox.boxObject.y; newMarginTop += sbo.y - this._scrollBox.boxObject.y;
@ -221,12 +228,16 @@ var browserMenuDragging = {
menupopup.onDragExit = function (event) { menupopup.onDragExit = function (event) {
var target = event.originalTarget; var target = event.originalTarget;
while (target) { while (target) {
if (/menupopup/.test(target.localName)) if (/menupopup/.test(target.localName)) {
break; break;
}
target = target.parentNode; target = target.parentNode;
} }
if (this != target)
if (this != target) {
return; return;
}
event.stopPropagation(); event.stopPropagation();
browserMenuDragging.debug("onDragExit " + browserMenuDragging.STAY_OPEN_ONDRAGEXIT); browserMenuDragging.debug("onDragExit " + browserMenuDragging.STAY_OPEN_ONDRAGEXIT);
@ -236,13 +247,13 @@ var browserMenuDragging = {
// If we have not moved to a valid new target clear the drop indicator // If we have not moved to a valid new target clear the drop indicator
// this happens when moving out of the popup. // this happens when moving out of the popup.
target = event.relatedTarget; target = event.relatedTarget;
if (!target) if (!target) {
this._indicatorBar.hidden = true; this._indicatorBar.hidden = true;
}
// Close any folder being hovered over // Close any folder being hovered over
if (this._overFolder.elt) { if (this._overFolder.elt) {
this._overFolder.closeTimer = this._overFolder this._overFolder.closeTimer = this._overFolder.setTimer(this._overFolder.hoverTime);
.setTimer(this._overFolder.hoverTime);
} }
// The auto-opened attribute is set when this folder was automatically // The auto-opened attribute is set when this folder was automatically
@ -268,12 +279,13 @@ var browserMenuDragging = {
hideTooltip: function() { hideTooltip: function() {
['bhTooltip', 'btTooltip2'].forEach(function(id) { ['bhTooltip', 'btTooltip2'].forEach(function(id) {
var tooltip = document.getElementById(id); var tooltip = document.getElementById(id);
if (tooltip) if (tooltip) {
tooltip.hidePopup(); tooltip.hidePopup();
}
}); });
}, },
get getVer(){ get getVer() {
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
@ -281,17 +293,18 @@ var browserMenuDragging = {
return ver; return ver;
}, },
debug: function(aMsg){ debug: function(aMsg) {
if (!browserMenuDragging.DEBUG) if (!browserMenuDragging.DEBUG) {
return; return;
}
Components.classes["@mozilla.org/consoleservice;1"] Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService) .getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg); .logStringMessage(aMsg);
}, },
setPref: function(aPrefString, aPrefType, aValue){ setPref: function(aPrefString, aPrefType, aValue) {
var xpPref = Components.classes["@mozilla.org/preferences-service;1"] var xpPref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService); .getService(Components.interfaces.nsIPrefService);
try{ try{
switch (aPrefType){ switch (aPrefType){
case 'complex': case 'complex':
@ -305,7 +318,7 @@ var browserMenuDragging = {
default: default:
return xpPref.setBoolPref(aPrefString, aValue); break; return xpPref.setBoolPref(aPrefString, aValue); break;
} }
}catch(e){ } catch(e) {
} }
return null; return null;
}, },
@ -315,7 +328,8 @@ var browserMenuDragging = {
var pbi = Components.classes["@mozilla.org/preferences;1"]. var pbi = Components.classes["@mozilla.org/preferences;1"].
getService(Components.interfaces.nsIPrefBranch2); getService(Components.interfaces.nsIPrefBranch2);
pbi.addObserver(aObserver.domain, aObserver, false); pbi.addObserver(aObserver.domain, aObserver, false);
} catch(e) {} } catch(e) {
}
}, },
removePrefListener: function(aObserver) { removePrefListener: function(aObserver) {
@ -323,7 +337,8 @@ var browserMenuDragging = {
var pbi = Components.classes["@mozilla.org/preferences;1"]. var pbi = Components.classes["@mozilla.org/preferences;1"].
getService(Components.interfaces.nsIPrefBranch2); getService(Components.interfaces.nsIPrefBranch2);
pbi.removeObserver(aObserver.domain, aObserver); pbi.removeObserver(aObserver.domain, aObserver);
} catch(e) {} } catch(e) {
}
}, },
PrefListener:{ PrefListener:{

View file

@ -40,8 +40,9 @@ var StarUI = {
_blockCommands: function() { _blockCommands: function() {
this._blockedCommands.forEach(function(elt) { this._blockedCommands.forEach(function(elt) {
// make sure not to permanently disable this item (see bug 409155) // make sure not to permanently disable this item (see bug 409155)
if (elt.hasAttribute("wasDisabled")) if (elt.hasAttribute("wasDisabled")) {
return; return;
}
if (elt.getAttribute("disabled") == "true") { if (elt.getAttribute("disabled") == "true") {
elt.setAttribute("wasDisabled", "true"); elt.setAttribute("wasDisabled", "true");
} else { } else {
@ -53,8 +54,9 @@ var StarUI = {
_restoreCommandsState: function() { _restoreCommandsState: function() {
this._blockedCommands.forEach(function(elt) { this._blockedCommands.forEach(function(elt) {
if (elt.getAttribute("wasDisabled") != "true") if (elt.getAttribute("wasDisabled") != "true") {
elt.removeAttribute("disabled"); elt.removeAttribute("disabled");
}
elt.removeAttribute("wasDisabled"); elt.removeAttribute("wasDisabled");
}); });
}, },
@ -64,8 +66,9 @@ var StarUI = {
switch (aEvent.type) { switch (aEvent.type) {
case "popuphidden": case "popuphidden":
if (aEvent.originalTarget == this.panel) { if (aEvent.originalTarget == this.panel) {
if (!this._element("editBookmarkPanelContent").hidden) if (!this._element("editBookmarkPanelContent").hidden) {
this.quitEditMode(); this.quitEditMode();
}
this._restoreCommandsState(); this._restoreCommandsState();
this._itemId = -1; this._itemId = -1;
@ -102,8 +105,9 @@ var StarUI = {
} }
switch (aEvent.keyCode) { switch (aEvent.keyCode) {
case KeyEvent.DOM_VK_ESCAPE: case KeyEvent.DOM_VK_ESCAPE:
if (!this._element("editBookmarkPanelContent").hidden) if (!this._element("editBookmarkPanelContent").hidden) {
this.cancelButtonOnCommand(); this.cancelButtonOnCommand();
}
break; break;
case KeyEvent.DOM_VK_RETURN: case KeyEvent.DOM_VK_RETURN:
if (aEvent.target.className == "expander-up" || if (aEvent.target.className == "expander-up" ||
@ -126,8 +130,9 @@ var StarUI = {
function(aItemId, aAnchorElement, aPosition) { function(aItemId, aAnchorElement, aPosition) {
// Performance: load the overlay the first time the panel is opened // Performance: load the overlay the first time the panel is opened
// (see bug 392443). // (see bug 392443).
if (this._overlayLoading) if (this._overlayLoading) {
return; return;
}
if (this._overlayLoaded) { if (this._overlayLoaded) {
this._doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition); this._doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition);
@ -157,8 +162,9 @@ var StarUI = {
_doShowEditBookmarkPanel: _doShowEditBookmarkPanel:
function(aItemId, aAnchorElement, aPosition) { function(aItemId, aAnchorElement, aPosition) {
if (this.panel.state != "closed") if (this.panel.state != "closed") {
return; return;
}
this._blockCommands(); // un-done in the popuphiding handler this._blockCommands(); // un-done in the popuphiding handler
@ -168,8 +174,8 @@ var StarUI = {
// we are about editing it, then use Edit This Bookmark. // we are about editing it, then use Edit This Bookmark.
this._element("editBookmarkPanelTitle").value = this._element("editBookmarkPanelTitle").value =
this._batching ? this._batching ?
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") : gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle"); gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
// No description; show the Done, Cancel; // No description; show the Done, Cancel;
this._element("editBookmarkPanelDescription").textContent = ""; this._element("editBookmarkPanelDescription").textContent = "";
@ -222,8 +228,7 @@ var StarUI = {
var elt = this._element(fieldToFocus); var elt = this._element(fieldToFocus);
elt.focus(); elt.focus();
elt.select(); elt.select();
} } else {
else {
// Note this isn't actually used anymore, we should remove this // Note this isn't actually used anymore, we should remove this
// once we decide not to bring back the page bookmarked notification // once we decide not to bring back the page bookmarked notification
this.panel.focus(); this.panel.focus();
@ -294,8 +299,8 @@ var PlacesCommandHook = {
title = title || url.spec; title = title || url.spec;
description = PlacesUIUtils.getDescriptionFromDocument(webNav.document); description = PlacesUIUtils.getDescriptionFromDocument(webNav.document);
charset = webNav.document.characterSet; charset = webNav.document.characterSet;
} catch(e) {
} }
catch (e) { }
if (aShowEditUI) { if (aShowEditUI) {
// If we bookmark the page here (i.e. page was not "starred" already) // If we bookmark the page here (i.e. page was not "starred" already)
@ -305,7 +310,8 @@ var PlacesCommandHook = {
} }
var parent = aParent != undefined ? var parent = aParent != undefined ?
aParent : PlacesUtils.unfiledBookmarksFolderId; aParent :
PlacesUtils.unfiledBookmarksFolderId;
var descAnno = { name: PlacesUIUtils.DESCRIPTION_ANNO, value: description }; var descAnno = { name: PlacesUIUtils.DESCRIPTION_ANNO, value: description };
var txn = new PlacesCreateBookmarkTransaction(uri, parent, var txn = new PlacesCreateBookmarkTransaction(uri, parent,
PlacesUtils.bookmarks.DEFAULT_INDEX, PlacesUtils.bookmarks.DEFAULT_INDEX,
@ -313,17 +319,20 @@ var PlacesCommandHook = {
PlacesUtils.transactionManager.doTransaction(txn); PlacesUtils.transactionManager.doTransaction(txn);
itemId = txn.item.id; itemId = txn.item.id;
// Set the character-set // Set the character-set
if (charset && !PrivateBrowsingUtils.isWindowPrivate(aBrowser.contentWindow)) if (charset && !PrivateBrowsingUtils.isWindowPrivate(aBrowser.contentWindow)) {
PlacesUtils.setCharsetForURI(uri, charset); PlacesUtils.setCharsetForURI(uri, charset);
}
} }
// Revert the contents of the location bar // Revert the contents of the location bar
if (gURLBar) if (gURLBar) {
gURLBar.handleRevert(); gURLBar.handleRevert();
}
// If it was not requested to open directly in "edit" mode, we are done. // If it was not requested to open directly in "edit" mode, we are done.
if (!aShowEditUI) if (!aShowEditUI) {
return; return;
}
// Try to dock the panel to: // Try to dock the panel to:
// 1. the bookmarks menu button // 1. the bookmarks menu button
@ -365,20 +374,19 @@ var PlacesCommandHook = {
var linkURI = makeURI(aURL); var linkURI = makeURI(aURL);
var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI); var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
if (itemId == -1) { if (itemId == -1) {
PlacesUIUtils.showBookmarkDialog({ action: "add" PlacesUIUtils.showBookmarkDialog({ action: "add",
, type: "bookmark" type: "bookmark",
, uri: linkURI uri: linkURI,
, title: aTitle title: aTitle,
, hiddenRows: [ "description" hiddenRows: [ "description",
, "location" "location",
, "loadInSidebar" "loadInSidebar",
, "keyword" ] "keyword" ]
}, window); }, window);
} } else {
else { PlacesUIUtils.showBookmarkDialog({ action: "edit",
PlacesUIUtils.showBookmarkDialog({ action: "edit" type: "bookmark",
, type: "bookmark" itemId: itemId
, itemId: itemId
}, window); }, window);
} }
}, },
@ -408,10 +416,10 @@ var PlacesCommandHook = {
bookmarkCurrentPages: function() { bookmarkCurrentPages: function() {
let pages = this.uniqueCurrentPages; let pages = this.uniqueCurrentPages;
if (pages.length > 1) { if (pages.length > 1) {
PlacesUIUtils.showBookmarkDialog({ action: "add" PlacesUIUtils.showBookmarkDialog({ action: "add",
, type: "folder" type: "folder",
, URIList: pages URIList: pages,
, hiddenRows: [ "description" ] hiddenRows: [ "description" ]
}, window); }, window);
} }
}, },
@ -419,11 +427,11 @@ var PlacesCommandHook = {
/** /**
* Updates disabled state for the "Bookmark All Tabs" command. * Updates disabled state for the "Bookmark All Tabs" command.
*/ */
updateBookmarkAllTabsCommand: updateBookmarkAllTabsCommand: function() {
function() {
// There's nothing to do in non-browser windows. // There's nothing to do in non-browser windows.
if (window.location.href != getBrowserURL()) if (window.location.href != getBrowserURL()) {
return; return;
}
// Disable "Bookmark All Tabs" if there are less than two // Disable "Bookmark All Tabs" if there are less than two
// "unique current pages". // "unique current pages".
@ -450,16 +458,16 @@ var PlacesCommandHook = {
description = PlacesUIUtils.getDescriptionFromDocument(gBrowser.contentDocument); description = PlacesUIUtils.getDescriptionFromDocument(gBrowser.contentDocument);
} }
PlacesUIUtils.showBookmarkDialog({ action: "add" PlacesUIUtils.showBookmarkDialog({ action: "add",
, type: "livemark" type: "livemark",
, feedURI: feedURI feedURI: feedURI,
, siteURI: gBrowser.currentURI siteURI: gBrowser.currentURI,
, title: title title: title,
, description: description description: description,
, defaultInsertionPoint: toolbarIP defaultInsertionPoint: toolbarIP,
, hiddenRows: [ "feedLocation" hiddenRows: [ "feedLocation",
, "siteLocation" "siteLocation",
, "description" ] "description" ]
}, window); }, window);
}, },
@ -477,8 +485,7 @@ var PlacesCommandHook = {
// No currently open places window, so open one with the specified mode. // No currently open places window, so open one with the specified mode.
openDialog("chrome://browser/content/places/places.xul", openDialog("chrome://browser/content/places/places.xul",
"", "chrome,toolbar=yes,dialog=no,resizable", aLeftPaneRoot); "", "chrome,toolbar=yes,dialog=no,resizable", aLeftPaneRoot);
} } else {
else {
organizer.PlacesOrganizer.selectLeftPaneQuery(aLeftPaneRoot); organizer.PlacesOrganizer.selectLeftPaneQuery(aLeftPaneRoot);
organizer.focus(); organizer.focus();
} }
@ -507,10 +514,11 @@ HistoryMenu.prototype = {
let restoreItem = this._rootElt.ownerDocument.getElementById("Browser:RestoreLastSession"); let restoreItem = this._rootElt.ownerDocument.getElementById("Browser:RestoreLastSession");
if (this._ss.canRestoreLastSession && if (this._ss.canRestoreLastSession &&
!PrivateBrowsingUtils.isWindowPrivate(window)) !PrivateBrowsingUtils.isWindowPrivate(window)) {
restoreItem.removeAttribute("disabled"); restoreItem.removeAttribute("disabled");
else } else {
restoreItem.setAttribute("disabled", true); restoreItem.setAttribute("disabled", true);
}
}, },
toggleRecentlyClosedTabs: function() { toggleRecentlyClosedTabs: function() {
@ -518,10 +526,11 @@ HistoryMenu.prototype = {
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0]; var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
// no restorable tabs, so disable menu // no restorable tabs, so disable menu
if (this._ss.getClosedTabCount(window) == 0) if (this._ss.getClosedTabCount(window) == 0) {
undoMenu.setAttribute("disabled", true); undoMenu.setAttribute("disabled", true);
else } else {
undoMenu.removeAttribute("disabled"); undoMenu.removeAttribute("disabled");
}
}, },
/** /**
@ -531,8 +540,9 @@ HistoryMenu.prototype = {
* The event when the user clicks the menu item * The event when the user clicks the menu item
*/ */
_undoCloseMiddleClick: function(aEvent) { _undoCloseMiddleClick: function(aEvent) {
if (aEvent.button != 1) if (aEvent.button != 1) {
return; return;
}
undoCloseTab(aEvent.originalTarget.value); undoCloseTab(aEvent.originalTarget.value);
gBrowser.moveTabToEnd(); gBrowser.moveTabToEnd();
@ -546,8 +556,9 @@ HistoryMenu.prototype = {
var undoPopup = undoMenu.firstChild; var undoPopup = undoMenu.firstChild;
// remove existing menu items // remove existing menu items
while (undoPopup.hasChildNodes()) while (undoPopup.hasChildNodes()) {
undoPopup.removeChild(undoPopup.firstChild); undoPopup.removeChild(undoPopup.firstChild);
}
// no restorable tabs, so make sure menu is disabled, and return // no restorable tabs, so make sure menu is disabled, and return
if (this._ss.getClosedTabCount(window) == 0) { if (this._ss.getClosedTabCount(window) == 0) {
@ -566,8 +577,9 @@ HistoryMenu.prototype = {
if (undoItems[i].image) { if (undoItems[i].image) {
let iconURL = undoItems[i].image; let iconURL = undoItems[i].image;
// don't initiate a connection just to fetch a favicon (see bug 467828) // don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL)) if (/^https?:/.test(iconURL)) {
iconURL = "moz-anno:favicon:" + iconURL; iconURL = "moz-anno:favicon:" + iconURL;
}
m.setAttribute("image", iconURL); m.setAttribute("image", iconURL);
} }
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon"); m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
@ -579,12 +591,14 @@ HistoryMenu.prototype = {
// normalize them. // normalize them.
let tabData = undoItems[i].state; let tabData = undoItems[i].state;
let activeIndex = (tabData.index || tabData.entries.length) - 1; let activeIndex = (tabData.index || tabData.entries.length) - 1;
if (activeIndex >= 0 && tabData.entries[activeIndex]) if (activeIndex >= 0 && tabData.entries[activeIndex]) {
m.setAttribute("targetURI", tabData.entries[activeIndex].url); m.setAttribute("targetURI", tabData.entries[activeIndex].url);
}
m.addEventListener("click", this._undoCloseMiddleClick, false); m.addEventListener("click", this._undoCloseMiddleClick, false);
if (i == 0) if (i == 0) {
m.setAttribute("key", "key_undoCloseTab"); m.setAttribute("key", "key_undoCloseTab");
}
undoPopup.appendChild(m); undoPopup.appendChild(m);
} }
@ -595,8 +609,9 @@ HistoryMenu.prototype = {
m.id = "menu_restoreAllTabs"; m.id = "menu_restoreAllTabs";
m.setAttribute("label", strings.getString("menuRestoreAllTabs.label")); m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
m.addEventListener("command", function() { m.addEventListener("command", function() {
for (var i = 0; i < undoItems.length; i++) for (var i = 0; i < undoItems.length; i++) {
undoCloseTab(); undoCloseTab();
}
}, false); }, false);
}, },
@ -605,10 +620,11 @@ HistoryMenu.prototype = {
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0]; var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
// no restorable windows, so disable menu // no restorable windows, so disable menu
if (this._ss.getClosedWindowCount() == 0) if (this._ss.getClosedWindowCount() == 0) {
undoMenu.setAttribute("disabled", true); undoMenu.setAttribute("disabled", true);
else } else {
undoMenu.removeAttribute("disabled"); undoMenu.removeAttribute("disabled");
}
}, },
/** /**
@ -618,12 +634,12 @@ HistoryMenu.prototype = {
let undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0]; let undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
let undoPopup = undoMenu.firstChild; let undoPopup = undoMenu.firstChild;
let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel"); let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
let menuLabelStringSingleTab = let menuLabelStringSingleTab = gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
// remove existing menu items // remove existing menu items
while (undoPopup.hasChildNodes()) while (undoPopup.hasChildNodes()) {
undoPopup.removeChild(undoPopup.firstChild); undoPopup.removeChild(undoPopup.firstChild);
}
// no restorable windows, so make sure menu is disabled, and return // no restorable windows, so make sure menu is disabled, and return
if (this._ss.getClosedWindowCount() == 0) { if (this._ss.getClosedWindowCount() == 0) {
@ -649,8 +665,9 @@ HistoryMenu.prototype = {
if (selectedTab.image) { if (selectedTab.image) {
let iconURL = selectedTab.image; let iconURL = selectedTab.image;
// don't initiate a connection just to fetch a favicon (see bug 467828) // don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL)) if (/^https?:/.test(iconURL)) {
iconURL = "moz-anno:favicon:" + iconURL; iconURL = "moz-anno:favicon:" + iconURL;
}
m.setAttribute("image", iconURL); m.setAttribute("image", iconURL);
} }
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon"); m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
@ -659,11 +676,13 @@ HistoryMenu.prototype = {
// Set the targetURI attribute so it will be shown in tooltip. // Set the targetURI attribute so it will be shown in tooltip.
// SessionStore uses one-based indexes, so we need to normalize them. // SessionStore uses one-based indexes, so we need to normalize them.
let activeIndex = (selectedTab.index || selectedTab.entries.length) - 1; let activeIndex = (selectedTab.index || selectedTab.entries.length) - 1;
if (activeIndex >= 0 && selectedTab.entries[activeIndex]) if (activeIndex >= 0 && selectedTab.entries[activeIndex]) {
m.setAttribute("targetURI", selectedTab.entries[activeIndex].url); m.setAttribute("targetURI", selectedTab.entries[activeIndex].url);
}
if (i == 0) if (i == 0) {
m.setAttribute("key", "key_undoCloseWindow"); m.setAttribute("key", "key_undoCloseWindow");
}
undoPopup.appendChild(m); undoPopup.appendChild(m);
} }
@ -682,8 +701,9 @@ HistoryMenu.prototype = {
// Enable/disable the Tabs From Other Computers menu. Some of the menus handled // Enable/disable the Tabs From Other Computers menu. Some of the menus handled
// by HistoryMenu do not have this menuitem. // by HistoryMenu do not have this menuitem.
let menuitem = this._rootElt.getElementsByClassName("syncTabsMenuItem")[0]; let menuitem = this._rootElt.getElementsByClassName("syncTabsMenuItem")[0];
if (!menuitem) if (!menuitem) {
return; return;
}
// If Sync isn't configured yet, then don't show the menuitem. // If Sync isn't configured yet, then don't show the menuitem.
if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED || if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED ||
@ -706,8 +726,9 @@ HistoryMenu.prototype = {
PlacesMenu.prototype._onPopupShowing.apply(this, arguments); PlacesMenu.prototype._onPopupShowing.apply(this, arguments);
// Don't handle events for submenus. // Don't handle events for submenus.
if (aEvent.target != aEvent.currentTarget) if (aEvent.target != aEvent.currentTarget) {
return; return;
}
this.toggleRestoreLastSession(); this.toggleRestoreLastSession();
this.toggleRecentlyClosedTabs(); this.toggleRecentlyClosedTabs();
@ -718,8 +739,9 @@ HistoryMenu.prototype = {
_onCommand: function(aEvent) { _onCommand: function(aEvent) {
let placesNode = aEvent.target._placesNode; let placesNode = aEvent.target._placesNode;
if (placesNode) { if (placesNode) {
if (!PrivateBrowsingUtils.isWindowPrivate(window)) if (!PrivateBrowsingUtils.isWindowPrivate(window)) {
PlacesUIUtils.markPageAsTyped(placesNode.uri); PlacesUIUtils.markPageAsTyped(placesNode.uri);
}
openUILink(placesNode.uri, aEvent, { ignoreAlt: true }); openUILink(placesNode.uri, aEvent, { ignoreAlt: true });
} }
} }
@ -750,21 +772,23 @@ var BookmarksEventHandler = {
#else #else
var modifKey = aEvent.ctrlKey || aEvent.shiftKey; var modifKey = aEvent.ctrlKey || aEvent.shiftKey;
#endif #endif
if (aEvent.button == 2 || (aEvent.button == 0 && !modifKey)) if (aEvent.button == 2 || (aEvent.button == 0 && !modifKey)) {
return; return;
}
var target = aEvent.originalTarget; var target = aEvent.originalTarget;
// If this event bubbled up from a menu or menuitem, close the menus. // If this event bubbled up from a menu or menuitem, close the menus.
// Do this before opening tabs, to avoid hiding the open tabs confirm-dialog. // Do this before opening tabs, to avoid hiding the open tabs confirm-dialog.
if (target.localName == "menu" || target.localName == "menuitem") { if (target.localName == "menu" || target.localName == "menuitem") {
for (node = target.parentNode; node; node = node.parentNode) { for (node = target.parentNode; node; node = node.parentNode) {
if (node.localName == "menupopup") if (node.localName == "menupopup") {
node.hidePopup(); node.hidePopup();
else if (node.localName != "menu" && } else if (node.localName != "menu" &&
node.localName != "splitmenu" && node.localName != "splitmenu" &&
node.localName != "hbox" && node.localName != "hbox" &&
node.localName != "vbox" ) node.localName != "vbox" ) {
break; break;
}
} }
} }
@ -772,10 +796,10 @@ var BookmarksEventHandler = {
// Don't open the root folder in tabs when the empty area on the toolbar // Don't open the root folder in tabs when the empty area on the toolbar
// is middle-clicked or when a non-bookmark item except for Open in Tabs) // is middle-clicked or when a non-bookmark item except for Open in Tabs)
// in a bookmarks menupopup is middle-clicked. // in a bookmarks menupopup is middle-clicked.
if (target.localName == "menu" || target.localName == "toolbarbutton") if (target.localName == "menu" || target.localName == "toolbarbutton") {
PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent, aView); PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent, aView);
} }
else if (aEvent.button == 1) { } else if (aEvent.button == 1) {
// left-clicks with modifier are already served by onCommand // left-clicks with modifier are already served by onCommand
this.onCommand(aEvent, aView); this.onCommand(aEvent, aView);
} }
@ -792,8 +816,9 @@ var BookmarksEventHandler = {
*/ */
onCommand: function(aEvent, aView) { onCommand: function(aEvent, aView) {
var target = aEvent.originalTarget; var target = aEvent.originalTarget;
if (target._placesNode) if (target._placesNode) {
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent, aView); PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent, aView);
}
}, },
fillInBHTooltip: function(aDocument, aEvent) { fillInBHTooltip: function(aDocument, aEvent) {
@ -805,47 +830,52 @@ var BookmarksEventHandler = {
var tree = aDocument.tooltipNode.parentNode; var tree = aDocument.tooltipNode.parentNode;
var tbo = tree.treeBoxObject; var tbo = tree.treeBoxObject;
var cell = tbo.getCellAt(aEvent.clientX, aEvent.clientY); var cell = tbo.getCellAt(aEvent.clientX, aEvent.clientY);
if (cell.row == -1) if (cell.row == -1) {
return false; return false;
}
node = tree.view.nodeForTreeIndex(cell.row); node = tree.view.nodeForTreeIndex(cell.row);
cropped = tbo.isCellCropped(cell.row, cell.col); cropped = tbo.isCellCropped(cell.row, cell.col);
} } else {
else {
// Check whether the tooltipNode is a Places node. // Check whether the tooltipNode is a Places node.
// In such a case use it, otherwise check for targetURI attribute. // In such a case use it, otherwise check for targetURI attribute.
var tooltipNode = aDocument.tooltipNode; var tooltipNode = aDocument.tooltipNode;
if (tooltipNode._placesNode) if (tooltipNode._placesNode) {
node = tooltipNode._placesNode; node = tooltipNode._placesNode;
else { } else {
// This is a static non-Places node. // This is a static non-Places node.
targetURI = tooltipNode.getAttribute("targetURI"); targetURI = tooltipNode.getAttribute("targetURI");
} }
} }
if (!node && !targetURI) if (!node && !targetURI) {
return false; return false;
}
// Show node.label as tooltip's title for non-Places nodes. // Show node.label as tooltip's title for non-Places nodes.
var title = node ? node.title : tooltipNode.label; var title = node ? node.title : tooltipNode.label;
// Show URL only for Places URI-nodes or nodes with a targetURI attribute. // Show URL only for Places URI-nodes or nodes with a targetURI attribute.
var url; var url;
if (targetURI || PlacesUtils.nodeIsURI(node)) if (targetURI || PlacesUtils.nodeIsURI(node)) {
url = targetURI || node.uri; url = targetURI || node.uri;
}
// Show tooltip for containers only if their title is cropped. // Show tooltip for containers only if their title is cropped.
if (!cropped && !url) if (!cropped && !url) {
return false; return false;
}
var tooltipTitle = aDocument.getElementById("bhtTitleText"); var tooltipTitle = aDocument.getElementById("bhtTitleText");
tooltipTitle.hidden = (!title || (title == url)); tooltipTitle.hidden = (!title || (title == url));
if (!tooltipTitle.hidden) if (!tooltipTitle.hidden) {
tooltipTitle.textContent = title; tooltipTitle.textContent = title;
}
var tooltipUrl = aDocument.getElementById("bhtUrlText"); var tooltipUrl = aDocument.getElementById("bhtUrlText");
tooltipUrl.hidden = !url; tooltipUrl.hidden = !url;
if (!tooltipUrl.hidden) if (!tooltipUrl.hidden) {
tooltipUrl.value = url; tooltipUrl.value = url;
}
// Show tooltip. // Show tooltip.
return true; return true;
@ -869,12 +899,14 @@ var PlacesMenuDNDHandler = {
*/ */
onDragEnter: function(event) { onDragEnter: function(event) {
// Opening menus in a Places popup is handled by the view itself. // Opening menus in a Places popup is handled by the view itself.
if (!this._isStaticContainer(event.target)) if (!this._isStaticContainer(event.target)) {
return; return;
}
let popup = event.target.lastChild; let popup = event.target.lastChild;
if (this._loadTimer || popup.state === "showing" || popup.state === "open") if (this._loadTimer || popup.state === "showing" || popup.state === "open") {
return; return;
}
this._loadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); this._loadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._loadTimer.initWithCallback(() => { this._loadTimer.initWithCallback(() => {
@ -894,12 +926,14 @@ var PlacesMenuDNDHandler = {
onDragLeave: function(event) { onDragLeave: function(event) {
// Handle menu-button separate targets. // Handle menu-button separate targets.
if (event.relatedTarget === event.currentTarget || if (event.relatedTarget === event.currentTarget ||
event.relatedTarget.parentNode === event.currentTarget) event.relatedTarget.parentNode === event.currentTarget) {
return; return;
}
// Closing menus in a Places popup is handled by the view itself. // Closing menus in a Places popup is handled by the view itself.
if (!this._isStaticContainer(event.target)) if (!this._isStaticContainer(event.target)) {
return; return;
}
let popup = event.target.lastChild; let popup = event.target.lastChild;
@ -933,7 +967,8 @@ var PlacesMenuDNDHandler = {
(node.localName == "toolbarbutton" && (node.localName == "toolbarbutton" &&
(node.getAttribute("type") == "menu" || (node.getAttribute("type") == "menu" ||
node.getAttribute("type") == "menu-button")); node.getAttribute("type") == "menu-button"));
let isStatic = !("_placesNode" in node) && node.lastChild && let isStatic = !("_placesNode" in node) &&
node.lastChild &&
node.lastChild.hasAttribute("placespopup") && node.lastChild.hasAttribute("placespopup") &&
!node.parentNode.hasAttribute("placespopup"); !node.parentNode.hasAttribute("placespopup");
return isMenu && isStatic; return isMenu && isStatic;
@ -948,8 +983,9 @@ var PlacesMenuDNDHandler = {
let ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId, let ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX, PlacesUtils.bookmarks.DEFAULT_INDEX,
Ci.nsITreeView.DROP_ON); Ci.nsITreeView.DROP_ON);
if (ip && PlacesControllerDragHelper.canDrop(ip, event.dataTransfer)) if (ip && PlacesControllerDragHelper.canDrop(ip, event.dataTransfer)) {
event.preventDefault(); event.preventDefault();
}
event.stopPropagation(); event.stopPropagation();
}, },
@ -985,8 +1021,9 @@ var PlacesToolbarHelper = {
init: function() { init: function() {
let viewElt = this._viewElt; let viewElt = this._viewElt;
if (!viewElt || viewElt._placesView) if (!viewElt || viewElt._placesView) {
return; return;
}
// If the bookmarks toolbar item is hidden because the parent toolbar is // If the bookmarks toolbar item is hidden because the parent toolbar is
// collapsed or hidden (i.e. in a popup), spare the initialization. Also, // collapsed or hidden (i.e. in a popup), spare the initialization. Also,
@ -995,16 +1032,18 @@ var PlacesToolbarHelper = {
let toolbar = viewElt.parentNode.parentNode; let toolbar = viewElt.parentNode.parentNode;
if (toolbar.collapsed || if (toolbar.collapsed ||
getComputedStyle(toolbar, "").display == "none" || getComputedStyle(toolbar, "").display == "none" ||
this._isCustomizing) this._isCustomizing) {
return; return;
}
new PlacesToolbar(this._place); new PlacesToolbar(this._place);
}, },
customizeStart: function() { customizeStart: function() {
let viewElt = this._viewElt; let viewElt = this._viewElt;
if (viewElt && viewElt._placesView) if (viewElt && viewElt._placesView) {
viewElt._placesView.uninit(); viewElt._placesView.uninit();
}
this._isCustomizing = true; this._isCustomizing = true;
}, },
@ -1050,25 +1089,23 @@ var BookmarkingUI = {
STATUS_UNSTARRED: 0, STATUS_UNSTARRED: 0,
STATUS_STARRED: 1, STATUS_STARRED: 1,
get status() { get status() {
if (this._pendingStmt) if (this._pendingStmt) {
return this.STATUS_UPDATING; return this.STATUS_UPDATING;
}
return this.star && return this.star &&
this.star.hasAttribute("starred") ? this.STATUS_STARRED this.star.hasAttribute("starred") ? this.STATUS_STARRED : this.STATUS_UNSTARRED;
: this.STATUS_UNSTARRED;
}, },
get _starredTooltip() get _starredTooltip()
{ {
delete this._starredTooltip; delete this._starredTooltip;
return this._starredTooltip = return this._starredTooltip = gNavigatorBundle.getString("starButtonOn.tooltip");
gNavigatorBundle.getString("starButtonOn.tooltip");
}, },
get _unstarredTooltip() get _unstarredTooltip()
{ {
delete this._unstarredTooltip; delete this._unstarredTooltip;
return this._unstarredTooltip = return this._unstarredTooltip = gNavigatorBundle.getString("starButtonOff.tooltip");
gNavigatorBundle.getString("starButtonOff.tooltip");
}, },
/** /**
@ -1084,11 +1121,14 @@ var BookmarkingUI = {
onPopupShowing: function(event) { onPopupShowing: function(event) {
// Don't handle events for submenus. // Don't handle events for submenus.
if (event.target != event.currentTarget) if (event.target != event.currentTarget) {
return; return;
}
if (!this._popupNeedsUpdate) if (!this._popupNeedsUpdate) {
return; return;
}
this._popupNeedsUpdate = false; this._popupNeedsUpdate = false;
let popup = event.target; let popup = event.target;
@ -1124,8 +1164,7 @@ var BookmarkingUI = {
if (aState == "invalid") { if (aState == "invalid") {
this.star.setAttribute("disabled", "true"); this.star.setAttribute("disabled", "true");
this.star.removeAttribute("starred"); this.star.removeAttribute("starred");
} } else {
else {
this.star.removeAttribute("disabled"); this.star.removeAttribute("disabled");
} }
}, },
@ -1142,8 +1181,7 @@ var BookmarkingUI = {
if (onPersonalToolbar) { if (onPersonalToolbar) {
this.button.classList.add("bookmark-item"); this.button.classList.add("bookmark-item");
this.button.classList.remove("toolbarbutton-1"); this.button.classList.remove("toolbarbutton-1");
} } else {
else {
this.button.classList.remove("bookmark-item"); this.button.classList.remove("bookmark-item");
this.button.classList.add("toolbarbutton-1"); this.button.classList.add("toolbarbutton-1");
} }
@ -1252,8 +1290,7 @@ var BookmarkingUI = {
if (this._itemIds.length > 0) { if (this._itemIds.length > 0) {
this.star.setAttribute("starred", "true"); this.star.setAttribute("starred", "true");
this.star.setAttribute("tooltiptext", this._starredTooltip); this.star.setAttribute("tooltiptext", this._starredTooltip);
} } else {
else {
this.star.removeAttribute("starred"); this.star.removeAttribute("starred");
this.star.setAttribute("tooltiptext", this._unstarredTooltip); this.star.setAttribute("tooltiptext", this._unstarredTooltip);
} }
@ -1300,9 +1337,8 @@ var BookmarkingUI = {
if (index != -1 && aNewValue != this._uri.spec) { if (index != -1 && aNewValue != this._uri.spec) {
this._itemIds.splice(index, 1); this._itemIds.splice(index, 1);
this._updateStar(); this._updateStar();
} } else if (index == -1 && aNewValue == this._uri.spec) {
// If another bookmark is now pointing to the tracked uri, register it. // If another bookmark is now pointing to the tracked uri, register it.
else if (index == -1 && aNewValue == this._uri.spec) {
this._itemIds.push(aItemId); this._itemIds.push(aItemId);
this._updateStar(); this._updateStar();
} }

View file

@ -64,8 +64,9 @@ var gPluginHandler = {
// Map the plugin's name to a filtered version more suitable for user UI. // Map the plugin's name to a filtered version more suitable for user UI.
makeNicePluginName : function(aName) { makeNicePluginName : function(aName) {
if (aName == "Shockwave Flash") if (aName == "Shockwave Flash") {
return "Adobe Flash"; return "Adobe Flash";
}
// Clean up the plugin name by stripping off any trailing version numbers // Clean up the plugin name by stripping off any trailing version numbers
// or "plugin". EG, "Foo Bar Plugin 1.23_02" --> "Foo Bar" // or "plugin". EG, "Foo Bar Plugin 1.23_02" --> "Foo Bar"
@ -94,34 +95,37 @@ var gPluginHandler = {
let callbackArgs = Array.prototype.slice.call(arguments).slice(2); let callbackArgs = Array.prototype.slice.call(arguments).slice(2);
linkNode.addEventListener("click", linkNode.addEventListener("click",
function(evt) { function(evt) {
if (!evt.isTrusted) if (!evt.isTrusted) {
return; return;
}
evt.preventDefault(); evt.preventDefault();
if (callbackArgs.length == 0) if (callbackArgs.length == 0) {
callbackArgs = [ evt ]; callbackArgs = [ evt ];
}
(self[callbackName]).apply(self, callbackArgs); (self[callbackName]).apply(self, callbackArgs);
}, }, true);
true);
linkNode.addEventListener("keydown", linkNode.addEventListener("keydown",
function(evt) { function(evt) {
if (!evt.isTrusted) if (!evt.isTrusted) {
return; return;
}
if (evt.keyCode == evt.DOM_VK_RETURN) { if (evt.keyCode == evt.DOM_VK_RETURN) {
evt.preventDefault(); evt.preventDefault();
if (callbackArgs.length == 0) if (callbackArgs.length == 0) {
callbackArgs = [ evt ]; callbackArgs = [ evt ];
}
evt.preventDefault(); evt.preventDefault();
(self[callbackName]).apply(self, callbackArgs); (self[callbackName]).apply(self, callbackArgs);
} }
}, }, true);
true);
}, },
// Helper to get the binding handler type from a plugin object // Helper to get the binding handler type from a plugin object
_getBindingType : function(plugin) { _getBindingType : function(plugin) {
if (!(plugin instanceof Ci.nsIObjectLoadingContent)) if (!(plugin instanceof Ci.nsIObjectLoadingContent)) {
return null; return null;
}
switch (plugin.pluginFallbackType) { switch (plugin.pluginFallbackType) {
case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED: case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED:
@ -153,13 +157,13 @@ var gPluginHandler = {
let eventType = event.type; let eventType = event.type;
if (eventType === "PluginRemoved") { if (eventType === "PluginRemoved") {
doc = event.target; doc = event.target;
} } else {
else {
plugin = event.target; plugin = event.target;
doc = plugin.ownerDocument; doc = plugin.ownerDocument;
if (!(plugin instanceof Ci.nsIObjectLoadingContent)) if (!(plugin instanceof Ci.nsIObjectLoadingContent)) {
return; return;
}
} }
if (eventType == "PluginBindingAttached") { if (eventType == "PluginBindingAttached") {
@ -182,8 +186,9 @@ var gPluginHandler = {
let shouldShowNotification = false; let shouldShowNotification = false;
let browser = gBrowser.getBrowserForDocument(doc.defaultView.top.document); let browser = gBrowser.getBrowserForDocument(doc.defaultView.top.document);
if (!browser) if (!browser) {
return; return;
}
switch (eventType) { switch (eventType) {
case "PluginCrashed": case "PluginCrashed":
@ -278,8 +283,9 @@ var gPluginHandler = {
// if this isn't a known plugin, we can't activate it // if this isn't a known plugin, we can't activate it
// (this also guards pluginHost.getPermissionStringForType against // (this also guards pluginHost.getPermissionStringForType against
// unexpected input) // unexpected input)
if (!gPluginHandler.isKnownPlugin(objLoadingContent)) if (!gPluginHandler.isKnownPlugin(objLoadingContent)) {
return false; return false;
}
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType); let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
@ -303,19 +309,22 @@ var gPluginHandler = {
hideClickToPlayOverlay: function(aPlugin) { hideClickToPlayOverlay: function(aPlugin) {
let overlay = this.getPluginUI(aPlugin, "main"); let overlay = this.getPluginUI(aPlugin, "main");
if (overlay) if (overlay) {
overlay.style.visibility = "hidden"; overlay.style.visibility = "hidden";
}
}, },
stopPlayPreview: function(aPlugin, aPlayPlugin) { stopPlayPreview: function(aPlugin, aPlayPlugin) {
let objLoadingContent = aPlugin.QueryInterface(Ci.nsIObjectLoadingContent); let objLoadingContent = aPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
if (objLoadingContent.activated) if (objLoadingContent.activated) {
return; return;
}
if (aPlayPlugin) if (aPlayPlugin) {
objLoadingContent.playPlugin(); objLoadingContent.playPlugin();
else } else {
objLoadingContent.cancelPlayPreview(); objLoadingContent.cancelPlayPreview();
}
}, },
// Callback for user clicking on a disabled plugin // Callback for user clicking on a disabled plugin
@ -347,8 +356,9 @@ var gPluginHandler = {
let objLoadingContent = aPlugin.QueryInterface(Ci.nsIObjectLoadingContent); let objLoadingContent = aPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
// guard against giving pluginHost.getPermissionStringForType a type // guard against giving pluginHost.getPermissionStringForType a type
// not associated with any known plugin // not associated with any known plugin
if (!gPluginHandler.isKnownPlugin(objLoadingContent)) if (!gPluginHandler.isKnownPlugin(objLoadingContent)) {
return; return;
}
let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType); let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
let principal = doc.defaultView.top.document.nodePrincipal; let principal = doc.defaultView.top.document.nodePrincipal;
let pluginPermission = Services.perms.testPermissionFromPrincipal(principal, permissionString); let pluginPermission = Services.perms.testPermissionFromPrincipal(principal, permissionString);
@ -356,8 +366,9 @@ var gPluginHandler = {
let overlay = this.getPluginUI(aPlugin, "main"); let overlay = this.getPluginUI(aPlugin, "main");
if (pluginPermission == Ci.nsIPermissionManager.DENY_ACTION) { if (pluginPermission == Ci.nsIPermissionManager.DENY_ACTION) {
if (overlay) if (overlay) {
overlay.style.visibility = "hidden"; overlay.style.visibility = "hidden";
}
return; return;
} }
@ -365,8 +376,9 @@ var gPluginHandler = {
overlay.addEventListener("click", gPluginHandler._overlayClickListener, true); overlay.addEventListener("click", gPluginHandler._overlayClickListener, true);
let closeIcon = gPluginHandler.getPluginUI(aPlugin, "closeIcon"); let closeIcon = gPluginHandler.getPluginUI(aPlugin, "closeIcon");
closeIcon.addEventListener("click", function(aEvent) { closeIcon.addEventListener("click", function(aEvent) {
if (aEvent.button == 0 && aEvent.isTrusted) if (aEvent.button == 0 && aEvent.isTrusted) {
gPluginHandler.hideClickToPlayOverlay(aPlugin); gPluginHandler.hideClickToPlayOverlay(aPlugin);
}
}, true); }, true);
} }
}, },
@ -379,8 +391,8 @@ var gPluginHandler = {
// drag-and-dropped a tab from a window containing only that tab. In // drag-and-dropped a tab from a window containing only that tab. In
// that case, the window gets destroyed. // that case, the window gets destroyed.
let browser = gBrowser.getBrowserForDocument ? let browser = gBrowser.getBrowserForDocument ?
gBrowser.getBrowserForDocument(contentWindow.document) : gBrowser.getBrowserForDocument(contentWindow.document) :
null; null;
// If browser is null here, we've been drag-and-dropped from another // If browser is null here, we've been drag-and-dropped from another
// window, and this is the wrong click handler. // window, and this is the wrong click handler.
if (!browser) { if (!browser) {
@ -422,8 +434,9 @@ var gPluginHandler = {
// MozPlayPlugin event can be dispatched from the extension chrome // MozPlayPlugin event can be dispatched from the extension chrome
// code to replace the preview content with the native plugin // code to replace the preview content with the native plugin
previewContent.addEventListener("MozPlayPlugin", function playPluginHandler(aEvent) { previewContent.addEventListener("MozPlayPlugin", function playPluginHandler(aEvent) {
if (!aEvent.isTrusted) if (!aEvent.isTrusted) {
return; return;
}
previewContent.removeEventListener("MozPlayPlugin", playPluginHandler, true); previewContent.removeEventListener("MozPlayPlugin", playPluginHandler, true);
@ -432,8 +445,9 @@ var gPluginHandler = {
// cleaning up: removes overlay iframe from the DOM // cleaning up: removes overlay iframe from the DOM
let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0]; let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0];
if (iframe) if (iframe) {
previewContent.removeChild(iframe); previewContent.removeChild(iframe);
}
}, true); }, true);
if (!playPreviewInfo.ignoreCTP) { if (!playPreviewInfo.ignoreCTP) {
@ -450,11 +464,13 @@ var gPluginHandler = {
let plugins = cwu.plugins; let plugins = cwu.plugins;
for (let plugin of plugins) { for (let plugin of plugins) {
let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
if (overlay) if (overlay) {
overlay.removeEventListener("click", gPluginHandler._overlayClickListener, true); overlay.removeEventListener("click", gPluginHandler._overlayClickListener, true);
}
let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
if (gPluginHandler.canActivatePlugin(objLoadingContent)) if (gPluginHandler.canActivatePlugin(objLoadingContent)) {
gPluginHandler._handleClickToPlayEvent(plugin); gPluginHandler._handleClickToPlayEvent(plugin);
}
} }
gPluginHandler._showClickToPlayNotification(browser); gPluginHandler._showClickToPlayNotification(browser);
}, },
@ -462,8 +478,7 @@ var gPluginHandler = {
_clickToPlayNotificationEventCallback: function(event) { _clickToPlayNotificationEventCallback: function(event) {
if (event == "showing") { if (event == "showing") {
gPluginHandler._makeCenterActions(this); gPluginHandler._makeCenterActions(this);
} } else if (event == "dismissed") {
else if (event == "dismissed") {
// Once the popup is dismissed, clicking the icon should show the full // Once the popup is dismissed, clicking the icon should show the full
// list again // list again
this.options.primaryPlugin = null; this.options.primaryPlugin = null;
@ -503,8 +518,7 @@ var gPluginHandler = {
if (permissionObj) { if (permissionObj) {
pluginInfo.pluginPermissionPrePath = permissionObj.principal.originNoSuffix; pluginInfo.pluginPermissionPrePath = permissionObj.principal.originNoSuffix;
pluginInfo.pluginPermissionType = permissionObj.expireType; pluginInfo.pluginPermissionType = permissionObj.expireType;
} } else {
else {
pluginInfo.pluginPermissionPrePath = principal.originNoSuffix; pluginInfo.pluginPermissionPrePath = principal.originNoSuffix;
pluginInfo.pluginPermissionType = undefined; pluginInfo.pluginPermissionType = undefined;
} }
@ -513,8 +527,7 @@ var gPluginHandler = {
// TODO: allow the blocklist to specify a better link, bug 873093 // TODO: allow the blocklist to specify a better link, bug 873093
if (pluginInfo.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE) { if (pluginInfo.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE) {
url = Services.urlFormatter.formatURLPref("plugins.update.url"); url = Services.urlFormatter.formatURLPref("plugins.update.url");
} } else if (pluginInfo.blocklistState != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
else if (pluginInfo.blocklistState != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
url = Services.blocklist.getPluginBlocklistURL(pluginInfo.pluginTag); url = Services.blocklist.getPluginBlocklistURL(pluginInfo.pluginTag);
} }
pluginInfo.detailsLink = url; pluginInfo.detailsLink = url;
@ -635,8 +648,9 @@ var gPluginHandler = {
} }
let dismissed = notification ? notification.dismissed : true; let dismissed = notification ? notification.dismissed : true;
if (aPrimaryPlugin) if (aPrimaryPlugin) {
dismissed = false; dismissed = false;
}
let primaryPluginPermission = null; let primaryPluginPermission = null;
if (aPrimaryPlugin) { if (aPrimaryPlugin) {
@ -649,8 +663,7 @@ var gPluginHandler = {
primaryPlugin: primaryPluginPermission primaryPlugin: primaryPluginPermission
}; };
PopupNotifications.show(aBrowser, "click-to-play-plugins", PopupNotifications.show(aBrowser, "click-to-play-plugins",
"", icon, "", icon, null, null, options);
null, null, options);
}, },
// Crashed-plugin observer. Notified once per plugin crash, before events // Crashed-plugin observer. Notified once per plugin crash, before events
@ -658,16 +671,18 @@ var gPluginHandler = {
pluginCrashed : function(subject, topic, data) { pluginCrashed : function(subject, topic, data) {
let propertyBag = subject; let propertyBag = subject;
if (!(propertyBag instanceof Ci.nsIPropertyBag2) || if (!(propertyBag instanceof Ci.nsIPropertyBag2) ||
!(propertyBag instanceof Ci.nsIWritablePropertyBag2)) !(propertyBag instanceof Ci.nsIWritablePropertyBag2)) {
return; return;
}
}, },
// Crashed-plugin event listener. Called for every instance of a // Crashed-plugin event listener. Called for every instance of a
// plugin in content. // plugin in content.
pluginInstanceCrashed: function(plugin, aEvent) { pluginInstanceCrashed: function(plugin, aEvent) {
// Ensure the plugin and event are of the right type. // Ensure the plugin and event are of the right type.
if (!(aEvent instanceof Ci.nsIDOMDataContainerEvent)) if (!(aEvent instanceof Ci.nsIDOMDataContainerEvent)) {
return; return;
}
let submittedReport = aEvent.getData("submittedCrashReport"); let submittedReport = aEvent.getData("submittedCrashReport");
let doPrompt = true; // XXX followup for .getData("doPrompt"); let doPrompt = true; // XXX followup for .getData("doPrompt");
@ -731,15 +746,17 @@ var gPluginHandler = {
function hideNotificationBar() { function hideNotificationBar() {
let notification = notificationBox.getNotificationWithValue("plugin-crashed"); let notification = notificationBox.getNotificationWithValue("plugin-crashed");
if (notification) if (notification) {
notificationBox.removeNotification(notification, true); notificationBox.removeNotification(notification, true);
}
} }
function showNotificationBar(pluginDumpID, browserDumpID) { function showNotificationBar(pluginDumpID, browserDumpID) {
// If there's already an existing notification bar, don't do anything. // If there's already an existing notification bar, don't do anything.
let notification = notificationBox.getNotificationWithValue("plugin-crashed"); let notification = notificationBox.getNotificationWithValue("plugin-crashed");
if (notification) if (notification) {
return; return;
}
// Configure the notification bar // Configure the notification bar
let priority = notificationBox.PRIORITY_WARNING_MEDIUM; let priority = notificationBox.PRIORITY_WARNING_MEDIUM;
@ -757,7 +774,7 @@ var gPluginHandler = {
}]; }];
notification = notificationBox.appendNotification(messageString, "plugin-crashed", notification = notificationBox.appendNotification(messageString, "plugin-crashed",
iconURL, priority, buttons); iconURL, priority, buttons);
// Add the "learn more" link. // Add the "learn more" link.
let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

View file

@ -109,12 +109,14 @@ var gSyncUI = {
// Functions called by observers // Functions called by observers
onActivityStart: function() { onActivityStart: function() {
if (!gBrowser) if (!gBrowser) {
return; return;
}
let button = document.getElementById("sync-button"); let button = document.getElementById("sync-button");
if (!button) if (!button) {
return; return;
}
button.setAttribute("status", "active"); button.setAttribute("status", "active");
}, },
@ -173,7 +175,10 @@ var gSyncUI = {
buttons.push(new Weave.NotificationButton( buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.login.prefs.label"), this._stringBundle.GetStringFromName("error.login.prefs.label"),
this._stringBundle.GetStringFromName("error.login.prefs.accesskey"), this._stringBundle.GetStringFromName("error.login.prefs.accesskey"),
function() { gSyncUI.openPrefs(); return true; } function() {
gSyncUI.openPrefs();
return true;
}
)); ));
let notification = new Weave.Notification(title, description, null, let notification = new Weave.Notification(title, description, null,
@ -197,7 +202,10 @@ var gSyncUI = {
buttons.push(new Weave.NotificationButton( buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"), this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"),
this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.accesskey"), this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.accesskey"),
function() { gSyncUI.openQuotaDialog(); return true; } function() {
gSyncUI.openQuotaDialog();
return true;
}
)); ));
let notification = new Weave.Notification( let notification = new Weave.Notification(
@ -216,10 +224,11 @@ var gSyncUI = {
}, },
handleToolbarButton: function() { handleToolbarButton: function() {
if (this._needsSetup()) if (this._needsSetup()) {
this.openSetup(); this.openSetup();
else } else {
this.doSync(); this.doSync();
}
}, },
//XXXzpao should be part of syncCommon.js - which we might want to make a module... //XXXzpao should be part of syncCommon.js - which we might want to make a module...
@ -237,9 +246,9 @@ var gSyncUI = {
openSetup: function(wizardType) { openSetup: function(wizardType) {
let win = Services.wm.getMostRecentWindow("Weave:AccountSetup"); let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
if (win) if (win) {
win.focus(); win.focus();
else { } else {
window.openDialog("chrome://browser/content/sync/setup.xul", window.openDialog("chrome://browser/content/sync/setup.xul",
"weaveSetup", "centerscreen,chrome,resizable=no", "weaveSetup", "centerscreen,chrome,resizable=no",
wizardType); wizardType);
@ -247,25 +256,28 @@ var gSyncUI = {
}, },
openAddDevice: function() { openAddDevice: function() {
if (!Weave.Utils.ensureMPUnlocked()) if (!Weave.Utils.ensureMPUnlocked()) {
return; return;
}
let win = Services.wm.getMostRecentWindow("Sync:AddDevice"); let win = Services.wm.getMostRecentWindow("Sync:AddDevice");
if (win) if (win) {
win.focus(); win.focus();
else } else {
window.openDialog("chrome://browser/content/sync/addDevice.xul", window.openDialog("chrome://browser/content/sync/addDevice.xul",
"syncAddDevice", "centerscreen,chrome,resizable=no"); "syncAddDevice", "centerscreen,chrome,resizable=no");
}
}, },
openQuotaDialog: function() { openQuotaDialog: function() {
let win = Services.wm.getMostRecentWindow("Sync:ViewQuota"); let win = Services.wm.getMostRecentWindow("Sync:ViewQuota");
if (win) if (win) {
win.focus(); win.focus();
else } else {
Services.ww.activeWindow.openDialog( Services.ww.activeWindow.openDialog(
"chrome://browser/content/sync/quota.xul", "", "chrome://browser/content/sync/quota.xul", "",
"centerscreen,chrome,dialog,modal"); "centerscreen,chrome,dialog,modal");
}
}, },
openPrefs: function() { openPrefs: function() {
@ -275,12 +287,14 @@ var gSyncUI = {
// Helpers // Helpers
_updateLastSyncTime: function() { _updateLastSyncTime: function() {
if (!gBrowser) if (!gBrowser) {
return; return;
}
let syncButton = document.getElementById("sync-button"); let syncButton = document.getElementById("sync-button");
if (!syncButton) if (!syncButton) {
return; return;
}
let lastSync = Services.prefs.getCharPref("services.sync.lastSync"); let lastSync = Services.prefs.getCharPref("services.sync.lastSync");
if (!lastSync || this._needsSetup()) { if (!lastSync || this._needsSetup()) {
@ -339,8 +353,9 @@ var gSyncUI = {
// Check if the client is outdated in some way // Check if the client is outdated in some way
let outdated = Weave.Status.sync == Weave.VERSION_OUT_OF_DATE; let outdated = Weave.Status.sync == Weave.VERSION_OUT_OF_DATE;
for (let [engine, reason] in Iterator(Weave.Status.engines)) for (let [engine, reason] in Iterator(Weave.Status.engines)) {
outdated = outdated || reason == Weave.VERSION_OUT_OF_DATE; outdated = outdated || reason == Weave.VERSION_OUT_OF_DATE;
}
if (outdated) { if (outdated) {
description = this._stringBundle.GetStringFromName( description = this._stringBundle.GetStringFromName(
@ -353,8 +368,7 @@ var gSyncUI = {
return true; return true;
} }
)); ));
} } else if (Weave.Status.sync == Weave.OVER_QUOTA) {
else if (Weave.Status.sync == Weave.OVER_QUOTA) {
description = this._stringBundle.GetStringFromName( description = this._stringBundle.GetStringFromName(
"error.sync.quota.description"); "error.sync.quota.description");
buttons.push(new Weave.NotificationButton( buttons.push(new Weave.NotificationButton(
@ -362,23 +376,30 @@ var gSyncUI = {
"error.sync.viewQuotaButton.label"), "error.sync.viewQuotaButton.label"),
this._stringBundle.GetStringFromName( this._stringBundle.GetStringFromName(
"error.sync.viewQuotaButton.accesskey"), "error.sync.viewQuotaButton.accesskey"),
function() { gSyncUI.openQuotaDialog(); return true; } ) function() {
); gSyncUI.openQuotaDialog();
} return true;
else if (Weave.Status.enforceBackoff) { }
));
} else if (Weave.Status.enforceBackoff) {
priority = Weave.Notifications.PRIORITY_INFO; priority = Weave.Notifications.PRIORITY_INFO;
buttons.push(new Weave.NotificationButton( buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.label"), this._stringBundle.GetStringFromName("error.sync.serverStatusButton.label"),
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.accesskey"), this._stringBundle.GetStringFromName("error.sync.serverStatusButton.accesskey"),
function() { gSyncUI.openServerStatus(); return true; } function() {
gSyncUI.openServerStatus();
return true;
}
)); ));
} } else {
else {
priority = Weave.Notifications.PRIORITY_INFO; priority = Weave.Notifications.PRIORITY_INFO;
buttons.push(new Weave.NotificationButton( buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.sync.tryAgainButton.label"), this._stringBundle.GetStringFromName("error.sync.tryAgainButton.label"),
this._stringBundle.GetStringFromName("error.sync.tryAgainButton.accesskey"), this._stringBundle.GetStringFromName("error.sync.tryAgainButton.accesskey"),
function() { gSyncUI.doSync(); return true; } function() {
gSyncUI.doSync();
return true;
}
)); ));
} }

View file

@ -23,8 +23,9 @@ var tabPreviews = {
}, },
init: function() { init: function() {
if (this._selectedTab) if (this._selectedTab) {
return; return;
}
this._selectedTab = gBrowser.selectedTab; this._selectedTab = gBrowser.selectedTab;
gBrowser.tabContainer.addEventListener("TabSelect", this, false); gBrowser.tabContainer.addEventListener("TabSelect", this, false);
@ -40,8 +41,9 @@ var tabPreviews = {
aTab.__thumbnail_lastURI = null; aTab.__thumbnail_lastURI = null;
} }
if (aTab.__thumbnail) if (aTab.__thumbnail) {
return aTab.__thumbnail; return aTab.__thumbnail;
}
if (aTab.getAttribute("pending") == "true") { if (aTab.getAttribute("pending") == "true") {
let img = new Image; let img = new Image;
@ -90,8 +92,9 @@ var tabPreviews = {
self._pendingUpdate = false; self._pendingUpdate = false;
if (aTab.parentNode && if (aTab.parentNode &&
!aTab.hasAttribute("busy") && !aTab.hasAttribute("busy") &&
!aTab.hasAttribute("pending")) !aTab.hasAttribute("pending")) {
self.capture(aTab, true); self.capture(aTab, true);
}
}, 2000, this, this._selectedTab); }, 2000, this, this._selectedTab);
} }
this._selectedTab = event.target; this._selectedTab = event.target;
@ -123,20 +126,23 @@ var tabPreviewPanelHelper = {
}; };
}, },
_popupshown: function(host) { _popupshown: function(host) {
if ("setupGUI" in host) if ("setupGUI" in host) {
host.setupGUI(); host.setupGUI();
}
}, },
_popuphiding: function(host) { _popuphiding: function(host) {
if ("suspendGUI" in host) if ("suspendGUI" in host) {
host.suspendGUI(); host.suspendGUI();
}
if (host._prevFocus) { if (host._prevFocus) {
Cc["@mozilla.org/focus-manager;1"] Cc["@mozilla.org/focus-manager;1"]
.getService(Ci.nsIFocusManager) .getService(Ci.nsIFocusManager)
.setFocus(host._prevFocus, Ci.nsIFocusManager.FLAG_NOSCROLL); .setFocus(host._prevFocus, Ci.nsIFocusManager.FLAG_NOSCROLL);
host._prevFocus = null; host._prevFocus = null;
} else } else {
gBrowser.selectedBrowser.focus(); gBrowser.selectedBrowser.focus();
}
if (host.tabToSelect) { if (host.tabToSelect) {
gBrowser.selectedTab = host.tabToSelect; gBrowser.selectedTab = host.tabToSelect;
@ -149,23 +155,23 @@ var tabPreviewPanelHelper = {
* Ctrl-Tab panel * Ctrl-Tab panel
*/ */
var ctrlTab = { var ctrlTab = {
get panel () { get panel() {
delete this.panel; delete this.panel;
return this.panel = document.getElementById("ctrlTab-panel"); return this.panel = document.getElementById("ctrlTab-panel");
}, },
get showAllButton () { get showAllButton() {
delete this.showAllButton; delete this.showAllButton;
return this.showAllButton = document.getElementById("ctrlTab-showAll"); return this.showAllButton = document.getElementById("ctrlTab-showAll");
}, },
get previews () { get previews() {
delete this.previews; delete this.previews;
return this.previews = this.panel.getElementsByClassName("ctrlTab-preview"); return this.previews = this.panel.getElementsByClassName("ctrlTab-preview");
}, },
get recentlyUsedLimit () { get recentlyUsedLimit() {
delete this.recentlyUsedLimit; delete this.recentlyUsedLimit;
return this.recentlyUsedLimit = gPrefService.getIntPref("browser.ctrlTab.recentlyUsedLimit"); return this.recentlyUsedLimit = gPrefService.getIntPref("browser.ctrlTab.recentlyUsedLimit");
}, },
get keys () { get keys() {
var keys = {}; var keys = {};
["close", "find", "selectAll"].forEach(function(key) { ["close", "find", "selectAll"].forEach(function(key) {
keys[key] = document.getElementById("key_" + key) keys[key] = document.getElementById("key_" + key)
@ -176,17 +182,26 @@ var ctrlTab = {
return this.keys = keys; return this.keys = keys;
}, },
_selectedIndex: 0, _selectedIndex: 0,
get selected () this._selectedIndex < 0 ? get selected() {
document.activeElement : return this._selectedIndex < 0 ? document.activeElement : this.previews.item(this._selectedIndex);
this.previews.item(this._selectedIndex), },
get isOpen () this.panel.state == "open" || this.panel.state == "showing" || this._timer, get isOpen() {
get tabCount () this.tabList.length, return this.panel.state == "open" || this.panel.state == "showing" || this._timer;
get tabPreviewCount () Math.min(this.previews.length - 1, this.tabCount), },
get canvasWidth () Math.min(tabPreviews.width, get tabCount() {
Math.ceil(screen.availWidth * .85 / this.tabPreviewCount)), return this.tabList.length;
get canvasHeight () Math.round(this.canvasWidth * tabPreviews.aspectRatio), },
get tabPreviewCount() {
return Math.min(this.previews.length - 1, this.tabCount);
},
get canvasWidth() {
return Math.min(tabPreviews.width, Math.ceil(screen.availWidth * .85 / this.tabPreviewCount));
},
get canvasHeight() {
return Math.round(this.canvasWidth * tabPreviews.aspectRatio);
},
get tabList () { get tabList() {
if (this._tabList) if (this._tabList)
return this._tabList; return this._tabList;
@ -196,8 +211,9 @@ var ctrlTab = {
let list = Array.filter(gBrowser.tabs, function(tab) !tab.hidden); let list = Array.filter(gBrowser.tabs, function(tab) !tab.hidden);
// Rotate the list until the selected tab is first // Rotate the list until the selected tab is first
while (!list[0].selected) while (!list[0].selected) {
list.push(list.shift()); list.push(list.shift());
}
list = list.filter(function(tab) !tab.closing); list = list.filter(function(tab) !tab.closing);
@ -206,8 +222,9 @@ var ctrlTab = {
for (let tab of this._recentlyUsedTabs) { for (let tab of this._recentlyUsedTabs) {
if (!tab.hidden && !tab.closing) { if (!tab.hidden && !tab.closing) {
recentlyUsedTabs.push(tab); recentlyUsedTabs.push(tab);
if (this.recentlyUsedLimit > 0 && recentlyUsedTabs.length >= this.recentlyUsedLimit) if (this.recentlyUsedLimit > 0 && recentlyUsedTabs.length >= this.recentlyUsedLimit) {
break; break;
}
} }
} }
for (let i = recentlyUsedTabs.length - 1; i >= 0; i--) { for (let i = recentlyUsedTabs.length - 1; i >= 0; i--) {
@ -249,18 +266,20 @@ var ctrlTab = {
(!gPrefService.prefHasUserValue("browser.ctrlTab.disallowForScreenReaders") || (!gPrefService.prefHasUserValue("browser.ctrlTab.disallowForScreenReaders") ||
!gPrefService.getBoolPref("browser.ctrlTab.disallowForScreenReaders")); !gPrefService.getBoolPref("browser.ctrlTab.disallowForScreenReaders"));
if (enable) if (enable) {
this.init(); this.init();
else } else {
this.uninit(); this.uninit();
}
}, },
observe: function(aSubject, aTopic, aPrefName) { observe: function(aSubject, aTopic, aPrefName) {
this.readPref(); this.readPref();
}, },
updatePreviews: function() { updatePreviews: function() {
for (let i = 0; i < this.previews.length; i++) for (let i = 0; i < this.previews.length; i++) {
this.updatePreview(this.previews[i], this.tabList[i]); this.updatePreview(this.previews[i], this.tabList[i]);
}
var showAllLabel = gNavigatorBundle.getString("ctrlTab.showAll.label"); var showAllLabel = gNavigatorBundle.getString("ctrlTab.showAll.label");
this.showAllButton.label = this.showAllButton.label =
@ -268,13 +287,15 @@ var ctrlTab = {
}, },
updatePreview: function(aPreview, aTab) { updatePreview: function(aPreview, aTab) {
if (aPreview == this.showAllButton) if (aPreview == this.showAllButton) {
return; return;
}
aPreview._tab = aTab; aPreview._tab = aTab;
if (aPreview.firstChild) if (aPreview.firstChild) {
aPreview.removeChild(aPreview.firstChild); aPreview.removeChild(aPreview.firstChild);
}
if (aTab) { if (aTab) {
let canvasWidth = this.canvasWidth; let canvasWidth = this.canvasWidth;
let canvasHeight = this.canvasHeight; let canvasHeight = this.canvasHeight;
@ -305,10 +326,11 @@ var ctrlTab = {
let selectedIndex = Array.indexOf(this.previews, this.selected); let selectedIndex = Array.indexOf(this.previews, this.selected);
do { do {
selectedIndex += aForward ? 1 : -1; selectedIndex += aForward ? 1 : -1;
if (selectedIndex < 0) if (selectedIndex < 0) {
selectedIndex = this.previews.length - 1; selectedIndex = this.previews.length - 1;
else if (selectedIndex >= this.previews.length) } else if (selectedIndex >= this.previews.length)
selectedIndex = 0; selectedIndex = 0;
}
} while (this.previews[selectedIndex].hidden); } while (this.previews[selectedIndex].hidden);
if (this._selectedIndex == -1) { if (this._selectedIndex == -1) {
@ -331,15 +353,17 @@ var ctrlTab = {
}, },
pick: function(aPreview) { pick: function(aPreview) {
if (!this.tabCount) if (!this.tabCount) {
return; return;
}
var select = (aPreview || this.selected); var select = (aPreview || this.selected);
if (select == this.showAllButton) if (select == this.showAllButton) {
this.showAllTabs(); this.showAllTabs();
else } else {
this.close(select._tab); this.close(select._tab);
}
}, },
showAllTabs: function(aPreview) { showAllTabs: function(aPreview) {
@ -348,27 +372,31 @@ var ctrlTab = {
}, },
remove: function(aPreview) { remove: function(aPreview) {
if (aPreview._tab) if (aPreview._tab) {
gBrowser.removeTab(aPreview._tab); gBrowser.removeTab(aPreview._tab);
}
}, },
attachTab: function(aTab, aPos) { attachTab: function(aTab, aPos) {
if (aPos == 0) if (aPos == 0) {
this._recentlyUsedTabs.unshift(aTab); this._recentlyUsedTabs.unshift(aTab);
else if (aPos) } else if (aPos) {
this._recentlyUsedTabs.splice(aPos, 0, aTab); this._recentlyUsedTabs.splice(aPos, 0, aTab);
else } else {
this._recentlyUsedTabs.push(aTab); this._recentlyUsedTabs.push(aTab);
}
}, },
detachTab: function(aTab) { detachTab: function(aTab) {
var i = this._recentlyUsedTabs.indexOf(aTab); var i = this._recentlyUsedTabs.indexOf(aTab);
if (i >= 0) if (i >= 0) {
this._recentlyUsedTabs.splice(i, 1); this._recentlyUsedTabs.splice(i, 1);
}
}, },
open: function() { open: function() {
if (this.isOpen) if (this.isOpen) {
return; return;
}
allTabs.close(); allTabs.close();
@ -397,15 +425,17 @@ var ctrlTab = {
}, },
close: function(aTabToSelect) { close: function(aTabToSelect) {
if (!this.isOpen) if (!this.isOpen) {
return; return;
}
if (this._timer) { if (this._timer) {
clearTimeout(this._timer); clearTimeout(this._timer);
this._timer = null; this._timer = null;
this.suspendGUI(); this.suspendGUI();
if (aTabToSelect) if (aTabToSelect) {
gBrowser.selectedTab = aTabToSelect; gBrowser.selectedTab = aTabToSelect;
}
return; return;
} }
@ -421,8 +451,9 @@ var ctrlTab = {
// to be under the mouse pointer initially won't be selected unintentionally. // to be under the mouse pointer initially won't be selected unintentionally.
this._trackMouseOver = false; this._trackMouseOver = false;
setTimeout(function(self) { setTimeout(function(self) {
if (self.isOpen) if (self.isOpen) {
self._trackMouseOver = true; self._trackMouseOver = true;
}
}, 0, this); }, 0, this);
}, },
@ -490,10 +521,12 @@ var ctrlTab = {
this._tabList = null; this._tabList = null;
this.updatePreviews(); this.updatePreviews();
if (this.selected.hidden) if (this.selected.hidden) {
this.advanceFocus(false); this.advanceFocus(false);
if (this.selected == this.showAllButton) }
if (this.selected == this.showAllButton) {
this.advanceFocus(false); this.advanceFocus(false);
}
// If the current tab is removed, another tab can steal our focus. // If the current tab is removed, another tab can steal our focus.
if (aTab.selected && this.panel.state == "open") { if (aTab.selected && this.panel.state == "open") {
@ -523,15 +556,17 @@ var ctrlTab = {
break; break;
case "TabClose": case "TabClose":
this.detachTab(event.target); this.detachTab(event.target);
if (this.isOpen) if (this.isOpen) {
this.removeClosingTabFromUI(event.target); this.removeClosingTabFromUI(event.target);
}
break; break;
case "keypress": case "keypress":
this.onKeyPress(event); this.onKeyPress(event);
break; break;
case "keyup": case "keyup":
if (event.keyCode == event.DOM_VK_CONTROL) if (event.keyCode == event.DOM_VK_CONTROL) {
this.pick(); this.pick();
}
break; break;
} }
}, },
@ -555,10 +590,11 @@ var ctrlTab = {
// Also disable the <key> to ensure Shift+Ctrl+Tab never triggers // Also disable the <key> to ensure Shift+Ctrl+Tab never triggers
// Show All Tabs. // Show All Tabs.
var key_showAllTabs = document.getElementById("key_showAllTabs"); var key_showAllTabs = document.getElementById("key_showAllTabs");
if (enable) if (enable) {
key_showAllTabs.removeAttribute("disabled"); key_showAllTabs.removeAttribute("disabled");
else } else {
key_showAllTabs.setAttribute("disabled", "true"); key_showAllTabs.setAttribute("disabled", "true");
}
} }
}; };
@ -567,29 +603,36 @@ var ctrlTab = {
* All Tabs panel * All Tabs panel
*/ */
var allTabs = { var allTabs = {
get panel () { get panel() {
delete this.panel; delete this.panel;
return this.panel = document.getElementById("allTabs-panel"); return this.panel = document.getElementById("allTabs-panel");
}, },
get filterField () { get filterField() {
delete this.filterField; delete this.filterField;
return this.filterField = document.getElementById("allTabs-filter"); return this.filterField = document.getElementById("allTabs-filter");
}, },
get container () { get container() {
delete this.container; delete this.container;
return this.container = document.getElementById("allTabs-container"); return this.container = document.getElementById("allTabs-container");
}, },
get tabCloseButton () { get tabCloseButton() {
delete this.tabCloseButton; delete this.tabCloseButton;
return this.tabCloseButton = document.getElementById("allTabs-tab-close-button"); return this.tabCloseButton = document.getElementById("allTabs-tab-close-button");
}, },
get toolbarButton() document.getElementById("alltabs-button"), get toolbarButton() {
get previews () this.container.getElementsByClassName("allTabs-preview"), return document.getElementById("alltabs-button");
get isOpen () this.panel.state == "open" || this.panel.state == "showing", },
get previews() {
return this.container.getElementsByClassName("allTabs-preview");
},
get isOpen() {
return this.panel.state == "open" || this.panel.state == "showing";
},
init: function() { init: function() {
if (this._initiated) if (this._initiated) {
return; return;
}
this._initiated = true; this._initiated = true;
tabPreviews.init(); tabPreviews.init();
@ -605,16 +648,18 @@ var allTabs = {
}, },
uninit: function() { uninit: function() {
if (!this._initiated) if (!this._initiated) {
return; return;
}
gBrowser.tabContainer.removeEventListener("TabOpen", this, false); gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
gBrowser.tabContainer.removeEventListener("TabAttrModified", this, false); gBrowser.tabContainer.removeEventListener("TabAttrModified", this, false);
gBrowser.tabContainer.removeEventListener("TabMove", this, false); gBrowser.tabContainer.removeEventListener("TabMove", this, false);
gBrowser.tabContainer.removeEventListener("TabClose", this, false); gBrowser.tabContainer.removeEventListener("TabClose", this, false);
while (this.container.hasChildNodes()) while (this.container.hasChildNodes()) {
this.container.removeChild(this.container.firstChild); this.container.removeChild(this.container.firstChild);
}
this._initiated = false; this._initiated = false;
}, },
@ -622,8 +667,9 @@ var allTabs = {
prefName: "browser.allTabs.previews", prefName: "browser.allTabs.previews",
readPref: function() { readPref: function() {
var allTabsButton = this.toolbarButton; var allTabsButton = this.toolbarButton;
if (!allTabsButton) if (!allTabsButton) {
return; return;
}
if (gPrefService.getBoolPref(this.prefName)) { if (gPrefService.getBoolPref(this.prefName)) {
allTabsButton.removeAttribute("type"); allTabsButton.removeAttribute("type");
@ -639,10 +685,12 @@ var allTabs = {
}, },
pick: function(aPreview) { pick: function(aPreview) {
if (!aPreview) if (!aPreview) {
aPreview = this._firstVisiblePreview; aPreview = this._firstVisiblePreview;
if (aPreview) }
if (aPreview) {
this.tabToSelect = aPreview._tab; this.tabToSelect = aPreview._tab;
}
this.close(); this.close();
}, },
@ -653,8 +701,9 @@ var allTabs = {
}, },
filter: function() { filter: function() {
if (this._currentFilter == this.filterField.value) if (this._currentFilter == this.filterField.value) {
return; return;
}
this._currentFilter = this.filterField.value; this._currentFilter = this.filterField.value;
@ -676,15 +725,16 @@ var allTabs = {
let tabstring = tab.linkedBrowser.currentURI.spec; let tabstring = tab.linkedBrowser.currentURI.spec;
try { try {
tabstring = decodeURI(tabstring); tabstring = decodeURI(tabstring);
} catch (e) {} } catch (e) {
}
tabstring = tab.label + " " + tab.label.toLocaleLowerCase() + " " + tabstring; tabstring = tab.label + " " + tab.label.toLocaleLowerCase() + " " + tabstring;
for (let i = 0; i < filter.length; i++) for (let i = 0; i < filter.length; i++) {
matches += tabstring.includes(filter[i]); matches += tabstring.includes(filter[i]);
}
} }
if (matches < filter.length || tab.hidden || (hidePinnedTabs && tab.pinned)) { if (matches < filter.length || tab.hidden || (hidePinnedTabs && tab.pinned)) {
preview.hidden = true; preview.hidden = true;
} } else {
else {
this._visible++; this._visible++;
this._updatePreview(preview); this._updatePreview(preview);
preview.hidden = false; preview.hidden = false;
@ -708,8 +758,9 @@ var allTabs = {
this.init(); this.init();
if (this.isOpen) if (this.isOpen) {
return; return;
}
this._maxPanelHeight = Math.max(gBrowser.clientHeight, screen.availHeight / 2); this._maxPanelHeight = Math.max(gBrowser.clientHeight, screen.availHeight / 2);
this._maxPanelWidth = Math.max(gBrowser.clientWidth, screen.availWidth / 2); this._maxPanelWidth = Math.max(gBrowser.clientWidth, screen.availWidth / 2);
@ -758,27 +809,31 @@ var allTabs = {
handleEvent: function(event) { handleEvent: function(event) {
if (event.type.startsWith("Tab")) { if (event.type.startsWith("Tab")) {
var tab = event.target; var tab = event.target;
if (event.type != "TabOpen") if (event.type != "TabOpen") {
var preview = this._getPreview(tab); var preview = this._getPreview(tab);
}
} }
switch (event.type) { switch (event.type) {
case "TabAttrModified": case "TabAttrModified":
// tab attribute modified (e.g. label, crop, busy, image) // tab attribute modified (e.g. label, crop, busy, image)
if (!preview.hidden) if (!preview.hidden) {
this._updatePreview(preview); this._updatePreview(preview);
}
break; break;
case "TabOpen": case "TabOpen":
if (this.isOpen) if (this.isOpen) {
this.close(); this.close();
}
this._addPreview(tab); this._addPreview(tab);
break; break;
case "TabMove": case "TabMove":
let siblingPreview = tab.nextSibling && let siblingPreview = tab.nextSibling &&
this._getPreview(tab.nextSibling); this._getPreview(tab.nextSibling);
if (siblingPreview) if (siblingPreview) {
siblingPreview.parentNode.insertBefore(preview, siblingPreview); siblingPreview.parentNode.insertBefore(preview, siblingPreview);
else } else {
this.container.lastChild.appendChild(preview); this.container.lastChild.appendChild(preview);
}
if (this.isOpen && !preview.hidden) { if (this.isOpen && !preview.hidden) {
this._reflow(); this._reflow();
preview.focus(); preview.focus();
@ -801,23 +856,23 @@ var allTabs = {
_visible: 0, _visible: 0,
_currentFilter: null, _currentFilter: null,
get _stack () { get _stack() {
delete this._stack; delete this._stack;
return this._stack = document.getElementById("allTabs-stack"); return this._stack = document.getElementById("allTabs-stack");
}, },
get _browserCommandSet () { get _browserCommandSet() {
delete this._browserCommandSet; delete this._browserCommandSet;
return this._browserCommandSet = document.getElementById("mainCommandSet"); return this._browserCommandSet = document.getElementById("mainCommandSet");
}, },
get _previewLabelHeight () { get _previewLabelHeight() {
delete this._previewLabelHeight; delete this._previewLabelHeight;
return this._previewLabelHeight = parseInt(getComputedStyle(this.previews[0], "").lineHeight); return this._previewLabelHeight = parseInt(getComputedStyle(this.previews[0], "").lineHeight);
}, },
get _visiblePreviews () get _visiblePreviews()
Array.filter(this.previews, function(preview) !preview.hidden), Array.filter(this.previews, function(preview) !preview.hidden),
get _firstVisiblePreview () { get _firstVisiblePreview() {
if (this._visible == 0) if (this._visible == 0)
return null; return null;
var previews = this.previews; var previews = this.previews;
@ -860,10 +915,12 @@ var allTabs = {
var previews = Array.slice(this.previews); var previews = Array.slice(this.previews);
while (this.container.hasChildNodes()) while (this.container.hasChildNodes()) {
this.container.removeChild(this.container.firstChild); this.container.removeChild(this.container.firstChild);
for (let i = rows || 1; i > 0; i--) }
for (let i = rows || 1; i > 0; i--) {
this.container.appendChild(document.createElement("hbox")); this.container.appendChild(document.createElement("hbox"));
}
var row = this.container.firstChild; var row = this.container.firstChild;
var colCount = 0; var colCount = 0;
@ -907,19 +964,23 @@ var allTabs = {
_getPreview: function(aTab) { _getPreview: function(aTab) {
var previews = this.previews; var previews = this.previews;
for (let i = 0; i < previews.length; i++) for (let i = 0; i < previews.length; i++) {
if (previews[i]._tab == aTab) if (previews[i]._tab == aTab) {
return previews[i]; return previews[i];
}
}
return null; return null;
}, },
_updateTabCloseButton: function(event) { _updateTabCloseButton: function(event) {
if (event && event.target == this.tabCloseButton) if (event && event.target == this.tabCloseButton) {
return; return;
}
if (this.tabCloseButton._targetPreview) { if (this.tabCloseButton._targetPreview) {
if (event && event.target == this.tabCloseButton._targetPreview) if (event && event.target == this.tabCloseButton._targetPreview) {
return; return;
}
this.tabCloseButton._targetPreview.removeAttribute("closebuttonhover"); this.tabCloseButton._targetPreview.removeAttribute("closebuttonhover");
} }
@ -954,22 +1015,25 @@ var allTabs = {
aPreview.setAttribute("label", aPreview._tab.label); aPreview.setAttribute("label", aPreview._tab.label);
aPreview.setAttribute("tooltiptext", aPreview._tab.label); aPreview.setAttribute("tooltiptext", aPreview._tab.label);
aPreview.setAttribute("crop", aPreview._tab.crop); aPreview.setAttribute("crop", aPreview._tab.crop);
if (aPreview._tab.image) if (aPreview._tab.image) {
aPreview.setAttribute("image", aPreview._tab.image); aPreview.setAttribute("image", aPreview._tab.image);
else } else {
aPreview.removeAttribute("image"); aPreview.removeAttribute("image");
}
aPreview.removeAttribute("soundplaying"); aPreview.removeAttribute("soundplaying");
aPreview.removeAttribute("muted"); aPreview.removeAttribute("muted");
if (aPreview._tab.hasAttribute("muted")) if (aPreview._tab.hasAttribute("muted")) {
aPreview.setAttribute("muted", "true"); aPreview.setAttribute("muted", "true");
else if (aPreview._tab.hasAttribute("soundplaying")) } else if (aPreview._tab.hasAttribute("soundplaying")) {
aPreview.setAttribute("soundplaying", "true"); aPreview.setAttribute("soundplaying", "true");
}
var thumbnail = tabPreviews.get(aPreview._tab); var thumbnail = tabPreviews.get(aPreview._tab);
if (aPreview.firstChild) { if (aPreview.firstChild) {
if (aPreview.firstChild == thumbnail) if (aPreview.firstChild == thumbnail) {
return; return;
}
aPreview.removeChild(aPreview.firstChild); aPreview.removeChild(aPreview.firstChild);
} }
aPreview.appendChild(thumbnail); aPreview.appendChild(thumbnail);
@ -1014,8 +1078,9 @@ var allTabs = {
switch (event.keyCode) { switch (event.keyCode) {
case event.DOM_VK_UP: case event.DOM_VK_UP:
case event.DOM_VK_DOWN: case event.DOM_VK_DOWN:
if (event.target != this.filterField) if (event.target != this.filterField) {
this._advanceFocusVertically(event); this._advanceFocusVertically(event);
}
break; break;
case event.DOM_VK_RETURN: case event.DOM_VK_RETURN:
if (event.target == this.filterField) { if (event.target == this.filterField) {
@ -1030,8 +1095,9 @@ var allTabs = {
_advanceFocusVertically: function(event) { _advanceFocusVertically: function(event) {
var preview = document.activeElement; var preview = document.activeElement;
if (!preview || preview.parentNode.parentNode != this.container) if (!preview || preview.parentNode.parentNode != this.container) {
return; return;
}
event.stopPropagation(); event.stopPropagation();
@ -1057,8 +1123,9 @@ var allTabs = {
let rows = Math.ceil(previews.length / columns); let rows = Math.ceil(previews.length / columns);
row = rows - 1; row = rows - 1;
column--; column--;
if (outOfBounds()) if (outOfBounds()) {
row--; row--;
}
} }
} else { } else {
row++; row++;

View file

@ -32,13 +32,15 @@ var gBrowserThumbnails = {
init: function() { init: function() {
// Bug 863512 - Make page thumbnails work in electrolysis // Bug 863512 - Make page thumbnails work in electrolysis
if (gMultiProcessBrowser) if (gMultiProcessBrowser) {
return; return;
}
try { try {
if (Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled")) if (Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled"))
return; return;
} catch (e) {} } catch (e) {
}
PageThumbs.addExpirationFilter(this); PageThumbs.addExpirationFilter(this);
gBrowser.addTabsProgressListener(this); gBrowser.addTabsProgressListener(this);
@ -56,8 +58,9 @@ var gBrowserThumbnails = {
uninit: function() { uninit: function() {
// Bug 863512 - Make page thumbnails work in electrolysis // Bug 863512 - Make page thumbnails work in electrolysis
if (gMultiProcessBrowser) if (gMultiProcessBrowser) {
return; return;
}
PageThumbs.removeExpirationFilter(this); PageThumbs.removeExpirationFilter(this);
gBrowser.removeTabsProgressListener(this); gBrowser.removeTabsProgressListener(this);
@ -72,8 +75,9 @@ var gBrowserThumbnails = {
switch (aEvent.type) { switch (aEvent.type) {
case "scroll": case "scroll":
let browser = aEvent.currentTarget; let browser = aEvent.currentTarget;
if (this._timeouts.has(browser)) if (this._timeouts.has(browser)) {
this._delayedCapture(browser); this._delayedCapture(browser);
}
break; break;
case "TabSelect": case "TabSelect":
this._delayedCapture(aEvent.target.linkedBrowser); this._delayedCapture(aEvent.target.linkedBrowser);
@ -106,20 +110,23 @@ var gBrowserThumbnails = {
onStateChange: function(aBrowser, aWebProgress, onStateChange: function(aBrowser, aWebProgress,
aRequest, aStateFlags, aStatus) { aRequest, aStateFlags, aStatus) {
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
this._delayedCapture(aBrowser); this._delayedCapture(aBrowser);
}
}, },
_capture: function(aBrowser) { _capture: function(aBrowser) {
if (this._shouldCapture(aBrowser)) if (this._shouldCapture(aBrowser)) {
PageThumbs.captureAndStore(aBrowser); PageThumbs.captureAndStore(aBrowser);
}
}, },
_delayedCapture: function(aBrowser) { _delayedCapture: function(aBrowser) {
if (this._timeouts.has(aBrowser)) if (this._timeouts.has(aBrowser)) {
clearTimeout(this._timeouts.get(aBrowser)); clearTimeout(this._timeouts.get(aBrowser));
else } else {
aBrowser.addEventListener("scroll", this, true); aBrowser.addEventListener("scroll", this, true);
}
let timeout = setTimeout(function() { let timeout = setTimeout(function() {
this._clearTimeout(aBrowser); this._clearTimeout(aBrowser);
@ -131,50 +138,60 @@ var gBrowserThumbnails = {
_shouldCapture: function(aBrowser) { _shouldCapture: function(aBrowser) {
// Capture only if it's the currently selected tab. // Capture only if it's the currently selected tab.
if (aBrowser != gBrowser.selectedBrowser) if (aBrowser != gBrowser.selectedBrowser) {
return false; return false;
}
// Don't capture in per-window private browsing mode. // Don't capture in per-window private browsing mode.
if (PrivateBrowsingUtils.isWindowPrivate(window)) if (PrivateBrowsingUtils.isWindowPrivate(window)) {
return false; return false;
}
let doc = aBrowser.contentDocument; let doc = aBrowser.contentDocument;
// FIXME Bug 720575 - Don't capture thumbnails for SVG or XML documents as // FIXME Bug 720575 - Don't capture thumbnails for SVG or XML documents as
// that currently regresses Talos SVG tests. // that currently regresses Talos SVG tests.
if (doc instanceof XMLDocument) if (doc instanceof XMLDocument) {
return false; return false;
}
// There's no point in taking screenshot of loading pages. // There's no point in taking screenshot of loading pages.
if (aBrowser.docShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) if (aBrowser.docShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) {
return false; return false;
}
// Don't take screenshots of about: pages. // Don't take screenshots of about: pages.
if (aBrowser.currentURI.schemeIs("about")) if (aBrowser.currentURI.schemeIs("about")) {
return false; return false;
}
let channel = aBrowser.docShell.currentDocumentChannel; let channel = aBrowser.docShell.currentDocumentChannel;
// No valid document channel. We shouldn't take a screenshot. // No valid document channel. We shouldn't take a screenshot.
if (!channel) if (!channel) {
return false; return false;
}
// Don't take screenshots of internally redirecting about: pages. // Don't take screenshots of internally redirecting about: pages.
// This includes error pages. // This includes error pages.
let uri = channel.originalURI; let uri = channel.originalURI;
if (uri.schemeIs("about")) if (uri.schemeIs("about")) {
return false; return false;
}
let httpChannel; let httpChannel;
try { try {
httpChannel = channel.QueryInterface(Ci.nsIHttpChannel); httpChannel = channel.QueryInterface(Ci.nsIHttpChannel);
} catch (e) { /* Not an HTTP channel. */ } } catch (e) {
// Not an HTTP channel.
}
if (httpChannel) { if (httpChannel) {
// Continue only if we have a 2xx status code. // Continue only if we have a 2xx status code.
try { try {
if (Math.floor(httpChannel.responseStatus / 100) != 2) if (Math.floor(httpChannel.responseStatus / 100) != 2) {
return false; return false;
}
} catch (e) { } catch (e) {
// Can't get response information from the httpChannel // Can't get response information from the httpChannel
// because mResponseHead is not available. // because mResponseHead is not available.
@ -182,12 +199,14 @@ var gBrowserThumbnails = {
} }
// Cache-Control: no-store. // Cache-Control: no-store.
if (httpChannel.isNoStoreResponse()) if (httpChannel.isNoStoreResponse()) {
return false; return false;
}
// Don't capture HTTPS pages unless the user explicitly enabled it. // Don't capture HTTPS pages unless the user explicitly enabled it.
if (uri.schemeIs("https") && !this._sslDiskCacheEnabled) if (uri.schemeIs("https") && !this._sslDiskCacheEnabled) {
return false; return false;
}
} }
return true; return true;

View file

@ -5,7 +5,7 @@
var WebrtcIndicator = { var WebrtcIndicator = {
init: function () { init: function () {
let temp = {}; let temp = { };
Cu.import("resource:///modules/webrtcUI.jsm", temp); Cu.import("resource:///modules/webrtcUI.jsm", temp);
this.UIModule = temp.webrtcUI; this.UIModule = temp.webrtcUI;
@ -35,14 +35,16 @@ var WebrtcIndicator = {
}, },
clearPopup: function (aPopup) { clearPopup: function (aPopup) {
while (aPopup.lastChild) while (aPopup.lastChild) {
aPopup.removeChild(aPopup.lastChild); aPopup.removeChild(aPopup.lastChild);
}
}, },
menuCommand: function (aMenuitem) { menuCommand: function (aMenuitem) {
let streamData = this._menuitemData.get(aMenuitem); let streamData = this._menuitemData.get(aMenuitem);
if (!streamData) if (!streamData) {
return; return;
}
let browserWindow = streamData.browser.ownerDocument.defaultView; let browserWindow = streamData.browser.ownerDocument.defaultView;
if (streamData.tab) { if (streamData.tab) {