[Pale-Moon] Issue #1737 - Format some Windows specific browser jsm modules

This commit is contained in:
Moonchild 2021-02-17 22:55:22 +00:00 • committed by roytam1
commit 62df9eb775
2 changed files with 99 additions and 70 deletions

View file

@ -149,18 +149,18 @@ this.WinTaskbarJumpList =
*/ */
startup: function() { startup: function() {
// exit if this isn't win7 or higher. // Exit if there's something wrong with getting the taskbar service.
if (!this._initTaskbar()) if (!this._initTaskbar()) {
return; return;
}
// Win shell shortcut maintenance. If we've gone through an update, // Win shell shortcut maintenance. If we've gone through an update,
// this will update any pinned taskbar shortcuts. Not specific to // this will update any pinned taskbar shortcuts. Not specific to
// jump lists, but this was a convienent place to call it. // jump lists, but this was a convienent place to call it.
try { try {
// dev builds may not have helper.exe, ignore failures. // builds may not have helper.exe, ignore failures.
this._shortcutMaintenance(); this._shortcutMaintenance();
} catch (ex) { } catch(ex) {}
}
// Store our task list config data // Store our task list config data
this._tasks = tasksCfg; this._tasks = tasksCfg;
@ -177,8 +177,9 @@ this.WinTaskbarJumpList =
update: function() { update: function() {
// are we disabled via prefs? don't do anything! // are we disabled via prefs? don't do anything!
if (!this._enabled) if (!this._enabled) {
return; return;
}
// do what we came here to do, update the taskbar jumplist // do what we came here to do, update the taskbar jumplist
this._buildList(); this._buildList();
@ -235,18 +236,22 @@ this.WinTaskbarJumpList =
return; return;
} }
if (!this._startBuild()) if (!this._startBuild()) {
return; return;
}
if (this._showTasks) if (this._showTasks) {
this._buildTasks(); this._buildTasks();
}
// Space for frequent items takes priority over recent. // Space for frequent items takes priority over recent.
if (this._showFrequent) if (this._showFrequent) {
this._buildFrequent(); this._buildFrequent();
}
if (this._showRecent) if (this._showRecent) {
this._buildRecent(); this._buildRecent();
}
this._commitBuild(); this._commitBuild();
}, },
@ -256,8 +261,8 @@ this.WinTaskbarJumpList =
*/ */
_startBuild: function() { _startBuild: function() {
var removedItems = Cc["@mozilla.org/array;1"]. var removedItems = Cc["@mozilla.org/array;1"]
createInstance(Ci.nsIMutableArray); .createInstance(Ci.nsIMutableArray);
this._builder.abortListBuild(); this._builder.abortListBuild();
if (this._builder.initListBuild(removedItems)) { if (this._builder.initListBuild(removedItems)) {
// Prior to building, delete removed items from history. // Prior to building, delete removed items from history.
@ -277,20 +282,24 @@ this.WinTaskbarJumpList =
var items = Cc["@mozilla.org/array;1"]. var items = Cc["@mozilla.org/array;1"].
createInstance(Ci.nsIMutableArray); createInstance(Ci.nsIMutableArray);
this._tasks.forEach(function(task) { this._tasks.forEach(function(task) {
if ((this._shuttingDown && !task.close) || (!this._shuttingDown && !task.open)) if ((this._shuttingDown && !task.close) ||
(!this._shuttingDown && !task.open)) {
return; return;
}
var item = this._getHandlerAppItem(task.title, task.description, var item = this._getHandlerAppItem(task.title, task.description,
task.args, task.iconIndex, null); task.args, task.iconIndex, null);
items.appendElement(item, false); items.appendElement(item, false);
}, this); }, this);
if (items.length > 0) if (items.length > 0) {
this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_TASKS, items); this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_TASKS, items);
}
}, },
_buildCustom: function(title, items) { _buildCustom: function(title, items) {
if (items.length > 0) if (items.length > 0) {
this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_CUSTOMLIST, items, title); this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_CUSTOMLIST, items, title);
}
}, },
_buildFrequent: function() { _buildFrequent: function() {
@ -329,8 +338,7 @@ this.WinTaskbarJumpList =
items.appendElement(shortcut, false); items.appendElement(shortcut, false);
this._frequentHashList.push(aResult.uri); this._frequentHashList.push(aResult.uri);
}, },
this this);
);
}, },
_buildRecent: function() { _buildRecent: function() {
@ -374,8 +382,7 @@ this.WinTaskbarJumpList =
items.appendElement(shortcut, false); items.appendElement(shortcut, false);
count++; count++;
}, },
this this);
);
}, },
_deleteActiveJumpList: function() { _deleteActiveJumpList: function() {
@ -386,22 +393,25 @@ this.WinTaskbarJumpList =
* Jump list item creation helpers * Jump list item creation helpers
*/ */
_getHandlerAppItem: function(name, description, _getHandlerAppItem: function(name,
args, iconIndex, description,
faviconPageUri) { args,
iconIndex,
faviconPageUri) {
var file = Services.dirsvc.get("XREExeF", Ci.nsILocalFile); var file = Services.dirsvc.get("XREExeF", Ci.nsILocalFile);
var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]. var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
createInstance(Ci.nsILocalHandlerApp); createInstance(Ci.nsILocalHandlerApp);
handlerApp.executable = file; handlerApp.executable = file;
// handlers default to the leaf name if a name is not specified // handlers default to the leaf name if a name is not specified
if (name && name.length != 0) if (name && name.length != 0) {
handlerApp.name = name; handlerApp.name = name;
}
handlerApp.detailedDescription = description; handlerApp.detailedDescription = description;
handlerApp.appendParameter(args); handlerApp.appendParameter(args);
var item = Cc["@mozilla.org/windows-jumplistshortcut;1"]. var item = Cc["@mozilla.org/windows-jumplistshortcut;1"]
createInstance(Ci.nsIJumpListShortcut); .createInstance(Ci.nsIJumpListShortcut);
item.app = handlerApp; item.app = handlerApp;
item.iconIndex = iconIndex; item.iconIndex = iconIndex;
item.faviconPageUri = faviconPageUri; item.faviconPageUri = faviconPageUri;
@ -409,8 +419,8 @@ this.WinTaskbarJumpList =
}, },
_getSeparatorItem: function() { _getSeparatorItem: function() {
var item = Cc["@mozilla.org/windows-jumplistseparator;1"]. var item = Cc["@mozilla.org/windows-jumplistseparator;1"]
createInstance(Ci.nsIJumpListSeparator); .createInstance(Ci.nsIJumpListSeparator);
return item; return item;
}, },
@ -449,8 +459,9 @@ this.WinTaskbarJumpList =
}, },
_clearHistory: function(items) { _clearHistory: function(items) {
if (!items) if (!items) {
return; return;
}
var URIsToRemove = []; var URIsToRemove = [];
var e = items.enumerate(); var e = items.enumerate();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
@ -459,7 +470,7 @@ this.WinTaskbarJumpList =
try { // in case we get a bad uri try { // in case we get a bad uri
let uriSpec = oldItem.app.getParameter(0); let uriSpec = oldItem.app.getParameter(0);
URIsToRemove.push(NetUtil.newURI(uriSpec)); URIsToRemove.push(NetUtil.newURI(uriSpec));
} catch (err) { } } catch(err) {}
} }
} }
if (URIsToRemove.length > 0) { if (URIsToRemove.length > 0) {
@ -512,8 +523,7 @@ this.WinTaskbarJumpList =
this._timer.initWithCallback(this, this._timer.initWithCallback(this,
_prefs.getIntPref(PREF_TASKBAR_REFRESH)*1000, _prefs.getIntPref(PREF_TASKBAR_REFRESH)*1000,
this._timer.TYPE_REPEATING_SLACK); this._timer.TYPE_REPEATING_SLACK);
} } else if ((!this._enabled || this._shuttingDown) && this._timer) {
else if ((!this._enabled || this._shuttingDown) && this._timer) {
this._timer.cancel(); this._timer.cancel();
delete this._timer; delete this._timer;
} }
@ -524,8 +534,7 @@ this.WinTaskbarJumpList =
if (this._enabled && !this._shuttingDown && !this._hasIdleObserver) { if (this._enabled && !this._shuttingDown && !this._hasIdleObserver) {
_idle.addIdleObserver(this, IDLE_TIMEOUT_SECONDS); _idle.addIdleObserver(this, IDLE_TIMEOUT_SECONDS);
this._hasIdleObserver = true; this._hasIdleObserver = true;
} } else if ((!this._enabled || this._shuttingDown) && this._hasIdleObserver) {
else if ((!this._enabled || this._shuttingDown) && this._hasIdleObserver) {
_idle.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS); _idle.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS);
this._hasIdleObserver = false; this._hasIdleObserver = false;
} }
@ -551,31 +560,32 @@ this.WinTaskbarJumpList =
observe: function(aSubject, aTopic, aData) { observe: function(aSubject, aTopic, aData) {
switch (aTopic) { switch (aTopic) {
case "nsPref:changed": case "nsPref:changed":
if (this._enabled == true && !_prefs.getBoolPref(PREF_TASKBAR_ENABLED)) if (this._enabled == true && !_prefs.getBoolPref(PREF_TASKBAR_ENABLED)) {
this._deleteActiveJumpList(); this._deleteActiveJumpList();
}
this._refreshPrefs(); this._refreshPrefs();
this._updateTimer(); this._updateTimer();
this._updateIdleObserver(); this._updateIdleObserver();
this.update(); this.update();
break; break;
case "profile-before-change": case "profile-before-change":
this._shutdown(); this._shutdown();
break; break;
case "browser:purge-session-history": case "browser:purge-session-history":
this.update(); this.update();
break; break;
case "idle": case "idle":
if (this._timer) { if (this._timer) {
this._timer.cancel(); this._timer.cancel();
delete this._timer; delete this._timer;
} }
break; break;
case "back": case "back":
this._updateTimer(); this._updateTimer();
break; break;
} }
}, },
}; };

