From 682f1a94e963b0f00211cc2d012d2108b7644789 Mon Sep 17 00:00:00 2001 From: "law%netscape.com" Date: Thu, 6 Dec 2001 03:28:10 +0000 Subject: [PATCH] Bug 60708; prevent user from creating helper app entries with blank mime type fields; r=pchen, sr=ben --- .../resources/content/overrideHandler.js | 19 +++++++++++++++++++ .../content/pref-applications-edit.xul | 4 ++++ .../content/pref-applications-new.js | 5 +++++ .../locale/en-US/pref-applications.properties | 4 +++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/xpfe/components/prefwindow/resources/content/overrideHandler.js b/xpfe/components/prefwindow/resources/content/overrideHandler.js index 4424ae7d297c..62b54a5d4f7c 100644 --- a/xpfe/components/prefwindow/resources/content/overrideHandler.js +++ b/xpfe/components/prefwindow/resources/content/overrideHandler.js @@ -403,3 +403,22 @@ function removeOverride(aMIMEType) } } } + +function checkInput() { + var result = true; + // Check for empty MIME type field. + if ( gMIMEField.value == "" ) { + // Input is not OK. + result = false; + + // Focus the mime type field. + gMIMEField.focus(); + + // Put up alert. Title is same as parent dialog's. + var title = window.document.documentElement.getAttribute( "title" ); + var text = gPrefApplicationsBundle.getString("emptyMIMEType"); + var prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); + prompter.alert(window, title, text); + } + return result; +} diff --git a/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul b/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul index 891b77896945..ef17b5b74169 100644 --- a/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul +++ b/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul @@ -178,6 +178,10 @@ function onAccept() { + // Validate input. + if ( !checkInput() ) { + return false; + } getDS(); // figure out if this mime type already exists. if (gMIMEField.value != gOldMIME) { diff --git a/xpfe/components/prefwindow/resources/content/pref-applications-new.js b/xpfe/components/prefwindow/resources/content/pref-applications-new.js index a5d878a09d66..484a62bd8e22 100644 --- a/xpfe/components/prefwindow/resources/content/pref-applications-new.js +++ b/xpfe/components/prefwindow/resources/content/pref-applications-new.js @@ -65,6 +65,11 @@ function chooseApp() var gDS = null; function onOK() { + // Make sure all fields are filled in OK. + if ( !checkInput() ) { + return false; + } + const mimeTypes = "UMimTyp"; var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService(); if (fileLocator) diff --git a/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties b/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties index e70bb087ef7a..5a8e92c1cece 100644 --- a/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties +++ b/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties @@ -9,5 +9,7 @@ programsFilter=Programs 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. + removeHandlerTitle=Remove File Type -removeHandler=If you remove a registered type, the helper will no longer be able to automatically handle files of this type. %n%nAre you sure you want to remove this file type? \ No newline at end of file +removeHandler=If you remove a registered type, the helper will no longer be able to automatically handle files of this type. %n%nAre you sure you want to remove this file type?