2008-10-29 22:20:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2008-10-29 22:20:08 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
#include "MediaDocument.h"
|
2008-10-29 22:20:08 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2013-03-19 05:23:54 -07:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-01-12 13:53:01 -08:00
|
|
|
#include "nsIDocumentInlines.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-10-29 22:20:08 -07:00
|
|
|
|
2013-07-11 14:26:54 -07:00
|
|
|
class VideoDocument MOZ_FINAL : public MediaDocument
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aReset = true,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContentSink* aSink = nullptr);
|
2012-01-07 18:43:48 -08:00
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
|
2008-10-29 22:20:08 -07:00
|
|
|
|
|
|
|
protected:
|
2009-01-16 01:07:26 -08:00
|
|
|
|
|
|
|
// Sets document <title> to reflect the file name and description.
|
|
|
|
void UpdateTitle(nsIChannel* aChannel);
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
|
|
|
|
nsIStreamListener** aListener);
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
nsRefPtr<MediaDocumentStreamListener> mStreamListener;
|
2008-10-29 22:20:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2011-05-26 01:06:31 -07:00
|
|
|
VideoDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aReset,
|
2011-05-26 01:06:31 -07:00
|
|
|
nsIContentSink* aSink)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
|
|
|
nsresult rv =
|
2011-05-26 01:06:31 -07:00
|
|
|
MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
|
|
|
|
aDocListener, aReset, aSink);
|
2008-10-29 22:20:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
mStreamListener = new MediaDocumentStreamListener(this);
|
2008-10-29 22:20:08 -07:00
|
|
|
|
|
|
|
// Create synthetic document
|
|
|
|
rv = CreateSyntheticVideoDocument(aChannel,
|
|
|
|
getter_AddRefs(mStreamListener->mNextStream));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*aDocListener = mStreamListener);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-01-07 18:43:48 -08:00
|
|
|
void
|
|
|
|
VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
|
|
|
{
|
|
|
|
// Set the script global object on the superclass before doing
|
|
|
|
// anything that might require it....
|
|
|
|
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
|
|
|
|
2012-07-27 06:35:09 -07:00
|
|
|
if (aScriptGlobalObject) {
|
|
|
|
if (!nsContentUtils::IsChildOfSameType(this) &&
|
|
|
|
GetReadyStateEnum() != nsIDocument::READYSTATE_COMPLETE) {
|
|
|
|
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
|
2012-10-05 14:44:11 -07:00
|
|
|
LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/media/TopLevelVideoDocument.css"));
|
2012-07-27 06:35:09 -07:00
|
|
|
}
|
|
|
|
BecomeInteractive();
|
2012-01-07 18:43:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult
|
2011-05-26 01:06:31 -07:00
|
|
|
VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
|
|
|
|
nsIStreamListener** aListener)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
|
|
|
// make our generic document
|
2011-05-26 01:06:31 -07:00
|
|
|
nsresult rv = MediaDocument::CreateSyntheticDocument();
|
2008-10-29 22:20:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* body = GetBodyElement();
|
2008-10-29 22:20:08 -07:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on video document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make content
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 07:20:58 -07:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::video, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-10-29 22:20:08 -07:00
|
|
|
|
2013-03-19 05:23:54 -07:00
|
|
|
nsRefPtr<HTMLMediaElement> element =
|
|
|
|
static_cast<HTMLMediaElement*>(NS_NewHTMLVideoElement(nodeInfo.forget(),
|
|
|
|
NOT_FROM_PARSER));
|
2008-10-29 22:20:08 -07:00
|
|
|
if (!element)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2011-10-17 07:59:28 -07:00
|
|
|
element->SetAutoplay(true);
|
|
|
|
element->SetControls(true);
|
2008-10-29 22:20:08 -07:00
|
|
|
element->LoadWithChannel(aChannel, aListener);
|
2009-01-16 01:07:26 -08:00
|
|
|
UpdateTitle(aChannel);
|
2009-04-09 18:14:34 -07:00
|
|
|
|
2009-10-14 19:20:50 -07:00
|
|
|
if (nsContentUtils::IsChildOfSameType(this)) {
|
2009-04-09 18:14:34 -07:00
|
|
|
// Video documents that aren't toplevel should fill their frames and
|
|
|
|
// not have margins
|
|
|
|
element->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
|
|
|
|
NS_LITERAL_STRING("position:absolute; top:0; left:0; width:100%; height:100%"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2009-04-09 18:14:34 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return body->AppendChildTo(element, false);
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
|
|
|
|
2009-01-16 01:07:26 -08:00
|
|
|
void
|
2011-05-26 01:06:31 -07:00
|
|
|
VideoDocument::UpdateTitle(nsIChannel* aChannel)
|
2009-01-16 01:07:26 -08:00
|
|
|
{
|
|
|
|
if (!aChannel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoString fileName;
|
2014-10-29 22:08:00 -07:00
|
|
|
GetFileName(fileName, aChannel);
|
2009-01-16 01:07:26 -08:00
|
|
|
SetTitle(fileName);
|
|
|
|
}
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewVideoDocument(nsIDocument** aResult)
|
|
|
|
{
|
2011-05-26 01:06:31 -07:00
|
|
|
mozilla::dom::VideoDocument* doc = new mozilla::dom::VideoDocument();
|
2008-10-29 22:20:08 -07:00
|
|
|
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = doc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|