зеркало из https://github.com/mozilla/pjs.git
Fix bug 86640 -- change helper app dialog to properly remember the selected
course of action, move the "neverAsk" information from prefs back to mimeTypes.rdf, remove the "Reset" button from helper app prefs, set up a way to select "use default OS helper" for a given type. Patch by Bill Law <law@netscape.com> and Philip K. Warren <pkw@us.ibm.com>, r=biesi, sr=bzbarsky, what passes for moa in helper apps=bzbarsky.
This commit is contained in:
Родитель
df75e4e018
Коммит
5f9095c9ce
|
@ -1,4 +1,4 @@
|
|||
<!ENTITY caption.label "Downloading #1">
|
||||
<!ENTITY caption.label "Opening #1">
|
||||
|
||||
<!-- Localization note: The default intro text has 2 "inserts":
|
||||
#1 - replaced with the descriptive text that describes the mime type
|
||||
|
@ -7,30 +7,29 @@
|
|||
If there is no descriptive text, then the alternative text is used which
|
||||
has only insert #2.
|
||||
-->
|
||||
<!ENTITY intro.label "You have chosen to download a file of type: "#1" [#2] from">
|
||||
<!ENTITY intro.noDesc.label "You have chosen to download a file of type: #2 from">
|
||||
<!ENTITY intro.label "You have chosen to open a file of type: "#1" (#2) from">
|
||||
<!ENTITY intro.noDesc.label "You have chosen to open a file of type: #2 from">
|
||||
|
||||
<!ENTITY prompt.label "What should #1 do with this file?">
|
||||
|
||||
<!ENTITY default.set.label "Advanced...">
|
||||
<!ENTITY default.set.accesskey "A">
|
||||
<!ENTITY alwaysAsk.label "Always show this dialog before handling files of this type">
|
||||
<!ENTITY alwaysAsk.accesskey "a">
|
||||
|
||||
<!ENTITY alwaysAsk.label "Always ask before opening this type of file">
|
||||
<!ENTITY alwaysAsk.accesskey "l">
|
||||
<!ENTITY saveToDisk.label "Save it to disk">
|
||||
<!ENTITY saveToDisk.accesskey "s">
|
||||
|
||||
<!ENTITY saveToDisk.label "Save this file to disk">
|
||||
<!ENTITY saveToDisk.accesskey "d">
|
||||
<!ENTITY useSystemDefault.label "Open it with the default application (#1)">
|
||||
<!ENTITY useSystemDefault.noDesc.label "Open it with the default application">
|
||||
<!ENTITY useSystemDefault.accesskey "o">
|
||||
|
||||
<!-- LOCALIZATION NOTE: do not localize "#1" -->
|
||||
<!ENTITY openUsing.label "Open using #1">
|
||||
<!ENTITY openUsing.accesskey "o">
|
||||
|
||||
<!ENTITY noApplicationSpecified.label " an application">
|
||||
<!ENTITY openUsing.label "Open it with">
|
||||
<!ENTITY openUsing.accesskey "w">
|
||||
|
||||
<!ENTITY chooseApp.label "Choose...">
|
||||
<!ENTITY chooseApp.accesskey "c">
|
||||
|
||||
<!ENTITY chooseAppFilePickerTitle "Choose Application">
|
||||
|
||||
<!ENTITY badApp "The application you specified ["#1"] could not be found. Check the file name or select another application.">
|
||||
<!ENTITY badApp "The application you specified ("#1") could not be found. Check the file name or select another application.">
|
||||
<!ENTITY badApp.title "Application not found">
|
||||
|
|
|
@ -57,7 +57,6 @@ function nsHelperAppDialog() {
|
|||
this.mLauncher = null;
|
||||
this.mContext = null;
|
||||
this.mSourcePath = null;
|
||||
this.choseApp = false;
|
||||
this.chosenApp = null;
|
||||
this.givenDefaultApp = false;
|
||||
this.strings = new Array;
|
||||
|
@ -240,20 +239,6 @@ nsHelperAppDialog.prototype = {
|
|||
|
||||
// initDialog: Fill various dialog fields with initial content.
|
||||
initDialog : function() {
|
||||
// Check if file is executable (in which case, we will go straight to
|
||||
// "save to disk").
|
||||
var ignore1 = new Object;
|
||||
var ignore2 = new Object;
|
||||
var tmpFile = this.mLauncher.getDownloadInfo( ignore1, ignore2 );
|
||||
if ( tmpFile.isExecutable() ) {
|
||||
this.mLauncher.saveToDisk( null, false );
|
||||
// Make sure onunload handler doesn't cancel.
|
||||
this.mDialog.dialog = null;
|
||||
// Close the dialog.
|
||||
this.mDialog.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Put product brand short name in prompt.
|
||||
var prompt = this.dialogElement( "prompt" );
|
||||
var modified = this.replaceInsert( prompt.firstChild.nodeValue, 1, this.getString( "brandShortName" ) );
|
||||
|
@ -294,18 +279,8 @@ nsHelperAppDialog.prototype = {
|
|||
|
||||
this.initAppAndSaveToDiskValues();
|
||||
|
||||
// always make sure the window starts off with this checked....
|
||||
this.dialogElement( "alwaysAskMe" ).checked = true;
|
||||
|
||||
// Add special debug hook.
|
||||
if ( this.debug ) {
|
||||
prompt.setAttribute( "onclick", "dialog.doDebug()" );
|
||||
}
|
||||
|
||||
// Set up dialog button callbacks.
|
||||
var object = this; // "this.onOK()" doesn't work!
|
||||
this.mDialog.doSetOKCancel( function () { return object.onOK(); },
|
||||
function () { return object.onCancel(); } );
|
||||
// Initialize "always ask me" box.
|
||||
this.dialogElement( "alwaysAskMe" ).checked = this.mLauncher.MIMEInfo.alwaysAskBeforeHandling;
|
||||
|
||||
// Position it.
|
||||
if ( this.mDialog.opener ) {
|
||||
|
@ -324,10 +299,10 @@ nsHelperAppDialog.prototype = {
|
|||
var intro = this.dialogElement( "intro" );
|
||||
var desc = this.mLauncher.MIMEInfo.Description;
|
||||
var modified;
|
||||
if ( desc != "" )
|
||||
if ( desc )
|
||||
{
|
||||
// Use intro with descriptive text.
|
||||
modified = this.replaceInsert( this.getString( "intro.withDesc" ), 1, this.mLauncher.MIMEInfo.Description );
|
||||
modified = this.replaceInsert( this.getString( "intro.withDesc" ), 1, desc );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -366,79 +341,135 @@ nsHelperAppDialog.prototype = {
|
|||
location.value = pathString;
|
||||
},
|
||||
|
||||
// initAppAndSaveToDiskValues:
|
||||
initAppAndSaveToDiskValues: function() {
|
||||
// Returns true iff opening the default application makes sense.
|
||||
openWithDefaultOK: function() {
|
||||
var result;
|
||||
|
||||
// Pre-select the choice the user made last time.
|
||||
this.chosenApp = this.mLauncher.MIMEInfo.preferredApplicationHandler;
|
||||
var applicationDescription = this.mLauncher.MIMEInfo.applicationDescription;
|
||||
|
||||
if (applicationDescription != "")
|
||||
{
|
||||
this.updateApplicationName(applicationDescription);
|
||||
this.givenDefaultApp = true;
|
||||
// The checking is different on Windows...
|
||||
if ( this.mDialog.navigator.platform.indexOf( "Win" ) != -1 ) {
|
||||
// Windows presents some special cases.
|
||||
// We need to prevent use of "system default" when the file is
|
||||
// executable (so the user doesn't launch nasty programs downloaded
|
||||
// from the web), and, enable use of "system default" if it isn't
|
||||
// executable (because we will prompt the user for the default app
|
||||
// in that case).
|
||||
|
||||
// Need to get temporary file and check for executable-ness.
|
||||
var ignore1 = new Object;
|
||||
var ignore2 = new Object;
|
||||
var tmpFile = this.mLauncher.getDownloadInfo( ignore1, ignore2 );
|
||||
|
||||
// Default is Ok if the file isn't executable (and vice-versa).
|
||||
result = !tmpFile.isExecutable();
|
||||
} else {
|
||||
// On other platforms, default is Ok if there is a default app.
|
||||
// Note that nsIMIMEInfo providers need to ensure that this holds true
|
||||
// on each platform.
|
||||
result = this.mLauncher.MIMEInfo.defaultApplicationHandler;
|
||||
}
|
||||
else if (this.chosenApp && this.chosenApp.path)
|
||||
{
|
||||
// If a user-chosen application, show its path.
|
||||
this.updateApplicationName(this.chosenApp.path);
|
||||
this.choseApp = true;
|
||||
return result;
|
||||
},
|
||||
|
||||
// Set "default" application description field.
|
||||
initDefaultApp: function() {
|
||||
// Use description, if provided.
|
||||
var desc = this.mLauncher.MIMEInfo.defaultDescription;
|
||||
if ( !desc ) {
|
||||
// Otherwise, use helper application file name
|
||||
var app = this.mLauncher.MIMEInfo.defaultApplicationHandler;
|
||||
if ( app ) {
|
||||
desc = app.leafName;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.updateApplicationName(this.getString("noApplicationSpecified"));
|
||||
|
||||
if ( (applicationDescription || this.choseApp) && this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.saveToDisk )
|
||||
{
|
||||
var openUsing = this.dialogElement( "openUsing" );
|
||||
openUsing.radioGroup.selectedItem = openUsing;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save to disk.
|
||||
var saveToDisk = this.dialogElement( "saveToDisk" );
|
||||
saveToDisk.radioGroup.selectedItem = saveToDisk;
|
||||
// Disable choose app button.
|
||||
this.dialogElement( "chooseApp" ).setAttribute( "disabled", "true" );
|
||||
if ( desc ) {
|
||||
this.dialogElement( "useSystemDefault" ).label = this.replaceInsert( this.getString( "defaultApp" ), 1, desc );
|
||||
}
|
||||
},
|
||||
|
||||
// initAppAndSaveToDiskValues:
|
||||
initAppAndSaveToDiskValues: function() {
|
||||
// Fill in helper app info, if there is any.
|
||||
this.chosenApp = this.mLauncher.MIMEInfo.preferredApplicationHandler;
|
||||
// Initialize "default application" field.
|
||||
this.initDefaultApp();
|
||||
|
||||
// Fill application name textbox.
|
||||
if (this.chosenApp && this.chosenApp.path) {
|
||||
this.dialogElement( "appPath" ).value = this.chosenApp.path;
|
||||
}
|
||||
|
||||
if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useSystemDefault) {
|
||||
// Open (using system default).
|
||||
var useDefault = this.dialogElement( "useSystemDefault" );
|
||||
useDefault.radioGroup.selectedItem = useDefault;
|
||||
} else if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useHelperApp) {
|
||||
// Open with given helper app.
|
||||
var openUsing = this.dialogElement( "openUsing" );
|
||||
openUsing.radioGroup.selectedItem = openUsing;
|
||||
} else {
|
||||
// Save to disk.
|
||||
var saveToDisk = this.dialogElement( "saveToDisk" );
|
||||
saveToDisk.radioGroup.selectedItem = saveToDisk;
|
||||
}
|
||||
// If we don't have a "default app" then disable that choice.
|
||||
if ( !this.openWithDefaultOK() ) {
|
||||
// Disable that choice.
|
||||
var useDefault = this.dialogElement( "useSystemDefault" );
|
||||
useDefault.hidden = true;
|
||||
// If that's the default, then switch to "save to disk."
|
||||
if ( useDefault.selected ) {
|
||||
useDefault.radioGroup.selectedItem = this.dialogElement( "saveToDisk" );
|
||||
}
|
||||
}
|
||||
|
||||
// Enable/Disable choose application button and textfield
|
||||
this.toggleChoice();
|
||||
|
||||
updateApplicationName: function(newValue)
|
||||
{
|
||||
var applicationText = this.getString( "openUsingString" );
|
||||
applicationText = this.replaceInsert( applicationText, 1, newValue );
|
||||
var expl = this.dialogElement( "openUsing" );
|
||||
expl.label = applicationText;
|
||||
// If we're running on the Mac, disable the application <textbox>.
|
||||
if ( this.mDialog.navigator.platform.indexOf( "Mac" ) != -1 ) {
|
||||
this.dialogElement( "appPath" ).disabled = true;
|
||||
}
|
||||
},
|
||||
|
||||
// Enable pick app button if the user chooses that option.
|
||||
toggleChoice : function () {
|
||||
// See what option is selected.
|
||||
if ( this.dialogElement( "openUsing" ).selected ) {
|
||||
// We can enable the pick app button.
|
||||
this.dialogElement( "chooseApp" ).removeAttribute( "disabled" );
|
||||
this.dialogElement( "chooseApp" ).disabled =
|
||||
this.dialogElement( "appPath" ).disabled = !this.dialogElement( "openUsing" ).selected;
|
||||
this.updateOKButton();
|
||||
},
|
||||
|
||||
// Returns the user-selected application
|
||||
helperAppChoice: function() {
|
||||
var result = this.chosenApp;
|
||||
var typed = this.dialogElement( "appPath" ).value;
|
||||
// First, see if one was chosen via the Choose... button.
|
||||
if ( result ) {
|
||||
// Verify that the user didn't type in something different later.
|
||||
if ( typed != result.path ) {
|
||||
// Use what was typed in.
|
||||
try {
|
||||
result.QueryInterface( Components.interfaces.nsILocalFile ).initWithPath( typed );
|
||||
} catch( e ) {
|
||||
// Invalid path was typed.
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// We can disable the pick app button.
|
||||
this.dialogElement( "chooseApp" ).setAttribute( "disabled", "true" );
|
||||
// The user didn't use the Choose... button, try using what they typed in.
|
||||
result = Components.classes[ "@mozilla.org/file/local;1" ]
|
||||
.createInstance( Components.interfaces.nsILocalFile );
|
||||
try {
|
||||
result.initWithPath( typed );
|
||||
} catch( e ) {
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.updateOKButton();
|
||||
// Remember what was chosen.
|
||||
this.chosenApp = result;
|
||||
return result;
|
||||
},
|
||||
|
||||
processAlwaysAskState : function ()
|
||||
{
|
||||
// if the user deselected the always ask checkbox, then store that on the mime object for future use...
|
||||
if (!this.dialogElement( "alwaysAskMe" ).checked)
|
||||
{
|
||||
// we first need to rest the user action if the user selected save to disk instead of open...
|
||||
// reset the preferred action in this case...we need to do this b4 setting the always ask before handling state
|
||||
|
||||
if (!this.dialogElement( "openUsing" ).selected)
|
||||
this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.saveToDisk;
|
||||
|
||||
|
||||
this.mLauncher.MIMEInfo.alwaysAskBeforeHandling = false;
|
||||
}
|
||||
},
|
||||
updateOKButton: function() {
|
||||
var ok = false;
|
||||
if ( this.dialogElement( "saveToDisk" ).selected )
|
||||
|
@ -446,44 +477,121 @@ nsHelperAppDialog.prototype = {
|
|||
// This is always OK.
|
||||
ok = true;
|
||||
}
|
||||
else if ( this.dialogElement( "useSystemDefault" ).selected )
|
||||
{
|
||||
// No app need be specified in this case.
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// only enable the OK button if we have a default app to use or if
|
||||
// the user chose an app....
|
||||
if ((this.choseApp && this.chosenApp.path) || this.givenDefaultApp)
|
||||
ok = true;
|
||||
// only enable the OK button if we have a default app to use or if
|
||||
// the user chose an app....
|
||||
ok = this.chosenApp || /\S/.test( this.dialogElement( "appPath" ).value );
|
||||
}
|
||||
|
||||
// Enable Ok button if ok to press.
|
||||
this.dialogElement( "ok" ).disabled = !ok;
|
||||
this.mDialog.document.documentElement.getButton( "accept" ).disabled = !ok;
|
||||
},
|
||||
|
||||
|
||||
// Returns true iff the user-specified helper app has been modified.
|
||||
appChanged: function() {
|
||||
return this.helperAppChoice() != this.mLauncher.MIMEInfo.preferredApplicationHandler;
|
||||
},
|
||||
|
||||
// See if the user changed things, and if so, update the
|
||||
// mimeTypes.rdf entry for this mime type.
|
||||
updateHelperAppPref: function() {
|
||||
var needUpdate = false;
|
||||
// If current selection differs from what's in the mime info object,
|
||||
// then we need to update.
|
||||
if ( this.dialogElement( "saveToDisk" ).selected ) {
|
||||
needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.saveToDisk;
|
||||
if ( needUpdate )
|
||||
this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.saveToDisk;
|
||||
} else if ( this.dialogElement( "useSystemDefault" ).selected ) {
|
||||
needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useSystemDefault;
|
||||
if ( needUpdate )
|
||||
this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useSystemDefault;
|
||||
} else {
|
||||
// For "open with", we need to check both preferred action and whether the user chose
|
||||
// a new app.
|
||||
needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useHelperApp || this.appChanged();
|
||||
if ( needUpdate ) {
|
||||
this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useHelperApp;
|
||||
// App may have changed - Update application and description
|
||||
var app = this.helperAppChoice();
|
||||
this.mLauncher.MIMEInfo.preferredApplicationHandler = app;
|
||||
this.mLauncher.MIMEInfo.applicationDescription = app.leafName;
|
||||
}
|
||||
}
|
||||
// We will also need to update if the "always ask" flag has changed.
|
||||
needUpdate = needUpdate || this.mLauncher.MIMEInfo.alwaysAskBeforeHandling != this.dialogElement( "alwaysAskMe" ).checked;
|
||||
|
||||
// One last special case: If the input "always ask" flag was false, then we always
|
||||
// update. In that case we are displaying the helper app dialog for the first
|
||||
// time for this mime type and we need to store the user's action in the mimeTypes.rdf
|
||||
// data source (whether that action has changed or not; if it didn't change, then we need
|
||||
// to store the "always ask" flag so the helper app dialog will or won't display
|
||||
// next time, per the user's selection).
|
||||
needUpdate = needUpdate || !this.mLauncher.MIMEInfo.alwaysAskBeforeHandling;
|
||||
|
||||
// Make sure mime info has updated setting for the "always ask" flag.
|
||||
this.mLauncher.MIMEInfo.alwaysAskBeforeHandling = this.dialogElement( "alwaysAskMe" ).checked;
|
||||
|
||||
if ( needUpdate ) {
|
||||
// We update by passing this mime info into the "Edit Type" helper app
|
||||
// pref dialog. It will update the data source and close the dialog
|
||||
// automatically.
|
||||
this.mDialog.openDialog( "chrome://communicator/content/pref/pref-applications-edit.xul",
|
||||
"_blank",
|
||||
"chrome,modal=yes,resizable=no",
|
||||
this );
|
||||
}
|
||||
},
|
||||
|
||||
// onOK:
|
||||
onOK: function() {
|
||||
|
||||
this.processAlwaysAskState();
|
||||
|
||||
// Remove our web progress listener (a progress dialog will be
|
||||
// taking over).
|
||||
this.mLauncher.setWebProgressListener( null );
|
||||
|
||||
if ( this.dialogElement( "openUsing" ).selected )
|
||||
{
|
||||
// If no app "chosen" then convert input string to file.
|
||||
if (this.chosenApp)
|
||||
this.mLauncher.launchWithApplication( this.chosenApp, false );
|
||||
else
|
||||
this.mLauncher.launchWithApplication( null, false );
|
||||
}
|
||||
else
|
||||
this.mLauncher.saveToDisk( null, false );
|
||||
// Verify typed app path, if necessary.
|
||||
if ( this.dialogElement( "openUsing" ).selected ) {
|
||||
var helperApp = this.helperAppChoice();
|
||||
if ( !helperApp || !helperApp.exists() ) {
|
||||
// Show alert and try again.
|
||||
var msg = this.replaceInsert( this.getString( "badApp" ), 1, this.dialogElement( "appPath" ).value );
|
||||
var svc = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ]
|
||||
.getService( Components.interfaces.nsIPromptService );
|
||||
svc.alert( this.mDialog, this.getString( "badApp.title" ), msg );
|
||||
// Disable the OK button.
|
||||
this.mDialog.document.documentElement.getButton( "accept" ).disabled = true;
|
||||
// Select and focus the input field if input field is not disabled
|
||||
var path = this.dialogElement( "appPath" );
|
||||
if ( !path.disabled ) {
|
||||
path.select();
|
||||
path.focus();
|
||||
}
|
||||
// Clear chosen application.
|
||||
this.chosenApp = null;
|
||||
// Leave dialog up.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Unhook dialog from this object.
|
||||
this.mDialog.dialog = null;
|
||||
|
||||
// Close up dialog by returning true.
|
||||
return true;
|
||||
//this.mDialog.close();
|
||||
// Update user pref for this mime type (if necessary).
|
||||
this.updateHelperAppPref();
|
||||
|
||||
// Remove our web progress listener (a progress dialog will be
|
||||
// taking over).
|
||||
this.mLauncher.setWebProgressListener( null );
|
||||
|
||||
if ( this.dialogElement( "saveToDisk" ).selected )
|
||||
this.mLauncher.saveToDisk( null, false );
|
||||
else
|
||||
this.mLauncher.launchWithApplication( null, false );
|
||||
|
||||
// Unhook dialog from this object.
|
||||
this.mDialog.dialog = null;
|
||||
|
||||
// Close up dialog by returning true.
|
||||
return true;
|
||||
},
|
||||
|
||||
// onCancel:
|
||||
|
@ -527,71 +635,12 @@ nsHelperAppDialog.prototype = {
|
|||
|
||||
if ( fp.show() == nsIFilePicker.returnOK && fp.file ) {
|
||||
// Remember the file they chose to run.
|
||||
this.choseApp = true;
|
||||
this.chosenApp = fp.file;
|
||||
this.chosenApp = fp.file;
|
||||
// Update dialog.
|
||||
|
||||
this.updateApplicationName(this.chosenApp.path);
|
||||
this.dialogElement( "appPath" ).value = this.chosenApp.path;
|
||||
}
|
||||
},
|
||||
|
||||
// setDefault: Open "edit MIMEInfo" dialog (borrowed from prefs).
|
||||
setDefault: function() {
|
||||
// Get RDF service.
|
||||
var rdf = Components.classes[ "@mozilla.org/rdf/rdf-service;1" ]
|
||||
.getService( Components.interfaces.nsIRDFService );
|
||||
// Now ask if it knows about this mime type.
|
||||
var exists = false;
|
||||
var fileLocator = Components.classes[ "@mozilla.org/file/directory_service;1" ]
|
||||
.getService( Components.interfaces.nsIProperties );
|
||||
var file = fileLocator.get( "UMimTyp", Components.interfaces.nsIFile );
|
||||
|
||||
// Get the data source; load it synchronously if it must be
|
||||
// initialized.
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
var fileurl = fileHandler.getURLSpecFromFile(file);
|
||||
|
||||
var ds = rdf.GetDataSourceBlocking( fileurl );
|
||||
|
||||
// Now check if this mimetype is really in there;
|
||||
// This is done by seeing if there's a "value" arc from the mimetype resource
|
||||
// to the mimetype literal string.
|
||||
var mimeRes = rdf.GetResource( "urn:mimetype:" + this.mLauncher.MIMEInfo.MIMEType );
|
||||
var valueProperty = rdf.GetResource( "http://home.netscape.com/NC-rdf#value" );
|
||||
var mimeLiteral = rdf.GetLiteral( this.mLauncher.MIMEInfo.MIMEType );
|
||||
exists = ds.HasAssertion( mimeRes, valueProperty, mimeLiteral, true );
|
||||
|
||||
var dlgUrl;
|
||||
if ( exists ) {
|
||||
// Open "edit mime type" dialog.
|
||||
dlgUrl = "chrome://communicator/content/pref/pref-applications-edit.xul";
|
||||
} else {
|
||||
// Open "add mime type" dialog.
|
||||
dlgUrl = "chrome://communicator/content/pref/pref-applications-new.xul";
|
||||
}
|
||||
|
||||
// Open whichever dialog is appropriate, passing this dialog object as argument.
|
||||
this.updateSelf = false; // dialog will reset to true onOK
|
||||
this.mDialog.openDialog( dlgUrl,
|
||||
"_blank",
|
||||
"chrome,modal=yes,resizable=no",
|
||||
this );
|
||||
|
||||
if (this.updateSelf) {
|
||||
// Refresh dialog with updated info about the default action.
|
||||
this.initIntro();
|
||||
this.initAppAndSaveToDiskValues();
|
||||
}
|
||||
},
|
||||
|
||||
// updateMIMEInfo: This is called from the pref-applications-edit dialog when the user
|
||||
// presses OK. Take the updated MIMEInfo and have the helper app service
|
||||
// "write" it back out to the RDF datasource.
|
||||
updateMIMEInfo: function() {
|
||||
this.dumpObjectProperties( "\tMIMEInfo", this.mLauncher.MIMEInfo );
|
||||
},
|
||||
|
||||
// dumpInfo:
|
||||
doDebug: function() {
|
||||
const nsIProgressDialog = Components.interfaces.nsIProgressDialog;
|
||||
|
|
|
@ -26,82 +26,80 @@
|
|||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!DOCTYPE dialog [
|
||||
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
|
||||
%brandDTD;
|
||||
<!ENTITY % nsHelperAppDlgDTD SYSTEM "chrome://global/locale/nsHelperAppDlg.dtd" >
|
||||
%nsHelperAppDlgDTD;
|
||||
]>
|
||||
|
||||
<window id="nsHelperAppDlg"
|
||||
<dialog id="nsHelperAppDlg"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&caption.label;"
|
||||
onload="dialog.initDialog()"
|
||||
onunload="if (dialog) dialog.onCancel()"
|
||||
style="width: 40em;"
|
||||
class="dialog">
|
||||
|
||||
ondialogaccept="return dialog.onOK()"
|
||||
ondialogcancel="return dialog.onCancel()">
|
||||
|
||||
<keyset id="dialogKeys"/>
|
||||
|
||||
<vbox>
|
||||
<hbox flex="1">
|
||||
<vbox flex="1">
|
||||
<description id="intro">&intro.label;</description>
|
||||
<description id="location" crop="center" value=""/>
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<description id="prompt">&prompt.label;</description>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<image id="contentTypeImage"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<radiogroup id="mode" oncommand="dialog.toggleChoice()" align="stretch">
|
||||
<hbox flex="1" align="center">
|
||||
<radio id="openUsing" flex="1"
|
||||
label="&openUsing.label;"
|
||||
accesskey="&openUsing.accesskey;"/>
|
||||
<spacer flex="1"/>
|
||||
<button id="chooseApp"
|
||||
label="&chooseApp.label;"
|
||||
accesskey="&chooseApp.accesskey;"
|
||||
oncommand="dialog.chooseApp()"/>
|
||||
<hbox>
|
||||
<vbox flex="1">
|
||||
<description id="intro">&intro.label;</description>
|
||||
<description id="location" crop="center" value=""/>
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<description id="prompt">&prompt.label;</description>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<image id="contentTypeImage"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
<vbox>
|
||||
<hbox align="center">
|
||||
<radio id="saveToDisk"
|
||||
label="&saveToDisk.label;"
|
||||
accesskey="&saveToDisk.accesskey;"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</radiogroup>
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<hbox align="center">
|
||||
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
|
||||
<radiogroup id="mode" oncommand="dialog.toggleChoice()" align="stretch">
|
||||
<hbox>
|
||||
<radio id="useSystemDefault"
|
||||
flex="1"
|
||||
label="&useSystemDefault.noDesc.label;"
|
||||
accesskey="&useSystemDefault.accesskey;"/>
|
||||
<spacer flex="1"/>
|
||||
</hbox>
|
||||
<hbox align="center">
|
||||
<radio id="openUsing"
|
||||
label="&openUsing.label;"
|
||||
accesskey="&openUsing.accesskey;"/>
|
||||
<textbox id="appPath"
|
||||
flex="1"
|
||||
oninput="dialog.updateOKButton()"
|
||||
onfocus="this.select()"/>
|
||||
<button id="chooseApp"
|
||||
label="&chooseApp.label;"
|
||||
accesskey="&chooseApp.accesskey;"
|
||||
oncommand="dialog.chooseApp()"/>
|
||||
</hbox>
|
||||
<hbox>
|
||||
<radio id="saveToDisk"
|
||||
label="&saveToDisk.label;"
|
||||
accesskey="&saveToDisk.accesskey;"/>
|
||||
<spacer flex="1"/>
|
||||
</hbox>
|
||||
</radiogroup>
|
||||
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
|
||||
<checkbox id="alwaysAskMe" label="&alwaysAsk.label;" accesskey="&alwaysAsk.accesskey;"/>
|
||||
</hbox>
|
||||
|
||||
<separator class="groove"/>
|
||||
</vbox>
|
||||
|
||||
<separator class="groove"/>
|
||||
|
||||
<hbox>
|
||||
<button id="default.set" label="&default.set.label;" accesskey="&default.set.accesskey;"
|
||||
oncommand="dialog.setDefault()"/>
|
||||
<spacer flex="1"/>
|
||||
<hbox id="okCancelButtonsRight"/>
|
||||
</hbox>
|
||||
|
||||
<!-- Localizable strings (from .dtd) -->
|
||||
<strings style="display:none;">
|
||||
<string id="brandShortName"> &brandShortName; </string>
|
||||
<string id="intro.withDesc"> &intro.label; </string>
|
||||
<string id="intro.noDesc"> &intro.noDesc.label; </string>
|
||||
<string id="openUsingString"> &openUsing.label; </string>
|
||||
<string id="defaultApp"> &useSystemDefault.label; </string>
|
||||
<string id="badApp"> &badApp; </string>
|
||||
<string id="badApp.title"> &badApp.title; </string>
|
||||
<string id="noApplicationSpecified"> &noApplicationSpecified.label;</string>
|
||||
</strings>
|
||||
</window>
|
||||
</dialog>
|
||||
|
|
|
@ -35,12 +35,12 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* An nsIMIMEInfo gives a user access to mime information.
|
||||
/**
|
||||
* An nsIMIMEInfo gives a user access to mime information.
|
||||
* there is a one-to-many relationship between MIME types
|
||||
* and file extensions. This means that a MIMEInfo object
|
||||
* may have multiple file extensions associated with it.
|
||||
* However, the reverse is not true.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
@ -52,58 +52,64 @@ typedef long nsMIMEInfoHandleAction;
|
|||
|
||||
[scriptable, uuid(6A57EAE0-2FE8-11d3-A164-0050041CAF44)]
|
||||
interface nsIMIMEInfo : nsISupports {
|
||||
/* Gives you an array of file types associated with this type.
|
||||
/**
|
||||
* Gives you an array of file types associated with this type.
|
||||
*
|
||||
* @return Number of elements in the array.
|
||||
* @return Array of extensions.
|
||||
*/
|
||||
void GetFileExtensions(out PRUint32 elementCount,
|
||||
void GetFileExtensions(out PRUint32 elementCount,
|
||||
[array, size_is(elementCount)] out string extensions);
|
||||
|
||||
/* Set File Extensions. Input is a comma deliminated list of extensions
|
||||
*/
|
||||
void SetFileExtensions( in string aExtensions );
|
||||
/**
|
||||
* Set File Extensions. Input is a comma delimited list of extensions.
|
||||
*/
|
||||
void SetFileExtensions( in string aExtensions );
|
||||
|
||||
/* Returns whether or not the given extension is
|
||||
/**
|
||||
* Returns whether or not the given extension is
|
||||
* associated with this MIME info.
|
||||
*
|
||||
* @return TRUE if the assocaition exists.
|
||||
* @return TRUE if the association exists.
|
||||
*/
|
||||
|
||||
boolean ExtensionExists(in string aExtension);
|
||||
|
||||
/*
|
||||
* Append a given extension to the set of extensions
|
||||
*/
|
||||
/**
|
||||
* Append a given extension to the set of extensions
|
||||
*/
|
||||
void AppendExtension(in string aExtension);
|
||||
|
||||
/* Returns a clone of this MIMEInfo.
|
||||
/**
|
||||
* Returns a clone of this MIMEInfo.
|
||||
*
|
||||
* @return A clone of the MIMEInfo
|
||||
*/
|
||||
|
||||
nsIMIMEInfo clone();
|
||||
|
||||
/* Returns the first extension association in
|
||||
/**
|
||||
* Returns the first extension association in
|
||||
* the internal set of extensions.
|
||||
*
|
||||
* @return The first extension.
|
||||
*/
|
||||
attribute string primaryExtension;
|
||||
|
||||
/* The MIME type of this MIMEInfo.
|
||||
/**
|
||||
* The MIME type of this MIMEInfo.
|
||||
*
|
||||
* @return String representing the MIME type.
|
||||
*/
|
||||
attribute string MIMEType;
|
||||
attribute string MIMEType;
|
||||
|
||||
/* A human readable description of the MIME info
|
||||
/**
|
||||
* A human readable description of the MIME info.
|
||||
*
|
||||
* @return The description
|
||||
*/
|
||||
attribute wstring Description;
|
||||
attribute wstring Description;
|
||||
|
||||
/* Gives you arbitrary data about the MIMEInfo. An example
|
||||
/**
|
||||
* Gives you arbitrary data about the MIMEInfo. An example
|
||||
* of this is a generic image graphically representing
|
||||
* this MIME info. This image can be used to generically
|
||||
* and graphically represent the type.
|
||||
|
@ -112,45 +118,64 @@ interface nsIMIMEInfo : nsISupports {
|
|||
*/
|
||||
readonly attribute nsIURI DataURI;
|
||||
|
||||
/*
|
||||
* Mac Type and creator types
|
||||
/**
|
||||
* Mac Type and creator types
|
||||
*/
|
||||
attribute PRUint32 MacType;
|
||||
attribute PRUint32 MacCreator;
|
||||
|
||||
/* Returns whether or not these two MIME infos are logically
|
||||
attribute PRUint32 MacType;
|
||||
attribute PRUint32 MacCreator;
|
||||
|
||||
/**
|
||||
* Returns whether or not these two MIME infos are logically
|
||||
* equivelent maintaining the one-to-many relationship between
|
||||
* MIME types and file extensions.
|
||||
*
|
||||
* @returns TRUE if the two are considered equal
|
||||
*/
|
||||
boolean Equals(in nsIMIMEInfo aMIMEInfo);
|
||||
boolean Equals(in nsIMIMEInfo aMIMEInfo);
|
||||
|
||||
/* Returns a nsIFile that points to the application the user has said
|
||||
* they want associated with this content type. This is not always guarunteed
|
||||
* to be set!!
|
||||
*/
|
||||
attribute nsIFile preferredApplicationHandler;
|
||||
/**
|
||||
* Returns a nsIFile that points to the application the user has said
|
||||
* they want associated with this content type. This is not always
|
||||
* guaranteed to be set!!
|
||||
*/
|
||||
attribute nsIFile preferredApplicationHandler;
|
||||
|
||||
/* a pretty name description of the associated application */
|
||||
attribute wstring applicationDescription;
|
||||
/**
|
||||
* a pretty name description of the associated application
|
||||
*/
|
||||
attribute wstring applicationDescription;
|
||||
|
||||
const long saveToDisk = 0;
|
||||
/**
|
||||
* Returns a nsIFile that points to the application that is associated
|
||||
* by default with this content type. This will usually be specified in
|
||||
* the platform settings somehow. This is not always guaranteed
|
||||
* to be set!!
|
||||
*/
|
||||
attribute nsIFile defaultApplicationHandler;
|
||||
|
||||
/**
|
||||
* a pretty name description of the default application
|
||||
*/
|
||||
attribute wstring defaultDescription;
|
||||
|
||||
const long saveToDisk = 0;
|
||||
const long alwaysAsk = 1;
|
||||
const long useHelperApp = 2;
|
||||
const long handleInternally = 3;
|
||||
const long useSystemDefault = 4;
|
||||
const long handleInternally = 3;
|
||||
const long useSystemDefault = 4;
|
||||
|
||||
/* preferredAction is how the user specified they would like to handle
|
||||
* this content type: save to disk, use specified helper app, use OS
|
||||
* default handler or handle using navigator.
|
||||
*/
|
||||
attribute nsMIMEInfoHandleAction preferredAction;
|
||||
/**
|
||||
* preferredAction is how the user specified they would like to handle
|
||||
* this content type: save to disk, use specified helper app, use OS
|
||||
* default handler or handle using navigator.
|
||||
*/
|
||||
attribute nsMIMEInfoHandleAction preferredAction;
|
||||
|
||||
/* alwaysAskBeforeHandling: if true, we should always give the user a dialog
|
||||
* asking how to dispose of this content.
|
||||
*/
|
||||
attribute boolean alwaysAskBeforeHandling;
|
||||
/**
|
||||
* alwaysAskBeforeHandling: if true, we should always give the user a
|
||||
* dialog asking how to dispose of this content.
|
||||
*/
|
||||
attribute boolean alwaysAskBeforeHandling;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -38,12 +38,6 @@
|
|||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#define NEVER_ASK_FOR_SAVE_TO_DISK_PREF "browser.helperApps.neverAsk.saveToDisk"
|
||||
#define NEVER_ASK_FOR_OPEN_FILE_PREF "browser.helperApps.neverAsk.openFile"
|
||||
|
||||
// nsISupports methods
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo);
|
||||
|
@ -51,10 +45,12 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo);
|
|||
// nsMIMEInfoImpl methods
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl() {
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
mAlwaysAskBeforeHandling = PR_TRUE;
|
||||
}
|
||||
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType) :mMIMEType( aMIMEType ){
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
mAlwaysAskBeforeHandling = PR_TRUE;
|
||||
}
|
||||
|
||||
PRUint32
|
||||
|
@ -287,6 +283,18 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetApplicationDescription(const PRUnichar * aAppli
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultDescription(PRUnichar ** aDefaultDescription)
|
||||
{
|
||||
*aDefaultDescription = ToNewUnicode(mDefaultAppDescription);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDefaultDescription(const PRUnichar * aDefaultDescription)
|
||||
{
|
||||
mDefaultAppDescription = aDefaultDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredApplicationHandler(nsIFile ** aPreferredAppHandler)
|
||||
{
|
||||
*aPreferredAppHandler = mPreferredApplication;
|
||||
|
@ -300,6 +308,19 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredApplicationHandler(nsIFile * aPreferre
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultApplicationHandler(nsIFile ** aDefaultAppHandler)
|
||||
{
|
||||
*aDefaultAppHandler = mDefaultApplication;
|
||||
NS_IF_ADDREF(*aDefaultAppHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDefaultApplicationHandler(nsIFile * aDefaultAppHandler)
|
||||
{
|
||||
mDefaultApplication = aDefaultAppHandler;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredAction(nsMIMEInfoHandleAction * aPreferredAction)
|
||||
{
|
||||
*aPreferredAction = mPreferredAction;
|
||||
|
@ -314,104 +335,13 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredAction(nsMIMEInfoHandleAction aPreferr
|
|||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetAlwaysAskBeforeHandling(PRBool * aAlwaysAsk)
|
||||
{
|
||||
// this is a bit complicated. We now store the always ask preference in two preferences:
|
||||
// browser.helperApps.neverAsk.saveToDisk and
|
||||
// browser.helperApps.neverAsk.openFile
|
||||
// Both lists are comma delimited lists containing mime types which the user has specifically
|
||||
// decided to override the helper app dialog for.
|
||||
|
||||
// for get always ask, we just need to search both pref branches for our mime type...
|
||||
PRBool mimeTypeIsPresent = PR_FALSE;
|
||||
CheckPrefForMimeType(NEVER_ASK_FOR_SAVE_TO_DISK_PREF, &mimeTypeIsPresent);
|
||||
|
||||
if (mimeTypeIsPresent)
|
||||
{
|
||||
*aAlwaysAsk = PR_FALSE;
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckPrefForMimeType(NEVER_ASK_FOR_OPEN_FILE_PREF, &mimeTypeIsPresent);
|
||||
if (mimeTypeIsPresent)
|
||||
{
|
||||
*aAlwaysAsk = PR_FALSE;
|
||||
// do we need to force a preferred action here? I don't think so...
|
||||
}
|
||||
}
|
||||
*aAlwaysAsk = mAlwaysAskBeforeHandling;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// re-write me to use new string apis to avoid the extra string copy of the pref value in order to call ::Find
|
||||
void nsMIMEInfoImpl::CheckPrefForMimeType(const char * prefName, PRBool * aMimeTypeIsPresent)
|
||||
{
|
||||
*aMimeTypeIsPresent = PR_FALSE;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefs, &rv);
|
||||
if (NS_SUCCEEDED(rv) && prefBranch)
|
||||
{
|
||||
nsXPIDLCString prefCString;
|
||||
nsCAutoString prefValue;
|
||||
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
||||
if (NS_SUCCEEDED(rv) && *prefCString.get())
|
||||
{
|
||||
nsUnescape(NS_CONST_CAST(char*,(const char*)prefCString.get()));
|
||||
|
||||
prefValue = prefCString; // i should be able to avoid this string copy
|
||||
PRInt32 pos = prefValue.Find(mMIMEType, PR_TRUE);
|
||||
if (pos >= 0)
|
||||
*aMimeTypeIsPresent = PR_TRUE;
|
||||
}
|
||||
} // if we got the prefs service
|
||||
}
|
||||
|
||||
void nsMIMEInfoImpl::SetRememberPrefForMimeType(const char * prefName)
|
||||
{
|
||||
// first, make sure it isn't already there...
|
||||
PRBool mimeTypeIsPresent = PR_FALSE;
|
||||
CheckPrefForMimeType(prefName, &mimeTypeIsPresent);
|
||||
if (mimeTypeIsPresent) return; // mime type is already present...
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefs, &rv);
|
||||
if (NS_SUCCEEDED(rv) && prefBranch)
|
||||
{
|
||||
// read out the current pref string and unescape it.
|
||||
nsXPIDLCString prefCString;
|
||||
nsCAutoString prefValue;
|
||||
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
||||
if (NS_SUCCEEDED(rv) && *prefCString.get())
|
||||
{
|
||||
nsUnescape(NS_CONST_CAST(char*,(const char*)prefCString.get()));
|
||||
prefValue = prefCString;
|
||||
}
|
||||
|
||||
if (!prefValue.IsEmpty()) // if the pref string isn't empty...
|
||||
{
|
||||
prefValue.Append(", ");
|
||||
prefValue.Append(mMIMEType);
|
||||
}
|
||||
else
|
||||
prefValue = mMIMEType;
|
||||
|
||||
// always escape the pref b4 storing it in case someone enters some funky characters for a mime type...
|
||||
nsXPIDLCString escapedPrefString;
|
||||
escapedPrefString.Adopt(nsEscape(prefValue.get(), url_XAlphas));
|
||||
prefBranch->SetCharPref(prefName, escapedPrefString);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
||||
{
|
||||
if (!aAlwaysAsk)
|
||||
{
|
||||
if (mPreferredAction == nsIMIMEInfo::saveToDisk)
|
||||
SetRememberPrefForMimeType(NEVER_ASK_FOR_SAVE_TO_DISK_PREF);
|
||||
else
|
||||
SetRememberPrefForMimeType(NEVER_ASK_FOR_OPEN_FILE_PREF);
|
||||
}
|
||||
mAlwaysAskBeforeHandling = aAlwaysAsk;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -64,11 +64,11 @@ public:
|
|||
protected:
|
||||
nsCString mMIMEType;
|
||||
nsCOMPtr<nsIFile> mPreferredApplication; // preferred application associated with this type.
|
||||
nsCOMPtr<nsIFile> mDefaultApplication; // default application associated with this type.
|
||||
nsMIMEInfoHandleAction mPreferredAction; // preferred action to associate with this type
|
||||
nsString mPreferredAppDescription;
|
||||
|
||||
void CheckPrefForMimeType(const char * prefName, PRBool * aMimeTypeIsPresent);
|
||||
void SetRememberPrefForMimeType(const char * prefName);
|
||||
nsString mDefaultAppDescription;
|
||||
PRBool mAlwaysAskBeforeHandling;
|
||||
};
|
||||
|
||||
#endif //__nsmimeinfoimpl_h___
|
||||
|
|
|
@ -108,14 +108,10 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf
|
|||
|
||||
PRBool executable = PR_TRUE;
|
||||
local->IsExecutable(&executable);
|
||||
if (!executable)
|
||||
{
|
||||
rv = local->Launch();
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
if (executable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = local->Launch();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,7 +246,7 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
|
|||
NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
// if the extension is null, return immediately
|
||||
if (!aFileExt)
|
||||
if (!aFileExt || !*aFileExt)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// first, see if the base class already has an entry....
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// override nsIMIMEService methods to contain mime.types and mime.info look up steps
|
||||
// method overrides for mime.types and mime.info look up steps
|
||||
NS_IMETHODIMP GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
NS_IMETHODIMP GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retval);
|
||||
|
||||
|
|
|
@ -53,17 +53,29 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf
|
|||
if (aMIMEInfo)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
if (application)
|
||||
|
||||
nsMIMEInfoHandlerAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
if (action==nsIMIMEInfo::useHelperApp)
|
||||
{
|
||||
nsCOMPtr <nsILocalFileMac> app = do_QueryInterface(application, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr <nsILocalFile> docToLoad = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = app->LaunchWithDoc(docToLoad, PR_FALSE);
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
else
|
||||
{
|
||||
aMIMEInfo->GetDefaultApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
|
||||
if (!application)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr <nsILocalFileMac> app = do_QueryInterface(application, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr <nsILocalFile> docToLoad = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = app->LaunchWithDoc(docToLoad, PR_FALSE);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -139,35 +151,35 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
|
|||
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
nsresult rv = NS_OK;
|
||||
if (!localFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
|
||||
if (localFile)
|
||||
{
|
||||
if (localFile)
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
///////////////////////////
|
||||
// nsIMIMEService overrides --> used to leverage internet config information for mime types.
|
||||
// method overrides --> use internet config information for mime type lookup.
|
||||
///////////////////////////
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char * aFileExt, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
// first, ask our base class. We may already have this information cached....
|
||||
// first, ask our base class....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromExtension(aFileExt, aMIMEInfo);
|
||||
if (NS_SUCCEEDED(rv) && *aMIMEInfo)
|
||||
{
|
||||
UpdateCreatorInfo(*aMIMEInfo);
|
||||
return rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// oops, we didn't find an entry....ask the internet config service to look it up for us...
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForExtensionFromOS(const char * aFileExt, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// ask the internet config service to look it up for us...
|
||||
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
|
||||
if (icService)
|
||||
{
|
||||
|
@ -185,15 +197,20 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char * aFileExt, nsIM
|
|||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char * aMIMEType, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
// first, ask our base class. We may already have this information cached....
|
||||
// first, ask our base class....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromMIMEType(aMIMEType, aMIMEInfo);
|
||||
if (NS_SUCCEEDED(rv) && *aMIMEInfo)
|
||||
{
|
||||
UpdateCreatorInfo(*aMIMEInfo);
|
||||
return rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// oops, we didn't find an entry....ask the internet config service to look it up for us...
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForMimeTypeFromOS(const char * aMIMEType, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// ask the internet config service to look it up for us...
|
||||
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
|
||||
if (icService)
|
||||
{
|
||||
|
|
|
@ -44,9 +44,11 @@ public:
|
|||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
NS_IMETHOD LoadUrl(nsIURI * aURL);
|
||||
|
||||
// nsIMIMEService over-rides --> used to hook the mime service into internet config....
|
||||
// method overrides --> used to hook the mime service into internet config....
|
||||
NS_IMETHOD GetFromExtension(const char * aFileExt, nsIMIMEInfo ** aMIMEInfo);
|
||||
NS_IMETHOD GetFromMIMEType(const char * aMIMEType, nsIMIMEInfo ** aMIMEInfo);
|
||||
nsresult GetMIMEInfoForExtensionFromOS(const char * aFileExt, nsIMIMEInfo ** aMIMEInfo);
|
||||
nsresult GetMIMEInfoForMimeTypeFromOS(const char * aMIMEType, nsIMIMEInfo ** aMIMEInfo);
|
||||
|
||||
// GetFileTokenForPath must be implemented by each platform.
|
||||
// platformAppPath --> a platform specific path to an application that we got out of the
|
||||
|
|
|
@ -85,7 +85,11 @@
|
|||
|
||||
#include "nsITextToSubURI.h"
|
||||
|
||||
const char *FORCE_ALWAYS_ASK_PREF = "browser.helperApps.alwaysAsk.force";
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
const char *NEVER_ASK_PREF_BRANCH = "browser.helperApps.neverAsk.";
|
||||
const char *NEVER_ASK_FOR_SAVE_TO_DISK_PREF = "saveToDisk";
|
||||
const char *NEVER_ASK_FOR_OPEN_FILE_PREF = "openFile";
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
||||
|
@ -231,6 +235,7 @@ nsresult nsExternalHelperAppService::InitDataSource()
|
|||
rdf->GetResource(NC_RDF_FILEEXTENSIONS,getter_AddRefs(kNC_FileExtensions));
|
||||
rdf->GetResource(NC_RDF_PATH, getter_AddRefs(kNC_Path));
|
||||
rdf->GetResource(NC_RDF_SAVETODISK, getter_AddRefs(kNC_SaveToDisk));
|
||||
rdf->GetResource(NC_RDF_USESYSTEMDEFAULT,getter_AddRefs(kNC_UseSystemDefault));
|
||||
rdf->GetResource(NC_RDF_HANDLEINTERNAL,getter_AddRefs(kNC_HandleInternal));
|
||||
rdf->GetResource(NC_RDF_ALWAYSASK, getter_AddRefs(kNC_AlwaysAsk));
|
||||
rdf->GetResource(NC_RDF_PRETTYNAME, getter_AddRefs(kNC_PrettyName));
|
||||
|
@ -255,12 +260,13 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
|
|||
|
||||
// (1) Try to find a mime object by looking the mime type
|
||||
GetFromMIMEType(aMimeContentType, getter_AddRefs(mimeInfo));
|
||||
|
||||
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
||||
|
||||
if (!mimeInfo)
|
||||
{
|
||||
// if we couldn't find one, don't give up yet! Try and see if there is an extension in the
|
||||
// url itself...
|
||||
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
||||
if (url)
|
||||
{
|
||||
url->GetFileExtension(fileExtension);
|
||||
|
@ -275,6 +281,30 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (url)
|
||||
{
|
||||
// Get default app/description.
|
||||
nsCOMPtr<nsIFile> defaultApp;
|
||||
nsXPIDLString defaultDescription;
|
||||
mimeInfo->GetDefaultApplicationHandler(getter_AddRefs(defaultApp));
|
||||
mimeInfo->GetDefaultDescription(getter_Copies(defaultDescription));
|
||||
// If neither description nor app are specified, then we try to get
|
||||
// these from the per-platform OS settings based on the file extension.
|
||||
if (defaultDescription.IsEmpty() && !defaultApp)
|
||||
{
|
||||
nsCOMPtr<nsIMIMEInfo> osInfo;
|
||||
url->GetFileExtension(fileExtension);
|
||||
if (NS_SUCCEEDED(GetMIMEInfoForExtensionFromOS(fileExtension.get(), getter_AddRefs(osInfo))))
|
||||
{
|
||||
// Extract default application and default description.
|
||||
osInfo->GetDefaultApplicationHandler(getter_AddRefs(defaultApp));
|
||||
osInfo->GetDefaultDescription(getter_Copies(defaultDescription));
|
||||
// Copy to result mime info object.
|
||||
mimeInfo->SetDefaultApplicationHandler(defaultApp);
|
||||
mimeInfo->SetDefaultDescription(defaultDescription.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// (2) if we don't have a match yet, see if this type is in our list of extras.
|
||||
if (!mimeInfo)
|
||||
|
@ -386,7 +416,7 @@ nsExternalAppHandler * nsExternalHelperAppService::CreateNewExternalHandler(nsIM
|
|||
// add any XP intialization code for an external handler that we may need here...
|
||||
// right now we don't have any but i bet we will before we are done.
|
||||
|
||||
handler->Init(aMIMEInfo, aTempFileExtension, aWindowContext);
|
||||
handler->Init(aMIMEInfo, aTempFileExtension, aWindowContext, this);
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
@ -477,7 +507,7 @@ nsresult nsExternalHelperAppService::FillContentHandlerProperties(const char * a
|
|||
rv = InitDataSource();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCString contentTypeHandlerNodeName (NC_CONTENT_NODE_HANDLER_PREFIX);
|
||||
nsCAutoString contentTypeHandlerNodeName(NC_CONTENT_NODE_HANDLER_PREFIX);
|
||||
contentTypeHandlerNodeName.Append(aContentType);
|
||||
|
||||
nsCOMPtr<nsIRDFResource> contentTypeHandlerNodeResource;
|
||||
|
@ -493,17 +523,22 @@ nsresult nsExternalHelperAppService::FillContentHandlerProperties(const char * a
|
|||
if (stringValue && trueString.Equals(stringValue))
|
||||
aMIMEInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
|
||||
// use system default
|
||||
FillLiteralValueFromTarget(contentTypeHandlerNodeResource,kNC_UseSystemDefault, &stringValue);
|
||||
if (stringValue && trueString.Equals(stringValue))
|
||||
aMIMEInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
|
||||
// handle internal
|
||||
FillLiteralValueFromTarget(contentTypeHandlerNodeResource,kNC_HandleInternal, &stringValue);
|
||||
if (stringValue && trueString.Equals(stringValue))
|
||||
aMIMEInfo->SetPreferredAction(nsIMIMEInfo::handleInternally);
|
||||
|
||||
// always ask --> these fields aren't stored in the data source anymore
|
||||
//FillLiteralValueFromTarget(contentTypeHandlerNodeResource,kNC_AlwaysAsk, &stringValue);
|
||||
//if (trueString.Equals(stringValue))
|
||||
// aMIMEInfo->SetAlwaysAskBeforeHandling(PR_TRUE);
|
||||
// else
|
||||
// aMIMEInfo->SetAlwaysAskBeforeHandling(PR_FALSE);
|
||||
// always ask
|
||||
FillLiteralValueFromTarget(contentTypeHandlerNodeResource,kNC_AlwaysAsk, &stringValue);
|
||||
if (trueString.Equals(stringValue))
|
||||
aMIMEInfo->SetAlwaysAskBeforeHandling(PR_TRUE);
|
||||
else
|
||||
aMIMEInfo->SetAlwaysAskBeforeHandling(PR_FALSE);
|
||||
|
||||
|
||||
// now digest the external application information
|
||||
|
@ -520,7 +555,7 @@ nsresult nsExternalHelperAppService::FillContentHandlerProperties(const char * a
|
|||
aMIMEInfo->SetApplicationDescription(stringValue);
|
||||
|
||||
FillLiteralValueFromTarget(externalAppNodeResource, kNC_Path, &stringValue);
|
||||
if (stringValue)
|
||||
if (stringValue && stringValue[0])
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
GetFileTokenForPath(stringValue, getter_AddRefs(application));
|
||||
|
@ -532,6 +567,42 @@ nsresult nsExternalHelperAppService::FillContentHandlerProperties(const char * a
|
|||
return rv;
|
||||
}
|
||||
|
||||
PRBool nsExternalHelperAppService::MIMETypeIsInDataSource(const char * aContentType)
|
||||
{
|
||||
nsresult rv = InitDataSource();
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
if (mOverRideDataSource)
|
||||
{
|
||||
// Get the RDF service.
|
||||
nsCOMPtr<nsIRDFService> rdf = do_GetService(kRDFServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
// Build uri for the mimetype resource.
|
||||
nsCAutoString contentTypeNodeName(NC_CONTENT_NODE_PREFIX);
|
||||
nsCAutoString contentType(aContentType);
|
||||
ToLowerCase(contentType);
|
||||
contentTypeNodeName.Append(contentType);
|
||||
|
||||
// Get the mime type resource.
|
||||
nsCOMPtr<nsIRDFResource> contentTypeNodeResource;
|
||||
rv = rdf->GetResource(contentTypeNodeName.get(), getter_AddRefs(contentTypeNodeResource));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
// Test that there's a #value arc from the mimetype resource to the mimetype literal string.
|
||||
nsCOMPtr<nsIRDFLiteral> mimeLiteral;
|
||||
NS_ConvertUTF8toUCS2 mimeType(contentType);
|
||||
rv = rdf->GetLiteral( mimeType.get(), getter_AddRefs( mimeLiteral ) );
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
PRBool exists = PR_FALSE;
|
||||
rv = mOverRideDataSource->HasAssertion(contentTypeNodeResource, kNC_Value, mimeLiteral, PR_TRUE, &exists );
|
||||
|
||||
if (NS_SUCCEEDED(rv) && exists) return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromDS(const char * aContentType, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -550,7 +621,7 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromDS(const char * a
|
|||
|
||||
|
||||
// Build uri for the mimetype resource.
|
||||
nsCString contentTypeNodeName (NC_CONTENT_NODE_PREFIX);
|
||||
nsCAutoString contentTypeNodeName(NC_CONTENT_NODE_PREFIX);
|
||||
nsCAutoString contentType(aContentType);
|
||||
ToLowerCase(contentType);
|
||||
contentTypeNodeName.Append(contentType);
|
||||
|
@ -642,6 +713,22 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromDS(const char *
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromOS(const char * aContentType, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
NS_PRECONDITION(aMIMEInfo, "Null out param");
|
||||
*aMIMEInfo = nsnull;
|
||||
// Should be implemented by per-platform derived classes.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromOS(const char * aFileExtension, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
NS_PRECONDITION(aMIMEInfo, "Null out param");
|
||||
*aMIMEInfo = nsnull;
|
||||
// Should be implemented by per-platform derived classes.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// begin external protocol service default implementation...
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -750,12 +837,14 @@ nsExternalAppHandler::nsExternalAppHandler()
|
|||
mProgressListenerInitialized = PR_FALSE;
|
||||
mContentLength = -1;
|
||||
mProgress = 0;
|
||||
mHelperAppService = nsnull;
|
||||
}
|
||||
|
||||
nsExternalAppHandler::~nsExternalAppHandler()
|
||||
{
|
||||
if (mDataBuffer)
|
||||
nsMemory::Free(mDataBuffer);
|
||||
NS_IF_RELEASE(mHelperAppService);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExternalAppHandler::GetInterface(const nsIID & aIID, void * *aInstancePtr)
|
||||
|
@ -1186,7 +1275,11 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
|
|||
{
|
||||
aChannel->GetContentLength( &mContentLength );
|
||||
}
|
||||
|
||||
|
||||
// Extract mime type for later use below.
|
||||
nsXPIDLCString MIMEType;
|
||||
mMimeInfo->GetMIMEType( getter_Copies( MIMEType ) );
|
||||
|
||||
// retarget all load notifcations to our docloader instead of the original window's docloader...
|
||||
RetargetLoadNotifications(request);
|
||||
// ignore failure...
|
||||
|
@ -1196,11 +1289,9 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
|
|||
{
|
||||
// Turn off content encoding conversions if needed
|
||||
PRBool applyConversion = PR_TRUE;
|
||||
|
||||
|
||||
nsCOMPtr<nsIExternalHelperAppService> extHandler = do_GetService("@mozilla.org/uriloader/external-helper-app-service;1");
|
||||
if (extHandler) {
|
||||
nsXPIDLCString MIMEType;
|
||||
mMimeInfo->GetMIMEType( getter_Copies( MIMEType ) );
|
||||
extHandler->ApplyDecodingForType(MIMEType, &applyConversion);
|
||||
|
||||
if (applyConversion) {
|
||||
|
@ -1235,6 +1326,42 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
|
|||
} else {
|
||||
mMimeInfo->GetAlwaysAskBeforeHandling(&alwaysAsk);
|
||||
}
|
||||
if (alwaysAsk)
|
||||
{
|
||||
// But we *don't* ask if this mimeInfo didn't come from
|
||||
// our mimeTypes.rdf data source and the user has said
|
||||
// at some point in the distant past that they don't
|
||||
// want to be asked. The latter fact would have been
|
||||
// stored in pref strings back in the old days.
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized properly");
|
||||
if (!mHelperAppService->MIMETypeIsInDataSource(MIMEType.get()))
|
||||
{
|
||||
if (!GetNeverAskFlagFromPref(NEVER_ASK_FOR_SAVE_TO_DISK_PREF, MIMEType.get()))
|
||||
{
|
||||
// Don't need to ask after all.
|
||||
alwaysAsk = PR_FALSE;
|
||||
// Make sure action matches pref (save to disk).
|
||||
mMimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
}
|
||||
else if (!GetNeverAskFlagFromPref(NEVER_ASK_FOR_OPEN_FILE_PREF, MIMEType.get()))
|
||||
{
|
||||
// Don't need to ask after all.
|
||||
alwaysAsk = PR_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This mime type isn't in our mimeTypes.rdf data source nor has
|
||||
// the user told us not to ask. In this case we set the "always ask"
|
||||
// attribute in the mime info object to false so the corresponding
|
||||
// checkbox in the helper app dialog is unchecked. That way, when
|
||||
// the user selects an action on that dialog and presses Ok, then
|
||||
// that action will be used in the future without prompting (unless
|
||||
// they explicitly check that checkbox).
|
||||
mMimeInfo->SetAlwaysAskBeforeHandling(PR_FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alwaysAsk)
|
||||
{
|
||||
// do this first! make sure we don't try to take an action until the user tells us what they want to do
|
||||
|
@ -1536,7 +1663,7 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction()
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo, const char * aTempFileExtension, nsISupports * aWindowContext)
|
||||
nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo, const char * aTempFileExtension, nsISupports * aWindowContext, nsExternalHelperAppService *aHelperAppService)
|
||||
{
|
||||
mWindowContext = aWindowContext;
|
||||
mMimeInfo = aMIMEInfo;
|
||||
|
@ -1546,6 +1673,9 @@ nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo, const char * aTempF
|
|||
mTempFileExtension = PRUnichar('.');
|
||||
mTempFileExtension.AppendWithConversion(aTempFileExtension);
|
||||
|
||||
mHelperAppService = aHelperAppService;
|
||||
NS_IF_ADDREF(mHelperAppService);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1778,8 +1908,6 @@ NS_IMETHODIMP nsExternalAppHandler::LaunchWithApplication(nsIFile * aApplication
|
|||
if (mCanceled)
|
||||
return NS_OK;
|
||||
|
||||
mMimeInfo->SetPreferredAction(nsIMIMEInfo::useHelperApp);
|
||||
|
||||
// user has chosen to launch using an application, fire any refresh tags now...
|
||||
ProcessAnyRefreshTags();
|
||||
|
||||
|
@ -1860,6 +1988,33 @@ void nsExternalAppHandler::ProcessAnyRefreshTags()
|
|||
}
|
||||
}
|
||||
|
||||
PRBool nsExternalAppHandler::GetNeverAskFlagFromPref(const char * prefName, const char * aContentType)
|
||||
{
|
||||
// Search the obsolete pref strings.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
if (prefs)
|
||||
rv = prefs->GetBranch(NEVER_ASK_PREF_BRANCH, getter_AddRefs(prefBranch));
|
||||
if (NS_SUCCEEDED(rv) && prefBranch)
|
||||
{
|
||||
nsXPIDLCString prefCString;
|
||||
nsCAutoString prefValue;
|
||||
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
||||
if (NS_SUCCEEDED(rv) && !prefCString.IsEmpty())
|
||||
{
|
||||
NS_UnescapeURL(prefCString);
|
||||
nsACString::const_iterator start, end;
|
||||
prefCString.BeginReading(start);
|
||||
prefCString.EndReading(end);
|
||||
if (CaseInsensitiveFindInReadable(nsDependentCString(aContentType), start, end))
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
// Default is true, if not found in the pref string.
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// nsIURIContentListener implementation
|
||||
NS_IMETHODIMP
|
||||
nsExternalAppHandler::OnStartURIOpen(nsIURI* aURI, PRBool* aAbortOpen)
|
||||
|
@ -1957,6 +2112,29 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromExtension(const char *aFileExt,
|
|||
if (!*_retval)
|
||||
rv = GetMIMEInfoForExtensionFromDS(aFileExt, _retval);
|
||||
|
||||
// if we don't have a match in mimeTypes.rdf, then try the per-platform OS settings
|
||||
if (!*_retval)
|
||||
{
|
||||
rv = GetMIMEInfoForExtensionFromOS(aFileExt, _retval);
|
||||
}
|
||||
else if (!cachedInfo)
|
||||
{
|
||||
// Get OS settings so we can fill the "default" fields in the MIMEInfo we got
|
||||
// from mimeTypes.rdf.
|
||||
nsCOMPtr<nsIMIMEInfo> osInfo;
|
||||
if (NS_SUCCEEDED(GetMIMEInfoForExtensionFromOS(aFileExt, getter_AddRefs(osInfo))))
|
||||
{
|
||||
// Extract default application and default description.
|
||||
nsCOMPtr<nsIFile> defaultApp;
|
||||
nsXPIDLString defaultDescription;
|
||||
osInfo->GetDefaultApplicationHandler(getter_AddRefs(defaultApp));
|
||||
osInfo->GetDefaultDescription(getter_Copies(defaultDescription));
|
||||
// Copy to result mime info object.
|
||||
(*_retval)->SetDefaultApplicationHandler(defaultApp);
|
||||
(*_retval)->SetDefaultDescription(defaultDescription.get());
|
||||
}
|
||||
}
|
||||
|
||||
// if we still don't have a match, then we give up, we don't know
|
||||
// anything about it... return an error.
|
||||
|
||||
|
@ -1982,6 +2160,29 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromMIMEType(const char *aMIMEType,
|
|||
if (!*_retval)
|
||||
rv = GetMIMEInfoForMimeTypeFromDS(aMIMEType, _retval);
|
||||
|
||||
// if we don't have a match in mimeTypes.rdf, then try the per-platform OS settings
|
||||
if (!*_retval)
|
||||
{
|
||||
rv = GetMIMEInfoForMimeTypeFromOS(aMIMEType, _retval);
|
||||
}
|
||||
else if (!cachedInfo)
|
||||
{
|
||||
// Get OS settings so we can fill the "default" fields in the MIMEInfo we got
|
||||
// from mimeTypes.rdf.
|
||||
nsCOMPtr<nsIMIMEInfo> osInfo;
|
||||
if (NS_SUCCEEDED(GetMIMEInfoForMimeTypeFromOS(aMIMEType, getter_AddRefs(osInfo))))
|
||||
{
|
||||
// Extract default application and default description.
|
||||
nsCOMPtr<nsIFile> defaultApp;
|
||||
nsXPIDLString defaultDescription;
|
||||
osInfo->GetDefaultApplicationHandler(getter_AddRefs(defaultApp));
|
||||
osInfo->GetDefaultDescription(getter_Copies(defaultDescription));
|
||||
// Copy to result mime info object.
|
||||
(*_retval)->SetDefaultApplicationHandler(defaultApp);
|
||||
(*_retval)->SetDefaultDescription(defaultDescription.get());
|
||||
}
|
||||
}
|
||||
|
||||
// if we still don't have a match, then we give up, we don't know anything about it...
|
||||
// return an error.
|
||||
|
||||
|
@ -2099,7 +2300,7 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromFile( nsIFile* aFile, char
|
|||
}
|
||||
}
|
||||
|
||||
nsCString fileExt( ext );
|
||||
nsCAutoString fileExt( ext );
|
||||
// Handle the mac case
|
||||
#if defined(XP_MAC) || defined (XP_MACOSX)
|
||||
nsCOMPtr<nsILocalFileMac> macFile;
|
||||
|
|
|
@ -83,12 +83,24 @@ public:
|
|||
// in a in memory data source....
|
||||
nsresult GetMIMEInfoForExtensionFromDS(const char * aFileExtension, nsIMIMEInfo ** aMIMEInfo);
|
||||
|
||||
// GetMIMEInfoForMimeTypeFromOS --> Given a content type, look up the system default information to
|
||||
// see if we can create a mime info object for this content type.
|
||||
virtual nsresult GetMIMEInfoForMimeTypeFromOS(const char * aContentType, nsIMIMEInfo ** aMIMEInfo);
|
||||
|
||||
// GetMIMEInfoForExtensionFromOS --> Given an extension, look up the system default information to
|
||||
// see if we can create a mime info object for this extension.
|
||||
virtual nsresult GetMIMEInfoForExtensionFromOS(const char * aFileExtension, nsIMIMEInfo ** aMIMEInfo);
|
||||
|
||||
// GetFileTokenForPath must be implemented by each platform.
|
||||
// platformAppPath --> a platform specific path to an application that we got out of the
|
||||
// rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform
|
||||
// aFile --> an nsIFile representation of that platform application path.
|
||||
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile) = 0;
|
||||
|
||||
|
||||
// helper routine used to test whether a given mime type is in our
|
||||
// mimeTypes.rdf data source
|
||||
PRBool MIMETypeIsInDataSource(const char * aContentType);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFDataSource> mOverRideDataSource;
|
||||
|
||||
|
@ -96,6 +108,7 @@ protected:
|
|||
nsCOMPtr<nsIRDFResource> kNC_Value;
|
||||
nsCOMPtr<nsIRDFResource> kNC_FileExtensions;
|
||||
nsCOMPtr<nsIRDFResource> kNC_Path;
|
||||
nsCOMPtr<nsIRDFResource> kNC_UseSystemDefault;
|
||||
nsCOMPtr<nsIRDFResource> kNC_SaveToDisk;
|
||||
nsCOMPtr<nsIRDFResource> kNC_AlwaysAsk;
|
||||
nsCOMPtr<nsIRDFResource> kNC_HandleInternal;
|
||||
|
@ -165,7 +178,7 @@ public:
|
|||
nsExternalAppHandler();
|
||||
virtual ~nsExternalAppHandler();
|
||||
|
||||
virtual nsresult Init(nsIMIMEInfo * aMIMEInfo, const char * aFileExtension, nsISupports * aWindowContext);
|
||||
virtual nsresult Init(nsIMIMEInfo * aMIMEInfo, const char * aFileExtension, nsISupports * aWindowContext, nsExternalHelperAppService *aHelperAppService);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mTempFile;
|
||||
|
@ -229,6 +242,8 @@ protected:
|
|||
// helper routine which peaks at the mime action specified by mMimeInfo
|
||||
// and calls either MoveFile or OpenWithApplication
|
||||
nsresult ExecuteDesiredAction();
|
||||
// helper routine that searches a pref string for a given mime type
|
||||
PRBool GetNeverAskFlagFromPref(const char * prefName, const char * aContentType);
|
||||
|
||||
// initialize an nsIDownload object for use as a progress object
|
||||
nsresult InitializeDownload(nsIDownload*);
|
||||
|
@ -245,6 +260,7 @@ protected:
|
|||
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
|
||||
nsCOMPtr<nsIChannel> mOriginalChannel; // in the case of a redirect, this will be the pre-redirect channel.
|
||||
nsCOMPtr<nsIHelperAppLauncherDialog> mDialog;
|
||||
nsExternalHelperAppService *mHelperAppService;
|
||||
};
|
||||
|
||||
#endif // nsExternalHelperAppService_h__
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
|
||||
// handler properties
|
||||
#define NC_RDF_SAVETODISK NC_NAMESPACE_URI"saveToDisk"
|
||||
#define NC_RDF_USESYSTEMDEFAULT NC_NAMESPACE_URI"useSystemDefault"
|
||||
#define NC_RDF_HANDLEINTERNAL NC_NAMESPACE_URI"handleInternal"
|
||||
#define NC_RDF_ALWAYSASK NC_NAMESPACE_URI"alwaysAsk"
|
||||
#define NC_RDF_EXTERNALAPPLICATION NC_NAMESPACE_URI"externalApplication"
|
||||
|
|
|
@ -38,12 +38,6 @@
|
|||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#define NEVER_ASK_FOR_SAVE_TO_DISK_PREF "browser.helperApps.neverAsk.saveToDisk"
|
||||
#define NEVER_ASK_FOR_OPEN_FILE_PREF "browser.helperApps.neverAsk.openFile"
|
||||
|
||||
// nsISupports methods
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo);
|
||||
|
@ -51,10 +45,12 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo);
|
|||
// nsMIMEInfoImpl methods
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl() {
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
mAlwaysAskBeforeHandling = PR_TRUE;
|
||||
}
|
||||
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType) :mMIMEType( aMIMEType ){
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
mAlwaysAskBeforeHandling = PR_TRUE;
|
||||
}
|
||||
|
||||
PRUint32
|
||||
|
@ -287,6 +283,18 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetApplicationDescription(const PRUnichar * aAppli
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultDescription(PRUnichar ** aDefaultDescription)
|
||||
{
|
||||
*aDefaultDescription = ToNewUnicode(mDefaultAppDescription);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDefaultDescription(const PRUnichar * aDefaultDescription)
|
||||
{
|
||||
mDefaultAppDescription = aDefaultDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredApplicationHandler(nsIFile ** aPreferredAppHandler)
|
||||
{
|
||||
*aPreferredAppHandler = mPreferredApplication;
|
||||
|
@ -300,6 +308,19 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredApplicationHandler(nsIFile * aPreferre
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultApplicationHandler(nsIFile ** aDefaultAppHandler)
|
||||
{
|
||||
*aDefaultAppHandler = mDefaultApplication;
|
||||
NS_IF_ADDREF(*aDefaultAppHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDefaultApplicationHandler(nsIFile * aDefaultAppHandler)
|
||||
{
|
||||
mDefaultApplication = aDefaultAppHandler;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredAction(nsMIMEInfoHandleAction * aPreferredAction)
|
||||
{
|
||||
*aPreferredAction = mPreferredAction;
|
||||
|
@ -314,104 +335,13 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredAction(nsMIMEInfoHandleAction aPreferr
|
|||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetAlwaysAskBeforeHandling(PRBool * aAlwaysAsk)
|
||||
{
|
||||
// this is a bit complicated. We now store the always ask preference in two preferences:
|
||||
// browser.helperApps.neverAsk.saveToDisk and
|
||||
// browser.helperApps.neverAsk.openFile
|
||||
// Both lists are comma delimited lists containing mime types which the user has specifically
|
||||
// decided to override the helper app dialog for.
|
||||
|
||||
// for get always ask, we just need to search both pref branches for our mime type...
|
||||
PRBool mimeTypeIsPresent = PR_FALSE;
|
||||
CheckPrefForMimeType(NEVER_ASK_FOR_SAVE_TO_DISK_PREF, &mimeTypeIsPresent);
|
||||
|
||||
if (mimeTypeIsPresent)
|
||||
{
|
||||
*aAlwaysAsk = PR_FALSE;
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckPrefForMimeType(NEVER_ASK_FOR_OPEN_FILE_PREF, &mimeTypeIsPresent);
|
||||
if (mimeTypeIsPresent)
|
||||
{
|
||||
*aAlwaysAsk = PR_FALSE;
|
||||
// do we need to force a preferred action here? I don't think so...
|
||||
}
|
||||
}
|
||||
*aAlwaysAsk = mAlwaysAskBeforeHandling;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// re-write me to use new string apis to avoid the extra string copy of the pref value in order to call ::Find
|
||||
void nsMIMEInfoImpl::CheckPrefForMimeType(const char * prefName, PRBool * aMimeTypeIsPresent)
|
||||
{
|
||||
*aMimeTypeIsPresent = PR_FALSE;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefs, &rv);
|
||||
if (NS_SUCCEEDED(rv) && prefBranch)
|
||||
{
|
||||
nsXPIDLCString prefCString;
|
||||
nsCAutoString prefValue;
|
||||
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
||||
if (NS_SUCCEEDED(rv) && *prefCString.get())
|
||||
{
|
||||
nsUnescape(NS_CONST_CAST(char*,(const char*)prefCString.get()));
|
||||
|
||||
prefValue = prefCString; // i should be able to avoid this string copy
|
||||
PRInt32 pos = prefValue.Find(mMIMEType, PR_TRUE);
|
||||
if (pos >= 0)
|
||||
*aMimeTypeIsPresent = PR_TRUE;
|
||||
}
|
||||
} // if we got the prefs service
|
||||
}
|
||||
|
||||
void nsMIMEInfoImpl::SetRememberPrefForMimeType(const char * prefName)
|
||||
{
|
||||
// first, make sure it isn't already there...
|
||||
PRBool mimeTypeIsPresent = PR_FALSE;
|
||||
CheckPrefForMimeType(prefName, &mimeTypeIsPresent);
|
||||
if (mimeTypeIsPresent) return; // mime type is already present...
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefs, &rv);
|
||||
if (NS_SUCCEEDED(rv) && prefBranch)
|
||||
{
|
||||
// read out the current pref string and unescape it.
|
||||
nsXPIDLCString prefCString;
|
||||
nsCAutoString prefValue;
|
||||
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
||||
if (NS_SUCCEEDED(rv) && *prefCString.get())
|
||||
{
|
||||
nsUnescape(NS_CONST_CAST(char*,(const char*)prefCString.get()));
|
||||
prefValue = prefCString;
|
||||
}
|
||||
|
||||
if (!prefValue.IsEmpty()) // if the pref string isn't empty...
|
||||
{
|
||||
prefValue.Append(", ");
|
||||
prefValue.Append(mMIMEType);
|
||||
}
|
||||
else
|
||||
prefValue = mMIMEType;
|
||||
|
||||
// always escape the pref b4 storing it in case someone enters some funky characters for a mime type...
|
||||
nsXPIDLCString escapedPrefString;
|
||||
escapedPrefString.Adopt(nsEscape(prefValue.get(), url_XAlphas));
|
||||
prefBranch->SetCharPref(prefName, escapedPrefString);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
||||
{
|
||||
if (!aAlwaysAsk)
|
||||
{
|
||||
if (mPreferredAction == nsIMIMEInfo::saveToDisk)
|
||||
SetRememberPrefForMimeType(NEVER_ASK_FOR_SAVE_TO_DISK_PREF);
|
||||
else
|
||||
SetRememberPrefForMimeType(NEVER_ASK_FOR_OPEN_FILE_PREF);
|
||||
}
|
||||
mAlwaysAskBeforeHandling = aAlwaysAsk;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -64,11 +64,11 @@ public:
|
|||
protected:
|
||||
nsCString mMIMEType;
|
||||
nsCOMPtr<nsIFile> mPreferredApplication; // preferred application associated with this type.
|
||||
nsCOMPtr<nsIFile> mDefaultApplication; // default application associated with this type.
|
||||
nsMIMEInfoHandleAction mPreferredAction; // preferred action to associate with this type
|
||||
nsString mPreferredAppDescription;
|
||||
|
||||
void CheckPrefForMimeType(const char * prefName, PRBool * aMimeTypeIsPresent);
|
||||
void SetRememberPrefForMimeType(const char * prefName);
|
||||
nsString mDefaultAppDescription;
|
||||
PRBool mAlwaysAskBeforeHandling;
|
||||
};
|
||||
|
||||
#endif //__nsmimeinfoimpl_h___
|
||||
|
|
|
@ -161,7 +161,6 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf
|
|||
const char * strPath = path.get();
|
||||
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
|
@ -1268,30 +1267,24 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
|
|||
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (localFile)
|
||||
{
|
||||
if (localFile)
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (!localFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForExtensionFromOS(const char *aFileExt, nsIMIMEInfo **_retval)
|
||||
{
|
||||
// if the extension is null, return immediately
|
||||
if (!aFileExt)
|
||||
if (!aFileExt || !*aFileExt)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// first, see if the base class already has an entry....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromExtension(aFileExt, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK; // okay we got an entry so we are done.
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
#ifdef DEBUG_bzbarsky
|
||||
fprintf(stderr, "Here we do an extension lookup for %s\n\n", aFileExt);
|
||||
|
@ -1337,12 +1330,12 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
|||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetPreferredApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useHelperApp);
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
#ifdef DEBUG_bzbarsky
|
||||
fprintf(stderr, "Here we want to set handler to: %s\n", NS_ConvertUCS2toUTF8(handler).get());
|
||||
#endif // DEBUG_bzbarsky
|
||||
mimeInfo->SetApplicationDescription(handler.get());
|
||||
mimeInfo->SetDefaultApplicationDescription(handler.get());
|
||||
}
|
||||
} else {
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
|
@ -1357,15 +1350,13 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char *aMIMEType,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForMimeTypeFromOS(const char *aMIMEType, nsIMIMEInfo ** _retval)
|
||||
{
|
||||
// if the extension is null, return immediately
|
||||
if (!aMIMEType)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// first, see if the base class already has an entry....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromMIMEType(aMIMEType, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK; // okay we got an entry so we are done.
|
||||
nsresult rv;
|
||||
#ifdef DEBUG_bzbarsky
|
||||
fprintf(stderr, "Here we do a mimetype lookup for %s\n\n\n", aMIMEType);
|
||||
#endif // DEBUG_bzbarsky
|
||||
|
@ -1432,13 +1423,13 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char *aMIMEType,
|
|||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetPreferredApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useHelperApp);
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
// FIXME set the handler
|
||||
#ifdef DEBUG_bzbarsky
|
||||
fprintf(stderr, "Here we want to set handler to: %s\n", NS_ConvertUCS2toUTF8(handler).get());
|
||||
#endif // DEBUG_bzbarsky
|
||||
mimeInfo->SetApplicationDescription(handler.get());
|
||||
mimeInfo->SetDefaultApplicationDescription(handler.get());
|
||||
} else {
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ public:
|
|||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// override nsIMIMEService methods to contain mime.types and mime.info look up steps
|
||||
NS_IMETHODIMP GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
NS_IMETHODIMP GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retval);
|
||||
// method overrides for mime.types and mime.info look up steps
|
||||
nsresult GetMIMEInfoForExtensionFromOS(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
nsresult GetMIMEInfoForMimeTypeFromOS(const char *aMIMEType, nsIMIMEInfo ** _retval);
|
||||
|
||||
// override nsIExternalProtocolService methods
|
||||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
|
|
|
@ -164,30 +164,38 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf
|
|||
aTempFile->GetNativePath(path);
|
||||
LOG(("Launching helper on '%s'\n", path.get()));
|
||||
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
if (application)
|
||||
nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
if (action == nsIMIMEInfo::useHelperApp)
|
||||
{
|
||||
if (LOG_ENABLED()) {
|
||||
nsCAutoString appPath;
|
||||
application->GetNativePath(appPath);
|
||||
LOG(("The helper is '%s'\n", appPath.get()));
|
||||
}
|
||||
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
const char * strPath = path.get();
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
if (NS_FAILED(rv = process->Run(PR_FALSE, &strPath, 1, &pid)))
|
||||
return rv;
|
||||
}
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if we had hooks into the OS we can use them here to launch the app
|
||||
aMIMEInfo->GetDefaultApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
|
||||
// The nsIMIMEInfo should have either the default or preferred
|
||||
// application handler attribute set to match the preferredAction!
|
||||
if (!application)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (LOG_ENABLED()) {
|
||||
nsCAutoString appPath;
|
||||
application->GetNativePath(appPath);
|
||||
LOG(("The helper is '%s'\n", appPath.get()));
|
||||
}
|
||||
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
const char * strPath = path.get();
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
if (NS_FAILED(rv = process->Run(PR_FALSE, &strPath, 1, &pid)))
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -1300,18 +1308,16 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForExtensionFromOS(const char *aFileExt,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
// if the extension is null, return immediately
|
||||
if (!aFileExt)
|
||||
if (!aFileExt || !*aFileExt)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// first, see if the base class already has an entry....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromExtension(aFileExt, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK; // okay we got an entry so we are done.
|
||||
|
||||
LOG(("Here we do an extension lookup for '%s'\n", aFileExt));
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsAutoString mimeType, majorType, minorType,
|
||||
mime_types_description, mailcap_description,
|
||||
handler, mozillaFlags;
|
||||
|
@ -1375,9 +1381,9 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
|||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetPreferredApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useHelperApp);
|
||||
mimeInfo->SetApplicationDescription(handler.get());
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(handler.get());
|
||||
}
|
||||
} else {
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
|
@ -1392,16 +1398,14 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char *aMIMEType,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForMimeTypeFromOS(const char *aMIMEType,
|
||||
nsIMIMEInfo ** _retval) {
|
||||
// if the extension is null, return immediately
|
||||
if (!aMIMEType)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// first, see if the base class already has an entry....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromMIMEType(aMIMEType, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK; // okay we got an entry so we are done.
|
||||
LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType));
|
||||
nsresult rv;
|
||||
nsAutoString extensions,
|
||||
mime_types_description, mailcap_description,
|
||||
handler, mozillaFlags;
|
||||
|
@ -1487,9 +1491,9 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char *aMIMEType,
|
|||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetPreferredApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useHelperApp);
|
||||
mimeInfo->SetApplicationDescription(handler.get());
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(handler.get());
|
||||
} else {
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ public:
|
|||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// override nsIMIMEService methods to contain mime.types and mime.info look up steps
|
||||
NS_IMETHODIMP GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
NS_IMETHODIMP GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retval);
|
||||
// method overrides for mime.types and mime.info look up steps
|
||||
nsresult GetMIMEInfoForExtensionFromOS(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
nsresult GetMIMEInfoForMimeTypeFromOS(const char *aMIMEType, nsIMIMEInfo **_retval);
|
||||
|
||||
// override nsIExternalProtocolService methods
|
||||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
|
|
|
@ -84,14 +84,10 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf
|
|||
|
||||
PRBool executable = PR_TRUE;
|
||||
local->IsExecutable(&executable);
|
||||
if (!executable)
|
||||
{
|
||||
rv = local->Launch();
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
if (executable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = local->Launch();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,19 +238,15 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
|
|||
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (localFile)
|
||||
{
|
||||
if (localFile)
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (!localFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
|
||||
|
@ -301,17 +293,14 @@ static nsresult GetMIMEInfoFromRegistry( LPBYTE fileType, nsIMIMEInfo *pInfo )
|
|||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIMIMEService method over-rides used to gather information from the windows registry for
|
||||
// method overrides used to gather information from the windows registry for
|
||||
// various mime types.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval)
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForExtensionFromOS(const char *aFileExt, nsIMIMEInfo **_retval)
|
||||
{
|
||||
// first, see if the base class already has an entry....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromExtension(aFileExt, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK; // okay we got an entry so we are done.
|
||||
if (!aFileExt || *aFileExt == '\0') return NS_ERROR_FAILURE;
|
||||
if (!aFileExt || !*aFileExt) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = NS_OK;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// windows registry assumes your file extension is going to include the '.'.
|
||||
// so make sure it's there...
|
||||
|
@ -351,7 +340,7 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt, nsIMI
|
|||
// the format of the description usually looks like appname.version.something.
|
||||
// for now, let's try to make it pretty and just show you the appname.
|
||||
|
||||
mimeInfo->SetApplicationDescription(description.get());
|
||||
mimeInfo->SetDefaultDescription(description.get());
|
||||
|
||||
// Get other nsIMIMEInfo fields from registry, if possible.
|
||||
if ( pFileDescription )
|
||||
|
@ -379,12 +368,8 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char *aFileExt, nsIMI
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo ** _retval)
|
||||
nsresult nsOSHelperAppService::GetMIMEInfoForMimeTypeFromOS(const char *aMIMEType, nsIMIMEInfo ** _retval)
|
||||
{
|
||||
// first, see if the base class already has an entry....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromMIMEType(aMIMEType, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK; // okay we got an entry so we are done.
|
||||
|
||||
if (PL_strcasecmp(aMIMEType, APPLICATION_OCTET_STREAM) == 0) {
|
||||
/* XXX Gross hack to wallpaper over the most common Win32
|
||||
* extension issues caused by the fix for bug 116938. See bug
|
||||
|
@ -406,8 +391,6 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char *aMIMEType, nsIMI
|
|||
// now look up based on the file extension.
|
||||
if (!fileExtension.IsEmpty())
|
||||
return GetFromExtension(fileExtension.get(), _retval);
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ public:
|
|||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
NS_IMETHOD LoadUrl(nsIURI * aURL);
|
||||
|
||||
// over ride nsIMIMEService methods to contain windows registry look up steps....
|
||||
NS_IMETHOD GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
NS_IMETHOD GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo ** _retval);
|
||||
// method overrides for windows registry look up steps....
|
||||
nsresult GetMIMEInfoForExtensionFromOS(const char *aFileExt, nsIMIMEInfo **_retval);
|
||||
nsresult GetMIMEInfoForMimeTypeFromOS(const char *aMIMEType, nsIMIMEInfo ** _retval);
|
||||
|
||||
// GetFileTokenForPath must be implemented by each platform.
|
||||
// platformAppPath --> a platform specific path to an application that we got out of the
|
||||
|
|
|
@ -138,7 +138,31 @@ HandlerOverride.prototype = {
|
|||
else
|
||||
changeMIMEStuff(HANDLER_URI(this.mimeType), "saveToDisk", aSavedToDisk);
|
||||
this.setHandlerProcedure("handleInternal", "false");
|
||||
this.setHandlerProcedure("useSystemDefault", "false");
|
||||
},
|
||||
|
||||
get useSystemDefault()
|
||||
{
|
||||
return getHandlerInfoForType(this.URI, "useSystemDefault");
|
||||
},
|
||||
|
||||
set useSystemDefault(aUseSystemDefault)
|
||||
{
|
||||
var handlerSource = gRDF.GetResource(HANDLER_URI(this.mimeType));
|
||||
var handlerProperty = gRDF.GetResource(NC_RDF("useSystemDefault"));
|
||||
var trueLiteral = gRDF.GetLiteral("true");
|
||||
var hasUseSystemDefault = gDS.HasAssertion(handlerSource, handlerProperty, trueLiteral, true);
|
||||
if (!hasUseSystemDefault) {
|
||||
var falseLiteral = gRDF.GetLiteral("false");
|
||||
hasUseSystemDefault = gDS.HasAssertion(handlerSource, handlerProperty, falseLiteral, true);
|
||||
}
|
||||
if (!this.mUpdateMode || !hasUseSystemDefault)
|
||||
assertMIMEStuff(HANDLER_URI(this.mimeType), "useSystemDefault", aUseSystemDefault);
|
||||
else
|
||||
changeMIMEStuff(HANDLER_URI(this.mimeType), "useSystemDefault", aUseSystemDefault);
|
||||
this.setHandlerProcedure("handleInternal", "false");
|
||||
this.setHandlerProcedure("saveToDisk", "false");
|
||||
},
|
||||
|
||||
get handleInternal()
|
||||
{
|
||||
|
@ -160,6 +184,7 @@ HandlerOverride.prototype = {
|
|||
else
|
||||
changeMIMEStuff(HANDLER_URI(this.mimeType), "handleInternal", aHandledInternally);
|
||||
this.setHandlerProcedure("saveToDisk", "false");
|
||||
this.setHandlerProcedure("useSystemDefault", "false");
|
||||
},
|
||||
|
||||
setHandlerProcedure: function (aHandlerProcedure, aValue)
|
||||
|
@ -317,7 +342,7 @@ function mimeHandlerExists(aMIMEType)
|
|||
{
|
||||
var valueProperty = gRDF.GetResource(NC_RDF("value"));
|
||||
var mimeSource = gRDF.GetResource(MIME_URI(aMIMEType));
|
||||
var mimeLiteral = gRDF.GetLiteral(gMIMEField.value);
|
||||
var mimeLiteral = gRDF.GetLiteral(aMIMEType);
|
||||
return gDS.HasAssertion(mimeSource, valueProperty, mimeLiteral, true);
|
||||
}
|
||||
|
||||
|
@ -349,7 +374,6 @@ function unassertMIMEStuff(aMIMEString, aPropertyString, aValueString)
|
|||
|
||||
function removeOverride(aMIMEType)
|
||||
{
|
||||
dump("*** mimeType = " + aMIMEType + "\n");
|
||||
// remove entry from seq
|
||||
var rdfc = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
|
||||
if (rdfc) {
|
||||
|
@ -372,7 +396,7 @@ function removeOverride(aMIMEType)
|
|||
// remove items from the graph
|
||||
var urns = [ [MIME_URI, ["description", "editable", "value", "fileExtensions", "smallIcon", "largeIcon"],
|
||||
[HANDLER_URI, "handlerProp"]],
|
||||
[HANDLER_URI, ["handleInternal", "saveToDisk", "alwaysAsk"],
|
||||
[HANDLER_URI, ["handleInternal", "saveToDisk", "alwaysAsk", "useSystemDefault"],
|
||||
[APP_URI, "externalApplication"]],
|
||||
[APP_URI, ["path", "prettyName"]] ];
|
||||
for (var i = 0; i < urns.length; i++) {
|
||||
|
@ -396,7 +420,7 @@ function removeOverride(aMIMEType)
|
|||
gDS.Unassert(mimeRes, propertyRes, mimeValue, true);
|
||||
}
|
||||
}
|
||||
if (urns[i][2]) {
|
||||
if ("2" in urns[i] && urns[i][2]) {
|
||||
var linkRes = gRDF.GetResource(NC_RDF(urns[i][2][1]), true);
|
||||
var linkTarget = gRDF.GetResource(urns[i][2][0](aMIMEType), true);
|
||||
gDS.Unassert(mimeRes, linkRes, linkTarget);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
style="width: 30em;"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&editType.label;"
|
||||
newtitle="&newType.label;"
|
||||
onload="Startup();"
|
||||
ondialogaccept="return onAccept();">
|
||||
|
||||
|
@ -41,28 +42,38 @@
|
|||
<script type="application/x-javascript" src="chrome://communicator/content/pref/overrideHandler.js"/>
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
var gExtensionLabel = null;
|
||||
var gExtension = null;
|
||||
var gMIMEField = null;
|
||||
var gHandlerGroup = null;
|
||||
var gAppPath = null;
|
||||
var gAskBeforeOpen = null;
|
||||
var gContentType = null;
|
||||
var gDescription = null;
|
||||
var gPrefApplicationsBundle = null;
|
||||
|
||||
var gOldMIME = null;
|
||||
var gOldDesc = null;
|
||||
var gOldExtensions = null;
|
||||
|
||||
const nsIMIMEInfo = Components.interfaces.nsIMIMEInfo;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
gContentType = document.getElementById("contentType");
|
||||
gExtensionLabel = document.getElementById("extension");
|
||||
gDescription = document.getElementById("description");
|
||||
gExtension = document.getElementById("extension");
|
||||
gMIMEField = document.getElementById("mimeType");
|
||||
gHandlerGroup = document.getElementById("handler");
|
||||
gAppPath = document.getElementById("appPath");
|
||||
gAskBeforeOpen = document.getElementById("askBeforeOpen");
|
||||
|
||||
gPrefApplicationsBundle = document.getElementById("bundle_prefApplications");
|
||||
|
||||
// Set values for radio items to nsIMIMEInfo constants
|
||||
var rSaveToDisk = document.getElementById("saveToDisk");
|
||||
var rUseHelperApp = document.getElementById("useHelperApp");
|
||||
var rUseSystemDefault = document.getElementById("useSystemDefault");
|
||||
rSaveToDisk.value = nsIMIMEInfo.saveToDisk;
|
||||
rUseHelperApp.value = nsIMIMEInfo.useHelperApp;
|
||||
rUseSystemDefault.value = nsIMIMEInfo.useSystemDefault;
|
||||
|
||||
var handlerInfo = window.arguments[0];
|
||||
|
||||
|
@ -71,32 +82,70 @@
|
|||
// Arg is an nsHelperAppDlg object in this case.
|
||||
window.gHelperAppDlg = window.arguments[0];
|
||||
var info = window.arguments[0].mLauncher.MIMEInfo;
|
||||
|
||||
// Get mime type from which we can construct a HandlerInfo...
|
||||
var mimeType = info.MIMEType.toLowerCase();
|
||||
|
||||
// Construct what we need from mime type URI.
|
||||
getDS();
|
||||
handlerInfo = window.arguments[0] = new HandlerOverride( MIME_URI( mimeType ) );
|
||||
|
||||
// Don't let the user change the mime type; we ignore any such changes anyway.
|
||||
gMIMEField.setAttribute( "readonly", "true" );
|
||||
|
||||
// Update entry (without dialog showing).
|
||||
try {
|
||||
updateEntry(info);
|
||||
} catch(e) { dump("updateEntry failed: " + e + "\n"); }
|
||||
|
||||
// Close the dialog.
|
||||
window.close();
|
||||
|
||||
// Done.
|
||||
return;
|
||||
}
|
||||
|
||||
// Default to true in case the preference cannot be retrieved
|
||||
var forceAlwaysAsk = true;
|
||||
try {
|
||||
var prefService = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPrefService);
|
||||
var prefBranch = prefService.getBranch("browser.helperApps.alwaysAsk.");
|
||||
forceAlwaysAsk = prefBranch.getBoolPref("force");
|
||||
} catch(e) {
|
||||
dump("forceAlwaysAsk defaulting to true since preference couldn't be opened\n");
|
||||
}
|
||||
|
||||
if ( !handlerInfo.URI )
|
||||
{
|
||||
// Opening for "New Type".
|
||||
var newTitle = document.documentElement.getAttribute("newtitle");
|
||||
document.documentElement.setAttribute("title", newTitle);
|
||||
|
||||
// Initialize some stuff to blank for new types.
|
||||
gOldMIME = gOldDesc = gOldExtensions = "";
|
||||
|
||||
// Make default "use system default."
|
||||
gHandlerGroup.selectedItem = gHandlerGroup.getElementsByAttribute("value",nsIMIMEInfo.useSystemDefault)[0];
|
||||
|
||||
// Always ask box default depends on pref.
|
||||
gAskBeforeOpen.checked = forceAlwaysAsk;
|
||||
gAskBeforeOpen.disabled = forceAlwaysAsk;
|
||||
|
||||
// Put focus on mime type field.
|
||||
gMIMEField.focus();
|
||||
|
||||
// Size/position the dialog.
|
||||
sizeToContent();
|
||||
window.moveToAlertPosition();
|
||||
|
||||
// Avoid the normal "edit" case code.
|
||||
return;
|
||||
}
|
||||
|
||||
gExtensionLabel.setAttribute("value", handlerInfo.extensions);
|
||||
gExtension.setAttribute("value", handlerInfo.extensions);
|
||||
gMIMEField.value = handlerInfo.mimeType;
|
||||
gOldMIME = handlerInfo.mimeType;
|
||||
gOldDesc = handlerInfo.description;
|
||||
gOldExtensions = handlerInfo.extensions;
|
||||
|
||||
// figure out how this type is handled
|
||||
var data = 0;
|
||||
if (handlerInfo.handleInternal == "true")
|
||||
data = 0;
|
||||
else if (handlerInfo.saveToDisk == "true")
|
||||
data = 1;
|
||||
var data = nsIMIMEInfo.saveToDisk;
|
||||
if (handlerInfo.saveToDisk == "true")
|
||||
data = nsIMIMEInfo.saveToDisk;
|
||||
else if (handlerInfo.useSystemDefault == "true")
|
||||
data = nsIMIMEInfo.useSystemDefault;
|
||||
else
|
||||
data = 2;
|
||||
data = nsIMIMEInfo.useHelperApp;
|
||||
|
||||
gHandlerGroup.selectedItem = gHandlerGroup.getElementsByAttribute("value", data)[0];
|
||||
doEnabling();
|
||||
|
@ -105,11 +154,6 @@
|
|||
if (appPath != undefined)
|
||||
gAppPath.value = appPath;
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"].
|
||||
getService(Components.interfaces.nsIPrefBranch);
|
||||
var forceAlwaysAsk = prefs.
|
||||
getBoolPref("browser.helperApps.alwaysAsk.force");
|
||||
|
||||
if (forceAlwaysAsk)
|
||||
{
|
||||
gAskBeforeOpen.checked = true;
|
||||
|
@ -120,7 +164,7 @@
|
|||
gAskBeforeOpen.checked = handlerInfo.alwaysAsk == "true" ? true : false;
|
||||
}
|
||||
|
||||
gContentType.setAttribute("value", handlerInfo.description);
|
||||
gDescription.setAttribute("value", handlerInfo.description);
|
||||
var ext;
|
||||
var posOfFirstSpace = handlerInfo.extensions.indexOf(" ");
|
||||
if (posOfFirstSpace > -1)
|
||||
|
@ -169,8 +213,8 @@
|
|||
|
||||
function selectAppRadio()
|
||||
{
|
||||
if (gHandlerGroup.value != "2")
|
||||
gHandlerGroup.selectedItem = gHandlerGroup.getElementsByAttribute("value", "2")[0];
|
||||
if (gHandlerGroup.value != nsIMIMEInfo.useHelperApp)
|
||||
gHandlerGroup.selectedItem = gHandlerGroup.getElementsByAttribute("value", nsIMIMEInfo.useHelperApp)[0];
|
||||
doEnabling();
|
||||
}
|
||||
|
||||
|
@ -187,6 +231,64 @@
|
|||
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
|
||||
}
|
||||
|
||||
function updateEntry(info)
|
||||
{
|
||||
// Initialize data source.
|
||||
getDS();
|
||||
|
||||
// Get mime type from which we can construct a HandlerInfo...
|
||||
var mimeType = info.MIMEType.toLowerCase();
|
||||
|
||||
// Create HandlerOverride and populate it.
|
||||
var entry = new HandlerOverride(MIME_URI(mimeType));
|
||||
entry.mUpdateMode = mimeHandlerExists(mimeType);
|
||||
entry.mimeType = mimeType;
|
||||
entry.isEditable = true;
|
||||
entry.alwaysAsk = info.alwaysAskBeforeHandling;
|
||||
|
||||
// If not updating (i.e., a newly encountered mime type),
|
||||
// then update extension list and description.
|
||||
if (!entry.mUpdateMode) {
|
||||
var extCount = { value: 0 };
|
||||
var extArray = { value: null };
|
||||
info.GetFileExtensions(extCount, extArray);
|
||||
for (var i = 0; i < extArray.value.length; i++) {
|
||||
entry.addExtension(extArray.value[i]);
|
||||
}
|
||||
entry.description = info.Description;
|
||||
entry.appDisplayName = "";
|
||||
}
|
||||
|
||||
if (info.preferredAction == nsIMIMEInfo.saveToDisk) {
|
||||
entry.saveToDisk = true;
|
||||
if (!entry.mUpdateMode) {
|
||||
// Creating a new entry, set path.
|
||||
entry.appPath = "";
|
||||
}
|
||||
} else if (info.preferredAction == nsIMIMEInfo.useSystemDefault ||
|
||||
info.preferredApplicationHandler == null) {
|
||||
entry.useSystemDefault = true;
|
||||
if (!entry.mUpdateMode) {
|
||||
// Creating a new entry, set path.
|
||||
entry.appPath = "";
|
||||
}
|
||||
} else {
|
||||
entry.saveToDisk = false;
|
||||
entry.useSystemDefault = false;
|
||||
entry.handleInternal = false;
|
||||
entry.appPath = info.preferredApplicationHandler.path;
|
||||
entry.appDisplayName = info.applicationDescription;
|
||||
}
|
||||
|
||||
// Do RDF magic.
|
||||
entry.buildLinks();
|
||||
|
||||
// flush the ds to disk.
|
||||
var remoteDS = gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
if (remoteDS)
|
||||
remoteDS.Flush();
|
||||
}
|
||||
|
||||
function onAccept()
|
||||
{
|
||||
// Validate input.
|
||||
|
@ -213,31 +315,34 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (gOldMIME)
|
||||
if (gOldMIME && gOldMIME != gMIMEField.value)
|
||||
removeOverride(gOldMIME); // delete old handler
|
||||
|
||||
// now save the information
|
||||
var handlerInfo = new HandlerOverride(MIME_URI(gMIMEField.value));
|
||||
handlerInfo.mUpdateMode = mimeHandlerExists(gMIMEField.value);
|
||||
handlerInfo.mUpdateMode = (gOldMIME == gMIMEField.value);
|
||||
handlerInfo.mimeType = gMIMEField.value;
|
||||
|
||||
// set description, editable, and extensions
|
||||
handlerInfo.description = gOldDesc
|
||||
handlerInfo.isEditable = true;
|
||||
var extensions = gOldExtensions.toLowerCase().split(" ");
|
||||
handlerInfo.description = gDescription.value;
|
||||
var extensions = gExtension.value.toLowerCase().split(" ");
|
||||
for (var i = 0; i < extensions.length; i++) {
|
||||
var currExtension = extensions[i];
|
||||
handlerInfo.addExtension(currExtension);
|
||||
}
|
||||
|
||||
// other info we need to set (not reflected in UI)
|
||||
if (gHandlerGroup.value == "2") {
|
||||
if (gHandlerGroup.value == nsIMIMEInfo.useHelperApp) {
|
||||
handlerInfo.appPath = gAppPath.value;
|
||||
handlerInfo.setHandlerProcedure("saveToDisk", "false");
|
||||
handlerInfo.setHandlerProcedure("useSystemDefault", "false");
|
||||
handlerInfo.setHandlerProcedure("handleInternal", "false");
|
||||
}
|
||||
else if (gHandlerGroup.value == "1")
|
||||
else if (gHandlerGroup.value == nsIMIMEInfo.saveToDisk)
|
||||
handlerInfo.saveToDisk = true;
|
||||
else if (gHandlerGroup.value == nsIMIMEInfo.useSystemDefault)
|
||||
handlerInfo.useSystemDefault = true;
|
||||
else
|
||||
handlerInfo.handleInternal = true;
|
||||
|
||||
|
@ -253,7 +358,7 @@
|
|||
if (file) {
|
||||
try {
|
||||
file.initWithPath(gAppPath.value);
|
||||
handlerInfo.appDisplayName = file.unicodeLeafName;
|
||||
handlerInfo.appDisplayName = file.leafName;
|
||||
}
|
||||
catch(e) {
|
||||
handlerInfo.appDisplayName = gAppPath.value;
|
||||
|
@ -268,83 +373,60 @@
|
|||
if (remoteDS)
|
||||
remoteDS.Flush();
|
||||
|
||||
// See if invoked on behalf of helper app dialog...
|
||||
if ( "gHelperAppDlg" in window ) {
|
||||
// Get mime info.
|
||||
var info = gHelperAppDlg.mLauncher.MIMEInfo;
|
||||
|
||||
// Update fields that might have changed.
|
||||
if ( gHandlerGroup.value == "1" ) {
|
||||
info.preferredAction = Components.interfaces.nsIMIMEInfo.saveToDisk;
|
||||
} else if ( gHandlerGroup.value == "2" ) {
|
||||
info.preferredAction = Components.interfaces.nsIMIMEInfo.useHelperApp;
|
||||
info.preferredApplicationHandler = file;
|
||||
info.applicationDescription = handlerInfo.appDisplayName;
|
||||
} else {
|
||||
info.preferredAction = Components.interfaces.nsIMIMEInfo.handleInternally;
|
||||
}
|
||||
|
||||
// tell the helper app dialog to update itself
|
||||
gHelperAppDlg.updateSelf = true;
|
||||
}
|
||||
|
||||
window.opener.gUpdateTypeRV = true;
|
||||
return true;
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
<vbox>
|
||||
<hbox align="center">
|
||||
<image id="contentTypeImage"/>
|
||||
<label id="contentType" crop="right"/>
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&mimetype.label;" accesskey="&mimetype.accesskey;" control="mimeType"/>
|
||||
<textbox id="mimeType"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&description.label;" accesskey="&description.accesskey;" control="description"/>
|
||||
<textbox id="description" crop="right" flex="1"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&extension.label;" accesskey="&extension.accesskey;" control="extension"/>
|
||||
<textbox id="extension"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</hbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<separator class="groove"/>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<grid>
|
||||
<columns>
|
||||
<column flex="1"/>
|
||||
<column flex="3"/>
|
||||
</columns>
|
||||
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&extension.label;"/>
|
||||
<label id="extension"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&mimetype.label;" accesskey="&mimetype.accesskey;"
|
||||
control="mimeType"/>
|
||||
<textbox id="mimeType" flex="1"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<groupbox>
|
||||
<caption label="&handledby.label;"/>
|
||||
|
||||
<description value="&handling.label;"/>
|
||||
<radiogroup id="handler">
|
||||
<!-- Turn this off since we can't make it work yet
|
||||
<radio value="4" label="&useDefault.label;" accesskey="&useDefault.accesskey;" oncommand="doEnabling();"/>
|
||||
-->
|
||||
<radio value="1" label="&saveToDisk.label;" accesskey="&saveToDisk.accesskey;" oncommand="doEnabling();"/>
|
||||
<radio id="useSystemDefault" label="&useDefault.label;" accesskey="&useDefault.accesskey;" oncommand="doEnabling();"/>
|
||||
<hbox align="center">
|
||||
<radio value="2" label="&application.label;" accesskey="&application.accesskey;" oncommand="doEnabling();"/>
|
||||
<radio id="useHelperApp" label="&application.label;" accesskey="&application.accesskey;" oncommand="doEnabling();"/>
|
||||
<textbox id="appPath" flex="1" onchange="selectAppRadio();"/>
|
||||
<button label="&browse.label;" accesskey="&browse.accesskey;"
|
||||
oncommand="chooseApp();"/>
|
||||
</hbox>
|
||||
<radio id="saveToDisk" label="&saveToDisk.label;" accesskey="&saveToDisk.accesskey;" oncommand="doEnabling();"/>
|
||||
</radiogroup>
|
||||
|
||||
</groupbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<hbox align="center">
|
||||
<checkbox id="askBeforeOpen" label="&askBeforeOpen.label;" accesskey="&askBeforeOpen.accesskey;"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
</dialog>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ var gDS = null;
|
|||
var gPrefApplicationsBundle = null;
|
||||
|
||||
var gExtensionField = null;
|
||||
var gMIMETypeField = null;
|
||||
var gMIMEDescField = null;
|
||||
var gHandlerField = null;
|
||||
var gNewTypeButton = null;
|
||||
var gEditButton = null;
|
||||
|
@ -33,7 +33,8 @@ var gRemoveButton = null;
|
|||
|
||||
function newType()
|
||||
{
|
||||
window.openDialog("chrome://communicator/content/pref/pref-applications-new.xul", "appEdit", "chrome,modal=yes,resizable=no");
|
||||
var handlerOverride = new HandlerOverride();
|
||||
window.openDialog("chrome://communicator/content/pref/pref-applications-edit.xul", "appEdit", "chrome,modal=yes,resizable=no", handlerOverride);
|
||||
if (gNewTypeRV) {
|
||||
//gList.builder.rebuild();
|
||||
gList.setAttribute("ref", "urn:mimetypes");
|
||||
|
@ -43,17 +44,22 @@ function newType()
|
|||
|
||||
function removeType()
|
||||
{
|
||||
var titleMsg = gPrefApplicationsBundle.getString("removeHandlerTitle");
|
||||
var dialogMsg = gPrefApplicationsBundle.getString("removeHandler");
|
||||
dialogMsg = dialogMsg.replace(/%n/g, "\n");
|
||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
||||
var remove = promptService.confirm(window, titleMsg, dialogMsg);
|
||||
if (remove) {
|
||||
var uri = gList.selectedItems[0].id;
|
||||
var handlerOverride = new HandlerOverride(uri);
|
||||
removeOverride(handlerOverride.mimeType);
|
||||
gList.setAttribute("ref", "urn:mimetypes");
|
||||
// Only prompt if setting is "useHelperApp".
|
||||
var uri = gList.selectedItems[0].id;
|
||||
var handlerOverride = new HandlerOverride(uri);
|
||||
if ( !handlerOverride.useSystemDefault && !handlerOverride.saveToDisk ) {
|
||||
var titleMsg = gPrefApplicationsBundle.getString("removeHandlerTitle");
|
||||
var dialogMsg = gPrefApplicationsBundle.getString("removeHandler");
|
||||
dialogMsg = dialogMsg.replace(/%n/g, "\n");
|
||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
||||
var remove = promptService.confirm(window, titleMsg, dialogMsg);
|
||||
if (!remove) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
removeOverride(handlerOverride.mimeType);
|
||||
gList.setAttribute("ref", "urn:mimetypes");
|
||||
selectApplication();
|
||||
}
|
||||
|
||||
function editType()
|
||||
|
@ -66,6 +72,89 @@ function editType()
|
|||
}
|
||||
}
|
||||
|
||||
const xmlSinkObserver = {
|
||||
onBeginLoad: function(aSink)
|
||||
{
|
||||
},
|
||||
onInterrupt: function(aSink)
|
||||
{
|
||||
},
|
||||
onResume: function(aSink)
|
||||
{
|
||||
},
|
||||
// This is called when the RDF data source has finished loading.
|
||||
onEndLoad: function(aSink)
|
||||
{
|
||||
// Unhook observer.
|
||||
aSink.removeXMLSinkObserver(this);
|
||||
|
||||
// Convert old "don't ask" pref info to helper app pref entries
|
||||
try {
|
||||
var prefService = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPrefService);
|
||||
var prefBranch = prefService.getBranch("browser.helperApps.neverAsk.");
|
||||
if (!prefBranch) return;
|
||||
} catch(e) { return; }
|
||||
|
||||
var neverAskSave = new Array();
|
||||
var neverAskOpen = new Array();
|
||||
try {
|
||||
neverAskSave = prefBranch.getCharPref("saveToDisk").split(",");
|
||||
} catch(e) {}
|
||||
try {
|
||||
neverAskOpen = prefBranch.getCharPref("openFile").split(",");
|
||||
} catch(e) {}
|
||||
|
||||
var i;
|
||||
var newEntries = {};
|
||||
for ( i = 0; i < neverAskSave.length; i++ ) {
|
||||
// See if mime type is in data source.
|
||||
var type = unescape(neverAskSave[i]);
|
||||
if (type != "" && !mimeHandlerExists(type)) {
|
||||
// Not in there, need to create an entry now so user can edit it.
|
||||
newEntries[type] = "saveToDisk";
|
||||
}
|
||||
}
|
||||
|
||||
for ( i = 0; i < neverAskOpen.length; i++ ) {
|
||||
// See if mime type is in data source.
|
||||
var type = unescape(neverAskOpen[i]);
|
||||
if (type != "" && !mimeHandlerExists(type)) {
|
||||
// Not in there, need to create an entry now so user can edit it.
|
||||
newEntries[type] = "useSystemDefault";
|
||||
}
|
||||
}
|
||||
|
||||
// Now create all new entries.
|
||||
for ( var newEntry in newEntries ) {
|
||||
this.createNewEntry(newEntry, newEntries[newEntry]);
|
||||
}
|
||||
|
||||
// Don't need these any more!
|
||||
try { prefBranch.clearUserPref("saveToDisk"); } catch(e) {}
|
||||
try { prefBranch.clearUserPref("openFile"); } catch(e) {}
|
||||
},
|
||||
onError: function(aSink, aStatus, aMsg)
|
||||
{
|
||||
},
|
||||
createNewEntry: function(mimeType, action)
|
||||
{
|
||||
// Create HandlerOverride and populate it.
|
||||
var entry = new HandlerOverride(MIME_URI(mimeType));
|
||||
entry.mUpdateMode = false;
|
||||
entry.mimeType = mimeType;
|
||||
entry.description = "";
|
||||
entry.isEditable = true;
|
||||
entry.alwaysAsk = false;
|
||||
entry.appPath = "";
|
||||
entry.appDisplayName = "";
|
||||
// This sets preferred action.
|
||||
entry[action] = true;
|
||||
|
||||
// Do RDF magic.
|
||||
entry.buildLinks();
|
||||
}
|
||||
}
|
||||
|
||||
function Startup()
|
||||
{
|
||||
// set up the string bundle
|
||||
|
@ -74,7 +163,7 @@ function Startup()
|
|||
// set up the elements
|
||||
gList = document.getElementById("appList");
|
||||
gExtensionField = document.getElementById("extension");
|
||||
gMIMETypeField = document.getElementById("mimeType");
|
||||
gMIMEDescField = document.getElementById("mimeDesc");
|
||||
gHandlerField = document.getElementById("handler");
|
||||
gNewTypeButton = document.getElementById("newTypeButton");
|
||||
gEditButton = document.getElementById("editButton");
|
||||
|
@ -90,12 +179,20 @@ function Startup()
|
|||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
dump("spec is " + fileHandler.getURLSpecFromFile(file));
|
||||
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
|
||||
|
||||
// intialize the listbox
|
||||
gList.database.AddDataSource(gDS);
|
||||
gList.setAttribute("ref", "urn:mimetypes");
|
||||
|
||||
// Test whether the data source is already loaded.
|
||||
if (gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).loaded) {
|
||||
// Do it now.
|
||||
xmlSinkObserver.onEndLoad(gDS.QueryInterface(Components.interfaces.nsIRDFXMLSink));
|
||||
} else {
|
||||
// Add observer that will kick in when data source load completes.
|
||||
gDS.QueryInterface(Components.interfaces.nsIRDFXMLSink).addXMLSinkObserver( xmlSinkObserver );
|
||||
}
|
||||
}
|
||||
|
||||
function selectApplication()
|
||||
|
@ -104,7 +201,7 @@ function selectApplication()
|
|||
var uri = gList.selectedItems[0].id;
|
||||
var handlerOverride = new HandlerOverride(uri);
|
||||
gExtensionField.setAttribute("value", handlerOverride.extensions);
|
||||
gMIMETypeField.setAttribute("value", handlerOverride.mimeType);
|
||||
gMIMEDescField.setAttribute("value", handlerOverride.description);
|
||||
|
||||
// figure out how this type is handled
|
||||
if (handlerOverride.handleInternal == "true")
|
||||
|
@ -113,8 +210,12 @@ function selectApplication()
|
|||
else if (handlerOverride.saveToDisk == "true")
|
||||
gHandlerField.setAttribute("value",
|
||||
gPrefApplicationsBundle.getString("saveToDisk"));
|
||||
else if (handlerOverride.useSystemDefault == "true")
|
||||
gHandlerField.setAttribute("value",
|
||||
gPrefApplicationsBundle.getString("useSystemDefault"));
|
||||
else
|
||||
gHandlerField.setAttribute("value", handlerOverride.appDisplayName);
|
||||
gHandlerField.setAttribute("value",
|
||||
gPrefApplicationsBundle.getFormattedString("useHelperApp", [handlerOverride.appDisplayName]));
|
||||
var ext;
|
||||
var posOfFirstSpace = handlerOverride.extensions.indexOf(" ");
|
||||
if (posOfFirstSpace > -1)
|
||||
|
@ -130,7 +231,7 @@ function selectApplication()
|
|||
gHandlerField.removeAttribute("value");
|
||||
document.getElementById("contentTypeImage").removeAttribute("src");
|
||||
gExtensionField.removeAttribute("value");
|
||||
gMIMETypeField.removeAttribute("value");
|
||||
gMIMEDescField.removeAttribute("value");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,12 +253,3 @@ function updateLockedButtonState(handlerEditable)
|
|||
gRemoveButton.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function clearRememberedSettings()
|
||||
{
|
||||
var prefBranch = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPrefBranch);
|
||||
if (prefBranch) {
|
||||
prefBranch.setCharPref("browser.helperApps.neverAsk.saveToDisk", "");
|
||||
prefBranch.setCharPref("browser.helperApps.neverAsk.openFile", "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
<groupbox flex="1">
|
||||
<caption label="&descript;"/>
|
||||
<label value="&fileTypes.label;"/>
|
||||
<hbox flex="1">
|
||||
<vbox flex="1">
|
||||
<vbox>
|
||||
<hbox flex="1">
|
||||
<listbox id="appList" flex="1"
|
||||
sortResource="http://home.netscape.com/NC-rdf#value"
|
||||
sortDirection="ascending"
|
||||
|
@ -73,48 +73,47 @@
|
|||
</rule>
|
||||
</template>
|
||||
</listbox>
|
||||
|
||||
<hbox>
|
||||
<vbox>
|
||||
<button id="newTypeButton"
|
||||
label="&newTypeButton.label;" accesskey="&newTypeButton.accesskey;"
|
||||
oncommand="newType();"/>
|
||||
<button id="editButton"
|
||||
label="&editButton.label;" accesskey="&editButton.accesskey;"
|
||||
oncommand="editType();"/>
|
||||
<button id="removeButton"
|
||||
label="&removeButton.label;" accesskey="&removeButton.accesskey;"
|
||||
oncommand="removeType();"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
<groupbox orient="horizontal">
|
||||
<caption label="&file;"/>
|
||||
<hbox flex="1">
|
||||
<vbox style="width: 40px; height: 40px;" pack="center" align="center">
|
||||
<image id="contentTypeImage"/>
|
||||
</vbox>
|
||||
<grid orient="horizontal">
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<row align="center">
|
||||
<label value="&mimeDesc;"/>
|
||||
<label id="mimeDesc" crop="right" flex="1"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&exten;"/>
|
||||
<label id="extension"/>
|
||||
<label id="extension" crop="right"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&mimeType;"/>
|
||||
<label id="mimeType"/>
|
||||
</row>
|
||||
<row>
|
||||
<row align="center">
|
||||
<label value="&handle;"/>
|
||||
<textbox id="handler" readonly="true" style="width: 175px" />
|
||||
<textbox id="handler" readonly="true" flex="1"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</hbox>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<button id="newTypeButton"
|
||||
label="&newTypeButton.label;" accesskey="&newTypeButton.accesskey;"
|
||||
oncommand="newType();"
|
||||
prefstring="pref.application.disable_button.new_type"/>
|
||||
<button id="editButton"
|
||||
label="&editButton.label;" accesskey="&editButton.accesskey;"
|
||||
oncommand="editType();"
|
||||
prefstring="pref.application.disable_button.edit"/>
|
||||
<button id="removeButton"
|
||||
label="&removeButton.label;" accesskey="&removeButton.accesskey;"
|
||||
oncommand="removeType();"
|
||||
prefstring="pref.application.disable_button.remove"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
<groupbox id="pluginFinderBox">
|
||||
<caption label="&plugins.label;"/>
|
||||
|
@ -126,12 +125,4 @@
|
|||
<description>&pluginFinderDesc.label;</description>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
<groupbox>
|
||||
<caption label="&fileOpening.label;"/>
|
||||
<hbox pack="start" align="center">
|
||||
<description flex="1">&resetText.label;</description>
|
||||
<spacer flex="1"/>
|
||||
<button label="&resetButton.label;" oncommand="clearRememberedSettings();"/>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
</page>
|
||||
|
|
|
@ -1,31 +1,24 @@
|
|||
|
||||
<!ENTITY editType.label "Edit Type">
|
||||
<!ENTITY newType.label "New Type">
|
||||
<!ENTITY extension.label "Extension:">
|
||||
<!ENTITY extension.accesskey "e">
|
||||
<!--LOCALIZATION NOTE (mimeType): 'MIME' should not be translated -->
|
||||
<!ENTITY mimetype.label "MIME Type:">
|
||||
<!ENTITY mimetype.accesskey "m">
|
||||
<!ENTITY description.label "Description:">
|
||||
<!ENTITY description.accesskey "d">
|
||||
|
||||
<!ENTITY handledby.label "Handled By">
|
||||
|
||||
<!ENTITY useDefault.label "Use system default">
|
||||
<!ENTITY useDefault.accesskey "u">
|
||||
<!ENTITY saveToDisk.label "Save to Disk">
|
||||
<!ENTITY handling.label "When a file of this type is encountered:">
|
||||
<!ENTITY useDefault.label "Open it using the default application">
|
||||
<!ENTITY useDefault.accesskey "o">
|
||||
<!ENTITY saveToDisk.label "Save it to Disk">
|
||||
<!ENTITY saveToDisk.accesskey "s">
|
||||
<!ENTITY application.label "Application">
|
||||
<!ENTITY application.accesskey "a">
|
||||
<!ENTITY application.label "Open it with:">
|
||||
<!ENTITY application.accesskey "w">
|
||||
|
||||
<!ENTITY browse.label "Choose...">
|
||||
<!ENTITY browse.accesskey "c">
|
||||
|
||||
<!ENTITY askBeforeOpen.label "Ask me before opening downloaded files of this type">
|
||||
<!ENTITY askBeforeOpen.label "Always ask me before handling files of this type">
|
||||
<!ENTITY askBeforeOpen.accesskey "k">
|
||||
|
||||
<!ENTITY newDescription.label "Description of type:">
|
||||
<!ENTITY newDescription.accesskey "d">
|
||||
<!ENTITY newExtensions.label "File extension:">
|
||||
<!ENTITY newExtensions.accesskey "e">
|
||||
<!ENTITY newMIME.label "MIME type:">
|
||||
<!ENTITY newMIME.accesskey "m">
|
||||
<!ENTITY newAppPath.label "Application to use:">
|
||||
<!ENTITY newAppPath.accesskey "a">
|
||||
<!ENTITY newTypeTitle.label "New Type">
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<!--LOCALIZATION NOTE : FILE The Applications prefs dialog -->
|
||||
<!ENTITY lHeader "Helper Applications">
|
||||
<!ENTITY descript "Specify which application should handle each file type">
|
||||
<!ENTITY descript "Specify how to handle files of each file type">
|
||||
<!ENTITY fileTypes.label "File types:">
|
||||
<!ENTITY aimLaunchSelect.label "AOL Instant Messenger Launch">
|
||||
<!ENTITY newTypeButton.label "New Type...">
|
||||
|
@ -12,12 +12,9 @@
|
|||
<!ENTITY removeButton.label "Remove">
|
||||
<!ENTITY removeButton.accesskey "r">
|
||||
<!ENTITY file "File Type Details">
|
||||
<!ENTITY exten "Extension:">
|
||||
<!--LOCALIZATION NOTE (mimeType): 'MIME' should not be translated -->
|
||||
<!ENTITY mimeType "MIME type:">
|
||||
<!ENTITY handle "Handled by:">
|
||||
<!ENTITY resetText.label "Click "Reset" to clear your file-opening preferences and be asked before opening files.">
|
||||
<!ENTITY resetButton.label "Reset">
|
||||
<!ENTITY exten "Extension(s):">
|
||||
<!ENTITY mimeDesc "Description:">
|
||||
<!ENTITY handle "When encountered:">
|
||||
<!ENTITY fileOpening.label "Opening files">
|
||||
<!ENTITY plugins.label "Plug-in Finder Service">
|
||||
<!ENTITY pluginFinder.label "Always use the Netscape Plug-in Finder Service (PFS) to get plug-ins.">
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# foo
|
||||
|
||||
saveToDisk=Save to Disk
|
||||
handleInternally=Handled Internally
|
||||
saveToDisk=Save these files to disk
|
||||
useSystemDefault=Open these files using the default application
|
||||
useHelperApp=Open these files with %S
|
||||
handleInternally=Display files of this type in the browser
|
||||
|
||||
chooseHandler=Choose Application Helper
|
||||
programsFilter=Programs
|
||||
|
||||
handlerExists=A helper already exists for the MIME type '%mime%'. Do you want to replace it?
|
||||
handlerExists=A helper already exists for the MIME type '%mime%'. Do you want to replace it?
|
||||
handlerExistsTitle=Helper Application Exists
|
||||
|
||||
emptyMIMEType=You must specify a MIME type.
|
||||
|
|
Загрузка…
Ссылка в новой задаче