View file

@ -82,13 +82,14 @@ function _imageFromURI(uri, privateMode, callback) {
// Ignore channels which do not support nsIPrivateBrowsingChannel // Ignore channels which do not support nsIPrivateBrowsingChannel
} }
NetUtil.asyncFetch(channel, function(inputStream, resultCode) { NetUtil.asyncFetch(channel, function(inputStream, resultCode) {
if (!Components.isSuccessCode(resultCode)) if (!Components.isSuccessCode(resultCode)) {
return; return;
}
try { try {
let out_img = { value: null }; let out_img = { value: null };
imgTools.decodeImageData(inputStream, channel.contentType, out_img); imgTools.decodeImageData(inputStream, channel.contentType, out_img);
callback(out_img.value); callback(out_img.value);
} catch (e) { } catch(e) {
// We failed, so use the default favicon (only if this wasn't the default // We failed, so use the default favicon (only if this wasn't the default
// favicon). // favicon).
let defaultURI = PlacesUtils.favicons.defaultFavicon; let defaultURI = PlacesUtils.favicons.defaultFavicon;
@ -211,7 +212,7 @@ PreviewController.prototype = {
testCacheBrowserDims: function () { testCacheBrowserDims: function () {
let dims = this.browserDims; let dims = this.browserDims;
return this._cachedWidth == dims.width && return this._cachedWidth == dims.width &&
this._cachedHeight == dims.height; this._cachedHeight == dims.height;
}, },
/** /**
@ -343,10 +344,10 @@ PreviewController.prototype = {
XPCOMUtils.defineLazyGetter(PreviewController.prototype, "canvasPreviewFlags", XPCOMUtils.defineLazyGetter(PreviewController.prototype, "canvasPreviewFlags",
function () { let canvasInterface = Ci.nsIDOMCanvasRenderingContext2D; function () { let canvasInterface = Ci.nsIDOMCanvasRenderingContext2D;
return canvasInterface.DRAWWINDOW_DRAW_VIEW return canvasInterface.DRAWWINDOW_DRAW_VIEW |
| canvasInterface.DRAWWINDOW_DRAW_CARET canvasInterface.DRAWWINDOW_DRAW_CARET |
| canvasInterface.DRAWWINDOW_ASYNC_DECODE_IMAGES canvasInterface.DRAWWINDOW_ASYNC_DECODE_IMAGES |
| canvasInterface.DRAWWINDOW_DO_NOT_FLUSH; canvasInterface.DRAWWINDOW_DO_NOT_FLUSH;
}); });
// TabWindow // TabWindow
@ -363,18 +364,21 @@ function TabWindow(win) {
this.previews = new Map(); this.previews = new Map();
for (let i = 0; i < this.tabEvents.length; i++) for (let i = 0; i < this.tabEvents.length; i++) {
this.tabbrowser.tabContainer.addEventListener(this.tabEvents[i], this, false); this.tabbrowser.tabContainer.addEventListener(this.tabEvents[i], this, false);
}
for (let i = 0; i < this.winEvents.length; i++) for (let i = 0; i < this.winEvents.length; i++) {
this.win.addEventListener(this.winEvents[i], this, false); this.win.addEventListener(this.winEvents[i], this, false);
}
this.tabbrowser.addTabsProgressListener(this); this.tabbrowser.addTabsProgressListener(this);
AeroPeek.windows.push(this); AeroPeek.windows.push(this);
let tabs = this.tabbrowser.tabs; let tabs = this.tabbrowser.tabs;
for (let i = 0; i < tabs.length; i++) for (let i = 0; i < tabs.length; i++) {
this.newTab(tabs[i]); this.newTab(tabs[i]);
}
this.updateTabOrdering(); this.updateTabOrdering();
AeroPeek.checkPreviewCount(); AeroPeek.checkPreviewCount();
@ -394,14 +398,17 @@ TabWindow.prototype = {
this.tabbrowser.removeTabsProgressListener(this); this.tabbrowser.removeTabsProgressListener(this);
for (let i = 0; i < this.winEvents.length; i++) for (let i = 0; i < this.winEvents.length; i++) {
this.win.removeEventListener(this.winEvents[i], this, false); this.win.removeEventListener(this.winEvents[i], this, false);
}
for (let i = 0; i < this.tabEvents.length; i++) for (let i = 0; i < this.tabEvents.length; i++) {
this.tabbrowser.tabContainer.removeEventListener(this.tabEvents[i], this, false); this.tabbrowser.tabContainer.removeEventListener(this.tabEvents[i], this, false);
}
for (let i = 0; i < tabs.length; i++) for (let i = 0; i < tabs.length; i++) {
this.removeTab(tabs[i]); this.removeTab(tabs[i]);
}
let idx = AeroPeek.windows.indexOf(this.win.gTaskbarTabGroup); let idx = AeroPeek.windows.indexOf(this.win.gTaskbarTabGroup);
AeroPeek.windows.splice(idx, 1); AeroPeek.windows.splice(idx, 1);
@ -411,6 +418,7 @@ TabWindow.prototype = {
get width () { get width () {
return this.win.innerWidth; return this.win.innerWidth;
}, },
get height () { get height () {
return this.win.innerHeight; return this.win.innerHeight;
}, },
@ -421,7 +429,8 @@ TabWindow.prototype = {
}, },
testCacheDims: function () { testCacheDims: function () {
return this._cachedWidth == this.width && this._cachedHeight == this.height; return this._cachedWidth == this.width &&
this._cachedHeight == this.height;
}, },
// Invoked when the given tab is added to this window // Invoked when the given tab is added to this window
@ -437,9 +446,9 @@ TabWindow.prototype = {
createTabPreview: function (controller) { createTabPreview: function (controller) {
let docShell = this.win let docShell = this.win
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation) .getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell); .QueryInterface(Ci.nsIDocShell);
let preview = AeroPeek.taskbar.createTaskbarTabPreview(docShell, controller); let preview = AeroPeek.taskbar.createTaskbarTabPreview(docShell, controller);
preview.visible = AeroPeek.enabled; preview.visible = AeroPeek.enabled;
preview.active = this.tabbrowser.selectedTab == controller.tab; preview.active = this.tabbrowser.selectedTab == controller.tab;
@ -466,9 +475,8 @@ TabWindow.prototype = {
set enabled (enable) { set enabled (enable) {
this._enabled = enable; this._enabled = enable;
// Because making a tab visible requires that the tab it is next to be // Because making a tab visible requires the tab it is next to be visible,
// visible, it is far simpler to unset the 'next' tab and recreate them all // it is far simpler to unset the 'next' tab and recreate them all at once.
// at once.
for (let [, preview] of this.previews) { for (let [, preview] of this.previews) {
preview.move(null); preview.move(null);
preview.visible = enable; preview.visible = enable;
@ -521,8 +529,9 @@ TabWindow.prototype = {
this.updateTabOrdering(); this.updateTabOrdering();
break; break;
case "resize": case "resize":
if (!AeroPeek._prefenabled) if (!AeroPeek._prefenabled) {
return; return;
}
this.onResize(); this.onResize();
break; break;
} }
@ -594,6 +603,7 @@ TabWindow.prototype = {
directRequestProtocols: new Set([ directRequestProtocols: new Set([
"file", "chrome", "resource", "about" "file", "chrome", "resource", "about"
]), ]),
onLinkIconAvailable: function (aBrowser, aIconURL) { onLinkIconAvailable: function (aBrowser, aIconURL) {
let self = this; let self = this;
let requestURL = null; let requestURL = null;
@ -603,7 +613,7 @@ TabWindow.prototype = {
let urlObject = NetUtil.newURI(aIconURL); let urlObject = NetUtil.newURI(aIconURL);
shouldRequestFaviconURL = shouldRequestFaviconURL =
!this.directRequestProtocols.has(urlObject.scheme); !this.directRequestProtocols.has(urlObject.scheme);
} catch (ex) {} } catch(ex) {}
requestURL = shouldRequestFaviconURL ? requestURL = shouldRequestFaviconURL ?
"moz-anno:favicon:" + aIconURL : "moz-anno:favicon:" + aIconURL :
@ -662,12 +672,14 @@ this.AeroPeek = {
cacheLifespan: 20, cacheLifespan: 20,
initialize: function () { initialize: function () {
if (!(WINTASKBAR_CONTRACTID in Cc)) if (!(WINTASKBAR_CONTRACTID in Cc)) {
return; return;
}
this.taskbar = Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar); this.taskbar = Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar);
this.available = this.taskbar.available; this.available = this.taskbar.available;
if (!this.available) if (!this.available) {
return; return;
}
this.prefs.addObserver(TOGGLE_PREF_NAME, this, true); this.prefs.addObserver(TOGGLE_PREF_NAME, this, true);
this.enabled = this._prefenabled = this.prefs.getBoolPref(TOGGLE_PREF_NAME); this.enabled = this._prefenabled = this.prefs.getBoolPref(TOGGLE_PREF_NAME);
@ -677,8 +689,9 @@ this.AeroPeek = {
destroy: function destroy() { destroy: function destroy() {
this._enabled = false; this._enabled = false;
if (this.cacheTimer) if (this.cacheTimer) {
this.cacheTimer.cancel(); this.cacheTimer.cancel();
}
}, },
get enabled() { get enabled() {
@ -686,8 +699,9 @@ this.AeroPeek = {
}, },
set enabled(enable) { set enabled(enable) {
if (this._enabled == enable) if (this._enabled == enable) {
return; return;
}
this._enabled = enable; this._enabled = enable;
@ -771,22 +785,25 @@ this.AeroPeek = {
onOpenWindow: function (win) { onOpenWindow: function (win) {
// This occurs when the taskbar service is not available (xp, vista) // This occurs when the taskbar service is not available (xp, vista)
if (!this.available || !this._prefenabled) if (!this.available || !this._prefenabled) {
return; return;
}
win.gTaskbarTabGroup = new TabWindow(win); win.gTaskbarTabGroup = new TabWindow(win);
}, },
onCloseWindow: function (win) { onCloseWindow: function (win) {
// This occurs when the taskbar service is not available (xp, vista) // This occurs when the taskbar service is not available (xp, vista)
if (!this.available || !this._prefenabled) if (!this.available || !this._prefenabled) {
return; return;
}
win.gTaskbarTabGroup.destroy(); win.gTaskbarTabGroup.destroy();
delete win.gTaskbarTabGroup; delete win.gTaskbarTabGroup;
if (this.windows.length == 0) if (this.windows.length == 0) {
this.destroy(); this.destroy();
}
}, },
resetCacheTimer: function () { resetCacheTimer: function () {
@ -804,11 +821,13 @@ this.AeroPeek = {
} }
switch (aTopic) { switch (aTopic) {
case "nsPref:changed": case "nsPref:changed":
if (aData == CACHE_EXPIRATION_TIME_PREF_NAME) if (aData == CACHE_EXPIRATION_TIME_PREF_NAME) {
break; break;
}
if (aData == DISABLE_THRESHOLD_PREF_NAME) if (aData == DISABLE_THRESHOLD_PREF_NAME) {
this.maxpreviews = this.prefs.getIntPref(DISABLE_THRESHOLD_PREF_NAME); this.maxpreviews = this.prefs.getIntPref(DISABLE_THRESHOLD_PREF_NAME);
}
// Might need to enable/disable ourselves // Might need to enable/disable ourselves
this.checkPreviewCount(); this.checkPreviewCount();
break; break;