Permalink
Browse files

Stub out a LoadListener class.

Gets to the point of properly reading the src attribute.
  • Loading branch information...
1 parent cb92791 commit 9d976113216763eabe771f223aefa3ea7c5504b4 @rillian committed Jan 24, 2012
Showing with 130 additions and 0 deletions.
  1. +130 −0 content/html/content/src/nsHTMLTrackElement.cpp
@@ -43,7 +43,12 @@
#include "nsStyleConsts.h"
#include "nsMappedAttributes.h"
#include "nsRuleData.h"
+#include "nsContentUtils.h"
#include "nsHTMLMediaElement.h"
+#include "nsIStreamListener.h"
+#include "nsIChannelEventSink.h"
+#include "nsIInterfaceRequestor.h"
+#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "nsThreadUtils.h"
@@ -78,6 +83,7 @@ class nsHTMLTrackElement : public nsGenericHTMLElement,
NS_DECL_NSIDOMHTMLTRACKELEMENT
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+ virtual nsresult SetAcceptHeader(nsIHttpChannel* aChannel);
// Override BindToTree() so that we can trigger a load when we add a
//
@@ -87,9 +93,74 @@ class nsHTMLTrackElement : public nsGenericHTMLElement,
bool aCompileEventHandlers);
virtual nsXPCClassInfo* GetClassInfo();
+
+ PRUint32 GetCurrentLoadID() { return mCurrentLoadID; }
+
+protected:
+ class LoadListener;
+ PRUint32 mCurrentLoadID;
+
+ nsresult NewURIFromString(const nsAutoString& aURISpec, nsIURI** aURI);
+};
+
+
+/** Channel Listener helper class */
+class nsHTMLTrackElement::LoadListener : public nsIStreamListener,
+ public nsIChannelEventSink,
+ public nsIInterfaceRequestor,
+ public nsIObserver
+{
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIREQUESTOBSERVER
+ NS_DECL_NSISTREAMLISTENER
+ NS_DECL_NSICHANNELEVENTSINK
+ NS_DECL_NSIINTERFACEREQUESTOR
+ NS_DECL_NSIOBSERVER
+
+public:
+ LoadListener(nsHTMLTrackElement *aElement)
+ : mElement(aElement),
+ mLoadID(aElement->GetCurrentLoadID())
+ {
+ NS_ABORT_IF_FALSE(mElement, "Must pass an element to the callback");
+ }
+
+private:
+ nsRefPtr<nsHTMLTrackElement> mElement;
+ nsCOMPtr<nsIStreamListener> mNextListener;
+ PRUint32 mLoadID;
};
+NS_IMPL_ISUPPORTS5(nsHTMLTrackElement::LoadListener, nsIRequestObserver,
+ nsIStreamListener, nsIChannelEventSink,
+ nsIInterfaceRequestor, nsIObserver)
+
+NS_IMETHODIMP
+nsHTMLTrackElement::LoadListener::Observe(nsISupports* aSubject,
+ const char *aTopic,
+ const PRUnichar* aData)
+{
+ nsContentUtils::UnregisterShutdownObserver(this);
+
+ // Clear mElement to break cycle so we don't leak on shutdown
+ mElement = nsnull;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHTMLTrackElement::LoadListener::OnDataAvailable(nsIRequest* aRequest,
+ nsISupports *aContext,
+ nsIInputStream* aStream,
+ PRUint32 aOffset,
+ PRUint32 aCount)
+{
+ printf("Track got data! %u bytes at offset %u\n", aCount, aOffset);
+ return NS_OK;
+}
+
+
+/** Track element implementaiton */
NS_IMPL_NS_NEW_HTML_ELEMENT(Track)
@@ -132,6 +203,51 @@ NS_IMPL_STRING_ATTR(nsHTMLTrackElement, Label, label)
NS_IMPL_BOOL_ATTR(nsHTMLTrackElement, Default, _default)
nsresult
+nsHTMLTrackElement::SetAcceptHeader(nsIHttpChannel *aChannel)
+{
+#ifdef MOZ_WEBVTT
+ nsCAutoString value(
+ "text/webvtt"
+ );
+
+ return aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
+ value,
+ false);
+#else
+ return NS_ERROR_NOT_IMPLEMENTED;
+#endif
+}
+
+/** copied from nsHTMLMediaElement::NewURIFromString */
+nsresult
+nsHTMLTrackElement::NewURIFromString(const nsAutoString& aURISpec,
+ nsIURI** aURI)
+{
+ NS_ENSURE_ARG_POINTER(aURI);
+
+ *aURI = nsnull;
+
+ nsCOMPtr<nsIDocument> doc = OwnerDoc();
+
+ nsCOMPtr<nsIURI> baseURI = GetBaseURI();
+ nsresult rv = nsContentUtils::NewURIWithDocumentCharset(aURI, aURISpec,
+ doc, baseURI);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ bool equal;
+ if (aURISpec.IsEmpty() &&
+ doc->GetDocumentURI() &&
+ NS_SUCCEEDED(doc->GetDocumentURI()->Equals(*aURI, &equal)) &&
+ equal) {
+ // give up
+ NS_RELEASE(*aURI);
+ return NS_ERROR_DOM_INVALID_STATE_ERR;
+ }
+
+ return NS_OK;
+}
+
+nsresult
nsHTMLTrackElement::BindToTree(nsIDocument *aDocument,
nsIContent *aParent,
nsIContent *aBindingParent,
@@ -153,6 +269,20 @@ nsHTMLTrackElement::BindToTree(nsIDocument *aDocument,
media->NotifyAddedSource();
LOG(PR_LOG_DEBUG, ("Track element sent notification to parent."));
+ // Find our 'src' url
+ nsAutoString src;
+ nsCOMPtr<nsIURI> uri;
+
+ if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
+ nsresult rv = NewURIFromString(src, getter_AddRefs(uri));
+ if (NS_SUCCEEDED(rv)) {
+ LOG(PR_LOG_ALWAYS, ("%p Trying to load from src=%s", this,
+ NS_ConvertUTF16toUTF8(src).get()));
+ printf("%p Trying to load from src=%s\n", this,
+ NS_ConvertUTF16toUTF8(src).get());
+ }
+ }
+
return NS_OK;
}

0 comments on commit 9d97611

Please sign in to comment.