Bug 598244 - nsFileControlFrame should not parse the accept attribute but nsHTMLInputElement should do that; r=mounir
authorJiten Thakkar <jitenmt@gmail.com>
Mon, 12 Mar 2012 11:36:02 +0100
changeset 88787 fead9a65565f75cb8472f771b801e6453561ea06
parent 88786 ff628801bd90b93da44e1a49687d720e6830a069
child 88788 35c41def4857fccbadb899abc5fb6b3037f3bf98
push id22223
push usermbrubeck@mozilla.com
push dateMon, 12 Mar 2012 20:31:41 +0000
treeherdermozilla-central@406113c400a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs598244
milestone13.0a1
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
Bug 598244 - nsFileControlFrame should not parse the accept attribute but nsHTMLInputElement should do that; r=mounir
layout/forms/nsFileControlFrame.cpp
layout/forms/nsFileControlFrame.h
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -154,67 +154,16 @@ nsFileControlFrame::DestroyFrom(nsIFrame
   }
   nsContentUtils::DestroyAnonymousContent(&mTextContent);
 
   mCaptureMouseListener->ForgetFrame();
   mMouseListener->ForgetFrame();
   nsBlockFrame::DestroyFrom(aDestructRoot);
 }
 
-struct CaptureCallbackData {
-  nsICapturePicker* picker;
-  PRUint32* mode;
-};
-
-typedef struct CaptureCallbackData CaptureCallbackData;
-
-bool CapturePickerAcceptCallback(const nsAString& aAccept, void* aClosure)
-{
-  nsresult rv;
-  bool captureEnabled;
-  CaptureCallbackData* closure = (CaptureCallbackData*)aClosure;
-
-  if (StringBeginsWith(aAccept,
-                       NS_LITERAL_STRING("image/"))) {
-    rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_STILL,
-                                             &captureEnabled);
-    NS_ENSURE_SUCCESS(rv, true);
-    if (captureEnabled) {
-      *closure->mode = nsICapturePicker::MODE_STILL;
-      return false;
-    }
-  } else if (StringBeginsWith(aAccept,
-                              NS_LITERAL_STRING("audio/"))) {
-    rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_AUDIO_CLIP,
-                                             &captureEnabled);
-    NS_ENSURE_SUCCESS(rv, true);
-    if (captureEnabled) {
-      *closure->mode = nsICapturePicker::MODE_AUDIO_CLIP;
-      return false;
-    }
-  } else if (StringBeginsWith(aAccept,
-                              NS_LITERAL_STRING("video/"))) {
-    rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_CLIP,
-                                             &captureEnabled);
-    NS_ENSURE_SUCCESS(rv, true);
-    if (captureEnabled) {
-      *closure->mode = nsICapturePicker::MODE_VIDEO_CLIP;
-      return false;
-    }
-    rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP,
-                                             &captureEnabled);
-    NS_ENSURE_SUCCESS(rv, true);
-    if (captureEnabled) {
-      *closure->mode = nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP;
-      return false;
-    }
-  }
-  return true;
-}
-
 nsresult
 nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
   // Get the NodeInfoManager and tag necessary to create input elements
   nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
 
   nsCOMPtr<nsINodeInfo> nodeInfo;
   nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nsnull,
