The Mother Of All Download Landings, Phase I

http://bugzilla.mozilla.org/show_bug.cgi?id=214259
Firebird Download System Upgrades.

components/prefwindow/content/nsPrefWindow.js
components/prefwindow/content/pref.xul
- Update PrefWindow to handle Queued tags better so it does not display until
  properly loaded.
This commit is contained in:
ben%bengoodger.com 2003-08-04 22:40:43 +00:00
Родитель 6113d67545
Коммит e88418ef93
5 изменённых файлов: 371 добавлений и 33 удалений

Просмотреть файл

@ -27,12 +27,15 @@ const _DEBUG = false;
**/
var queuedTag;
function initPanel ( aPrefTag )
var queuedWindow;
function initPanel ( aPrefTag, aWindow )
{
if( hPrefWindow )
hPrefWindow.onpageload( aPrefTag )
else
hPrefWindow.onpageload( aPrefTag, aWindow )
else {
queuedTag = aPrefTag;
queuedWindow = aWindow;
}
}
window.doneLoading = false;
@ -75,7 +78,7 @@ nsPrefWindow.prototype =
{
if( window.queuedTag )
{
this.onpageload( window.queuedTag );
this.onpageload( window.queuedTag, window.queuedWindow );
}
},
@ -87,7 +90,7 @@ nsPrefWindow.prototype =
{
tag = document.getElementById( hPrefWindow.contentFrame ).getAttribute("src");
}
hPrefWindow.wsm.savePageData( tag );
hPrefWindow.wsm.savePageData( tag, null );
for( var i = 0; i < hPrefWindow.okHandlers.length; i++ )
{
hPrefWindow.okHandlers[i]();
@ -279,7 +282,7 @@ nsPrefWindow.prototype =
{
oldURL = document.getElementById( this.contentFrame ).getAttribute("src");
}
this.wsm.savePageData( oldURL ); // save data from the current page.
this.wsm.savePageData( oldURL, null ); // save data from the current page.
if( aNewURL != oldURL )
{
document.getElementById( this.contentFrame ).setAttribute( "src", aNewURL );
@ -291,14 +294,23 @@ nsPrefWindow.prototype =
},
onpageload:
function ( aPageTag )
function ( aPageTag, aWindow )
{
var header = document.getElementById("header");
header.setAttribute("title",
window.frames[this.contentFrame].document.documentElement.getAttribute("headertitle"));
if (!aWindow)
aWindow = window.frames[this.contentFrame];
// Only update the header title for panels that are loaded in the main dialog,
// not sub-dialogs. (Removing this check will cause the header display area to
// be cleared whenever you open a sub-dialog that uses WSM)
if (aWindow == window.frames[this.contentFrame]) {
var header = document.getElementById("header");
header.setAttribute("title",
aWindow.document.documentElement.getAttribute("headertitle"));
}
if( !(aPageTag in this.wsm.dataManager.pageData) )
{
var prefElements = window.frames[this.contentFrame].document.getElementsByAttribute( "prefstring", "*" );
var prefElements = aWindow.document.getElementsByAttribute( "prefstring", "*" );
this.wsm.dataManager.pageData[aPageTag] = [];
for( var i = 0; i < prefElements.length; i++ )
{
@ -337,11 +349,11 @@ nsPrefWindow.prototype =
root.localname = prefElements[i].localName;
}
}
this.wsm.setPageData( aPageTag ); // do not set extra elements, accept hard coded defaults
this.wsm.setPageData( aPageTag, aWindow ); // do not set extra elements, accept hard coded defaults
if( 'Startup' in window.frames[ this.contentFrame ])
if( 'Startup' in aWindow)
{
window.frames[ this.contentFrame ].Startup();
aWindow.Startup();
}
this.wsm.dataManager.pageData[aPageTag].initialized=true;
}

Просмотреть файл

@ -0,0 +1,257 @@
var gPluginTypes = null;
var gPluginTypesList = null;
var gPrefs = null;
const kDisabledPluginTypesPref = "browser.download.pluginOverrideTypes";
const kPluginHandlerContractID = "@mozilla.org/content/plugin/document-loader-factory;1";
function init()
{
gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
gPluginTypes = new PluginTypes();
// Initialize the File Type list
gPluginTypesList = document.getElementById("pluginTypesList");
gPluginTypesList.treeBoxObject.view = gPluginTypes;
var x = document.documentElement.getAttribute("screenX");
if (x == "")
setTimeout("centerOverParent()", 0);
}
// This should actually go into some sort of pref fe utilities file.
function centerOverParent()
{
var parent = window.opener;
x = parent.screenX + (parent.outerWidth / 2) - (window.outerWidth / 2);
y = parent.screenY + (parent.outerHeight / 2) - (window.outerHeight / 2);
window.moveTo(x, y);
}
function onAccept()
{
var catman = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
// Update the disabled plugin types pref and the category manager.
var disabled = "";
for (var i = 0; i < gPluginTypes._pluginTypes.length; ++i) {
var currType = gPluginTypes._pluginTypes[i];
if (!currType.pluginEnabled) {
for (var j = 0; j < currType.MIMETypes.length; ++j) {
disabled += currType.MIMETypes[j] + ",";
catman.deleteCategoryEntry("Gecko-Content-Viewers", currType.MIMETypes[j], false);
}
}
else {
// We could have re-activated a deactivated Plugin handler, add all the handlers back again,
// replacing the existing ones.
for (j = 0; j < currType.MIMETypes.length; ++j)
catman.addCategoryEntry("Gecko-Content-Viewers", currType.MIMETypes[j],
kPluginHandlerContractID, false, true);
}
}
if (disabled != "") {
disabled = disabled.substr(0, disabled.length - 1);
gPrefs.setCharPref(kDisabledPluginTypesPref, disabled);
}
else if (gPrefs.prefHasUserValue(kDisabledPluginTypesPref)) {
// Clear the pref if we've restored plugin functionality to all
// listed types.
gPrefs.clearUserPref(kDisabledPluginTypesPref);
}
}
function PluginType (aPluginEnabled, aMIMEInfo)
{
this.pluginEnabled = aPluginEnabled;
this.MIMEInfo = aMIMEInfo;
this.MIMETypes = [this.MIMEInfo.MIMEType];
}
function PluginTypes()
{
var atomSvc = Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService);
this._enabledAtom = atomSvc.getAtom("enabled");
this._pluginTypes = [];
this._pluginTypeHash = { };
// Read enabled plugin type information from the category manager
var catman = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
var types = catman.enumerateCategory("Gecko-Content-Viewers");
while (types.hasMoreElements()) {
var currType = types.getNext().QueryInterface(Components.interfaces.nsISupportsCString).data;
var contractid = catman.getCategoryEntry("Gecko-Content-Viewers", currType);
if (contractid == kPluginHandlerContractID)
this.addType(currType, true);
}
// Read disabled plugin type information from preferences
try {
var types = gPrefs.getCharPref(kDisabledPluginTypesPref);
var disabledTypes = types.split(",");
for (var i = 0; i < disabledTypes.length; ++i)
this.addType(disabledTypes[i], false);
}
catch (e) { }
this._pluginTypes.sort(this.sortCallback);
}
PluginTypes.prototype = {
addType: function (aMIMEType, aPluginEnabled)
{
var mimeInfo = this.getMIMEInfoForType(aMIMEType);
if (mimeInfo) {
// We only want to show one entry per extension, even if several MIME
// types map to that extension, e.g. audio/wav, audio/x-wav. Hash the
// primary extension for the type to prevent duplicates. If we encounter
// a duplicate, record the additional MIME type so we know to deactivate
// support for it too if the user deactivates support for the extension.
if (!(mimeInfo.primaryExtension in this._pluginTypeHash)) {
var pluginType = new PluginType(aPluginEnabled, mimeInfo);
this._pluginTypeHash[mimeInfo.primaryExtension] = pluginType;
this._pluginTypes.push(pluginType);
}
else {
// Append this MIME type to the list of MIME types for the extension.
var pluginType = this._pluginTypeHash[mimeInfo.primaryExtension];
pluginType.MIMETypes.push(mimeInfo.MIMEType);
}
}
},
sortCallback: function (a, b)
{
var ac = a.MIMEInfo.primaryExtension.toLowerCase();
var bc = b.MIMEInfo.primaryExtension.toLowerCase();
if (ac < bc)
return -1;
else if (ac > bc)
return 1;
return 0;
},
#if 0
sortAscending: true,
sortCallback: function (a, b)
{
var ac = gPluginTypes.getSortProperty(a);
var bc = gPluginTypes.getSortProperty(b);
if (ac < bc)
return gPluginTypes.sortAscending ? -1 : 1;
else if (ac > bc)
return gPluginTypes.sortAscending ? 1 : -1;
return 0;
},
sortProperty: "fileExtension",
getSortProperty: function (aObject)
{
switch (sortProperty) {
case "fileExtension":
return aObject.MIMEInfo.primaryExtension.toLowerCase();
case "fileType":
var desc = aObject.MIMEInfo.Description;
// XXXben localize
return desc || aObject.MIMEInfo.primaryExtension.toUpperCase() + " file";
case "pluginEnabled":
return aObject.pluginEnabled;
}
return null;
},
#endif
getMIMEInfoForType: function (aType)
{
try {
var mimeSvc = Components.classes["@mozilla.org/mime;1"].getService(Components.interfaces.nsIMIMEService);
return mimeSvc.GetFromTypeAndExtension(aType, "");
}
catch (e) { }
return null;
},
// nsITreeView
get rowCount()
{
return this._pluginTypes.length;
},
getCellProperties: function (aRow, aCol, aProperties)
{
if (aCol == "pluginEnabled") {
if (this._pluginTypes[aRow].pluginEnabled)
aProperties.AppendElement(this._enabledAtom);
}
},
getImageSrc: function (aRow, aCol)
{
if (aCol == "fileExtension")
return "moz-icon://goat." + this._pluginTypes[aRow].MIMEInfo.primaryExtension + "?size=16";
return null;
},
getCellText: function (aRow, aCol)
{
var mimeInfo = this._pluginTypes[aRow].MIMEInfo;
if (aCol == "fileType") {
var desc = mimeInfo.Description;
// XXXben localize
return desc || mimeInfo.primaryExtension.toUpperCase() + " file";
}
else if (aCol == "fileExtension")
return mimeInfo.primaryExtension.toUpperCase();
return "";
},
cycleCell: function (aRow, aCol)
{
if (aCol == "pluginEnabled") {
this._pluginTypes[aRow].pluginEnabled = !this._pluginTypes[aRow].pluginEnabled;
gPluginTypesList.treeBoxObject.invalidateCell(aRow, aCol);
}
},
selection: null,
// Stuff we don't need...
isContainer: function (aRow) { return false; },
isContainerOpen: function (aRow) { return false; },
isContainerEmpty: function (aRow) { return true; },
isSeparator: function (aRow) { return false; },
isSorted: function () { return false; },
canDropOn: function (aRow) { return false; },
canDropBeforeAfter: function (aRow, aBefore) { return false; },
drop: function (aRow, aOrientation) { },
getParentIndex: function (aRow) { },
hasNextSibling: function (aRow, aNextIndex) { },
getLevel: function (aRow) { },
getProgressMode: function (aRow, aCol) { },
getCellValue: function (aRow, aCol) { },
setTree: function (aTree) { },
toggleOpenState: function (aRow) { },
cycleHeader: function (aCol, aColElt) { },
selectionChanged: function () { },
isEditable: function (aRow, aCol) { },
setCellText: function (aRow, aCol, aValue) { },
performAction: function (aAction) { },
performActionOnRow: function (aAction, aRow) { },
performActionOnCell: function (aAction, aRow, aCol) { },
getRowProperties: function (aRow, aProperties) { },
getColumnProperties: function (aCol, aColElt, aProperties) { }
};

