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