@@ -277,25 +226,22 @@ nsFileControlFrame::CreateAnonymousConte
 
   mBrowse->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                    NS_LITERAL_STRING("button"), false);
 
   // Create the capture button
   nsCOMPtr<nsICapturePicker> capturePicker;
   capturePicker = do_GetService("@mozilla.org/capturepicker;1");
   if (capturePicker) {
-    PRUint32 mode = 0;
-
     CaptureCallbackData data;
     data.picker = capturePicker;
-    data.mode = &mode;
-    ParseAcceptAttribute(&CapturePickerAcceptCallback, (void*)&data);
+    data.mode = GetCaptureMode(data);
 
-    if (mode != 0) {
-      mCaptureMouseListener->mMode = mode;
+    if (data.mode != 0) {
+      mCaptureMouseListener->mMode = data.mode;
       nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nsnull,
                                                      kNameSpaceID_XHTML,
                                                      nsIDOMNode::ELEMENT_NODE);
       NS_NewHTMLElement(getter_AddRefs(mCapture), nodeInfo.forget(),
                         dom::NOT_FROM_PARSER);
       if (!mCapture)
         return NS_ERROR_OUT_OF_MEMORY;
 
@@ -742,26 +688,58 @@ nsFileControlFrame::CreateAccessible()
   if (!accService)
     return nsnull;
 
   return accService->CreateHTMLFileInputAccessible(mContent,
                                                    PresContext()->PresShell());
 }
 #endif
 
-void 
-nsFileControlFrame::ParseAcceptAttribute(AcceptAttrCallback aCallback,
-                                         void* aClosure) const
+PRUint32
+nsFileControlFrame::GetCaptureMode(const CaptureCallbackData& aData)
 {
-  nsAutoString accept;
-  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accept, accept);
+  PRInt32 filters = nsHTMLInputElement::FromContent(mContent)->GetFilterFromAccept();
+  nsresult rv;
+  bool captureEnabled;
+
+  if (filters == nsIFilePicker::filterImages) {
+    rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_STILL,
+                                             &captureEnabled);
+    NS_ENSURE_SUCCESS(rv, 0);
+    if (captureEnabled) {
+      return nsICapturePicker::MODE_STILL;
+    }
+    return 0;
+  }
 
-  HTMLSplitOnSpacesTokenizer tokenizer(accept, ',');
-  // Empty loop body because aCallback is doing the work
-  while (tokenizer.hasMoreTokens() &&
-         (*aCallback)(tokenizer.nextToken(), aClosure));
+  if (filters == nsIFilePicker::filterAudio) {
+    rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_AUDIO_CLIP,
+                                             &captureEnabled);
+    NS_ENSURE_SUCCESS(rv, 0);
+    if (captureEnabled) {
+      return nsICapturePicker::MODE_AUDIO_CLIP;
+    }
+    return 0;
+  }
+
+  if (filters == nsIFilePicker::filterVideo) {
+    rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_CLIP,
+                                             &captureEnabled);
+    NS_ENSURE_SUCCESS(rv, 0);
+    if (captureEnabled) {
+      return nsICapturePicker::MODE_VIDEO_CLIP;
+    }
+    rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP,
+                                             &captureEnabled);
+    NS_ENSURE_SUCCESS(rv, 0);
+    if (captureEnabled) {
+      return nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP;
+    }
+    return 0;
+  }
+  
+  return 0;
 }
-
 ////////////////////////////////////////////////////////////
 // Mouse listener implementation
 
 NS_IMPL_ISUPPORTS1(nsFileControlFrame::MouseListener,
                    nsIDOMEventListener)
--- a/layout/forms/nsFileControlFrame.h
+++ b/layout/forms/nsFileControlFrame.h
@@ -89,23 +89,29 @@ public:
 
   // nsIAnonymousContentCreator
   virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
   virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
                                         PRUint32 aFilter);
 
 #ifdef ACCESSIBILITY
   virtual already_AddRefed<nsAccessible> CreateAccessible();
-#endif
+#endif  
 
   typedef bool (*AcceptAttrCallback)(const nsAString&, void*);
-  void ParseAcceptAttribute(AcceptAttrCallback aCallback, void* aClosure) const;
 
 protected:
-
+  
+  struct CaptureCallbackData {
+    nsICapturePicker* picker;
+    PRUint32 mode;
+  };
+  
+  PRUint32 GetCaptureMode(const CaptureCallbackData& aData);
+  
   class MouseListener;
   friend class MouseListener;
   class MouseListener : public nsIDOMEventListener {
   public:
     NS_DECL_ISUPPORTS
     
     MouseListener(nsFileControlFrame* aFrame) :
       mFrame(aFrame)