Просмотреть файл

@ -0,0 +1,40 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/"?>
<?xml-stylesheet href="chrome://browser/skin/pref/pref.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://browser/locale/pref/plugins.dtd">
<dialog id="plugins" title="&plugins.title;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="init();" ondialogaccept="onAccept();" style="width: 30em;"
persist="screenX screenY">
<script type="application/x-javascript" src="chrome://browser/content/pref/plugins.js"/>
<description>&pluginInfo.label;</description>
<separator class="thin"/>
<tree id="pluginTypesList" flex="1" hidecolumnpicker="true" rows="10" seltype="single">
<treecols>
<treecol id="fileExtension"
class="sortDirectionIndicator pluginsList" persist="width"
label="&extensionsHeader.label;" />
<treecol id="fileType" flex="1"
class="sortDirectionIndicator" persist="width"
label="&typeHeader.label;"/>
<splitter class="tree-splitter" />
<treecol id="pluginEnabled" cycler="true"
class="sortDirectionIndicator" persist="width"
label="&enabledHeader.label;"/>
</treecols>
<treechildren class="pluginTypesChildren"/>
</tree>
<separator class="thin"/>
<description>&pluginInfo2.label;</description>
<separator/>
</dialog>

Просмотреть файл

@ -30,12 +30,6 @@
throw "failed to create prefwindow";
hPrefWindow.init();
var prefsCategories = document.getElementById("prefsCategories");
var index = prefsCategories.getAttribute("lastpanel") || 0;
var button = prefsCategories.childNodes[index];
button.click();
button.focus();
}
function Shutdown ()
@ -43,8 +37,9 @@
var prefsCategories = document.getElementById("prefsCategories");
for (var i = 0; i < prefsCategories.childNodes.length; ++i) {
if (prefsCategories.childNodes[i].checked) {
prefsCategories.setAttribute("lastpanel", i);
document.persist("prefsCategories", "lastpanel");
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
pref.setIntPref("browser.preferences.lastpanel", i);
break;
}
}
@ -54,10 +49,9 @@
function switchPage(aEvent)
{
var newURL = "chrome://browser/content/pref/" + aEvent.target.getAttribute("url");
var newTag = aEvent.target.getAttribute("tag");
var newURL = aEvent.target.getAttribute("url");
if (hPrefWindow)
hPrefWindow.switchPage(newURL, newTag);
hPrefWindow.switchPage(newURL, "");
}
function visitLink(aEvent)
@ -80,14 +74,19 @@
<script type="application/x-javascript" src="chrome://browser/content/pref/nsPrefWindow.js"/>
<hbox flex="1">
<vbox id="prefsCategories" class="listBox buttonBox" oncommand="switchPage(event);" orient="vertical" lastpanel="0" persist="lastpanel">
<button id="catGeneralButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&general.label;" url="pref-navigator.xul"/>
<button id="catPrivacyButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&privacy.label;" url="pref-privacy.xul"/>
<button id="catFeaturesbutton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&features.label;" url="pref-features.xul"/>
<button id="catThemesButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&themes.label;" url="pref-themes.xul"/>
<button id="catExtButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&ext.label;" url="pref-extensions.xul"/>
<button id="catFontsButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&fonts.label;" url="pref-fonts.xul"/>
<button id="catProxiesButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&proxies.label;" url="pref-connection.xul"/>
<vbox id="prefsCategories" class="listBox buttonBox" oncommand="switchPage(event);" orient="vertical" lastpanel="1" persist="lastpanel">
<button id="catGeneralButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&general.label;"
url="chrome://browser/content/pref/pref-navigator.xul"/>
<button id="catPrivacyButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&privacy.label;"
url="chrome://browser/content/pref/pref-privacy.xul"/>
<button id="catFeaturesbutton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&features.label;"
url="chrome://browser/content/pref/pref-features.xul"/>
<button id="catDownloadsButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&downloads.label;"
url="chrome://browser/content/pref/pref-downloads.xul"/>
<button id="catThemesButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&themes.label;"
url="chrome://browser/content/pref/pref-themes.xul"/>
<button id="catExtButton" orient="vertical" class="buttonBoxButton" type="radio" group="categories" label="&ext.label;"
url="chrome://browser/content/pref/pref-extensions.xul"/>
</vbox>
<vbox flex="1">
@ -96,6 +95,27 @@
</vbox>
</hbox>
<!-- sigh. this dirty little thing is necessary because the load handler of the
preferences dialog causes the window to be shown even though the preferences
panel itself hasn't finished loading. -->
<script type="application/x-javascript">
<![CDATA[
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var lastPanel = 0;
try {
lastPanel = pref.getIntPref("browser.preferences.lastpanel");
}
catch (e) {
}
var prefsCategories = document.getElementById("prefsCategories");
var button = prefsCategories.childNodes[lastPanel];
document.getElementById("panelFrame").setAttribute("src", button.getAttribute("url"));
button.focus();
]]>
</script>
<separator/>
</dialog>

Просмотреть файл

@ -0,0 +1,9 @@
<!ENTITY plugins.title "Plug-Ins">
<!ENTITY pluginInfo.label "Plug-Ins are currently available for the following file types:">
<!ENTITY pluginInfo2.label "Disabling Plug-Ins for a file type will cause files of that type to be downloaded instead of being viewed in the Plug-In.">
<!ENTITY typeHeader.label "File Type">
<!ENTITY enabledHeader.label "Enabled">
<!ENTITY extensionsHeader.label "Extension">