bug 1116382 resolve MediaSource urls on Source element src attributes when set r=bholley
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 26 May 2015 23:01:14 +1200
changeset 247297 6e1078de459056a3eaee55d60b0212ee8a4afe7c
parent 247296 0c077afa1fbf37e572d8b1e650d963b5327dcff6
child 247298 941944df69124c843d38c9797a83374616d321d8
push id60669
push userktomlinson@mozilla.com
push dateFri, 05 Jun 2015 08:08:50 +0000
treeherdermozilla-inbound@94fcc63014b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1116382
milestone41.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 1116382 resolve MediaSource urls on Source element src attributes when set r=bholley
dom/html/HTMLSourceElement.cpp
dom/html/HTMLSourceElement.h
--- a/dom/html/HTMLSourceElement.cpp
+++ b/dom/html/HTMLSourceElement.cpp
@@ -4,21 +4,23 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLSourceElement.h"
 #include "mozilla/dom/HTMLSourceElementBinding.h"
 
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/ResponsiveImageSelector.h"
+#include "mozilla/dom/MediaSource.h"
 
 #include "nsGkAtoms.h"
 
 #include "nsIMediaList.h"
 #include "nsCSSParser.h"
+#include "nsHostObjectProtocolHandler.h"
 
 #include "mozilla/Preferences.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
 
 namespace mozilla {
 namespace dom {
 
@@ -26,18 +28,25 @@ HTMLSourceElement::HTMLSourceElement(alr
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLSourceElement::~HTMLSourceElement()
 {
 }
 
-NS_IMPL_ISUPPORTS_INHERITED(HTMLSourceElement, nsGenericHTMLElement,
-                            nsIDOMHTMLSourceElement)
+NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLSourceElement, nsGenericHTMLElement,
+                                   mSrcMediaSource)
+
+NS_IMPL_ADDREF_INHERITED(HTMLSourceElement, nsGenericHTMLElement)
+NS_IMPL_RELEASE_INHERITED(HTMLSourceElement, nsGenericHTMLElement)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLSourceElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLSourceElement)
+NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
 
 NS_IMPL_ELEMENT_CLONE(HTMLSourceElement)
 
 NS_IMPL_URI_ATTR(HTMLSourceElement, Src, src)
 NS_IMPL_STRING_ATTR(HTMLSourceElement, Type, type)
 NS_IMPL_STRING_ATTR(HTMLSourceElement, Srcset, srcset)
 NS_IMPL_STRING_ATTR(HTMLSourceElement, Sizes, sizes)
 NS_IMPL_STRING_ATTR(HTMLSourceElement, Media, media)
@@ -109,16 +118,26 @@ HTMLSourceElement::AfterSetAttr(int32_t 
     if (aValue) {
       nsString mediaStr = aValue->GetStringValue();
       if (!mediaStr.IsEmpty()) {
         nsCSSParser cssParser;
         mMediaList = new nsMediaList();
         cssParser.ParseMediaList(mediaStr, nullptr, 0, mMediaList, false);
       }
     }
+  } else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
+    mSrcMediaSource = nullptr;
+    if (aValue) {
+      nsString srcStr = aValue->GetStringValue();
+      nsCOMPtr<nsIURI> uri;
+      NewURIFromString(srcStr, getter_AddRefs(uri));
+      if (uri && IsMediaSourceURI(uri)) {
+        NS_GetSourceForMediaSourceURI(uri, getter_AddRefs(mSrcMediaSource));
+      }
+    }
   }
 
   return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
                                             aValue, aNotify);
 }
 
 void
 HTMLSourceElement::GetItemValueText(DOMString& aValue)
--- a/dom/html/HTMLSourceElement.h
+++ b/dom/html/HTMLSourceElement.h
@@ -20,16 +20,18 @@ namespace dom {
 class HTMLSourceElement final : public nsGenericHTMLElement,
                                 public nsIDOMHTMLSourceElement
 {
 public:
   explicit HTMLSourceElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSourceElement,
+                                           nsGenericHTMLElement)
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLSourceElement, source)
 
   // nsIDOMHTMLSourceElement
   NS_DECL_NSIDOMHTMLSOURCEELEMENT
 
   virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
 
@@ -44,16 +46,20 @@ public:
   bool MatchesCurrentMedia();
 
   // True if a source tag would match the given media attribute for the
   // specified document. Used by the preloader to determine valid <source> tags
   // prior to DOM creation.
   static bool WouldMatchMediaForDocument(const nsAString& aMediaStr,
                                          const nsIDocument *aDocument);
 
+  // Return the MediaSource object if any associated with the src attribute
+  // when it was set.
+  MediaSource* GetSrcMediaSource() { return mSrcMediaSource; };
+
   // WebIDL
   void GetSrc(nsString& aSrc)
   {
     GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
   }
   void SetSrc(const nsAString& aSrc, mozilla::ErrorResult& rv)
   {
     SetHTMLAttr(nsGkAtoms::src, aSrc, rv);
@@ -106,14 +112,15 @@ protected:
 
   virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue,
                                 bool aNotify) override;
 
 
 private:
   nsRefPtr<nsMediaList> mMediaList;
+  nsRefPtr<MediaSource> mSrcMediaSource;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HTMLSourceElement_h