Backout 5a0fe30e6b1a (bug 565274) for M4 test_bug377624.html failures on a CLOSED TREE
authorEd Morley <emorley@mozilla.com>
Thu, 03 May 2012 12:32:49 +0100
changeset 97051 94b06a04f17b0da37597cf3e19fa81683e0f08f0
parent 97050 47ececd6cb72896d24af7175a11e4efbd14549a7
child 97052 17b552b979d5b07867a9f8a961bf7efcf3186032
push id1116
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 19:38:18 +0000
treeherdermozilla-beta@95f959a8b4dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs565274, 377624
milestone15.0a1
backs out5a0fe30e6b1a9822242e9fcd002a6df6f690d645
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backout 5a0fe30e6b1a (bug 565274) for M4 test_bug377624.html failures on a CLOSED TREE
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLInputElement.h
dom/locales/en-US/chrome/layout/HtmlForm.properties
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -43,17 +43,16 @@
 
 #include "nsIDOMHTMLInputElement.h"
 #include "nsITextControlElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIRadioVisitor.h"
 #include "nsIPhonetic.h"
 
 #include "nsIControllers.h"
-#include "nsIStringBundle.h"
 #include "nsFocusManager.h"
 #include "nsPIDOMWindow.h"
 #include "nsContentCID.h"
 #include "nsIComponentManager.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
@@ -102,17 +101,16 @@
 
 // input type=file
 #include "nsILocalFile.h"
 #include "nsNetUtil.h"
 #include "nsDOMFile.h"
 #include "nsIFilePicker.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIContentPrefService.h"
-#include "nsIMIMEService.h"
 #include "nsIObserverService.h"
 #include "nsIPopupWindowManager.h"
 #include "nsGlobalWindow.h"
 
 // input type=image
 #include "nsImageLoadingContent.h"
 
 #include "mozAutoDocUpdate.h"
@@ -301,17 +299,29 @@ AsyncClickHandler::Run()
 
   nsresult rv = filePicker->Init(win, title,
                                  multi
                                   ? static_cast<PRInt16>(nsIFilePicker::modeOpenMultiple)
                                   : static_cast<PRInt16>(nsIFilePicker::modeOpen));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mInput->HasAttr(kNameSpaceID_None, nsGkAtoms::accept)) {
-    mInput->SetFilePickerFiltersFromAccept(filePicker);
+    PRInt32 filters = mInput->GetFilterFromAccept();
+
+    if (filters) {
+      // We add |filterAll| to be sure the user always has a sane fallback.
+      filePicker->AppendFilters(filters | nsIFilePicker::filterAll);
+
+      // If the accept attribute asked for a filter, we need to make it default.
+      // |filterAll| will always use index=0 so we need to set index=1 as the
+      // current filter.
+      filePicker->SetFilterIndex(1);
+    } else {
+      filePicker->AppendFilters(nsIFilePicker::filterAll);
+    }
   } else {
     filePicker->AppendFilters(nsIFilePicker::filterAll);
   }
 
   // Set default directry and filename
   nsAutoString defaultName;
 
   const nsCOMArray<nsIDOMFile>& oldFiles = mInput->GetFiles();
@@ -4129,132 +4139,16 @@ void
 nsHTMLInputElement::FieldSetDisabledChanged(bool aNotify)
 {
   UpdateValueMissingValidityState();
   UpdateBarredFromConstraintValidation();
 
   nsGenericHTMLFormElement::FieldSetDisabledChanged(aNotify);
 }
 
