Bug 462373 - Code simplifications for Media elements - r+sr=bzbarsky
authorChris Pearce <chris@pearce.org.nz>
Tue, 04 Nov 2008 21:50:24 +1300
changeset 21271 d2b0456f37ada4cdea7eb7e3500a1aee69575cca
parent 21270 18403769ec19f8d64ddf8e30d6a76468ae5a4fbc
child 21273 07e1dff41cb2afbc68ce63806e16d101690acb44
push id3452
push usercdouble@mozilla.com
push dateTue, 04 Nov 2008 08:50:57 +0000
treeherdermozilla-central@d2b0456f37ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs462373
milestone1.9.1b2pre
Bug 462373 - Code simplifications for Media elements - r+sr=bzbarsky
content/html/content/src/nsHTMLMediaElement.cpp
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -723,53 +723,49 @@ nsresult nsHTMLMediaElement::InitializeD
   return mDecoder->Load(nsnull, aChannel, aListener);
 }
 
 nsresult nsHTMLMediaElement::PickMediaElement()
 {
   // Implements:
   // http://www.whatwg.org/specs/web-apps/current-work/#pick-a
   nsAutoString src;
-  if (HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
-    if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
+  if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
 #ifdef MOZ_OGG
-      // Currently assuming an Ogg file
-      // TODO: Instantiate decoder based on type
-      if (mDecoder) {
-        mDecoder->ElementUnavailable();
-        mDecoder->Shutdown();
-        mDecoder = nsnull;
-      }
+    // Currently assuming an Ogg file
+    // TODO: Instantiate decoder based on type
+    if (mDecoder) {
+      mDecoder->ElementUnavailable();
+      mDecoder->Shutdown();
+      mDecoder = nsnull;
+    }
 
-      mDecoder = new nsOggDecoder();
-      if (mDecoder && !mDecoder->Init()) {
-        mDecoder = nsnull;
-      }
+    mDecoder = new nsOggDecoder();
+    if (mDecoder && !mDecoder->Init()) {
+      mDecoder = nsnull;
+    }
 #endif
-      return InitializeDecoder(src);
-    }
+    return InitializeDecoder(src);
   }
 
   // Checking of 'source' elements as per:
   // http://www.whatwg.org/specs/web-apps/current-work/#pick-a
   PRUint32 count = GetChildCount();
   for (PRUint32 i = 0; i < count; ++i) {
     nsIContent* child = GetChildAt(i);
     NS_ASSERTION(child, "GetChildCount lied!");
     
     nsCOMPtr<nsIContent> source = do_QueryInterface(child);
     if (source) {
-      if (source->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
-        nsAutoString type;
-        nsAutoString src;
-        if (source->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
-            source->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src) &&
-            CreateDecoder(NS_ConvertUTF16toUTF8(type)))
-          return InitializeDecoder(src);
-      }
+      nsAutoString type;
+      nsAutoString src;
+      if (source->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src) &&
+          source->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
+          CreateDecoder(NS_ConvertUTF16toUTF8(type)))
+        return InitializeDecoder(src);
     }
   }
 
   return NS_ERROR_DOM_INVALID_STATE_ERR;
 }
 
 nsresult nsHTMLMediaElement::InitializeDecoder(const nsAString& aURISpec)
 {
@@ -778,21 +774,20 @@ nsresult nsHTMLMediaElement::InitializeD
   nsCOMPtr<nsIDocument> doc = GetOwnerDoc();
   if (!doc) {
     return NS_ERROR_DOM_INVALID_STATE_ERR;
   }
 
   nsresult rv;
   nsCOMPtr<nsIURI> uri;
   nsCOMPtr<nsIURI> baseURL = GetBaseURI();
-  const nsAFlatCString &charset = doc->GetDocumentCharacterSet();
-  rv = NS_NewURI(getter_AddRefs(uri), aURISpec,
-                 charset.IsEmpty() ? nsnull : charset.get(), 
-                 baseURL, 
-                 nsContentUtils::GetIOService());
+  rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
+                                                 aURISpec,
+                                                 doc,
+                                                 baseURL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mDecoder) {
     mDecoder->ElementAvailable(this);
     rv = mDecoder->Load(uri, nsnull, nsnull);
     if (NS_FAILED(rv)) {
       mDecoder = nsnull;
     }