-void
-nsHTMLInputElement::SetFilePickerFiltersFromAccept(nsIFilePicker* filePicker)
-{
-  // We always add |filterAll|
-  filePicker->AppendFilters(nsIFilePicker::filterAll);
-
-  NS_ASSERTION(HasAttr(kNameSpaceID_None, nsGkAtoms::accept),
-               "You should not call SetFilePickerFiltersFromAccept if the"
-               " element has no accept attribute!");
-  nsAutoString accept;
-  nsTArray<nsFilePickerFilter> filters;
-  nsString allExtensionsList;
-
-  // Services to retrieve image/*, audio/*, video/* filters
-  nsCOMPtr<nsIStringBundleService> stringService =
-    mozilla::services::GetStringBundleService();
-  if (!stringService)
-    return;
-  nsCOMPtr<nsIStringBundle> titleBundle, filterBundle;
-  nsresult rv = stringService->CreateBundle("chrome://global/locale/filepicker.properties",
-                                            getter_AddRefs(titleBundle));
-  if (NS_FAILED(rv))
-    return;
-  rv = stringService->CreateBundle("chrome://global/content/filepicker.properties",
-                                   getter_AddRefs(filterBundle));
-  if (NS_FAILED(rv))
-    return;
-
-  // Service to retrieve mime type information for mime types filters
-  nsCOMPtr<nsIMIMEService> mimeService = do_GetService("@mozilla.org/mime;1");
-  if (!mimeService)
-    return;
-
-  GetAttr(kNameSpaceID_None, nsGkAtoms::accept, accept);
-
-  HTMLSplitOnSpacesTokenizer tokenizer(accept, ',');
-
-  // Retrieve all filters
-  while (tokenizer.hasMoreTokens()) {
-    const nsDependentSubstring& token = tokenizer.nextToken();
-
-    nsString filterName;
-    nsString extensionListStr;
-    bool isTrustedFilter = false;
-
-    // First, check for image/audio/video filters...
-    if (token.EqualsLiteral("image/*")) {
-      titleBundle->GetStringFromName(NS_LITERAL_STRING("imageTitle").get(), getter_Copies(filterName));
-      filterBundle->GetStringFromName(NS_LITERAL_STRING("imageFilter").get(), getter_Copies(extensionListStr));
-      isTrustedFilter = true;
-    } else if (token.EqualsLiteral("audio/*")) {
-      titleBundle->GetStringFromName(NS_LITERAL_STRING("audioTitle").get(), getter_Copies(filterName));
-      filterBundle->GetStringFromName(NS_LITERAL_STRING("audioFilter").get(), getter_Copies(extensionListStr));
-      isTrustedFilter = true;
-    } else if (token.EqualsLiteral("video/*")) {
-      titleBundle->GetStringFromName(NS_LITERAL_STRING("videoTitle").get(), getter_Copies(filterName));
-      filterBundle->GetStringFromName(NS_LITERAL_STRING("videoFilter").get(), getter_Copies(extensionListStr));
-      isTrustedFilter = true;
-    } else {
-      //... if no image/audio/video filter is found, check mime types filters
-      nsCOMPtr<nsIMIMEInfo> mimeInfo;
-      if (!token.IsEmpty() &&
-          NS_SUCCEEDED(mimeService->GetFromTypeAndExtension(NS_ConvertUTF16toUTF8(token),
-                                                            EmptyCString(), // No extension
-                                                            getter_AddRefs(mimeInfo)))) {
-        if (mimeInfo) {
-          // Get mime type name
-          nsCString mimeTypeName;
-          mimeInfo->GetType(mimeTypeName);
-          CopyUTF8toUTF16(mimeTypeName, filterName);
-          // Get extension list
-          nsCOMPtr<nsIUTF8StringEnumerator> extensions;
-          mimeInfo->GetFileExtensions(getter_AddRefs(extensions));
-          bool hasMore;
-          while (NS_SUCCEEDED(extensions->HasMore(&hasMore)) && hasMore) {
-            nsCString extension;
-            if (NS_FAILED(extensions->GetNext(extension)))
-              continue;
-            if (!extensionListStr.IsEmpty())
-              extensionListStr += NS_ConvertUTF8toUTF16("; ");
-            extensionListStr += NS_ConvertUTF8toUTF16("*.") +
-                                NS_ConvertUTF8toUTF16(extension);
-          }
-        }
-      }
-    }
-    nsFilePickerFilter filter(filterName, extensionListStr, isTrustedFilter);
-    if (!extensionListStr.IsEmpty() && !filters.Contains(filter)) {
-      if (!allExtensionsList.IsEmpty())
-        allExtensionsList += NS_ConvertUTF8toUTF16("; ");
-      allExtensionsList += extensionListStr;
-      filters.AppendElement(filter);
-    }
-  }
-
-  // Add "All Supported Types" filter
-  if (filters.Length() > 1) {
-    nsXPIDLString title;
-    nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
-                                       "AllSupportedTypes", title);
-    filePicker->AppendFilter(title, allExtensionsList);
-  }
-
-  // Add each filter
-  for (unsigned int i = 0; i < filters.Length(); ++i) {
-    const nsFilePickerFilter& filter = filters[i];
-    filePicker->AppendFilter(filter.mTitle, filter.mFilter);
-  }
-
-  if (filters.Length() == 1 && filters[0].mIsTrusted) {
-    // |filterAll| will always use index=0 so we need to set index=1 as the
-    // current filter.
-    filePicker->SetFilterIndex(1);
-  }
-}
-
 PRInt32
 nsHTMLInputElement::GetFilterFromAccept()
 {
   NS_ASSERTION(HasAttr(kNameSpaceID_None, nsGkAtoms::accept),
                "You should not call GetFileFiltersFromAccept if the element"
                " has no accept attribute!");
 
   PRInt32 filter = 0;
--- a/content/html/content/src/nsHTMLInputElement.h
+++ b/content/html/content/src/nsHTMLInputElement.h
@@ -48,18 +48,16 @@
 #include "nsTextEditorState.h"
 #include "nsCOMPtr.h"
 #include "nsIConstraintValidation.h"
 #include "nsDOMFile.h"
 #include "nsHTMLFormElement.h" // for ShouldShowInvalidUI()
 #include "nsIFile.h"
 
 class nsDOMFileList;
-class nsIFilePicker;
-class nsIMIMEInfo;
 class nsIRadioGroupContainer;
 class nsIRadioGroupVisitor;
 class nsIRadioVisitor;
 
 class UploadLastDir MOZ_FINAL : public nsIObserver, public nsSupportsWeakReference {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
@@ -271,33 +269,16 @@ public:
    *
    * @param aIgnoreSelf Whether the required attribute and the checked state
    * of the current radio should be ignored.
    * @note This method shouldn't be called if the radio elemnet hasn't a group.
    */
   void     UpdateValueMissingValidityStateForRadio(bool aIgnoreSelf);
 
   /**
-   * Set filters to the filePicker according to the accept attribute value.
-   *
-   * See:
-   * http://dev.w3.org/html5/spec/forms.html#attr-input-accept
-   *
-   * @note You should not call this function if the element has no @accept.
-   * @note "All Files" filter is always set, no matter if there is a valid
-   * filter specifed or not.
-   * @note If there is only one valid filter that is audio or video or image,
-   * it will be selected as the default filter. Otherwise "All files" remains
-   * the default filter.
-   * @note If more than one valid filter is found, the "All Supported Types"
-   * filter is added, which is the concatenation of all valid filters.
-   */
-  void SetFilePickerFiltersFromAccept(nsIFilePicker* filePicker);
-
-  /**
    * Returns the filter which should be used for the file picker according to
    * the accept attribute value.
    *
    * See:
    * http://dev.w3.org/html5/spec/forms.html#attr-input-accept
    *
    * @return Filter to use on the file picker with AppendFilters, 0 if none.
    *
@@ -618,39 +599,11 @@ protected:
   bool                     mShouldInitChecked   : 1;
   bool                     mParserCreating      : 1;
   bool                     mInInternalActivate  : 1;
   bool                     mCheckedIsToggled    : 1;
   bool                     mIndeterminate       : 1;
   bool                     mInhibitRestoration  : 1;
   bool                     mCanShowValidUI      : 1;
   bool                     mCanShowInvalidUI    : 1;
-
-private:
-  struct nsFilePickerFilter {
-    nsFilePickerFilter() {}
-
-    nsFilePickerFilter(const nsString& aTitle,
-                       const nsString& aFilter,
-                       const bool aIsTrusted)
-      : mTitle(aTitle), mFilter(aFilter), mIsTrusted(aIsTrusted) {}
-
-    nsFilePickerFilter(const nsFilePickerFilter& other) {
-      mTitle = other.mTitle;
-      mFilter = other.mFilter;
-      mIsTrusted = other.mIsTrusted;
-    }
-
-    bool operator== (const nsFilePickerFilter& other) const {
-      return mFilter == other.mFilter;
-    }
-
-    nsString mTitle;
-    nsString mFilter;
-    // mIsTrusted is true if mime type comes from a "trusted" source (e.g. our
-    // hard-coded set).
-    // false means it may come from an "untrusted" source (e.g. OS mime types
-    // mapping, which can be different accross OS, user's personal configuration, ...)
-    bool mIsTrusted; 
-  };
 };
 
 #endif
--- a/dom/locales/en-US/chrome/layout/HtmlForm.properties
+++ b/dom/locales/en-US/chrome/layout/HtmlForm.properties
@@ -44,9 +44,8 @@ MediaUpload=Media Upload
 # input field. The space needs be escaped in the property file to avoid 
 # trimming.
 IsIndexPromptWithSpace=This is a searchable index. Enter search keywords:\u0020
 ForgotPostWarning=Form contains enctype=%S, but does not contain method=post.  Submitting normally with method=GET and no enctype instead.
 ForgotFileEnctypeWarning=Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form.  The file will not be sent.
 # LOCALIZATION NOTE (DefaultFormSubject): %S will be replaced with brandShortName
 DefaultFormSubject=Form Post from %S
 CannotEncodeAllUnicode=A form was submitted in the %S encoding which cannot encode all Unicode characters, so user input may get corrupted. To avoid this problem, the page should be changed so that the form is submitted in the UTF-8 encoding either by changing the encoding of the page itself to UTF-8 or by specifying accept-charset=utf-8 on the form element.
-AllSupportedTypes=All Supported Types